LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sdext/source/pdfimport/tree - pdfiprocessor.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 18 19 94.7 %
Date: 2013-07-09 Functions: 14 16 87.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_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         532 :         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             :         OUString mirrorString( const OUString& i_rInString ) const;
     103             : 
     104             :     private:
     105             :         void processGlyphLine();
     106             :         void processGlyph(   double       fPreAvarageSpaceValue,
     107             :                              CharGlyph&   rGlyph,
     108             :                              ParagraphElement* pPara,
     109             :                              FrameElement* pFrame,
     110             :                              bool         bIsWhiteSpaceInLine );
     111             : 
     112             :         void drawGlyphLine( const OUString&                               rGlyphs,
     113             :                             const ::com::sun::star::geometry::RealRectangle2D& rRect,
     114             :                             const ::com::sun::star::geometry::Matrix2D&        rFontMatrix  );
     115             : 
     116             :         void drawCharGlyphs( OUString&             rGlyphs,
     117             :                              ::com::sun::star::geometry::RealRectangle2D&  rRect,
     118             :                              const GraphicsContext& aGC,
     119             :                              ParagraphElement* pPara,
     120             :                              FrameElement* pFrame,
     121             :                              bool bSpaceFlag );
     122             : 
     123             :         GraphicsContext& getTransformGlyphContext( CharGlyph& rGlyph );
     124             : 
     125             :         // ContentSink interface implementation
     126             : 
     127             :         virtual void setPageNum( sal_Int32 nNumPages );
     128             :         virtual void startPage( const ::com::sun::star::geometry::RealSize2D& rSize );
     129             :         virtual void endPage();
     130             : 
     131             :         virtual void hyperLink( const ::com::sun::star::geometry::RealRectangle2D& rBounds,
     132             :                                 const OUString&                             rURI );
     133             :         virtual void pushState();
     134             :         virtual void popState();
     135             :         virtual void setFlatness( double );
     136             :         virtual void setTransformation( const ::com::sun::star::geometry::AffineMatrix2D& rMatrix );
     137             :         virtual void setLineDash( const ::com::sun::star::uno::Sequence<double>& dashes,
     138             :                                   double                                         start );
     139             :         virtual void setLineJoin(sal_Int8);
     140             :         virtual void setLineCap(sal_Int8);
     141             :         virtual void setMiterLimit(double);
     142             :         virtual void setLineWidth(double);
     143             :         virtual void setFillColor( const ::com::sun::star::rendering::ARGBColor& rColor );
     144             :         virtual void setStrokeColor( const ::com::sun::star::rendering::ARGBColor& rColor );
     145             :         virtual void setBlendMode(sal_Int8);
     146             :         virtual void setFont( const FontAttributes& rFont );
     147             :         virtual void setTextRenderMode( sal_Int32 );
     148             : 
     149             :         virtual void strokePath( const ::com::sun::star::uno::Reference<
     150             :                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     151             :         virtual void fillPath( const ::com::sun::star::uno::Reference<
     152             :                                      ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     153             :         virtual void eoFillPath( const ::com::sun::star::uno::Reference<
     154             :                                        ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
     155             : 
     156             :         virtual void intersectClip(const ::com::sun::star::uno::Reference<
     157             :                                          ::com::sun::star::rendering::XPolyPolygon2D >& rPath);
     158             :         virtual void intersectEoClip(const ::com::sun::star::uno::Reference<
     159             :                                            ::com::sun::star::rendering::XPolyPolygon2D >& rPath);
     160             : 
     161             :         virtual void drawGlyphs( const OUString&                               rGlyphs,
     162             :                                  const ::com::sun::star::geometry::RealRectangle2D& rRect,
     163             :                                  const ::com::sun::star::geometry::Matrix2D&        rFontMatrix );
     164             :         virtual void endText();
     165             : 
     166             :         virtual void drawMask(const ::com::sun::star::uno::Sequence<
     167             :                                     ::com::sun::star::beans::PropertyValue>& xBitmap,
     168             :                               bool                                           bInvert );
     169             :         /// Given image must already be color-mapped and normalized to sRGB.
     170             :         virtual void drawImage(const ::com::sun::star::uno::Sequence<
     171             :                                      ::com::sun::star::beans::PropertyValue>& xBitmap );
     172             :         /** Given image must already be color-mapped and normalized to sRGB.
     173             : 
     174             :             maskColors must contain two sequences of color components
     175             :          */
     176             :         virtual void drawColorMaskedImage(const ::com::sun::star::uno::Sequence<
     177             :                                                 ::com::sun::star::beans::PropertyValue>& xBitmap,
     178             :                                           const ::com::sun::star::uno::Sequence<
     179             :                                                 ::com::sun::star::uno::Any>&             xMaskColors );
     180             :         virtual void drawMaskedImage(const ::com::sun::star::uno::Sequence<
     181             :                                            ::com::sun::star::beans::PropertyValue>& xBitmap,
     182             :                                      const ::com::sun::star::uno::Sequence<
     183             :                                            ::com::sun::star::beans::PropertyValue>& xMask,
     184             :                                      bool                                             bInvertMask);
     185             :         virtual void drawAlphaMaskedImage(const ::com::sun::star::uno::Sequence<
     186             :                                                 ::com::sun::star::beans::PropertyValue>& xImage,
     187             :                                           const ::com::sun::star::uno::Sequence<
     188             :                                                 ::com::sun::star::beans::PropertyValue>& xMask);
     189             : 
     190             :         /// nElements == -1 means fill in number of pages
     191             :         void startIndicator( const OUString& rText, sal_Int32 nElements = -1 );
     192             :         void endIndicator();
     193             : 
     194             :         void setupImage(ImageId nImage);
     195             : 
     196             :         typedef boost::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
     197             :         typedef boost::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
     198             : 
     199             :         typedef boost::unordered_map<sal_Int32,GraphicsContext> IdToGCMap;
     200             :         typedef boost::unordered_map<GraphicsContext,sal_Int32,GraphicsContextHash> GCToIdMap;
     201             : 
     202             :         typedef std::vector<GraphicsContext> GraphicsContextStack;
     203             : 
     204             :         ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange&            outRect,
     205             :                                                         const ::basegfx::B2DRange&      inRect,
     206             :                                                         const ::basegfx::B2DHomMatrix&  transformation );
     207             :         std::vector<CharGlyph>             m_GlyphsList;
     208             : 
     209             :         boost::shared_ptr<ElementFactory>  m_pElFactory;
     210             :         boost::shared_ptr<DocumentElement> m_pDocument;
     211             :         PageElement*                       m_pCurPage;
     212             :         Element*                           m_pCurElement;
     213             :         sal_Int32                          m_nNextFontId;
     214             :         IdToFontMap                        m_aIdToFont;
     215             :         FontToIdMap                        m_aFontToId;
     216             : 
     217             :         GraphicsContextStack               m_aGCStack;
     218             :         GraphicsContext                    m_prev_aGC;
     219             :         sal_Int32                          m_nNextGCId;
     220             :         IdToGCMap                          m_aIdToGC;
     221             :         GCToIdMap                          m_aGCToId;
     222             : 
     223             :         ImageContainer                     m_aImages;
     224             : 
     225             :         DocumentTextDirecion               m_eTextDirection;
     226             : 
     227             :         sal_Int32                          m_nPages;
     228             :         sal_Int32                          m_nNextZOrder;
     229             :         bool                               m_bIsWhiteSpaceInLine;
     230             :         com::sun::star::uno::Reference<
     231             :             com::sun::star::task::XStatusIndicator >
     232             :                                            m_xStatusIndicator;
     233             : 
     234             :         bool                               m_bHaveTextOnDocLevel;
     235             :     };
     236         270 :     class CharGlyph
     237             :     {
     238             :         public:
     239         208 :             CharGlyph(double fXPrevGlyphPosition, double fYPrevGlyphPosition, double fPrevGlyphHeight, double fPrevGlyphWidth,
     240             :                Element* pCurElement, const GraphicsContext& rCurrentContext, const com::sun::star::geometry::Matrix2D& rFontMatrix,
     241             :                const com::sun::star::geometry::RealRectangle2D& rRect, const OUString& rGlyphs  )
     242             :                : m_fXPrevGlyphPosition(fXPrevGlyphPosition), m_fYPrevGlyphPosition(fYPrevGlyphPosition), m_fPrevGlyphHeight(fPrevGlyphHeight),
     243             :                  m_fPrevGlyphWidth(fPrevGlyphWidth), m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext),
     244         208 :                  m_rFontMatrix(rFontMatrix), m_rRect(rRect), m_rGlyphs(rGlyphs) {};
     245             : 
     246         478 :             virtual ~CharGlyph(){};
     247         208 :             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             :             double getYPrevGlyphPosition() const { return m_fYPrevGlyphPosition; }
     254             :             double getXPrevGlyphPosition() const { return m_fXPrevGlyphPosition; }
     255             :             double getPrevGlyphHeight() const { return m_fPrevGlyphHeight; }
     256             :             double getPrevGlyphWidth () const { return m_fPrevGlyphWidth; }
     257        2102 :             double getPrevGlyphsSpace() const
     258             :             {
     259        2102 :                 if( (m_rRect.X1-m_fXPrevGlyphPosition)<0 )
     260         494 :                     return 0;
     261             :                 else
     262        1608 :                     return m_rRect.X1-m_fXPrevGlyphPosition;
     263             :             }
     264             : 
     265             :         private:
     266             : 
     267             :             double                      m_fXPrevGlyphPosition ;
     268             :             double                      m_fYPrevGlyphPosition ;
     269             :             double                      m_fPrevGlyphHeight ;
     270             :             double                      m_fPrevGlyphWidth ;
     271             :             Element*                    m_pCurElement ;
     272             :             GraphicsContext             m_rCurrentContext ;
     273             :             com::sun::star::geometry::Matrix2D          m_rFontMatrix ;
     274             :             com::sun::star::geometry::RealRectangle2D   m_rRect ;
     275             :             OUString               m_rGlyphs ;
     276             :     };
     277             : }
     278             : 
     279             : #endif
     280             : 
     281             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10