LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/tree - pdfiprocessor.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 15 0.0 %
Date: 2014-04-14 Functions: 0 15 0.0 %
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_PDFIPROCESSOR_HXX
      21             : #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_PDFIPROCESSOR_HXX
      22             : 
      23             : #include <com/sun/star/util/XStringMapping.hpp>
      24             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      25             : #include <com/sun/star/task/XStatusIndicator.hpp>
      26             : #include <com/sun/star/rendering/XVolatileBitmap.hpp>
      27             : #include <com/sun/star/geometry/RealSize2D.hpp>
      28             : #include <com/sun/star/geometry/RealPoint2D.hpp>
      29             : #include <com/sun/star/geometry/RealRectangle2D.hpp>
      30             : #include <com/sun/star/geometry/Matrix2D.hpp>
      31             : 
      32             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      33             : #include <basegfx/polygon/b2dpolygon.hxx>
      34             : #include <basegfx/matrix/b2dhommatrix.hxx>
      35             : #include <basegfx/range/b2drange.hxx>
      36             : 
      37             : #include <rtl/ustring.hxx>
      38             : #include <rtl/ustrbuf.hxx>
      39             : 
      40             : #include <boost/shared_ptr.hpp>
      41             : #include <list>
      42             : #include <boost/unordered_map.hpp>
      43             : 
      44             : #include "imagecontainer.hxx"
      45             : #include "contentsink.hxx"
      46             : #include "treevisitorfactory.hxx"
      47             : #include "genericelements.hxx"
      48             : 
      49             : namespace pdfi
      50             : {
      51             : 
      52             :     class  PDFIProcessor;
      53             :     struct Element;
      54             :     struct DocumentElement;
      55             :     struct PageElement;
      56             :     class  ElementFactory;
      57             :     class  XmlEmitter;
      58             :     class  CharGlyph;
      59             : 
      60             :     /** Main entry from the parser
      61             : 
      62             :         Creates the internal DOM tree from the render calls
      63             :      */
      64           0 :     class PDFIProcessor : public ContentSink
      65             :     {
      66             :     public:
      67             :         com::sun::star::uno::Reference<
      68             :             com::sun::star::uno::XComponentContext >  m_xContext;
      69             :         basegfx::B2DHomMatrix prevTextMatrix;
      70             :         double prevCharWidth;
      71             :         enum DocumentTextDirecion { LrTb, RlTb, TbLr };
      72             : 
      73             :         explicit PDFIProcessor( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStat,
      74             :             com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext) ;
      75             : 
      76             :         /// TEMP - enable writer-like text:p on doc level
      77             :         void enableToplevelText();
      78             : 
      79             :         void emit( XmlEmitter&               rEmitter,
      80             :                    const TreeVisitorFactory& rVisitorFactory );
      81             : 
      82             :         sal_Int32 getGCId( const GraphicsContext& rGC );
      83             :         const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
      84           0 :         GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
      85           0 :         const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
      86             : 
      87             :         ImageContainer& getImages() { return m_aImages; }
      88           0 :         boost::shared_ptr<ElementFactory> getElementFactory() const { return m_pElFactory; }
      89             : 
      90           0 :         const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& getStatusIndicator() const
      91           0 :         { return m_xStatusIndicator; }
      92             :         void setStatusIndicator( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStatus )
      93             :         { m_xStatusIndicator = xStatus; }
      94             : 
      95             :         const FontAttributes& getFont( sal_Int32 nFontId ) const;
      96             :         sal_Int32 getFontId( const FontAttributes& rAttr ) const;
      97             : 
      98             :         void sortElements( Element* pElement, bool bDeep = false );
      99             : 
     100             :         OUString mirrorString( const OUString& i_rInString ) const;
     101             : 
     102             :     private:
     103             :         void processGlyphLine();
     104             : 
     105             :         // ContentSink interface implementation
     106             : 
     107             :         virtual void setPageNum( sal_Int32 nNumPages ) SAL_OVERRIDE;
     108             :         virtual void startPage( const ::com::sun::star::geometry::RealSize2D& rSize ) SAL_OVERRIDE;
     109             :         virtual void endPage() SAL_OVERRIDE;
     110             : 
     111             :         virtual void hyperLink( const ::com::sun::star::geometry::RealRectangle2D& rBounds,
     112             :                                 const OUString&                             rURI ) SAL_OVERRIDE;
     113             :         virtual void pushState() SAL_OVERRIDE;
     114             :         virtual void popState() SAL_OVERRIDE;
     115             :         virtual void setFlatness( double ) SAL_OVERRIDE;
     116             :         virtual void setTransformation( const ::com::sun::star::geometry::AffineMatrix2D& rMatrix ) SAL_OVERRIDE;
     117             :         virtual void setLineDash( const ::com::sun::star::uno::Sequence<double>& dashes,
     118             :                                   double                                         start ) SAL_OVERRIDE;
     119             :         virtual void setLineJoin(sal_Int8) SAL_OVERRIDE;
     120             :         virtual void setLineCap(sal_Int8) SAL_OVERRIDE;
     121             :         virtual void setMiterLimit(double) SAL_OVERRIDE;
     122             :         virtual void setLineWidth(double) SAL_OVERRIDE;
     123             :         virtual void setFillColor( const ::com::sun::star::rendering::ARGBColor& rColor ) SAL_OVERRIDE;
     124             :         virtual void setStrokeColor( const ::com::sun::star::rendering::ARGBColor& rColor ) SAL_OVERRIDE;
     125             :         virtual void setBlendMode(sal_Int8) SAL_OVERRIDE;
     126             :         virtual void setFont( const FontAttributes& rFont ) SAL_OVERRIDE;
     127             :         virtual void setTextRenderMode( sal_Int32 ) SAL_OVERRIDE;
     128             : 
     129             :         virtual void strokePath( const ::com::sun::star::uno::Reference<
     130             :                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath ) SAL_OVERRIDE;
     131             :         virtual void fillPath( const ::com::sun::star::uno::Reference<
     132             :                                      ::com::sun::star::rendering::XPolyPolygon2D >& rPath ) SAL_OVERRIDE;
     133             :         virtual void eoFillPath( const ::com::sun::star::uno::Reference<
     134             :                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath ) SAL_OVERRIDE;
     135             : 
     136             :         virtual void intersectClip(const ::com::sun::star::uno::Reference<
     137             :                                          ::com::sun::star::rendering::XPolyPolygon2D >& rPath) SAL_OVERRIDE;
     138             :         virtual void intersectEoClip(const ::com::sun::star::uno::Reference<
     139             :                                            ::com::sun::star::rendering::XPolyPolygon2D >& rPath) SAL_OVERRIDE;
     140             : 
     141             :         virtual void drawGlyphs( const OUString&                               rGlyphs,
     142             :                                  const ::com::sun::star::geometry::RealRectangle2D& rRect,
     143             :                                  const ::com::sun::star::geometry::Matrix2D&        rFontMatrix ) SAL_OVERRIDE;
     144             :         virtual void endText() SAL_OVERRIDE;
     145             : 
     146             :         virtual void drawMask(const ::com::sun::star::uno::Sequence<
     147             :                                     ::com::sun::star::beans::PropertyValue>& xBitmap,
     148             :                               bool                                           bInvert ) SAL_OVERRIDE;
     149             :         /// Given image must already be color-mapped and normalized to sRGB.
     150             :         virtual void drawImage(const ::com::sun::star::uno::Sequence<
     151             :                                      ::com::sun::star::beans::PropertyValue>& xBitmap ) SAL_OVERRIDE;
     152             :         /** Given image must already be color-mapped and normalized to sRGB.
     153             : 
     154             :             maskColors must contain two sequences of color components
     155             :          */
     156             :         virtual void drawColorMaskedImage(const ::com::sun::star::uno::Sequence<
     157             :                                                 ::com::sun::star::beans::PropertyValue>& xBitmap,
     158             :                                           const ::com::sun::star::uno::Sequence<
     159             :                                                 ::com::sun::star::uno::Any>&             xMaskColors ) SAL_OVERRIDE;
     160             :         virtual void drawMaskedImage(const ::com::sun::star::uno::Sequence<
     161             :                                            ::com::sun::star::beans::PropertyValue>& xBitmap,
     162             :                                      const ::com::sun::star::uno::Sequence<
     163             :                                            ::com::sun::star::beans::PropertyValue>& xMask,
     164             :                                      bool                                             bInvertMask) SAL_OVERRIDE;
     165             :         virtual void drawAlphaMaskedImage(const ::com::sun::star::uno::Sequence<
     166             :                                                 ::com::sun::star::beans::PropertyValue>& xImage,
     167             :                                           const ::com::sun::star::uno::Sequence<
     168             :                                                 ::com::sun::star::beans::PropertyValue>& xMask) SAL_OVERRIDE;
     169             : 
     170             :         /// nElements == -1 means fill in number of pages
     171             :         void startIndicator( const OUString& rText, sal_Int32 nElements = -1 );
     172             :         void endIndicator();
     173             : 
     174             :         void setupImage(ImageId nImage);
     175             : 
     176             :         typedef boost::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
     177             :         typedef boost::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
     178             : 
     179             :         typedef boost::unordered_map<sal_Int32,GraphicsContext> IdToGCMap;
     180             :         typedef boost::unordered_map<GraphicsContext,sal_Int32,GraphicsContextHash> GCToIdMap;
     181             : 
     182             :         typedef std::vector<GraphicsContext> GraphicsContextStack;
     183             : 
     184             :         std::vector<CharGlyph>             m_GlyphsList;
     185             : 
     186             :         boost::shared_ptr<ElementFactory>  m_pElFactory;
     187             :         boost::shared_ptr<DocumentElement> m_pDocument;
     188             :         PageElement*                       m_pCurPage;
     189             :         Element*                           m_pCurElement;
     190             :         sal_Int32                          m_nNextFontId;
     191             :         IdToFontMap                        m_aIdToFont;
     192             :         FontToIdMap                        m_aFontToId;
     193             : 
     194             :         GraphicsContextStack               m_aGCStack;
     195             :         GraphicsContext                    m_prev_aGC;
     196             :         sal_Int32                          m_nNextGCId;
     197             :         IdToGCMap                          m_aIdToGC;
     198             :         GCToIdMap                          m_aGCToId;
     199             : 
     200             :         ImageContainer                     m_aImages;
     201             : 
     202             :         DocumentTextDirecion               m_eTextDirection;
     203             : 
     204             :         sal_Int32                          m_nPages;
     205             :         sal_Int32                          m_nNextZOrder;
     206             :         com::sun::star::uno::Reference<
     207             :             com::sun::star::task::XStatusIndicator >
     208             :                                            m_xStatusIndicator;
     209             : 
     210             :         bool                               m_bHaveTextOnDocLevel;
     211             :     };
     212           0 :     class CharGlyph
     213             :     {
     214             :         public:
     215           0 :             CharGlyph(Element* pCurElement, const GraphicsContext& rCurrentContext,
     216             :                 double width, double prevSpaceWidth, const OUString& rGlyphs  )
     217             :                : m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext),
     218           0 :                  m_Width(width), m_PrevSpaceWidth(prevSpaceWidth), m_rGlyphs(rGlyphs) {};
     219             : 
     220           0 :             virtual ~CharGlyph(){};
     221           0 :             OUString& getGlyph(){ return m_rGlyphs; }
     222           0 :             double getWidth(){ return m_Width; }
     223           0 :             double getPrevSpaceWidth(){ return m_PrevSpaceWidth; }
     224           0 :             GraphicsContext&  getGC(){ return m_rCurrentContext; }
     225           0 :             Element*  getCurElement(){ return m_pCurElement; }
     226             : 
     227             :         private:
     228             :             Element*                    m_pCurElement ;
     229             :             GraphicsContext             m_rCurrentContext ;
     230             :             double                      m_Width ;
     231             :             double                      m_PrevSpaceWidth ;
     232             :             OUString                    m_rGlyphs ;
     233             :     };
     234             : }
     235             : 
     236             : #endif
     237             : 
     238             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10