1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: genericelements.hxx,v $
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>
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
) :
67 rProcessor(_rProcessor
),
68 xStatusIndicator(_xStatusIndicator
)
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
82 Element( Element
* pParent
)
83 : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent
)
86 pParent
->Children
.push_back( this );
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
);
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
);
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
;
123 HyperlinkElement( Element
* pParent
, const rtl::OUString
& rURI
)
124 : Element( pParent
), URI( rURI
) {}
126 // ElementTreeVisitable
127 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< Element
* >::const_iterator
& );
132 struct GraphicalElement
: public Element
135 GraphicalElement( Element
* pParent
, sal_Int32 nGCId
)
136 : Element( pParent
), GCId( nGCId
), MirrorVertical( false ) {}
143 struct DrawElement
: public GraphicalElement
146 DrawElement( Element
* pParent
, sal_Int32 nGCId
)
147 : GraphicalElement( pParent
, nGCId
), isCharacter(false), ZOrder(0) {}
154 struct FrameElement
: public DrawElement
156 friend class ElementFactory
;
158 FrameElement( Element
* pParent
, sal_Int32 nGCId
)
159 : DrawElement( pParent
, nGCId
) {}
162 // ElementTreeVisitable
163 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< Element
* >::const_iterator
& );
166 struct TextElement
: public GraphicalElement
168 friend class ElementFactory
;
170 TextElement( Element
* pParent
, sal_Int32 nGCId
, sal_Int32 nFontId
)
171 : GraphicalElement( pParent
, nGCId
), FontId( nFontId
) {}
174 // ElementTreeVisitable
175 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< Element
* >::const_iterator
& );
177 rtl::OUStringBuffer Text
;
181 struct ParagraphElement
: public Element
183 friend class ElementFactory
;
185 ParagraphElement( Element
* pParent
) : Element( pParent
), Type( Normal
) {}
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
};
203 struct PolyPolyElement
: public DrawElement
205 friend class ElementFactory
;
207 PolyPolyElement( Element
* pParent
, sal_Int32 nGCId
,
208 const basegfx::B2DPolyPolygon
& rPolyPoly
,
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
);
220 basegfx::B2DPolyPolygon PolyPoly
;
224 struct ImageElement
: public DrawElement
226 friend class ElementFactory
;
228 ImageElement( Element
* pParent
, sal_Int32 nGCId
, ImageId nImage
)
229 : DrawElement( pParent
, nGCId
), Image( nImage
) {}
232 // ElementTreeVisitable
233 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< Element
* >::const_iterator
& );
238 struct PageElement
: public Element
240 friend class ElementFactory
;
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
)
248 // helper method for resolveHyperlinks
249 bool resolveHyperlink( std::list
<Element
*>::iterator link_it
, std::list
<Element
*>& rElements
);
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
268 Element
* HeaderElement
;
269 Element
* FooterElement
;
272 struct DocumentElement
: public Element
274 friend class ElementFactory
;
276 DocumentElement() : Element( NULL
) {}
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
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
,
306 const basegfx::B2DPolyPolygon
& rPolyPoly
,
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
,
314 { return new PageElement( pParent
, nPageNr
); }
315 virtual DocumentElement
* createDocumentElement()
316 { return new DocumentElement(); }