1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _DXCANVAS_IMPLTOOLS_HXX
29 #define _DXCANVAS_IMPLTOOLS_HXX
30 
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <com/sun/star/util/TriState.hpp>
34 
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <basegfx/polygon/b2dpolypolygon.hxx>
37 #include <basegfx/numeric/ftools.hxx>
38 
39 #include <boost/shared_ptr.hpp>
40 #include "dx_canvasfont.hxx"
41 
42 namespace basegfx
43 {
44     class B2DPoint;
45     class B2DRange;
46     class B2DHomMatrix;
47     class B2IPoint;
48     class B2IRange;
49 	class B2DPolyPolygon;
50 };
51 
52 namespace com { namespace sun { namespace star { namespace geometry
53 {
54     struct IntegerRectangle2D;
55     struct RealPoint2D;
56 } } } }
57 
58 namespace com { namespace sun { namespace star { namespace rendering
59 {
60     class  XCanvas;
61     class  XGraphicDevice;
62     class  XBitmap;
63     class  XPolyPolygon2D;
64     class  XCanvasFont;
65 } } } }
66 
67 
68 namespace dxcanvas
69 {
70     namespace tools
71     {
72         struct RawRGBABitmap;
73 
74         ::basegfx::B2DPolyPolygon
75         polyPolygonFromXPolyPolygon2D( const ::com::sun::star::uno::Reference<
76                                        ::com::sun::star::rendering::XPolyPolygon2D >& );
77 
78         Gdiplus::Graphics* createGraphicsFromHDC(HDC);
79         Gdiplus::Graphics* createGraphicsFromBitmap(const BitmapSharedPtr&);
80 
81         void setupGraphics( Gdiplus::Graphics& rGraphics );
82 
83         void gdiPlusMatrixFromB2DHomMatrix( Gdiplus::Matrix& 		rGdiplusMatrix,
84                                             const ::basegfx::B2DHomMatrix&	rMatrix );
85         void gdiPlusMatrixFromAffineMatrix2D( Gdiplus::Matrix& 							rGdiplusMatrix,
86                                               const ::com::sun::star::geometry::AffineMatrix2D& rMatrix );
87 
88         Gdiplus::PointF gdiPlusPointFFromRealPoint2D( const ::com::sun::star::geometry::RealPoint2D& );
89         Gdiplus::RectF 	gdiPlusRectFFromRectangle2D( const ::com::sun::star::geometry::RealRectangle2D& );
90         Gdiplus::Rect 	gdiPlusRectFromIntegerRectangle2D( const ::com::sun::star::geometry::IntegerRectangle2D& );
91         RECT 			gdiRectFromB2IRect( const ::basegfx::B2IRange& );
92 
93         ::com::sun::star::geometry::RealPoint2D		realPoint2DFromGdiPlusPointF( const Gdiplus::PointF& );
94         ::com::sun::star::geometry::RealRectangle2D	realRectangle2DFromGdiPlusRectF( const Gdiplus::RectF& );
95 
96         ::basegfx::B2DPoint	b2dPointFromGdiPlusPointF( const Gdiplus::PointF& );
97         ::basegfx::B2DRange	b2dRangeFromGdiPlusRectF( const Gdiplus::RectF& );
98 
99         ::com::sun::star::uno::Sequence< double > argbToDoubleSequence( const Gdiplus::ARGB& rColor );
100         ::com::sun::star::uno::Sequence< sal_Int8 > argbToIntSequence( const Gdiplus::ARGB& rColor );
101         Gdiplus::ARGB sequenceToArgb( const ::com::sun::star::uno::Sequence< sal_Int8 >& rColor );
102         Gdiplus::ARGB sequenceToArgb( const ::com::sun::star::uno::Sequence< double >&  rColor );
103 
104         GraphicsPathSharedPtr graphicsPathFromRealPoint2DSequence( const ::com::sun::star::uno::Sequence<
105                                                                  ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& );
106 
107         GraphicsPathSharedPtr graphicsPathFromB2DPolygon(
108             const ::basegfx::B2DPolygon& rPoly,
109             bool bNoLineJoin = false);
110 
111         GraphicsPathSharedPtr graphicsPathFromB2DPolyPolygon(
112             const ::basegfx::B2DPolyPolygon& rPoly,
113             bool bNoLineJoin = false);
114 
115         GraphicsPathSharedPtr graphicsPathFromXPolyPolygon2D(
116             const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >&,
117             bool bNoLineJoin = false );
118 
119         bool drawGdiPlusBitmap( const GraphicsSharedPtr& rGraphics,
120                                 const BitmapSharedPtr&	 rBitmap );
121         bool drawDIBits( const ::boost::shared_ptr< Gdiplus::Graphics >& rGraphics,
122                          const BITMAPINFO&                               rBI,
123                          const void*                                     pBits );
124 
125         bool drawRGBABits( const ::boost::shared_ptr< Gdiplus::Graphics >& rGraphics,
126                            const RawRGBABitmap&							   rRawRGBAData );
127 
128         BitmapSharedPtr bitmapFromXBitmap( const ::com::sun::star::uno::Reference<
129                                            		::com::sun::star::rendering::XBitmap >&	xBitmap );
130 
131         CanvasFont::ImplRef	canvasFontFromXFont( const ::com::sun::star::uno::Reference<
132                                                  	::com::sun::star::rendering::XCanvasFont >& xFont );
133 
134         void setModulateImageAttributes( Gdiplus::ImageAttributes& o_rAttr,
135                                          double                           nRedModulation,
136                                          double                           nGreenModulation,
137                                          double                           nBlueModulation,
138                                          double                           nAlphaModulation );
139     }
140 }
141 
142 #endif /* _DXCANVAS_IMPLTOOLS_HXX */
143