LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/tree - genericelements.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 54 54 100.0 %
Date: 2015-06-13 12:38:46 Functions: 37 40 92.5 %
Legend: Lines: hit not hit

          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_SDEXT_SOURCE_PDFIMPORT_TREE_GENERICELEMENTS_HXX
      21             : #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_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           4 :     struct EmitContext
      45             :     {
      46           4 :         EmitContext(
      47             :             XmlEmitter&                              _rEmitter,
      48             :             StyleContainer&                          _rStyles,
      49             :             ImageContainer&                          _rImages,
      50             :             PDFIProcessor&                           _rProcessor,
      51             :             const css::uno::Reference<
      52             :             css::task::XStatusIndicator>& _xStatusIndicator,
      53             :             css::uno::Reference< css::uno::XComponentContext >  xContext)
      54             :         :
      55             :             rEmitter(_rEmitter),
      56             :             rStyles(_rStyles),
      57             :             rImages(_rImages),
      58             :             rProcessor(_rProcessor),
      59             :             xStatusIndicator(_xStatusIndicator),
      60           4 :         m_xContext(xContext)
      61           4 :         {}
      62             : 
      63             :         XmlEmitter&     rEmitter;
      64             :         StyleContainer& rStyles;
      65             :         ImageContainer& rImages;
      66             :         PDFIProcessor&  rProcessor;
      67             :         css::uno::Reference<
      68             :             css::task::XStatusIndicator> xStatusIndicator;
      69             :         css::uno::Reference<
      70             :             css::uno::XComponentContext >  m_xContext;
      71             :     };
      72             : 
      73             :     struct Element : public ElementTreeVisitable
      74             :     {
      75             :     protected:
      76         361 :         Element( Element* pParent )
      77         361 :             : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent )
      78             :         {
      79         361 :             if( pParent )
      80         352 :                 pParent->Children.push_back( this );
      81         361 :         }
      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           4 :     struct ListElement : public Element
     107             :     {
     108           4 :         ListElement() : Element( NULL ) {}
     109             :         // ElementTreeVisitable
     110             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     111             :     };
     112             : 
     113           4 :     struct HyperlinkElement : public Element
     114             :     {
     115             :         friend class ElementFactory;
     116             :     protected:
     117           2 :         HyperlinkElement( Element* pParent, const OUString& rURI )
     118           2 :         : Element( pParent ), URI( rURI ) {}
     119             :     public:
     120             :         // ElementTreeVisitable
     121             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     122             : 
     123             :         OUString URI;
     124             :     };
     125             : 
     126         322 :     struct GraphicalElement : public Element
     127             :     {
     128             :     protected:
     129         322 :         GraphicalElement(Element* pParent, sal_Int32 nGCId)
     130             :             : Element(pParent)
     131             :             , GCId(nGCId)
     132             :             , MirrorVertical(false)
     133             :             , IsForText(false)
     134             :             , FontSize(0.0)
     135         322 :             , TextStyleId(0)
     136             :         {
     137         322 :         }
     138             : 
     139             :     public:
     140             :         sal_Int32 GCId;
     141             :         bool      MirrorVertical;
     142             :         bool      IsForText;
     143             :         double    FontSize;
     144             :         sal_Int32 TextStyleId;
     145             :     };
     146             : 
     147          36 :     struct DrawElement : public GraphicalElement
     148             :     {
     149             :     protected:
     150          36 :         DrawElement( Element* pParent, sal_Int32 nGCId )
     151          36 :         : GraphicalElement( pParent, nGCId ), isCharacter(false), ZOrder(0) {}
     152             : 
     153             :     public:
     154             :         bool      isCharacter;
     155             :         sal_Int32 ZOrder;
     156             :     };
     157             : 
     158          54 :     struct FrameElement : public DrawElement
     159             :     {
     160             :         friend class ElementFactory;
     161             :     protected:
     162          27 :         FrameElement( Element* pParent, sal_Int32 nGCId )
     163          27 :         : DrawElement( pParent, nGCId ) {}
     164             : 
     165             :     public:
     166             :         // ElementTreeVisitable
     167             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     168             :     };
     169             : 
     170         572 :     struct TextElement : public GraphicalElement
     171             :     {
     172             :         friend class ElementFactory;
     173             :     protected:
     174         286 :         TextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
     175         286 :         : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {}
     176             : 
     177             :     public:
     178             :         // ElementTreeVisitable
     179             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     180             : 
     181             :         OUStringBuffer Text;
     182             :         sal_Int32           FontId;
     183             :     };
     184             : 
     185          50 :     struct ParagraphElement : public Element
     186             :     {
     187             :         friend class ElementFactory;
     188             :     protected:
     189          25 :         ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ), bRtl( false ) {}
     190             : 
     191             :     public:
     192             :         // ElementTreeVisitable
     193             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) SAL_OVERRIDE;
     194             : 
     195             :         // returns true only if only a single line is contained
     196             :         bool isSingleLined( PDFIProcessor& rProc ) const;
     197             :         // returns the highest line height of the contained textelements
     198             :         // line height is font height if the text element is itself multilined
     199             :         double getLineHeight( PDFIProcessor& rProc ) const;
     200             :         // returns the first text element child; does not recurse through subparagraphs
     201             :         TextElement* getFirstTextChild() const;
     202             : 
     203             :         enum ParagraphType { Normal, Headline };
     204             :         ParagraphType       Type;
     205             :     bool bRtl;
     206             :     };
     207             : 
     208          12 :     struct PolyPolyElement : public DrawElement
     209             :     {
     210             :         friend class ElementFactory;
     211             :     protected:
     212             :         PolyPolyElement( Element* pParent, sal_Int32 nGCId,
     213             :                          const basegfx::B2DPolyPolygon& rPolyPoly,
     214             :                          sal_Int8 nAction );
     215             :     public:
     216             :         // ElementTreeVisitable
     217             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) SAL_OVERRIDE;
     218             : 
     219             :         void updateGeometry();
     220             : 
     221             : #if OSL_DEBUG_LEVEL > 1
     222             :         virtual void emitStructure( int nLevel );
     223             : #endif
     224             : 
     225             :         basegfx::B2DPolyPolygon PolyPoly;
     226             :         sal_Int8                Action;
     227             :     };
     228             : 
     229           6 :     struct ImageElement : public DrawElement
     230             :     {
     231             :         friend class ElementFactory;
     232             :     protected:
     233           3 :         ImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
     234           3 :         : DrawElement( pParent, nGCId ), Image( nImage ) {}
     235             : 
     236             :     public:
     237             :         // ElementTreeVisitable
     238             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     239             : 
     240             :         ImageId Image;
     241             :     };
     242             : 
     243             :     struct PageElement : public Element
     244             :     {
     245             :         friend class ElementFactory;
     246             :     protected:
     247           4 :         PageElement( Element* pParent, sal_Int32 nPageNr )
     248             :         : Element( pParent ), PageNumber( nPageNr ), Hyperlinks(),
     249             :         TopMargin( 0.0 ), BottomMargin( 0.0 ), LeftMargin( 0.0 ), RightMargin( 0.0 ),
     250           4 :         HeaderElement( NULL ), FooterElement( NULL )
     251           4 :         {}
     252             :     private:
     253             :         // helper method for resolveHyperlinks
     254             :         bool resolveHyperlink( std::list<Element*>::iterator link_it, std::list<Element*>& rElements );
     255             :         public:
     256             :         virtual ~PageElement();
     257             : 
     258             :         // ElementTreeVisitable
     259             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) SAL_OVERRIDE;
     260             : 
     261             :         void emitPageAnchoredElements( EmitContext& rEmitContext );
     262             :         static void updateParagraphGeometry( Element* pEle );
     263             :         void resolveHyperlinks();
     264             :         void resolveFontStyles( PDFIProcessor& rProc );
     265             :         void resolveUnderlines( PDFIProcessor& rProc );
     266             : 
     267             :         sal_Int32      PageNumber;
     268             :         ListElement    Hyperlinks; // contains not yet realized links on this page
     269             :         double         TopMargin;
     270             :         double         BottomMargin;
     271             :         double         LeftMargin;
     272             :         double         RightMargin;
     273             :         Element*       HeaderElement;
     274             :         Element*       FooterElement;
     275             :     };
     276             : 
     277             :     struct DocumentElement : public Element
     278             :     {
     279             :         friend class ElementFactory;
     280             :     protected:
     281           4 :         DocumentElement() : Element( NULL ) {}
     282             :     public:
     283             :         virtual ~DocumentElement();
     284             : 
     285             :         // ElementTreeVisitable
     286             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     287             : 
     288             :     };
     289             : 
     290             :     // this class is the differentiator of document types: it will create
     291             :     // Element objects with an optimize() method suitable for the document type
     292             :     class ElementFactory
     293             :     {
     294             :     public:
     295           4 :         ElementFactory() {}
     296             :         virtual ~ElementFactory();
     297             : 
     298           2 :         static HyperlinkElement* createHyperlinkElement( Element* pParent, const OUString& rURI )
     299           2 :         { return new HyperlinkElement( pParent, rURI ); }
     300             : 
     301         286 :         static TextElement* createTextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
     302         286 :         { return new TextElement( pParent, nGCId, nFontId ); }
     303          25 :         static ParagraphElement* createParagraphElement( Element* pParent )
     304          25 :         { return new ParagraphElement( pParent ); }
     305             : 
     306          27 :         static FrameElement* createFrameElement( Element* pParent, sal_Int32 nGCId )
     307          27 :         { return new FrameElement( pParent, nGCId ); }
     308             :         static PolyPolyElement*
     309           6 :             createPolyPolyElement( Element* pParent,
     310             :                                    sal_Int32 nGCId,
     311             :                                    const basegfx::B2DPolyPolygon& rPolyPoly,
     312             :                                    sal_Int8 nAction)
     313           6 :         { return new PolyPolyElement( pParent, nGCId, rPolyPoly, nAction ); }
     314           3 :         static ImageElement* createImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
     315           3 :         { return new ImageElement( pParent, nGCId, nImage ); }
     316             : 
     317           4 :         static PageElement* createPageElement( Element* pParent,
     318             :                                                 sal_Int32 nPageNr )
     319           4 :         { return new PageElement( pParent, nPageNr ); }
     320           4 :         static DocumentElement* createDocumentElement()
     321           4 :         { return new DocumentElement(); }
     322             :     };
     323             : }
     324             : 
     325             : #endif
     326             : 
     327             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11