1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterCanvasHelper.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterCanvasHelper.hxx"
37 #include "PresenterController.hxx"
38 #include "PresenterGeometryHelper.hxx"
39 #include <com/sun/star/rendering/CompositeOperation.hpp>
40 #include <com/sun/star/rendering/TextDirection.hpp>
41 #include <com/sun/star/rendering/TexturingMode.hpp>
43 using namespace ::com::sun::star
;
44 using namespace ::com::sun::star::uno
;
46 namespace sdext
{ namespace presenter
{
48 PresenterCanvasHelper::PresenterCanvasHelper (void)
50 geometry::AffineMatrix2D(1,0,0, 0,1,0),
53 geometry::AffineMatrix2D(1,0,0, 0,1,0),
56 rendering::CompositeOperation::SOURCE
)
63 PresenterCanvasHelper::~PresenterCanvasHelper (void)
70 void PresenterCanvasHelper::Paint (
71 const SharedBitmapDescriptor
& rpBitmap
,
72 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
73 const css::awt::Rectangle
& rRepaintBox
,
74 const css::awt::Rectangle
& rOuterBoundingBox
,
75 const css::awt::Rectangle
& rContentBoundingBox
) const
77 PaintRectangle(rpBitmap
,rxCanvas
,rRepaintBox
,rOuterBoundingBox
,rContentBoundingBox
,
78 maDefaultViewState
, maDefaultRenderState
);
84 void PresenterCanvasHelper::PaintRectangle (
85 const SharedBitmapDescriptor
& rpBitmap
,
86 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
87 const css::awt::Rectangle
& rRepaintBox
,
88 const css::awt::Rectangle
& rOuterBoundingBox
,
89 const css::awt::Rectangle
& rContentBoundingBox
,
90 const css::rendering::ViewState
& rDefaultViewState
,
91 const css::rendering::RenderState
& rDefaultRenderState
)
93 if (rpBitmap
.get() == NULL
)
96 if ( ! rxCanvas
.is() || ! rxCanvas
->getDevice().is())
99 // Create a clip polypolygon that has the content box as hole.
100 ::std::vector
<awt::Rectangle
> aRectangles
;
101 aRectangles
.reserve(2);
102 aRectangles
.push_back(
103 PresenterGeometryHelper::Intersection(rRepaintBox
, rOuterBoundingBox
));
104 if (rContentBoundingBox
.Width
> 0 && rContentBoundingBox
.Height
> 0)
105 aRectangles
.push_back(
106 PresenterGeometryHelper::Intersection(rRepaintBox
, rContentBoundingBox
));
107 Reference
<rendering::XPolyPolygon2D
> xPolyPolygon (
108 PresenterGeometryHelper::CreatePolygon(
110 rxCanvas
->getDevice()));
111 if ( ! xPolyPolygon
.is())
113 xPolyPolygon
->setFillRule(rendering::FillRule_EVEN_ODD
);
115 if (rpBitmap
->GetNormalBitmap().is())
117 if (rpBitmap
->meHorizontalTexturingMode
== PresenterBitmapDescriptor::Repeat
118 || rpBitmap
->meVerticalTexturingMode
== PresenterBitmapDescriptor::Repeat
)
121 Reference
<rendering::XBitmap
>(rpBitmap
->GetNormalBitmap(), UNO_QUERY
),
127 rDefaultRenderState
);
132 Reference
<rendering::XBitmap
>(rpBitmap
->GetNormalBitmap(), UNO_QUERY
),
133 awt::Point(rOuterBoundingBox
.X
, rOuterBoundingBox
.Y
),
138 rDefaultRenderState
);
144 rpBitmap
->maReplacementColor
,
149 rDefaultRenderState
);
156 void PresenterCanvasHelper::PaintTiledBitmap (
157 const css::uno::Reference
<css::rendering::XBitmap
>& rxTexture
,
158 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
159 const css::awt::Rectangle
& rRepaintBox
,
160 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& rxPolygon
,
161 const css::awt::Rectangle
& rHole
,
162 const css::rendering::ViewState
& rDefaultViewState
,
163 const css::rendering::RenderState
& rDefaultRenderState
)
165 if ( ! rxCanvas
.is() || ! rxCanvas
->getDevice().is())
168 if ( ! rxTexture
.is())
171 if ( ! rxPolygon
.is())
174 rendering::ViewState
aViewState (rDefaultViewState
);
175 aViewState
.Clip
= rxPolygon
;
177 // Create a local render state at which the location of the bitmap is
179 rendering::RenderState
aRenderState (rDefaultRenderState
);
182 // Tile the bitmap over the repaint box.
183 const geometry::IntegerSize2D
aBitmapSize (rxTexture
->getSize());
184 const sal_Int32 nLeft
= (rRepaintBox
.X
/ aBitmapSize
.Width
) * aBitmapSize
.Width
;
185 const sal_Int32 nTop
= (rRepaintBox
.Y
/ aBitmapSize
.Height
) * aBitmapSize
.Height
;
186 const sal_Int32 nRight
= ((rRepaintBox
.X
+ rRepaintBox
.Width
- 1 + aBitmapSize
.Width
- 1)
187 / aBitmapSize
.Width
) * aBitmapSize
.Width
;
188 const sal_Int32 nBottom
= ((rRepaintBox
.Y
+ rRepaintBox
.Height
- 1 + aBitmapSize
.Height
- 1)
189 / aBitmapSize
.Height
) * aBitmapSize
.Height
;
191 for (sal_Int32 nY
=nTop
; nY
<=nBottom
; nY
+=aBitmapSize
.Height
)
192 for (sal_Int32 nX
=nLeft
; nX
<=nRight
; nX
+=aBitmapSize
.Width
)
194 if (PresenterGeometryHelper::IsInside(
195 awt::Rectangle(nX
,nY
,aBitmapSize
.Width
,aBitmapSize
.Height
),
200 aRenderState
.AffineTransform
.m02
= nX
;
201 aRenderState
.AffineTransform
.m12
= nY
;
202 rxCanvas
->drawBitmap(
212 void PresenterCanvasHelper::PaintBitmap (
213 const css::uno::Reference
<css::rendering::XBitmap
>& rxBitmap
,
214 const awt::Point
& rLocation
,
215 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
216 const css::awt::Rectangle
& rRepaintBox
,
217 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& rxPolygon
,
218 const css::rendering::ViewState
& rDefaultViewState
,
219 const css::rendering::RenderState
& rDefaultRenderState
)
221 if ( ! rxCanvas
.is() || ! rxCanvas
->getDevice().is())
224 if ( ! rxBitmap
.is())
227 if ( ! rxPolygon
.is())
230 // Set the repaint box as clip rectangle at the view state.
231 rendering::ViewState
aViewState (rDefaultViewState
);
232 aViewState
.Clip
= PresenterGeometryHelper::CreatePolygon(rRepaintBox
, rxCanvas
->getDevice());
235 // Setup the rendering state so that the bitmap is painted top left in
236 // the polygon bounding box.
237 rendering::RenderState
aRenderState (rDefaultRenderState
);
238 aRenderState
.AffineTransform
= geometry::AffineMatrix2D(1,0, rLocation
.X
, 0,1,rLocation
.Y
);
239 aRenderState
.Clip
= rxPolygon
;
241 rxCanvas
->drawBitmap(
250 void PresenterCanvasHelper::PaintColor (
251 const css::util::Color nColor
,
252 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
253 const css::awt::Rectangle
& rRepaintBox
,
254 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& rxPolygon
,
255 const css::rendering::ViewState
& rDefaultViewState
,
256 const css::rendering::RenderState
& rDefaultRenderState
)
258 if ( ! rxCanvas
.is() || ! rxCanvas
->getDevice().is())
261 if ( ! rxPolygon
.is())
264 // Set the repaint box as clip rectangle at the view state.
265 rendering::ViewState
aViewState (rDefaultViewState
);
266 aViewState
.Clip
= PresenterGeometryHelper::CreatePolygon(rRepaintBox
, rxCanvas
->getDevice());
269 // Setup the rendering state to use the given color.
270 rendering::RenderState
aRenderState (rDefaultRenderState
);
271 SetDeviceColor(aRenderState
, nColor
);
273 rxCanvas
->fillPolyPolygon(
282 void PresenterCanvasHelper::SetDeviceColor(
283 rendering::RenderState
& rRenderState
,
284 const util::Color aColor
)
286 // Other component counts then 4 (RGBA) are not accepted (anymore).
288 OSL_ASSERT(rRenderState
.DeviceColor
.getLength() == 4);
289 if (rRenderState
.DeviceColor
.getLength() == 4)
291 rRenderState
.DeviceColor
[0] = ((aColor
>> 16) & 0x0ff) / 255.0;
292 rRenderState
.DeviceColor
[1] = ((aColor
>> 8) & 0x0ff) / 255.0;
293 rRenderState
.DeviceColor
[2] = ((aColor
>> 0) & 0x0ff) / 255.0;
294 rRenderState
.DeviceColor
[3] = 1.0 - ((aColor
>> 24) & 0x0ff) / 255.0;
301 css::geometry::RealRectangle2D
PresenterCanvasHelper::GetTextBoundingBox (
302 const css::uno::Reference
<css::rendering::XCanvasFont
>& rxFont
,
303 const ::rtl::OUString
& rsText
,
304 const sal_Int8 nTextDirection
)
306 if (rxFont
.is() && rsText
.getLength() > 0)
308 rendering::StringContext
aContext (rsText
, 0, rsText
.getLength());
309 Reference
<rendering::XTextLayout
> xLayout (
310 rxFont
->createTextLayout(aContext
, nTextDirection
, 0));
311 return xLayout
->queryTextBounds();
315 return geometry::RealRectangle2D(0,0,0,0);
322 css::geometry::RealSize2D
PresenterCanvasHelper::GetTextSize (
323 const css::uno::Reference
<css::rendering::XCanvasFont
>& rxFont
,
324 const ::rtl::OUString
& rsText
,
325 const sal_Int8 nTextDirection
)
327 const geometry::RealRectangle2D
aTextBBox (GetTextBoundingBox(rxFont
, rsText
, nTextDirection
));
328 return css::geometry::RealSize2D(aTextBBox
.X2
- aTextBBox
.X1
, aTextBBox
.Y2
- aTextBBox
.Y1
);
332 } } // end of namespace sdext::presenter