LCOV - code coverage report
Current view: top level - libreoffice/sdext/source/pdfimport/tree - pdfiprocessor.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 27 96.3 %
Date: 2012-12-27 Functions: 23 25 92.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_PDFI_PROCESSOR_HXX
      21             : #define INCLUDED_PDFI_PROCESSOR_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           4 :     class PDFIProcessor : public ContentSink
      65             :     {
      66             :     public:
      67             :         com::sun::star::uno::Reference<
      68             :             com::sun::star::uno::XComponentContext >  m_xContext;
      69             :         double fYPrevTextPosition;
      70             :         double fPrevTextHeight;
      71             :         double fXPrevTextPosition;
      72             :         double fPrevTextWidth;
      73             :         enum DocumentTextDirecion { LrTb, RlTb, TbLr };
      74             : 
      75             :         explicit PDFIProcessor( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStat,
      76             :             com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext) ;
      77             : 
      78             :         /// TEMP - enable writer-like text:p on doc level
      79             :         void enableToplevelText();
      80             : 
      81             :         void emit( XmlEmitter&               rEmitter,
      82             :                    const TreeVisitorFactory& rVisitorFactory );
      83             : 
      84             :         sal_Int32 getGCId( const GraphicsContext& rGC );
      85             :         const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
      86         530 :         GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
      87           0 :         const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
      88             : 
      89             :         ImageContainer& getImages() { return m_aImages; }
      90           1 :         boost::shared_ptr<ElementFactory> getElementFactory() const { return m_pElFactory; }
      91             : 
      92           4 :         const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& getStatusIndicator() const
      93           4 :         { return m_xStatusIndicator; }
      94             :         void setStatusIndicator( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStatus )
      95             :         { m_xStatusIndicator = xStatus; }
      96             : 
      97             :         const FontAttributes& getFont( sal_Int32 nFontId ) const;
      98             :         sal_Int32 getFontId( const FontAttributes& rAttr ) const;
      99             : 
     100             :         void sortElements( Element* pElement, bool bDeep = false );
     101             : 
     102             :         rtl::OUString mirrorString( const rtl::OUString& i_rInString );
     103             : 
     104             :     private:
     105             :         void prepareMirrorMap();
     106             :         void processGlyphLine();
     107             :         void processGlyph(   double       fPreAvarageSpaceValue,
     108             :                              CharGlyph&   rGlyph,
     109             :                              ParagraphElement* pPara,
     110             :                              FrameElement* pFrame,
     111             :                              bool         bIsWhiteSpaceInLine );
     112             : 
     113             :         void drawGlyphLine( const rtl::OUString&                               rGlyphs,
     114             :                             const ::com::sun::star::geometry::RealRectangle2D& rRect,
     115             :                             const ::com::sun::star::geometry::Matrix2D&        rFontMatrix  );
     116             : 
     117             :         void drawCharGlyphs( rtl::OUString&             rGlyphs,
     118             :                              ::com::sun::star::geometry::RealRectangle2D&  rRect,
     119             :                              GraphicsContext aGC,
     120             :                              ParagraphElement* pPara,
     121             :                              FrameElement* pFrame,
     122             :                              bool bSpaceFlag );
     123             : 
     124             :         GraphicsContext& getTransformGlyphContext( CharGlyph& rGlyph );
     125             : 
     126             :         // ContentSink interface implementation
     127             : 
     128             :         virtual void setPageNum( sal_Int32 nNumPages );
     129             :         virtual void startPage( const ::com::sun::star::geometry::RealSize2D& rSize );
     130             :         virtual void endPage();
     131             : 
     132             :         virtual void hyperLink( const ::com::sun::star::geometry::RealRectangle2D& rBounds,
     133             :                                 const ::rtl::OUString&                             rURI );
     134             :         virtual void pushState();
     135             :         virtual void popState();
     136             :         virtual void setFlatness( double );
     137             :         virtual void setTransformation( const ::com::sun::star::geometry::AffineMatrix2D& rMatrix );
     138             :         virtual void setLineDash( const ::com::sun::star::uno::Sequence<double>& dashes,
     139             :                                   double                                         start );
     140             :         virtual void setLineJoin(sal_Int8);
     141             :         virtual void setLineCap(sal_Int8);
     142             :         virtual void setMiterLimit(double);
     143             :         virtual void setLineWidth(double);
     144             :         virtual void setFillColor( const ::com::sun::star::rendering::ARGBColor& rColor );
     145             :         virtual void setStrokeColor( const ::com::sun::star::rendering::ARGBColor& rColor );
     146             :         virtual void setBlendMode(sal_Int8);
     147             :         virtual void setFont( const FontAttributes& rFont );
     148             :         virtual void setTextRenderMode( sal_Int32 );
     149             : 
     150             :         virtual void strokePath( const ::com::sun::star::uno::Reference<
     151             :                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     152             :         virtual void fillPath( const ::com::sun::star::uno::Reference<
     153             :                                      ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     154             :         virtual void eoFillPath( const ::com::sun::star::uno::Reference<
     155             :                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     156             : 
     157             :         virtual void intersectClip(const ::com::sun::star::uno::Reference<
     158             :                                          ::com::sun::star::rendering::XPolyPolygon2D >& rPath);
     159             :         virtual void intersectEoClip(const ::com::sun::star::uno::Reference<
     160             :                                            ::com::sun::star::rendering::XPolyPolygon2D >& rPath);
     161             : 
     162             :         virtual void drawGlyphs( const rtl::OUString&                               rGlyphs,
     163             :                                  const ::com::sun::star::geometry::RealRectangle2D& rRect,
     164             :                                  const ::com::sun::star::geometry::Matrix2D&        rFontMatrix );
     165             :         virtual void endText();
     166             : 
     167             :         virtual void drawMask(const ::com::sun::star::uno::Sequence<
     168             :                                     ::com::sun::star::beans::PropertyValue>& xBitmap,
     169             :                               bool                                           bInvert );
     170             :         /// Given image must already be color-mapped and normalized to sRGB.
     171             :         virtual void drawImage(const ::com::sun::star::uno::Sequence<
     172             :                                      ::com::sun::star::beans::PropertyValue>& xBitmap );
     173             :         /** Given image must already be color-mapped and normalized to sRGB.
     174             : 
     175             :             maskColors must contain two sequences of color components
     176             :          */
     177             :         virtual void drawColorMaskedImage(const ::com::sun::star::uno::Sequence<
     178             :                                                 ::com::sun::star::beans::PropertyValue>& xBitmap,
     179             :                                           const ::com::sun::star::uno::Sequence<
     180             :                                                 ::com::sun::star::uno::Any>&             xMaskColors );
     181             :         virtual void drawMaskedImage(const ::com::sun::star::uno::Sequence<
     182             :                                            ::com::sun::star::beans::PropertyValue>& xBitmap,
     183             :                                      const ::com::sun::star::uno::Sequence<
     184             :                                            ::com::sun::star::beans::PropertyValue>& xMask,
     185             :                                      bool                                             bInvertMask);
     186             :         virtual void drawAlphaMaskedImage(const ::com::sun::star::uno::Sequence<
     187             :                                                 ::com::sun::star::beans::PropertyValue>& xImage,
     188             :                                           const ::com::sun::star::uno::Sequence<
     189             :                                                 ::com::sun::star::beans::PropertyValue>& xMask);
     190             : 
     191             :         /// nElements == -1 means fill in number of pages
     192             :         void startIndicator( const rtl::OUString& rText, sal_Int32 nElements = -1 );
     193             :         void endIndicator();
     194             : 
     195             :         void setupImage(ImageId nImage);
     196             : 
     197             :         typedef boost::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
     198             :         typedef boost::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
     199             : 
     200             :         typedef boost::unordered_map<sal_Int32,GraphicsContext> IdToGCMap;
     201             :         typedef boost::unordered_map<GraphicsContext,sal_Int32,GraphicsContextHash> GCToIdMap;
     202             : 
     203             :         typedef std::vector<GraphicsContext> GraphicsContextStack;
     204             : 
     205             :         ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange&            outRect,
     206             :                                                         const ::basegfx::B2DRange&      inRect,
     207             :                                                         const ::basegfx::B2DHomMatrix&  transformation );
     208             :         std::vector<CharGlyph>             m_GlyphsList;
     209             : 
     210             :         boost::shared_ptr<ElementFactory>  m_pElFactory;
     211             :         boost::shared_ptr<DocumentElement> m_pDocument;
     212             :         PageElement*                       m_pCurPage;
     213             :         Element*                           m_pCurElement;
     214             :         sal_Int32                          m_nNextFontId;
     215             :         IdToFontMap                        m_aIdToFont;
     216             :         FontToIdMap                        m_aFontToId;
     217             : 
     218             :         GraphicsContextStack               m_aGCStack;
     219             :         GraphicsContext                    m_prev_aGC;
     220             :         sal_Int32                          m_nNextGCId;
     221             :         IdToGCMap                          m_aIdToGC;
     222             :         GCToIdMap                          m_aGCToId;
     223             : 
     224             :         ImageContainer                     m_aImages;
     225             : 
     226             :         DocumentTextDirecion               m_eTextDirection;
     227             : 
     228             :         sal_Int32                          m_nPages;
     229             :         sal_Int32                          m_nNextZOrder;
     230             :         bool                               m_bIsWhiteSpaceInLine;
     231             :         com::sun::star::uno::Reference<
     232             :             com::sun::star::task::XStatusIndicator >
     233             :                                            m_xStatusIndicator;
     234             : 
     235             :         bool                               m_bHaveTextOnDocLevel;
     236             :         std::vector< sal_Unicode >         m_aMirrorMap;
     237             :         com::sun::star::uno::Reference<
     238             :             com::sun::star::util::XStringMapping >
     239             :                                            m_xMirrorMapper;
     240             :         bool                               m_bMirrorMapperTried;
     241             :     };
     242         270 :     class CharGlyph
     243             :     {
     244             :         public:
     245         208 :             CharGlyph(){};
     246         478 :             virtual ~CharGlyph(){};
     247         208 :             rtl::OUString& getGlyph(){ return m_rGlyphs; }
     248         230 :             com::sun::star::geometry::RealRectangle2D& getRect(){ return m_rRect; }
     249          22 :             com::sun::star::geometry::Matrix2D&  getFontMatrix(){ return m_rFontMatrix; }
     250         318 :             GraphicsContext&  getGC(){ return m_rCurrentContext; }
     251          22 :             Element*  getCurElement(){ return m_pCurElement; }
     252             : 
     253         208 :             void  setGlyph (const rtl::OUString& rGlyphs ){ m_rGlyphs=rGlyphs; }
     254         208 :             void  setRect  (const ::com::sun::star::geometry::RealRectangle2D& rRect ){ m_rRect=rRect; }
     255         208 :             void  setFontMatrix (const ::com::sun::star::geometry::Matrix2D& rFontMatrix ){ m_rFontMatrix= rFontMatrix; }
     256         208 :             void  setGraphicsContext (GraphicsContext&  rCurrentContext ){ m_rCurrentContext= rCurrentContext; }
     257         208 :             void  setCurElement( Element* pCurElement ){ m_pCurElement= pCurElement; }
     258             : 
     259             :             double getYPrevGlyphPosition() const { return m_fYPrevGlyphPosition; }
     260             :             double getXPrevGlyphPosition() const { return m_fXPrevGlyphPosition; }
     261             :             double getPrevGlyphHeight() const { return m_fPrevGlyphHeight; }
     262             :             double getPrevGlyphWidth () const { return m_fPrevGlyphWidth; }
     263        2102 :             double getPrevGlyphsSpace() const
     264             :             {
     265        2102 :                 if( (m_rRect.X1-m_fXPrevGlyphPosition)<0 )
     266         494 :                     return 0;
     267             :                 else
     268        1608 :                     return m_rRect.X1-m_fXPrevGlyphPosition;
     269             :             }
     270             : 
     271         208 :             void setYPrevGlyphPosition( double fYPrevTextPosition ){ m_fYPrevGlyphPosition= fYPrevTextPosition; }
     272         208 :             void setXPrevGlyphPosition( double fXPrevTextPosition ){ m_fXPrevGlyphPosition= fXPrevTextPosition; }
     273         208 :             void setPrevGlyphHeight   ( double fPrevTextHeight ){ m_fPrevGlyphHeight= fPrevTextHeight; }
     274         208 :             void setPrevGlyphWidth    ( double fPrevTextWidth ){ m_fPrevGlyphWidth= fPrevTextWidth; }
     275             : 
     276             :         private:
     277             : 
     278             :             double                      m_fYPrevGlyphPosition ;
     279             :             double                      m_fXPrevGlyphPosition ;
     280             :             double                      m_fPrevGlyphHeight ;
     281             :             double                      m_fPrevGlyphWidth ;
     282             :             Element*                    m_pCurElement ;
     283             :             GraphicsContext             m_rCurrentContext ;
     284             :             com::sun::star::geometry::Matrix2D          m_rFontMatrix ;
     285             :             com::sun::star::geometry::RealRectangle2D   m_rRect ;
     286             :             rtl::OUString               m_rGlyphs ;
     287             :     };
     288             : }
     289             : 
     290             : #define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
     291             : 
     292             : #endif
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10