LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/tree - genericelements.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 53 53 100.0 %
Date: 2014-04-11 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           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         271 :         Element( Element* pParent )
      77         271 :             : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent )
      78             :         {
      79         271 :             if( pParent )
      80         266 :                 pParent->Children.push_back( this );
      81         271 :         }
      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& ) 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         240 :     struct GraphicalElement : public Element
     127             :     {
     128             :     protected:
     129         240 :         GraphicalElement( Element* pParent, sal_Int32 nGCId )
     130         240 :         : Element( pParent ), GCId( nGCId ), MirrorVertical( false ), IsForText (false) {}
     131             : 
     132             :     public:
     133             :         sal_Int32 GCId;
     134             :         bool      MirrorVertical;
     135             :         bool      IsForText;
     136             :     };
     137             : 
     138          32 :     struct DrawElement : public GraphicalElement
     139             :     {
     140             :     protected:
     141          32 :         DrawElement( Element* pParent, sal_Int32 nGCId )
     142          32 :         : GraphicalElement( pParent, nGCId ), isCharacter(false), ZOrder(0) {}
     143             : 
     144             :     public:
     145             :         bool      isCharacter;
     146             :         sal_Int32 ZOrder;
     147             :     };
     148             : 
     149          48 :     struct FrameElement : public DrawElement
     150             :     {
     151             :         friend class ElementFactory;
     152             :     protected:
     153          24 :         FrameElement( Element* pParent, sal_Int32 nGCId )
     154          24 :         : DrawElement( pParent, nGCId ) {}
     155             : 
     156             :     public:
     157             :         // ElementTreeVisitable
     158             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     159             :     };
     160             : 
     161         416 :     struct TextElement : public GraphicalElement
     162             :     {
     163             :         friend class ElementFactory;
     164             :     protected:
     165         208 :         TextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
     166         208 :         : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {}
     167             : 
     168             :     public:
     169             :         // ElementTreeVisitable
     170             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     171             : 
     172             :         OUStringBuffer Text;
     173             :         sal_Int32           FontId;
     174             :     };
     175             : 
     176          46 :     struct ParagraphElement : public Element
     177             :     {
     178             :         friend class ElementFactory;
     179             :     protected:
     180          23 :         ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ), bRtl( false ) {}
     181             : 
     182             :     public:
     183             :         // ElementTreeVisitable
     184             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) SAL_OVERRIDE;
     185             : 
     186             :         // returns true only if only a single line is contained
     187             :         bool isSingleLined( PDFIProcessor& rProc ) const;
     188             :         // returns the highest line height of the contained textelements
     189             :         // line height is font height if the text element is itself multilined
     190             :         double getLineHeight( PDFIProcessor& rProc ) const;
     191             :         // returns the first text element child; does not recurse through subparagraphs
     192             :         TextElement* getFirstTextChild() const;
     193             : 
     194             :         enum ParagraphType { Normal, Headline };
     195             :         ParagraphType       Type;
     196             :     bool bRtl;
     197             :     };
     198             : 
     199          12 :     struct PolyPolyElement : public DrawElement
     200             :     {
     201             :         friend class ElementFactory;
     202             :     protected:
     203             :         PolyPolyElement( Element* pParent, sal_Int32 nGCId,
     204             :                          const basegfx::B2DPolyPolygon& rPolyPoly,
     205             :                          sal_Int8 nAction );
     206             :     public:
     207             :         // ElementTreeVisitable
     208             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) SAL_OVERRIDE;
     209             : 
     210             :         void updateGeometry();
     211             : 
     212             : #if OSL_DEBUG_LEVEL > 1
     213             :         virtual void emitStructure( int nLevel );
     214             : #endif
     215             : 
     216             :         basegfx::B2DPolyPolygon PolyPoly;
     217             :         sal_Int8                Action;
     218             :     };
     219             : 
     220           4 :     struct ImageElement : public DrawElement
     221             :     {
     222             :         friend class ElementFactory;
     223             :     protected:
     224           2 :         ImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
     225           2 :         : DrawElement( pParent, nGCId ), Image( nImage ) {}
     226             : 
     227             :     public:
     228             :         // ElementTreeVisitable
     229             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     230             : 
     231             :         ImageId Image;
     232             :     };
     233             : 
     234             :     struct PageElement : public Element
     235             :     {
     236             :         friend class ElementFactory;
     237             :     protected:
     238           2 :         PageElement( Element* pParent, sal_Int32 nPageNr )
     239             :         : Element( pParent ), PageNumber( nPageNr ), Hyperlinks(),
     240             :         TopMargin( 0.0 ), BottomMargin( 0.0 ), LeftMargin( 0.0 ), RightMargin( 0.0 ),
     241           2 :         HeaderElement( NULL ), FooterElement( NULL )
     242           2 :         {}
     243             :     private:
     244             :         // helper method for resolveHyperlinks
     245             :         bool resolveHyperlink( std::list<Element*>::iterator link_it, std::list<Element*>& rElements );
     246             :         public:
     247             :         virtual ~PageElement();
     248             : 
     249             :         // ElementTreeVisitable
     250             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) SAL_OVERRIDE;
     251             : 
     252             :         void emitPageAnchoredElements( EmitContext& rEmitContext );
     253             :         static void updateParagraphGeometry( Element* pEle );
     254             :         void resolveHyperlinks();
     255             :         void resolveFontStyles( PDFIProcessor& rProc );
     256             :         void resolveUnderlines( PDFIProcessor& rProc );
     257             : 
     258             :         sal_Int32      PageNumber;
     259             :         ListElement    Hyperlinks; // contains not yet realized links on this page
     260             :         double         TopMargin;
     261             :         double         BottomMargin;
     262             :         double         LeftMargin;
     263             :         double         RightMargin;
     264             :         Element*       HeaderElement;
     265             :         Element*       FooterElement;
     266             :     };
     267             : 
     268             :     struct DocumentElement : public Element
     269             :     {
     270             :         friend class ElementFactory;
     271             :     protected:
     272           2 :         DocumentElement() : Element( NULL ) {}
     273             :     public:
     274             :         virtual ~DocumentElement();
     275             : 
     276             :         // ElementTreeVisitable
     277             :         virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) SAL_OVERRIDE;
     278             : 
     279             :     };
     280             : 
     281             :     // this class is the differentiator of document types: it will create
     282             :     // Element objects with an optimize() method suitable for the document type
     283             :     class ElementFactory
     284             :     {
     285             :     public:
     286           2 :         ElementFactory() {}
     287             :         virtual ~ElementFactory();
     288             : 
     289           2 :         virtual HyperlinkElement* createHyperlinkElement( Element* pParent, const OUString& rURI )
     290           2 :         { return new HyperlinkElement( pParent, rURI ); }
     291             : 
     292         208 :         virtual TextElement* createTextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
     293         208 :         { return new TextElement( pParent, nGCId, nFontId ); }
     294          23 :         virtual ParagraphElement* createParagraphElement( Element* pParent )
     295          23 :         { return new ParagraphElement( pParent ); }
     296             : 
     297          24 :         virtual FrameElement* createFrameElement( Element* pParent, sal_Int32 nGCId )
     298          24 :         { return new FrameElement( pParent, nGCId ); }
     299             :         virtual PolyPolyElement*
     300           6 :             createPolyPolyElement( Element* pParent,
     301             :                                    sal_Int32 nGCId,
     302             :                                    const basegfx::B2DPolyPolygon& rPolyPoly,
     303             :                                    sal_Int8 nAction)
     304           6 :         { return new PolyPolyElement( pParent, nGCId, rPolyPoly, nAction ); }
     305           2 :         virtual ImageElement* createImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
     306           2 :         { return new ImageElement( pParent, nGCId, nImage ); }
     307             : 
     308           2 :         virtual PageElement* createPageElement( Element* pParent,
     309             :                                                 sal_Int32 nPageNr )
     310           2 :         { return new PageElement( pParent, nPageNr ); }
     311           2 :         virtual DocumentElement* createDocumentElement()
     312           2 :         { return new DocumentElement(); }
     313             :     };
     314             : }
     315             : 
     316             : #endif
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10