1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DXCANVAS_IMPLTOOLS_HXX
25 #define _DXCANVAS_IMPLTOOLS_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <com/sun/star/util/TriState.hpp>
30 
31 #include <basegfx/polygon/b2dpolygon.hxx>
32 #include <basegfx/polygon/b2dpolypolygon.hxx>
33 #include <basegfx/numeric/ftools.hxx>
34 
35 #include <boost/shared_ptr.hpp>
36 #include "dx_canvasfont.hxx"
37 
38 namespace basegfx
39 {
40     class B2DPoint;
41     class B2DRange;
42     class B2DHomMatrix;
43     class B2IPoint;
44     class B2IRange;
45 	class B2DPolyPolygon;
46 };
47 
48 namespace com { namespace sun { namespace star { namespace geometry
49 {
50     struct IntegerRectangle2D;
51     struct RealPoint2D;
52 } } } }
53 
54 namespace com { namespace sun { namespace star { namespace rendering
55 {
56     class  XCanvas;
57     class  XGraphicDevice;
58     class  XBitmap;
59     class  XPolyPolygon2D;
60     class  XCanvasFont;
61 } } } }
62 
63 
64 namespace dxcanvas
65 {
66     namespace tools
67     {
68         struct RawRGBABitmap;
69 
70         ::basegfx::B2DPolyPolygon
71         polyPolygonFromXPolyPolygon2D( const ::com::sun::star::uno::Reference<
72                                        ::com::sun::star::rendering::XPolyPolygon2D >& );
73 
74         Gdiplus::Graphics* createGraphicsFromHDC(HDC);
75         Gdiplus::Graphics* createGraphicsFromBitmap(const BitmapSharedPtr&);
76 
77         void setupGraphics( Gdiplus::Graphics& rGraphics );
78 
79         void gdiPlusMatrixFromB2DHomMatrix( Gdiplus::Matrix& 		rGdiplusMatrix,
80                                             const ::basegfx::B2DHomMatrix&	rMatrix );
81         void gdiPlusMatrixFromAffineMatrix2D( Gdiplus::Matrix& 							rGdiplusMatrix,
82                                               const ::com::sun::star::geometry::AffineMatrix2D& rMatrix );
83 
84         Gdiplus::PointF gdiPlusPointFFromRealPoint2D( const ::com::sun::star::geometry::RealPoint2D& );
85         Gdiplus::RectF 	gdiPlusRectFFromRectangle2D( const ::com::sun::star::geometry::RealRectangle2D& );
86         Gdiplus::Rect 	gdiPlusRectFromIntegerRectangle2D( const ::com::sun::star::geometry::IntegerRectangle2D& );
87         RECT 			gdiRectFromB2IRect( const ::basegfx::B2IRange& );
88 
89         ::com::sun::star::geometry::RealPoint2D		realPoint2DFromGdiPlusPointF( const Gdiplus::PointF& );
90         ::com::sun::star::geometry::RealRectangle2D	realRectangle2DFromGdiPlusRectF( const Gdiplus::RectF& );
91 
92         ::basegfx::B2DPoint	b2dPointFromGdiPlusPointF( const Gdiplus::PointF& );
93         ::basegfx::B2DRange	b2dRangeFromGdiPlusRectF( const Gdiplus::RectF& );
94 
95         ::com::sun::star::uno::Sequence< double > argbToDoubleSequence( const Gdiplus::ARGB& rColor );
96         ::com::sun::star::uno::Sequence< sal_Int8 > argbToIntSequence( const Gdiplus::ARGB& rColor );
97         Gdiplus::ARGB sequenceToArgb( const ::com::sun::star::uno::Sequence< sal_Int8 >& rColor );
98         Gdiplus::ARGB sequenceToArgb( const ::com::sun::star::uno::Sequence< double >&  rColor );
99 
100         GraphicsPathSharedPtr graphicsPathFromRealPoint2DSequence( const ::com::sun::star::uno::Sequence<
101                                                                  ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& );
102 
103         GraphicsPathSharedPtr graphicsPathFromB2DPolygon(
104             const ::basegfx::B2DPolygon& rPoly,
105             bool bNoLineJoin = false);
106 
107         GraphicsPathSharedPtr graphicsPathFromB2DPolyPolygon(
108             const ::basegfx::B2DPolyPolygon& rPoly,
109             bool bNoLineJoin = false);
110 
111         GraphicsPathSharedPtr graphicsPathFromXPolyPolygon2D(
112             const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >&,
113             bool bNoLineJoin = false );
114 
115         bool drawGdiPlusBitmap( const GraphicsSharedPtr& rGraphics,
116                                 const BitmapSharedPtr&	 rBitmap );
117         bool drawDIBits( const ::boost::shared_ptr< Gdiplus::Graphics >& rGraphics,
118                          const BITMAPINFO&                               rBI,
119                          const void*                                     pBits );
120 
121         bool drawRGBABits( const ::boost::shared_ptr< Gdiplus::Graphics >& rGraphics,
122                            const RawRGBABitmap&							   rRawRGBAData );
123 
124         BitmapSharedPtr bitmapFromXBitmap( const ::com::sun::star::uno::Reference<
125                                            		::com::sun::star::rendering::XBitmap >&	xBitmap );
126 
127         CanvasFont::ImplRef	canvasFontFromXFont( const ::com::sun::star::uno::Reference<
128                                                  	::com::sun::star::rendering::XCanvasFont >& xFont );
129 
130         void setModulateImageAttributes( Gdiplus::ImageAttributes& o_rAttr,
131                                          double                           nRedModulation,
132                                          double                           nGreenModulation,
133                                          double                           nBlueModulation,
134                                          double                           nAlphaModulation );
135     }
136 }
137 
138 #endif /* _DXCANVAS_IMPLTOOLS_HXX */
139