LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/tree - pdfiprocessor.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 27 96.3 %
Date: 2012-08-25 Functions: 23 25 92.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 20 55.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef INCLUDED_PDFI_PROCESSOR_HXX
      30                 :            : #define INCLUDED_PDFI_PROCESSOR_HXX
      31                 :            : 
      32                 :            : #include "pdfihelper.hxx"
      33                 :            : 
      34                 :            : #include <com/sun/star/util/XStringMapping.hpp>
      35                 :            : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      36                 :            : #include <com/sun/star/task/XStatusIndicator.hpp>
      37                 :            : #include <com/sun/star/rendering/XVolatileBitmap.hpp>
      38                 :            : #include <com/sun/star/geometry/RealSize2D.hpp>
      39                 :            : #include <com/sun/star/geometry/RealPoint2D.hpp>
      40                 :            : #include <com/sun/star/geometry/RealRectangle2D.hpp>
      41                 :            : #include <com/sun/star/geometry/Matrix2D.hpp>
      42                 :            : 
      43                 :            : #include <basegfx/polygon/b2dpolypolygon.hxx>
      44                 :            : #include <basegfx/polygon/b2dpolygon.hxx>
      45                 :            : #include <basegfx/matrix/b2dhommatrix.hxx>
      46                 :            : #include <basegfx/range/b2drange.hxx>
      47                 :            : 
      48                 :            : #include <rtl/ustring.hxx>
      49                 :            : #include <rtl/ustrbuf.hxx>
      50                 :            : 
      51                 :            : #include <boost/shared_ptr.hpp>
      52                 :            : #include <list>
      53                 :            : #include <boost/unordered_map.hpp>
      54                 :            : 
      55                 :            : #include "imagecontainer.hxx"
      56                 :            : #include "contentsink.hxx"
      57                 :            : #include "treevisitorfactory.hxx"
      58                 :            : #include "genericelements.hxx"
      59                 :            : 
      60                 :            : namespace pdfi
      61                 :            : {
      62                 :            : 
      63                 :            :     class  PDFIProcessor;
      64                 :            :     struct Element;
      65                 :            :     struct DocumentElement;
      66                 :            :     struct PageElement;
      67                 :            :     class  ElementFactory;
      68                 :            :     class  XmlEmitter;
      69                 :            :     class  CharGlyph;
      70                 :            : 
      71                 :            :     /** Main entry from the parser
      72                 :            : 
      73                 :            :         Creates the internal DOM tree from the render calls
      74                 :            :      */
      75 [ +  - ][ +  - ]:         12 :     class PDFIProcessor : public ContentSink
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
      76                 :            :     {
      77                 :            :     public:
      78                 :            :         com::sun::star::uno::Reference<
      79                 :            :             com::sun::star::uno::XComponentContext >  m_xContext;
      80                 :            :         double fYPrevTextPosition;
      81                 :            :         double fPrevTextHeight;
      82                 :            :         double fXPrevTextPosition;
      83                 :            :         double fPrevTextWidth;
      84                 :            :         enum DocumentTextDirecion { LrTb, RlTb, TbLr };
      85                 :            : 
      86                 :            :         explicit PDFIProcessor( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStat,
      87                 :            :             com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext) ;
      88                 :            : 
      89                 :            :         /// TEMP - enable writer-like text:p on doc level
      90                 :            :         void enableToplevelText();
      91                 :            : 
      92                 :            :         void emit( XmlEmitter&               rEmitter,
      93                 :            :                    const TreeVisitorFactory& rVisitorFactory );
      94                 :            : 
      95                 :            :         sal_Int32 getGCId( const GraphicsContext& rGC );
      96                 :            :         const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
      97                 :       1590 :         GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
      98                 :          0 :         const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
      99                 :            : 
     100                 :            :         ImageContainer& getImages() { return m_aImages; }
     101                 :          3 :         boost::shared_ptr<ElementFactory> getElementFactory() const { return m_pElFactory; }
     102                 :            : 
     103                 :         12 :         const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& getStatusIndicator() const
     104                 :         12 :         { return m_xStatusIndicator; }
     105                 :            :         void setStatusIndicator( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStatus )
     106                 :            :         { m_xStatusIndicator = xStatus; }
     107                 :            : 
     108                 :            :         const FontAttributes& getFont( sal_Int32 nFontId ) const;
     109                 :            :         sal_Int32 getFontId( const FontAttributes& rAttr ) const;
     110                 :            : 
     111                 :            :         void sortElements( Element* pElement, bool bDeep = false );
     112                 :            : 
     113                 :            :         rtl::OUString mirrorString( const rtl::OUString& i_rInString );
     114                 :            : 
     115                 :            :     private:
     116                 :            :         void prepareMirrorMap();
     117                 :            :         void processGlyphLine();
     118                 :            :         void processGlyph(   double       fPreAvarageSpaceValue,
     119                 :            :                              CharGlyph&   rGlyph,
     120                 :            :                              ParagraphElement* pPara,
     121                 :            :                              FrameElement* pFrame,
     122                 :            :                              bool         bIsWhiteSpaceInLine );
     123                 :            : 
     124                 :            :         void drawGlyphLine( const rtl::OUString&                               rGlyphs,
     125                 :            :                             const ::com::sun::star::geometry::RealRectangle2D& rRect,
     126                 :            :                             const ::com::sun::star::geometry::Matrix2D&        rFontMatrix  );
     127                 :            : 
     128                 :            :         void drawCharGlyphs( rtl::OUString&             rGlyphs,
     129                 :            :                              ::com::sun::star::geometry::RealRectangle2D&  rRect,
     130                 :            :                              GraphicsContext aGC,
     131                 :            :                              ParagraphElement* pPara,
     132                 :            :                              FrameElement* pFrame,
     133                 :            :                              bool bSpaceFlag );
     134                 :            : 
     135                 :            :         GraphicsContext& getTransformGlyphContext( CharGlyph& rGlyph );
     136                 :            : 
     137                 :            :         // ContentSink interface implementation
     138                 :            : 
     139                 :            :         virtual void setPageNum( sal_Int32 nNumPages );
     140                 :            :         virtual void startPage( const ::com::sun::star::geometry::RealSize2D& rSize );
     141                 :            :         virtual void endPage();
     142                 :            : 
     143                 :            :         virtual void hyperLink( const ::com::sun::star::geometry::RealRectangle2D& rBounds,
     144                 :            :                                 const ::rtl::OUString&                             rURI );
     145                 :            :         virtual void pushState();
     146                 :            :         virtual void popState();
     147                 :            :         virtual void setFlatness( double );
     148                 :            :         virtual void setTransformation( const ::com::sun::star::geometry::AffineMatrix2D& rMatrix );
     149                 :            :         virtual void setLineDash( const ::com::sun::star::uno::Sequence<double>& dashes,
     150                 :            :                                   double                                         start );
     151                 :            :         virtual void setLineJoin(sal_Int8);
     152                 :            :         virtual void setLineCap(sal_Int8);
     153                 :            :         virtual void setMiterLimit(double);
     154                 :            :         virtual void setLineWidth(double);
     155                 :            :         virtual void setFillColor( const ::com::sun::star::rendering::ARGBColor& rColor );
     156                 :            :         virtual void setStrokeColor( const ::com::sun::star::rendering::ARGBColor& rColor );
     157                 :            :         virtual void setBlendMode(sal_Int8);
     158                 :            :         virtual void setFont( const FontAttributes& rFont );
     159                 :            :         virtual void setTextRenderMode( sal_Int32 );
     160                 :            : 
     161                 :            :         virtual void strokePath( const ::com::sun::star::uno::Reference<
     162                 :            :                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     163                 :            :         virtual void fillPath( const ::com::sun::star::uno::Reference<
     164                 :            :                                      ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     165                 :            :         virtual void eoFillPath( const ::com::sun::star::uno::Reference<
     166                 :            :                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     167                 :            : 
     168                 :            :         virtual void intersectClip(const ::com::sun::star::uno::Reference<
     169                 :            :                                          ::com::sun::star::rendering::XPolyPolygon2D >& rPath);
     170                 :            :         virtual void intersectEoClip(const ::com::sun::star::uno::Reference<
     171                 :            :                                            ::com::sun::star::rendering::XPolyPolygon2D >& rPath);
     172                 :            : 
     173                 :            :         virtual void drawGlyphs( const rtl::OUString&                               rGlyphs,
     174                 :            :                                  const ::com::sun::star::geometry::RealRectangle2D& rRect,
     175                 :            :                                  const ::com::sun::star::geometry::Matrix2D&        rFontMatrix );
     176                 :            :         virtual void endText();
     177                 :            : 
     178                 :            :         virtual void drawMask(const ::com::sun::star::uno::Sequence<
     179                 :            :                                     ::com::sun::star::beans::PropertyValue>& xBitmap,
     180                 :            :                               bool                                           bInvert );
     181                 :            :         /// Given image must already be color-mapped and normalized to sRGB.
     182                 :            :         virtual void drawImage(const ::com::sun::star::uno::Sequence<
     183                 :            :                                      ::com::sun::star::beans::PropertyValue>& xBitmap );
     184                 :            :         /** Given image must already be color-mapped and normalized to sRGB.
     185                 :            : 
     186                 :            :             maskColors must contain two sequences of color components
     187                 :            :          */
     188                 :            :         virtual void drawColorMaskedImage(const ::com::sun::star::uno::Sequence<
     189                 :            :                                                 ::com::sun::star::beans::PropertyValue>& xBitmap,
     190                 :            :                                           const ::com::sun::star::uno::Sequence<
     191                 :            :                                                 ::com::sun::star::uno::Any>&             xMaskColors );
     192                 :            :         virtual void drawMaskedImage(const ::com::sun::star::uno::Sequence<
     193                 :            :                                            ::com::sun::star::beans::PropertyValue>& xBitmap,
     194                 :            :                                      const ::com::sun::star::uno::Sequence<
     195                 :            :                                            ::com::sun::star::beans::PropertyValue>& xMask,
     196                 :            :                                      bool                                             bInvertMask);
     197                 :            :         virtual void drawAlphaMaskedImage(const ::com::sun::star::uno::Sequence<
     198                 :            :                                                 ::com::sun::star::beans::PropertyValue>& xImage,
     199                 :            :                                           const ::com::sun::star::uno::Sequence<
     200                 :            :                                                 ::com::sun::star::beans::PropertyValue>& xMask);
     201                 :            : 
     202                 :            :         /// nElements == -1 means fill in number of pages
     203                 :            :         void startIndicator( const rtl::OUString& rText, sal_Int32 nElements = -1 );
     204                 :            :         void endIndicator();
     205                 :            : 
     206                 :            :         void setupImage(ImageId nImage);
     207                 :            : 
     208                 :            :         typedef boost::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
     209                 :            :         typedef boost::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
     210                 :            : 
     211                 :            :         typedef boost::unordered_map<sal_Int32,GraphicsContext> IdToGCMap;
     212                 :            :         typedef boost::unordered_map<GraphicsContext,sal_Int32,GraphicsContextHash> GCToIdMap;
     213                 :            : 
     214                 :            :         typedef std::vector<GraphicsContext> GraphicsContextStack;
     215                 :            : 
     216                 :            :         ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange&            outRect,
     217                 :            :                                                         const ::basegfx::B2DRange&      inRect,
     218                 :            :                                                         const ::basegfx::B2DHomMatrix&  transformation );
     219                 :            :         std::vector<CharGlyph>             m_GlyphsList;
     220                 :            : 
     221                 :            :         boost::shared_ptr<ElementFactory>  m_pElFactory;
     222                 :            :         boost::shared_ptr<DocumentElement> m_pDocument;
     223                 :            :         PageElement*                       m_pCurPage;
     224                 :            :         Element*                           m_pCurElement;
     225                 :            :         sal_Int32                          m_nNextFontId;
     226                 :            :         IdToFontMap                        m_aIdToFont;
     227                 :            :         FontToIdMap                        m_aFontToId;
     228                 :            : 
     229                 :            :         GraphicsContextStack               m_aGCStack;
     230                 :            :         GraphicsContext                    m_prev_aGC;
     231                 :            :         sal_Int32                          m_nNextGCId;
     232                 :            :         IdToGCMap                          m_aIdToGC;
     233                 :            :         GCToIdMap                          m_aGCToId;
     234                 :            : 
     235                 :            :         ImageContainer                     m_aImages;
     236                 :            : 
     237                 :            :         DocumentTextDirecion               m_eTextDirection;
     238                 :            : 
     239                 :            :         sal_Int32                          m_nPages;
     240                 :            :         sal_Int32                          m_nNextZOrder;
     241                 :            :         double                             m_fWordSpace;
     242                 :            :         bool                               m_bIsWhiteSpaceInLine;
     243                 :            :         com::sun::star::uno::Reference<
     244                 :            :             com::sun::star::task::XStatusIndicator >
     245                 :            :                                            m_xStatusIndicator;
     246                 :            : 
     247                 :            :         bool                               m_bHaveTextOnDocLevel;
     248                 :            :         std::vector< sal_Unicode >         m_aMirrorMap;
     249                 :            :         com::sun::star::uno::Reference<
     250                 :            :             com::sun::star::util::XStringMapping >
     251                 :            :                                            m_xMirrorMapper;
     252                 :            :         bool                               m_bMirrorMapperTried;
     253                 :            :     };
     254                 :        810 :     class CharGlyph
     255                 :            :     {
     256                 :            :         public:
     257                 :        624 :             CharGlyph(){};
     258         [ -  + ]:       1434 :             virtual ~CharGlyph(){};
     259                 :        624 :             rtl::OUString& getGlyph(){ return m_rGlyphs; }
     260                 :        690 :             com::sun::star::geometry::RealRectangle2D& getRect(){ return m_rRect; }
     261                 :         66 :             com::sun::star::geometry::Matrix2D&  getFontMatrix(){ return m_rFontMatrix; }
     262                 :        954 :             GraphicsContext&  getGC(){ return m_rCurrentContext; }
     263                 :         66 :             Element*  getCurElement(){ return m_pCurElement; }
     264                 :            : 
     265                 :        624 :             void  setGlyph (const rtl::OUString& rGlyphs ){ m_rGlyphs=rGlyphs; }
     266                 :        624 :             void  setRect  (const ::com::sun::star::geometry::RealRectangle2D& rRect ){ m_rRect=rRect; }
     267                 :        624 :             void  setFontMatrix (const ::com::sun::star::geometry::Matrix2D& rFontMatrix ){ m_rFontMatrix= rFontMatrix; }
     268                 :        624 :             void  setGraphicsContext (GraphicsContext&  rCurrentContext ){ m_rCurrentContext= rCurrentContext; }
     269                 :        624 :             void  setCurElement( Element* pCurElement ){ m_pCurElement= pCurElement; }
     270                 :            : 
     271                 :            :             double getYPrevGlyphPosition() const { return m_fYPrevGlyphPosition; }
     272                 :            :             double getXPrevGlyphPosition() const { return m_fXPrevGlyphPosition; }
     273                 :            :             double getPrevGlyphHeight() const { return m_fPrevGlyphHeight; }
     274                 :            :             double getPrevGlyphWidth () const { return m_fPrevGlyphWidth; }
     275                 :       6306 :             double getPrevGlyphsSpace() const
     276                 :            :             {
     277         [ +  + ]:       6306 :                 if( (m_rRect.X1-m_fXPrevGlyphPosition)<0 )
     278                 :       1482 :                     return 0;
     279                 :            :                 else
     280                 :       6306 :                     return m_rRect.X1-m_fXPrevGlyphPosition;
     281                 :            :             }
     282                 :            : 
     283                 :        624 :             void setYPrevGlyphPosition( double fYPrevTextPosition ){ m_fYPrevGlyphPosition= fYPrevTextPosition; }
     284                 :        624 :             void setXPrevGlyphPosition( double fXPrevTextPosition ){ m_fXPrevGlyphPosition= fXPrevTextPosition; }
     285                 :        624 :             void setPrevGlyphHeight   ( double fPrevTextHeight ){ m_fPrevGlyphHeight= fPrevTextHeight; }
     286                 :        624 :             void setPrevGlyphWidth    ( double fPrevTextWidth ){ m_fPrevGlyphWidth= fPrevTextWidth; }
     287                 :            : 
     288                 :            :         private:
     289                 :            : 
     290                 :            :             double                      m_fYPrevGlyphPosition ;
     291                 :            :             double                      m_fXPrevGlyphPosition ;
     292                 :            :             double                      m_fPrevGlyphHeight ;
     293                 :            :             double                      m_fPrevGlyphWidth ;
     294                 :            :             Element*                    m_pCurElement ;
     295                 :            :             GraphicsContext             m_rCurrentContext ;
     296                 :            :             com::sun::star::geometry::Matrix2D          m_rFontMatrix ;
     297                 :            :             com::sun::star::geometry::RealRectangle2D   m_rRect ;
     298                 :            :             rtl::OUString               m_rGlyphs ;
     299                 :            :     };
     300                 :            : }
     301                 :            : 
     302                 :            : #define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
     303                 :            : 
     304                 :            : #endif
     305                 :            : 
     306                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10