Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_PDFI_GENERICELEMENTS_HXX
21 : #define INCLUDED_PDFI_GENERICELEMENTS_HXX
22 :
23 : #include "pdfihelper.hxx"
24 : #include "treevisiting.hxx"
25 :
26 : #include <com/sun/star/task/XStatusIndicator.hpp>
27 : #include <com/sun/star/uno/XComponentContext.hpp>
28 : #include <basegfx/polygon/b2dpolypolygon.hxx>
29 : #include <basegfx/range/b2drange.hxx>
30 : #include <rtl/ustring.hxx>
31 : #include <rtl/ustrbuf.hxx>
32 :
33 : #include <list>
34 :
35 : namespace pdfi
36 : {
37 : class XmlEmitter;
38 : class StyleContainer;
39 : class ImageContainer;
40 : class PDFIProcessor;
41 : class ElementFactory;
42 :
43 :
44 2 : struct EmitContext
45 : {
46 2 : EmitContext(
47 : XmlEmitter& _rEmitter,
48 : StyleContainer& _rStyles,
49 : ImageContainer& _rImages,
50 : PDFIProcessor& _rProcessor,
51 : const com::sun::star::uno::Reference<
52 : com::sun::star::task::XStatusIndicator>& _xStatusIndicator,
53 : com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext)
54 : :
55 : rEmitter(_rEmitter),
56 : rStyles(_rStyles),
57 : rImages(_rImages),
58 : rProcessor(_rProcessor),
59 : xStatusIndicator(_xStatusIndicator),
60 2 : m_xContext(xContext)
61 2 : {}
62 :
63 : XmlEmitter& rEmitter;
64 : StyleContainer& rStyles;
65 : ImageContainer& rImages;
66 : PDFIProcessor& rProcessor;
67 : com::sun::star::uno::Reference<
68 : com::sun::star::task::XStatusIndicator> xStatusIndicator;
69 : com::sun::star::uno::Reference<
70 : com::sun::star::uno::XComponentContext > m_xContext;
71 : };
72 :
73 : struct Element : public ElementTreeVisitable
74 : {
75 : protected:
76 267 : Element( Element* pParent )
77 267 : : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent )
78 : {
79 267 : if( pParent )
80 262 : pParent->Children.push_back( this );
81 267 : }
82 :
83 : public:
84 : virtual ~Element();
85 :
86 : /// Apply visitor to all children
87 : void applyToChildren( ElementTreeVisitor& );
88 : /// Union element geometry with given element
89 : void updateGeometryWith( const Element* pMergeFrom );
90 :
91 : #if OSL_DEBUG_LEVEL > 1
92 : // xxx refac TODO: move code to visitor
93 : virtual void emitStructure( int nLevel );
94 : #endif
95 : /** el must be a valid dereferencable iterator of el->Parent->Children
96 : pNewParent must not be NULL
97 : */
98 : static void setParent( std::list<Element*>::iterator& el, Element* pNewParent );
99 :
100 : double x, y, w, h;
101 : sal_Int32 StyleId;
102 : Element* Parent;
103 : std::list<Element*> Children;
104 : };
105 :
106 2 : struct ListElement : public Element
107 : {
108 2 : ListElement() : Element( NULL ) {}
109 : // ElementTreeVisitable
110 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
111 : };
112 :
113 4 : struct HyperlinkElement : public Element
114 : {
115 : friend class ElementFactory;
116 : protected:
117 2 : HyperlinkElement( Element* pParent, const rtl::OUString& rURI )
118 2 : : Element( pParent ), URI( rURI ) {}
119 : public:
120 : // ElementTreeVisitable
121 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
122 :
123 : rtl::OUString URI;
124 : };
125 :
126 236 : struct GraphicalElement : public Element
127 : {
128 : protected:
129 236 : GraphicalElement( Element* pParent, sal_Int32 nGCId )
130 236 : : Element( pParent ), GCId( nGCId ), MirrorVertical( false ) {}
131 :
132 : public:
133 : sal_Int32 GCId;
134 : bool MirrorVertical;
135 : };
136 :
137 28 : struct DrawElement : public GraphicalElement
138 : {
139 : protected:
140 28 : DrawElement( Element* pParent, sal_Int32 nGCId )
141 28 : : GraphicalElement( pParent, nGCId ), isCharacter(false), ZOrder(0) {}
142 :
143 : public:
144 : bool isCharacter;
145 : sal_Int32 ZOrder;
146 : };
147 :
148 44 : struct FrameElement : public DrawElement
149 : {
150 : friend class ElementFactory;
151 : protected:
152 22 : FrameElement( Element* pParent, sal_Int32 nGCId )
153 22 : : DrawElement( pParent, nGCId ) {}
154 :
155 : public:
156 : // ElementTreeVisitable
157 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
158 : };
159 :
160 416 : struct TextElement : public GraphicalElement
161 : {
162 : friend class ElementFactory;
163 : protected:
164 208 : TextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
165 208 : : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {}
166 :
167 : public:
168 : // ElementTreeVisitable
169 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
170 :
171 : rtl::OUStringBuffer Text;
172 : sal_Int32 FontId;
173 : };
174 :
175 46 : struct ParagraphElement : public Element
176 : {
177 : friend class ElementFactory;
178 : protected:
179 23 : ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ), bRtl( false ) {}
180 :
181 : public:
182 : // ElementTreeVisitable
183 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
184 :
185 : // returns true only if only a single line is contained
186 : bool isSingleLined( PDFIProcessor& rProc ) const;
187 : // returns the highest line height of the contained textelements
188 : // line height is font height if the text element is itself multilined
189 : double getLineHeight( PDFIProcessor& rProc ) const;
190 : // returns the first text element child; does not recurse through subparagraphs
191 : TextElement* getFirstTextChild() const;
192 :
193 : enum ParagraphType { Normal, Headline };
194 : ParagraphType Type;
195 : bool bRtl;
196 : };
197 :
198 12 : struct PolyPolyElement : public DrawElement
199 : {
200 : friend class ElementFactory;
201 : protected:
202 : PolyPolyElement( Element* pParent, sal_Int32 nGCId,
203 : const basegfx::B2DPolyPolygon& rPolyPoly,
204 : sal_Int8 nAction );
205 : public:
206 : // ElementTreeVisitable
207 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
208 :
209 : void updateGeometry();
210 :
211 : #if OSL_DEBUG_LEVEL > 1
212 : virtual void emitStructure( int nLevel );
213 : #endif
214 :
215 : basegfx::B2DPolyPolygon PolyPoly;
216 : sal_Int8 Action;
217 : };
218 :
219 0 : struct ImageElement : public DrawElement
220 : {
221 : friend class ElementFactory;
222 : protected:
223 0 : ImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
224 0 : : DrawElement( pParent, nGCId ), Image( nImage ) {}
225 :
226 : public:
227 : // ElementTreeVisitable
228 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
229 :
230 : ImageId Image;
231 : };
232 :
233 : struct PageElement : public Element
234 : {
235 : friend class ElementFactory;
236 : protected:
237 2 : PageElement( Element* pParent, sal_Int32 nPageNr )
238 : : Element( pParent ), PageNumber( nPageNr ), Hyperlinks(),
239 : TopMargin( 0.0 ), BottomMargin( 0.0 ), LeftMargin( 0.0 ), RightMargin( 0.0 ),
240 2 : HeaderElement( NULL ), FooterElement( NULL )
241 2 : {}
242 : private:
243 : // helper method for resolveHyperlinks
244 : bool resolveHyperlink( std::list<Element*>::iterator link_it, std::list<Element*>& rElements );
245 : public:
246 : virtual ~PageElement();
247 :
248 : // ElementTreeVisitable
249 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
250 :
251 : void emitPageAnchoredElements( EmitContext& rEmitContext );
252 : static void updateParagraphGeometry( Element* pEle );
253 : void resolveHyperlinks();
254 : void resolveFontStyles( PDFIProcessor& rProc );
255 : void resolveUnderlines( PDFIProcessor& rProc );
256 :
257 : sal_Int32 PageNumber;
258 : ListElement Hyperlinks; // contains not yet realized links on this page
259 : double TopMargin;
260 : double BottomMargin;
261 : double LeftMargin;
262 : double RightMargin;
263 : Element* HeaderElement;
264 : Element* FooterElement;
265 : };
266 :
267 : struct DocumentElement : public Element
268 : {
269 : friend class ElementFactory;
270 : protected:
271 2 : DocumentElement() : Element( NULL ) {}
272 : public:
273 : virtual ~DocumentElement();
274 :
275 : // ElementTreeVisitable
276 : virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
277 :
278 : };
279 :
280 : // this class is the differentiator of document types: it will create
281 : // Element objects with an optimize() method suitable for the document type
282 : class ElementFactory
283 : {
284 : public:
285 2 : ElementFactory() {}
286 : virtual ~ElementFactory();
287 :
288 2 : virtual HyperlinkElement* createHyperlinkElement( Element* pParent, const rtl::OUString& rURI )
289 2 : { return new HyperlinkElement( pParent, rURI ); }
290 :
291 208 : virtual TextElement* createTextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
292 208 : { return new TextElement( pParent, nGCId, nFontId ); }
293 23 : virtual ParagraphElement* createParagraphElement( Element* pParent )
294 23 : { return new ParagraphElement( pParent ); }
295 :
296 22 : virtual FrameElement* createFrameElement( Element* pParent, sal_Int32 nGCId )
297 22 : { return new FrameElement( pParent, nGCId ); }
298 : virtual PolyPolyElement*
299 6 : createPolyPolyElement( Element* pParent,
300 : sal_Int32 nGCId,
301 : const basegfx::B2DPolyPolygon& rPolyPoly,
302 : sal_Int8 nAction)
303 6 : { return new PolyPolyElement( pParent, nGCId, rPolyPoly, nAction ); }
304 0 : virtual ImageElement* createImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
305 0 : { return new ImageElement( pParent, nGCId, nImage ); }
306 :
307 2 : virtual PageElement* createPageElement( Element* pParent,
308 : sal_Int32 nPageNr )
309 2 : { return new PageElement( pParent, nPageNr ); }
310 2 : virtual DocumentElement* createDocumentElement()
311 2 : { return new DocumentElement(); }
312 : };
313 : }
314 :
315 : #endif
316 :
317 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|