/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #ifndef INCLUDED_PDFI_PROCESSOR_HXX #define INCLUDED_PDFI_PROCESSOR_HXX #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "imagecontainer.hxx" #include "contentsink.hxx" #include "treevisitorfactory.hxx" #include "genericelements.hxx" namespace pdfi { class PDFIProcessor; struct Element; struct DocumentElement; struct PageElement; class ElementFactory; class XmlEmitter; class CharGlyph; /** Main entry from the parser Creates the internal DOM tree from the render calls */ class PDFIProcessor : public ContentSink { public: com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext; double fYPrevTextPosition; double fPrevTextHeight; double fXPrevTextPosition; double fPrevTextWidth; enum DocumentTextDirecion { LrTb, RlTb, TbLr }; explicit PDFIProcessor( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStat, com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext) ; /// TEMP - enable writer-like text:p on doc level void enableToplevelText(); void emit( XmlEmitter& rEmitter, const TreeVisitorFactory& rVisitorFactory ); sal_Int32 getGCId( const GraphicsContext& rGC ); const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const; GraphicsContext& getCurrentContext() { return m_aGCStack.back(); } const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); } ImageContainer& getImages() { return m_aImages; } boost::shared_ptr getElementFactory() const { return m_pElFactory; } const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& getStatusIndicator() const { return m_xStatusIndicator; } void setStatusIndicator( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStatus ) { m_xStatusIndicator = xStatus; } const FontAttributes& getFont( sal_Int32 nFontId ) const; sal_Int32 getFontId( const FontAttributes& rAttr ) const; void sortElements( Element* pElement, bool bDeep = false ); OUString mirrorString( const OUString& i_rInString ) const; private: void processGlyphLine(); void processGlyph( double fPreAvarageSpaceValue, CharGlyph& rGlyph, ParagraphElement* pPara, FrameElement* pFrame, bool bIsWhiteSpaceInLine ); void drawGlyphLine( const OUString& rGlyphs, const ::com::sun::star::geometry::RealRectangle2D& rRect, const ::com::sun::star::geometry::Matrix2D& rFontMatrix ); void drawCharGlyphs( OUString& rGlyphs, ::com::sun::star::geometry::RealRectangle2D& rRect, const GraphicsContext& aGC, ParagraphElement* pPara, FrameElement* pFrame, bool bSpaceFlag ); GraphicsContext& getTransformGlyphContext( CharGlyph& rGlyph ); // ContentSink interface implementation virtual void setPageNum( sal_Int32 nNumPages ); virtual void startPage( const ::com::sun::star::geometry::RealSize2D& rSize ); virtual void endPage(); virtual void hyperLink( const ::com::sun::star::geometry::RealRectangle2D& rBounds, const OUString& rURI ); virtual void pushState(); virtual void popState(); virtual void setFlatness( double ); virtual void setTransformation( const ::com::sun::star::geometry::AffineMatrix2D& rMatrix ); virtual void setLineDash( const ::com::sun::star::uno::Sequence& dashes, double start ); virtual void setLineJoin(sal_Int8); virtual void setLineCap(sal_Int8); virtual void setMiterLimit(double); virtual void setLineWidth(double); virtual void setFillColor( const ::com::sun::star::rendering::ARGBColor& rColor ); virtual void setStrokeColor( const ::com::sun::star::rendering::ARGBColor& rColor ); virtual void setBlendMode(sal_Int8); virtual void setFont( const FontAttributes& rFont ); virtual void setTextRenderMode( sal_Int32 ); virtual void strokePath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& rPath ); virtual void fillPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& rPath ); virtual void eoFillPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& rPath ); virtual void intersectClip(const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& rPath); virtual void intersectEoClip(const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& rPath); virtual void drawGlyphs( const OUString& rGlyphs, const ::com::sun::star::geometry::RealRectangle2D& rRect, const ::com::sun::star::geometry::Matrix2D& rFontMatrix ); virtual void endText(); virtual void drawMask(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& xBitmap, bool bInvert ); /// Given image must already be color-mapped and normalized to sRGB. virtual void drawImage(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& xBitmap ); /** Given image must already be color-mapped and normalized to sRGB. maskColors must contain two sequences of color components */ virtual void drawColorMaskedImage(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& xBitmap, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& xMaskColors ); virtual void drawMaskedImage(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& xBitmap, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& xMask, bool bInvertMask); virtual void drawAlphaMaskedImage(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& xImage, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& xMask); /// nElements == -1 means fill in number of pages void startIndicator( const OUString& rText, sal_Int32 nElements = -1 ); void endIndicator(); void setupImage(ImageId nImage); typedef boost::unordered_map IdToFontMap; typedef boost::unordered_map FontToIdMap; typedef boost::unordered_map IdToGCMap; typedef boost::unordered_map GCToIdMap; typedef std::vector GraphicsContextStack; ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange& outRect, const ::basegfx::B2DRange& inRect, const ::basegfx::B2DHomMatrix& transformation ); std::vector m_GlyphsList; boost::shared_ptr m_pElFactory; boost::shared_ptr m_pDocument; PageElement* m_pCurPage; Element* m_pCurElement; sal_Int32 m_nNextFontId; IdToFontMap m_aIdToFont; FontToIdMap m_aFontToId; GraphicsContextStack m_aGCStack; GraphicsContext m_prev_aGC; sal_Int32 m_nNextGCId; IdToGCMap m_aIdToGC; GCToIdMap m_aGCToId; ImageContainer m_aImages; DocumentTextDirecion m_eTextDirection; sal_Int32 m_nPages; sal_Int32 m_nNextZOrder; bool m_bIsWhiteSpaceInLine; com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > m_xStatusIndicator; bool m_bHaveTextOnDocLevel; }; class CharGlyph { public: CharGlyph(double fXPrevGlyphPosition, double fYPrevGlyphPosition, double fPrevGlyphHeight, double fPrevGlyphWidth, Element* pCurElement, const GraphicsContext& rCurrentContext, const com::sun::star::geometry::Matrix2D& rFontMatrix, const com::sun::star::geometry::RealRectangle2D& rRect, const OUString& rGlyphs ) : m_fXPrevGlyphPosition(fXPrevGlyphPosition), m_fYPrevGlyphPosition(fYPrevGlyphPosition), m_fPrevGlyphHeight(fPrevGlyphHeight), m_fPrevGlyphWidth(fPrevGlyphWidth), m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext), m_rFontMatrix(rFontMatrix), m_rRect(rRect), m_rGlyphs(rGlyphs) {}; virtual ~CharGlyph(){}; OUString& getGlyph(){ return m_rGlyphs; } com::sun::star::geometry::RealRectangle2D& getRect(){ return m_rRect; } com::sun::star::geometry::Matrix2D& getFontMatrix(){ return m_rFontMatrix; } GraphicsContext& getGC(){ return m_rCurrentContext; } Element* getCurElement(){ return m_pCurElement; } double getYPrevGlyphPosition() const { return m_fYPrevGlyphPosition; } double getXPrevGlyphPosition() const { return m_fXPrevGlyphPosition; } double getPrevGlyphHeight() const { return m_fPrevGlyphHeight; } double getPrevGlyphWidth () const { return m_fPrevGlyphWidth; } double getPrevGlyphsSpace() const { if( (m_rRect.X1-m_fXPrevGlyphPosition)<0 ) return 0; else return m_rRect.X1-m_fXPrevGlyphPosition; } private: double m_fXPrevGlyphPosition ; double m_fYPrevGlyphPosition ; double m_fPrevGlyphHeight ; double m_fPrevGlyphWidth ; Element* m_pCurElement ; GraphicsContext m_rCurrentContext ; com::sun::star::geometry::Matrix2D m_rFontMatrix ; com::sun::star::geometry::RealRectangle2D m_rRect ; OUString m_rGlyphs ; }; } #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */