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 INCLUDED_PDFI_CONTENTSINK_HXX
25 #define INCLUDED_PDFI_CONTENTSINK_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <com/sun/star/rendering/ARGBColor.hpp>
30 #include <boost/shared_ptr.hpp>
31 
32 namespace rtl { class OUString; }
33 namespace com { namespace sun { namespace star {
34 namespace rendering
35 {
36     class  XPolyPolygon2D;
37 }
38 namespace geometry
39 {
40     struct Matrix2D;
41     struct AffineMatrix2D;
42     struct RealRectangle2D;
43     struct RealPoint2D;
44     struct RealSize2D;
45 }
46 namespace beans
47 {
48     struct PropertyValue;
49 } } } }
50 
51 namespace pdfi
52 {
53     struct FontAttributes
54     {
55         FontAttributes( const rtl::OUString& familyName_,
56                         bool                 isBold_,
57                         bool                 isItalic_,
58                         bool                 isUnderline_,
59                         bool                 isOutline_,
60                         double               size_ ) :
61             familyName(familyName_),
62             isBold(isBold_),
63             isItalic(isItalic_),
64             isUnderline(isUnderline_),
65             isOutline(isOutline_),
66             size(size_)
67         {}
68 
69         FontAttributes() :
70             familyName(),
71             isBold(false),
72             isItalic(false),
73             isUnderline(false),
74             isOutline(false),
75             size(0.0)
76         {}
77 
78         ::rtl::OUString     familyName;
79         bool                isBold;
80         bool                isItalic;
81         bool                isUnderline;
82         bool                isOutline;
83         double              size; // device pixel
84 
85         bool operator==(const FontAttributes& rFont) const
86         {
87             return familyName == rFont.familyName &&
88                 !isBold == !rFont.isBold &&
89                 !isItalic == !rFont.isItalic &&
90                 !isUnderline == !rFont.isUnderline &&
91                 !isOutline == !rFont.isOutline &&
92                 size == rFont.size;
93         }
94     };
95 
96     /** (preliminary) API wrapper around xpdf
97 
98         Wraps the functionality currently used from xpdf's OutputDev
99         interface. Subject to change.
100      */
101     struct ContentSink
102     {
103         virtual ~ContentSink() {}
104 
105         /// Total number of pages for upcoming document
106         virtual void setPageNum( sal_Int32 nNumPages ) = 0;
107         virtual void startPage( const ::com::sun::star::geometry::RealSize2D& rSize ) = 0;
108         virtual void endPage() = 0;
109 
110         virtual void hyperLink( const ::com::sun::star::geometry::RealRectangle2D& rBounds,
111                                 const ::rtl::OUString&                             rURI ) = 0;
112 
113         virtual void pushState() = 0;
114         virtual void popState() = 0;
115 
116         virtual void setFlatness( double ) = 0;
117         virtual void setTransformation( const ::com::sun::star::geometry::AffineMatrix2D& rMatrix ) = 0;
118         virtual void setLineDash( const ::com::sun::star::uno::Sequence<double>& dashes,
119                                   double                                         start ) = 0;
120         virtual void setLineJoin( sal_Int8 lineJoin ) = 0;
121         virtual void setLineCap( sal_Int8 lineCap ) = 0;
122         virtual void setMiterLimit(double) = 0;
123         virtual void setLineWidth(double) = 0;
124         virtual void setFillColor( const ::com::sun::star::rendering::ARGBColor& rColor ) = 0;
125         virtual void setStrokeColor( const ::com::sun::star::rendering::ARGBColor& rColor ) = 0;
126         virtual void setBlendMode( sal_Int8 blendMode ) = 0;
127         virtual void setFont( const FontAttributes& rFont ) = 0;
128         virtual void setTextRenderMode( sal_Int32 ) = 0;
129 
130 
131         virtual void strokePath( const ::com::sun::star::uno::Reference<
132                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath ) = 0;
133         virtual void fillPath( const ::com::sun::star::uno::Reference<
134                                      ::com::sun::star::rendering::XPolyPolygon2D >& rPath ) = 0;
135         virtual void eoFillPath( const ::com::sun::star::uno::Reference<
136                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath ) = 0;
137 
138         virtual void intersectClip(const ::com::sun::star::uno::Reference<
139                                          ::com::sun::star::rendering::XPolyPolygon2D >& rPath) = 0;
140         virtual void intersectEoClip(const ::com::sun::star::uno::Reference<
141                                            ::com::sun::star::rendering::XPolyPolygon2D >& rPath) = 0;
142 
143         virtual void drawGlyphs( const rtl::OUString&                               rGlyphs,
144                                  const ::com::sun::star::geometry::RealRectangle2D& rRect,
145                                  const ::com::sun::star::geometry::Matrix2D&        rFontMatrix ) = 0;
146 
147         /// issued when a sequence of associated glyphs is drawn
148         virtual void endText() = 0;
149 
150         /// draws given bitmap as a mask (using current fill color)
151         virtual void drawMask(const ::com::sun::star::uno::Sequence<
152                                     ::com::sun::star::beans::PropertyValue>& xBitmap,
153                               bool                                           bInvert ) = 0;
154         /// Given image must already be color-mapped and normalized to sRGB.
155         virtual void drawImage(const ::com::sun::star::uno::Sequence<
156                                      ::com::sun::star::beans::PropertyValue>& xBitmap ) = 0;
157         /** Given image must already be color-mapped and normalized to sRGB.
158 
159             maskColors must contain two sequences of color components
160          */
161         virtual void drawColorMaskedImage(const ::com::sun::star::uno::Sequence<
162                                                 ::com::sun::star::beans::PropertyValue>& xBitmap,
163                                           const ::com::sun::star::uno::Sequence<
164                                                 ::com::sun::star::uno::Any>&             xMaskColors ) = 0;
165         virtual void drawMaskedImage(const ::com::sun::star::uno::Sequence<
166                                            ::com::sun::star::beans::PropertyValue>& xBitmap,
167                                      const ::com::sun::star::uno::Sequence<
168                                            ::com::sun::star::beans::PropertyValue>& xMask,
169                                      bool                                             bInvertMask) = 0;
170         virtual void drawAlphaMaskedImage(const ::com::sun::star::uno::Sequence<
171                                                 ::com::sun::star::beans::PropertyValue>& xImage,
172                                           const ::com::sun::star::uno::Sequence<
173                                                 ::com::sun::star::beans::PropertyValue>& xMask) = 0;
174     };
175 
176     typedef boost::shared_ptr<ContentSink> ContentSinkSharedPtr;
177 }
178 
179 #endif /* INCLUDED_PDFI_CONTENTSINK_HXX */
180 
181