1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_GENERICELEMENTS_HXX
21 #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_GENERICELEMENTS_HXX
23 #include "pdfihelper.hxx"
24 #include "treevisiting.hxx"
26 #include <com/sun/star/task/XStatusIndicator.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <basegfx/polygon/b2dpolypolygon.hxx>
29 #include <rtl/ustring.hxx>
30 #include <rtl/ustrbuf.hxx>
46 XmlEmitter
& _rEmitter
,
47 StyleContainer
& _rStyles
,
48 ImageContainer
& _rImages
,
49 PDFIProcessor
& _rProcessor
,
50 const css::uno::Reference
<
51 css::task::XStatusIndicator
>& _xStatusIndicator
,
52 css::uno::Reference
< css::uno::XComponentContext
> const & xContext
)
57 rProcessor(_rProcessor
),
58 xStatusIndicator(_xStatusIndicator
),
63 StyleContainer
& rStyles
;
64 ImageContainer
& rImages
;
65 PDFIProcessor
& rProcessor
;
67 css::task::XStatusIndicator
> xStatusIndicator
;
69 css::uno::XComponentContext
> m_xContext
;
75 explicit Element( Element
* pParent
)
76 : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent
)
79 pParent
->Children
.emplace_back( this );
86 To be implemented by every tree node that needs to be
89 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& rParentIt
) = 0;
90 /// Apply visitor to all children
91 void applyToChildren( ElementTreeVisitor
& );
92 /// Union element geometry with given element
93 void updateGeometryWith( const Element
* pMergeFrom
);
95 #if OSL_DEBUG_LEVEL > 0
96 // xxx refact TODO: move code to visitor
97 virtual void emitStructure( int nLevel
);
99 /** el must be a valid dereferenceable iterator of el->Parent->Children
100 pNewParent must not be NULL
102 static void setParent( std::list
<std::unique_ptr
<Element
>>::iterator
const & el
, Element
* pNewParent
);
107 std::list
<std::unique_ptr
<Element
>> Children
;
110 struct ListElement
: public Element
112 ListElement() : Element( nullptr ) {}
113 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& ) override
;
116 struct HyperlinkElement
: public Element
118 friend class ElementFactory
;
120 HyperlinkElement( Element
* pParent
, const OUString
& rURI
)
121 : Element( pParent
), URI( rURI
) {}
123 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& ) override
;
128 struct GraphicalElement
: public Element
131 GraphicalElement(Element
* pParent
, sal_Int32 nGCId
)
134 , MirrorVertical(false)
146 sal_Int32 TextStyleId
;
149 struct DrawElement
: public GraphicalElement
152 DrawElement( Element
* pParent
, sal_Int32 nGCId
)
153 : GraphicalElement( pParent
, nGCId
), isCharacter(false), ZOrder(0) {}
160 struct FrameElement
: public DrawElement
162 friend class ElementFactory
;
164 FrameElement( Element
* pParent
, sal_Int32 nGCId
)
165 : DrawElement( pParent
, nGCId
) {}
168 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& ) override
;
171 struct TextElement
: public GraphicalElement
173 friend class ElementFactory
;
175 TextElement( Element
* pParent
, sal_Int32 nGCId
, sal_Int32 nFontId
)
176 : GraphicalElement( pParent
, nGCId
), FontId( nFontId
) {}
179 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& ) override
;
185 struct ParagraphElement
: public Element
187 friend class ElementFactory
;
189 explicit ParagraphElement( Element
* pParent
) : Element( pParent
), Type( Normal
), bRtl( false ) {}
192 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& rParentIt
) override
;
194 // returns true only if only a single line is contained
195 bool isSingleLined( PDFIProcessor
const & rProc
) const;
196 // returns the highest line height of the contained textelements
197 // line height is font height if the text element is itself multilined
198 double getLineHeight( PDFIProcessor
& rProc
) const;
199 // returns the first text element child; does not recurse through subparagraphs
200 TextElement
* getFirstTextChild() const;
202 enum ParagraphType
{ Normal
, Headline
};
207 struct PolyPolyElement
: public DrawElement
209 friend class ElementFactory
;
211 PolyPolyElement( Element
* pParent
, sal_Int32 nGCId
,
212 const basegfx::B2DPolyPolygon
& rPolyPoly
,
215 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& rParentIt
) override
;
217 void updateGeometry();
219 #if OSL_DEBUG_LEVEL > 0
220 virtual void emitStructure( int nLevel
) override
;
223 basegfx::B2DPolyPolygon PolyPoly
;
227 struct ImageElement
: public DrawElement
229 friend class ElementFactory
;
231 ImageElement( Element
* pParent
, sal_Int32 nGCId
, ImageId nImage
)
232 : DrawElement( pParent
, nGCId
), Image( nImage
) {}
235 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& ) override
;
240 struct PageElement
: public Element
242 friend class ElementFactory
;
244 PageElement( Element
* pParent
, sal_Int32 nPageNr
)
245 : Element( pParent
), PageNumber( nPageNr
), Hyperlinks(),
246 TopMargin( 0.0 ), BottomMargin( 0.0 ), LeftMargin( 0.0 ), RightMargin( 0.0 )
249 // helper method for resolveHyperlinks
250 bool resolveHyperlink( const std::list
<std::unique_ptr
<Element
>>::iterator
& link_it
, std::list
<std::unique_ptr
<Element
>>& rElements
);
252 virtual ~PageElement() override
;
254 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& rParentIt
) override
;
256 void resolveHyperlinks();
257 void resolveFontStyles( PDFIProcessor
const & rProc
);
258 void resolveUnderlines( PDFIProcessor
const & rProc
);
260 sal_Int32
const PageNumber
;
261 ListElement Hyperlinks
; // contains not yet realized links on this page
266 std::unique_ptr
<Element
> HeaderElement
;
267 std::unique_ptr
<Element
> FooterElement
;
270 struct DocumentElement
: public Element
272 friend class ElementFactory
;
274 DocumentElement() : Element( nullptr ) {}
276 virtual ~DocumentElement() override
;
278 virtual void visitedBy( ElementTreeVisitor
&, const std::list
< std::unique_ptr
<Element
> >::const_iterator
& ) override
;
281 // this class is the differentiator of document types: it will create
282 // Element objects with an optimize() method suitable for the document type
286 ElementFactory() = delete;
288 static HyperlinkElement
* createHyperlinkElement( Element
* pParent
, const OUString
& rURI
)
289 { return new HyperlinkElement( pParent
, rURI
); }
291 static TextElement
* createTextElement( Element
* pParent
, sal_Int32 nGCId
, sal_Int32 nFontId
)
292 { return new TextElement( pParent
, nGCId
, nFontId
); }
293 static ParagraphElement
* createParagraphElement( Element
* pParent
)
294 { return new ParagraphElement( pParent
); }
296 static FrameElement
* createFrameElement( Element
* pParent
, sal_Int32 nGCId
)
297 { return new FrameElement( pParent
, nGCId
); }
298 static PolyPolyElement
*
299 createPolyPolyElement( Element
* pParent
,
301 const basegfx::B2DPolyPolygon
& rPolyPoly
,
303 { return new PolyPolyElement( pParent
, nGCId
, rPolyPoly
, nAction
); }
304 static ImageElement
* createImageElement( Element
* pParent
, sal_Int32 nGCId
, ImageId nImage
)
305 { return new ImageElement( pParent
, nGCId
, nImage
); }
307 static PageElement
* createPageElement( Element
* pParent
,
309 { return new PageElement( pParent
, nPageNr
); }
310 static DocumentElement
* createDocumentElement()
311 { return new DocumentElement(); }
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */