merge the formfield patch from ooo-build
[ooovba.git] / sdext / source / pdfimport / tree / genericelements.hxx
blob4ba66aa5d146175ea53e0c821be27f1ff607e21d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: genericelements.hxx,v $
11 * $Revision: 1.2 $
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 #ifndef INCLUDED_PDFI_GENERICELEMENTS_HXX
33 #define INCLUDED_PDFI_GENERICELEMENTS_HXX
35 #include "pdfihelper.hxx"
36 #include "treevisiting.hxx"
38 #include <com/sun/star/task/XStatusIndicator.hpp>
39 #include <basegfx/polygon/b2dpolypolygon.hxx>
40 #include <basegfx/range/b2drange.hxx>
41 #include <rtl/ustring.hxx>
42 #include <rtl/ustrbuf.hxx>
44 #include <list>
46 namespace pdfi
48 class XmlEmitter;
49 class StyleContainer;
50 class ImageContainer;
51 class PDFIProcessor;
52 class ElementFactory;
55 struct EmitContext
57 EmitContext(
58 XmlEmitter& _rEmitter,
59 StyleContainer& _rStyles,
60 ImageContainer& _rImages,
61 PDFIProcessor& _rProcessor,
62 const com::sun::star::uno::Reference<
63 com::sun::star::task::XStatusIndicator>& _xStatusIndicator ) :
64 rEmitter(_rEmitter),
65 rStyles(_rStyles),
66 rImages(_rImages),
67 rProcessor(_rProcessor),
68 xStatusIndicator(_xStatusIndicator)
71 XmlEmitter& rEmitter;
72 StyleContainer& rStyles;
73 ImageContainer& rImages;
74 PDFIProcessor& rProcessor;
75 com::sun::star::uno::Reference<
76 com::sun::star::task::XStatusIndicator> xStatusIndicator;
79 struct Element : public ElementTreeVisitable
81 protected:
82 Element( Element* pParent )
83 : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent )
85 if( pParent )
86 pParent->Children.push_back( this );
89 public:
90 virtual ~Element();
92 /// Apply visitor to all children
93 void applyToChildren( ElementTreeVisitor& );
94 /// Union element geometry with given element
95 void updateGeometryWith( const Element* pMergeFrom );
97 #if OSL_DEBUG_LEVEL > 1
98 // xxx refac TODO: move code to visitor
99 virtual void emitStructure( int nLevel );
100 #endif
101 /** el must be a valid dereferencable iterator of el->Parent->Children
102 pNewParent must not be NULL
104 static void setParent( std::list<Element*>::iterator& el, Element* pNewParent );
106 double x, y, w, h;
107 sal_Int32 StyleId;
108 Element* Parent;
109 std::list<Element*> Children;
112 struct ListElement : public Element
114 ListElement() : Element( NULL ) {}
115 // ElementTreeVisitable
116 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
119 struct HyperlinkElement : public Element
121 friend class ElementFactory;
122 protected:
123 HyperlinkElement( Element* pParent, const rtl::OUString& rURI )
124 : Element( pParent ), URI( rURI ) {}
125 public:
126 // ElementTreeVisitable
127 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
129 rtl::OUString URI;
132 struct GraphicalElement : public Element
134 protected:
135 GraphicalElement( Element* pParent, sal_Int32 nGCId )
136 : Element( pParent ), GCId( nGCId ), MirrorVertical( false ) {}
138 public:
139 sal_Int32 GCId;
140 bool MirrorVertical;
143 struct DrawElement : public GraphicalElement
145 protected:
146 DrawElement( Element* pParent, sal_Int32 nGCId )
147 : GraphicalElement( pParent, nGCId ), isCharacter(false), ZOrder(0) {}
149 public:
150 bool isCharacter;
151 sal_Int32 ZOrder;
154 struct FrameElement : public DrawElement
156 friend class ElementFactory;
157 protected:
158 FrameElement( Element* pParent, sal_Int32 nGCId )
159 : DrawElement( pParent, nGCId ) {}
161 public:
162 // ElementTreeVisitable
163 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
166 struct TextElement : public GraphicalElement
168 friend class ElementFactory;
169 protected:
170 TextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
171 : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {}
173 public:
174 // ElementTreeVisitable
175 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
177 rtl::OUStringBuffer Text;
178 sal_Int32 FontId;
181 struct ParagraphElement : public Element
183 friend class ElementFactory;
184 protected:
185 ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ) {}
187 public:
188 // ElementTreeVisitable
189 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
191 // returns true only if only a single line is contained
192 bool isSingleLined( PDFIProcessor& rProc ) const;
193 // returns the highest line height of the contained textelements
194 // line height is font height if the text element is itself multilined
195 double getLineHeight( PDFIProcessor& rProc ) const;
196 // returns the first text element child; does not recurse through subparagraphs
197 TextElement* getFirstTextChild() const;
199 enum ParagraphType { Normal, Headline };
200 ParagraphType Type;
203 struct PolyPolyElement : public DrawElement
205 friend class ElementFactory;
206 protected:
207 PolyPolyElement( Element* pParent, sal_Int32 nGCId,
208 const basegfx::B2DPolyPolygon& rPolyPoly,
209 sal_Int8 nAction );
210 public:
211 // ElementTreeVisitable
212 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
214 void updateGeometry();
216 #if OSL_DEBUG_LEVEL > 1
217 virtual void emitStructure( int nLevel );
218 #endif
220 basegfx::B2DPolyPolygon PolyPoly;
221 sal_Int8 Action;
224 struct ImageElement : public DrawElement
226 friend class ElementFactory;
227 protected:
228 ImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
229 : DrawElement( pParent, nGCId ), Image( nImage ) {}
231 public:
232 // ElementTreeVisitable
233 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
235 ImageId Image;
238 struct PageElement : public Element
240 friend class ElementFactory;
241 protected:
242 PageElement( Element* pParent, sal_Int32 nPageNr )
243 : Element( pParent ), PageNumber( nPageNr ), Hyperlinks(),
244 TopMargin( 0.0 ), BottomMargin( 0.0 ), LeftMargin( 0.0 ), RightMargin( 0.0 ),
245 HeaderElement( NULL ), FooterElement( NULL )
247 private:
248 // helper method for resolveHyperlinks
249 bool resolveHyperlink( std::list<Element*>::iterator link_it, std::list<Element*>& rElements );
250 public:
251 virtual ~PageElement();
253 // ElementTreeVisitable
254 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
256 void emitPageAnchoredElements( EmitContext& rEmitContext );
257 static void updateParagraphGeometry( Element* pEle );
258 void resolveHyperlinks();
259 void resolveFontStyles( PDFIProcessor& rProc );
260 void resolveUnderlines( PDFIProcessor& rProc );
262 sal_Int32 PageNumber;
263 ListElement Hyperlinks; // contains not yet realized links on this page
264 double TopMargin;
265 double BottomMargin;
266 double LeftMargin;
267 double RightMargin;
268 Element* HeaderElement;
269 Element* FooterElement;
272 struct DocumentElement : public Element
274 friend class ElementFactory;
275 protected:
276 DocumentElement() : Element( NULL ) {}
277 public:
278 virtual ~DocumentElement();
280 // ElementTreeVisitable
281 virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
285 // this class is the differentiator of document types: it will create
286 // Element objects with an optimize() method suitable for the document type
287 class ElementFactory
289 public:
290 ElementFactory() {}
291 virtual ~ElementFactory();
293 virtual HyperlinkElement* createHyperlinkElement( Element* pParent, const rtl::OUString& rURI )
294 { return new HyperlinkElement( pParent, rURI ); }
296 virtual TextElement* createTextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
297 { return new TextElement( pParent, nGCId, nFontId ); }
298 virtual ParagraphElement* createParagraphElement( Element* pParent )
299 { return new ParagraphElement( pParent ); }
301 virtual FrameElement* createFrameElement( Element* pParent, sal_Int32 nGCId )
302 { return new FrameElement( pParent, nGCId ); }
303 virtual PolyPolyElement*
304 createPolyPolyElement( Element* pParent,
305 sal_Int32 nGCId,
306 const basegfx::B2DPolyPolygon& rPolyPoly,
307 sal_Int8 nAction)
308 { return new PolyPolyElement( pParent, nGCId, rPolyPoly, nAction ); }
309 virtual ImageElement* createImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
310 { return new ImageElement( pParent, nGCId, nImage ); }
312 virtual PageElement* createPageElement( Element* pParent,
313 sal_Int32 nPageNr )
314 { return new PageElement( pParent, nPageNr ); }
315 virtual DocumentElement* createDocumentElement()
316 { return new DocumentElement(); }
320 #endif