fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / filter / DocumentToGraphicRenderer.cxx
blobe33a94ec416e697cdde925ccc021a76e4c458a85
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/DocumentToGraphicRenderer.hxx>
22 #include <vcl/graphicfilter.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/outdev.hxx>
26 #include <tools/fract.hxx>
28 #include <com/sun/star/awt/XDevice.hpp>
29 #include <com/sun/star/text/XPageCursor.hpp>
30 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
31 #include <com/sun/star/beans/PropertyValues.hpp>
33 #include <toolkit/helper/vclunohelper.hxx>
35 using namespace css;
36 using namespace css::uno;
37 using namespace css::lang;
38 using namespace css::beans;
40 DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent>& rxDocument ) :
41 mxDocument(rxDocument),
42 mxModel( mxDocument, uno::UNO_QUERY ),
43 mxController( mxModel->getCurrentController() ),
44 mxRenderable (mxDocument, uno::UNO_QUERY ),
45 mxToolkit( VCLUnoHelper::CreateToolkit() )
49 DocumentToGraphicRenderer::~DocumentToGraphicRenderer()
53 Size DocumentToGraphicRenderer::getDocumentSizeInPixels(sal_Int32 aCurrentPage)
55 Size aSize100mm = getDocumentSizeIn100mm(aCurrentPage);
56 return Size( Application::GetDefaultDevice()->LogicToPixel( aSize100mm, MAP_100TH_MM ) );
59 Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 aCurrentPage)
61 Reference< awt::XDevice > xDevice(mxToolkit->createScreenCompatibleDevice( 32, 32 ) );
63 uno::Any selection;
64 selection <<= mxDocument;
66 PropertyValues renderProperties;
68 renderProperties.realloc( 3 );
69 renderProperties[0].Name = "IsPrinter";
70 renderProperties[0].Value <<= sal_True;
71 renderProperties[1].Name = "RenderDevice";
72 renderProperties[1].Value <<= xDevice;
73 renderProperties[2].Name = "View";
74 renderProperties[2].Value <<= mxController;
76 awt::Size aSize;
78 sal_Int32 nPages = mxRenderable->getRendererCount( selection, renderProperties );
79 if (nPages >= aCurrentPage)
81 Sequence< beans::PropertyValue > aResult = mxRenderable->getRenderer(aCurrentPage - 1, selection, renderProperties );
82 for( sal_Int32 nProperty = 0, nPropertyCount = aResult.getLength(); nProperty < nPropertyCount; ++nProperty )
84 if ( aResult[ nProperty ].Name == "PageSize" )
86 aResult[ nProperty ].Value >>= aSize;
91 return Size( aSize.Width, aSize.Height );
94 Graphic DocumentToGraphicRenderer::renderToGraphic(
95 sal_Int32 aCurrentPage,
96 Size aDocumentSizePixel,
97 Size aTargetSizePixel,
98 Color aPageColor)
101 if (!mxModel.is() || !mxController.is() || !mxRenderable.is())
102 return Graphic();
104 Reference< awt::XDevice > xDevice(mxToolkit->createScreenCompatibleDevice( aTargetSizePixel.Width(), aTargetSizePixel.Height() ) );
105 if (!xDevice.is())
106 return Graphic();
108 double fScaleX = aTargetSizePixel.Width() / (double) aDocumentSizePixel.Width();
109 double fScaleY = aTargetSizePixel.Height() / (double) aDocumentSizePixel.Height();
111 PropertyValues renderProps;
112 renderProps.realloc( 3 );
113 renderProps[0].Name = "IsPrinter";
114 renderProps[0].Value <<= sal_True;
115 renderProps[1].Name = "RenderDevice";
116 renderProps[1].Value <<= xDevice;
117 renderProps[2].Name = "View";
118 renderProps[2].Value <<= mxController;
120 GDIMetaFile aMtf;
122 OutputDevice* pOutputDev = VCLUnoHelper::GetOutputDevice( xDevice );
123 pOutputDev->SetAntialiasing(pOutputDev->GetAntialiasing() | AntialiasingFlags::EnableB2dDraw);
124 MapMode mm = pOutputDev->GetMapMode();
125 mm.SetScaleX( fScaleX );
126 mm.SetScaleY( fScaleY );
127 pOutputDev->SetMapMode( mm );
129 aMtf.Record( pOutputDev );
131 if (aPageColor != Color(COL_TRANSPARENT))
133 pOutputDev->SetBackground(Wallpaper(aPageColor));
134 pOutputDev->Erase();
137 uno::Any aSelection;
138 aSelection <<= mxDocument;
139 mxRenderable->render(aCurrentPage - 1, aSelection, renderProps );
141 aMtf.Stop();
142 aMtf.WindStart();
143 aMtf.SetPrefSize( aTargetSizePixel );
145 return Graphic(aMtf);
148 sal_Int32 DocumentToGraphicRenderer::getCurrentPageWriter()
150 Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(mxModel->getCurrentController(), UNO_QUERY);
151 Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), UNO_QUERY);
152 return xCursor->getPage();
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */