From 061ce55ac0864f170f3e6dbc944ec51c0bf7b569 Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Thu, 14 Aug 2008 16:14:14 +0000 Subject: INTEGRATION: CWS pdf25 (1.1.2); FILE ADDED 2008/07/24 12:32:59 akhva 1.1.2.1: #90061 --- sdext/source/pdfimport/tree/drawtreevisiting.hxx | 115 ++++++++ sdext/source/pdfimport/tree/genericelements.hxx | 319 +++++++++++++++++++++ sdext/source/pdfimport/tree/imagecontainer.hxx | 65 +++++ sdext/source/pdfimport/tree/pdfiprocessor.hxx | 295 +++++++++++++++++++ sdext/source/pdfimport/tree/style.hxx | 184 ++++++++++++ sdext/source/pdfimport/tree/treevisiting.hxx | 84 ++++++ sdext/source/pdfimport/tree/writertreevisiting.hxx | 120 ++++++++ 7 files changed, 1182 insertions(+) create mode 100644 sdext/source/pdfimport/tree/drawtreevisiting.hxx create mode 100644 sdext/source/pdfimport/tree/genericelements.hxx create mode 100644 sdext/source/pdfimport/tree/imagecontainer.hxx create mode 100644 sdext/source/pdfimport/tree/pdfiprocessor.hxx create mode 100644 sdext/source/pdfimport/tree/style.hxx create mode 100644 sdext/source/pdfimport/tree/treevisiting.hxx create mode 100644 sdext/source/pdfimport/tree/writertreevisiting.hxx (limited to 'sdext') diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.hxx b/sdext/source/pdfimport/tree/drawtreevisiting.hxx new file mode 100644 index 000000000000..a9fdb22a48d6 --- /dev/null +++ b/sdext/source/pdfimport/tree/drawtreevisiting.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: drawtreevisiting.hxx,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_PDFI_DRAWTREEVISITING_HXX +#define INCLUDED_PDFI_DRAWTREEVISITING_HXX + +#include "treevisiting.hxx" + + +namespace pdfi +{ + struct DrawElement; + + class DrawXmlOptimizer : public ElementTreeVisitor + { + private: + PDFIProcessor& m_rProcessor; + void optimizeTextElements(Element& rParent); + + public: + explicit DrawXmlOptimizer(PDFIProcessor& rProcessor) : + m_rProcessor(rProcessor) + {} + + virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( TextElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& ); + }; + + class DrawXmlFinalizer : public ElementTreeVisitor + { + private: + StyleContainer& m_rStyleContainer; + PDFIProcessor& m_rProcessor; + + public: + explicit DrawXmlFinalizer(StyleContainer& rStyleContainer, + PDFIProcessor& rProcessor) : + m_rStyleContainer(rStyleContainer), + m_rProcessor(rProcessor) + {} + + virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( TextElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& ); + }; + + class DrawXmlEmitter : public ElementTreeVisitor + { + private: + EmitContext& m_rEmitContext ; + /// writes Impress doc when false + const bool m_bWriteDrawDocument; + + void fillFrameProps( DrawElement& rElem, + PropertyMap& rProps, + const EmitContext& rEmitContext ); + + public: + enum DocType{ DRAW_DOC, IMPRESS_DOC }; + explicit DrawXmlEmitter(EmitContext& rEmitContext, DocType eDocType) : + m_rEmitContext(rEmitContext), + m_bWriteDrawDocument(eDocType==DRAW_DOC) + {} + + virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( TextElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& ); + }; +} + +#endif diff --git a/sdext/source/pdfimport/tree/genericelements.hxx b/sdext/source/pdfimport/tree/genericelements.hxx new file mode 100644 index 000000000000..34fbdf6391de --- /dev/null +++ b/sdext/source/pdfimport/tree/genericelements.hxx @@ -0,0 +1,319 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: genericelements.hxx,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_PDFI_GENERICELEMENTS_HXX +#define INCLUDED_PDFI_GENERICELEMENTS_HXX + +#include "pdfihelper.hxx" +#include "treevisiting.hxx" + +#include +#include +#include +#include +#include + +#include + +namespace pdfi +{ + class XmlEmitter; + class StyleContainer; + class ImageContainer; + class PDFIProcessor; + class ElementFactory; + + + struct EmitContext + { + EmitContext( + XmlEmitter& _rEmitter, + StyleContainer& _rStyles, + ImageContainer& _rImages, + PDFIProcessor& _rProcessor, + const com::sun::star::uno::Reference< + com::sun::star::task::XStatusIndicator>& _xStatusIndicator ) : + rEmitter(_rEmitter), + rStyles(_rStyles), + rImages(_rImages), + rProcessor(_rProcessor), + xStatusIndicator(_xStatusIndicator) + {} + + XmlEmitter& rEmitter; + StyleContainer& rStyles; + ImageContainer& rImages; + PDFIProcessor& rProcessor; + com::sun::star::uno::Reference< + com::sun::star::task::XStatusIndicator> xStatusIndicator; + }; + + struct Element : public ElementTreeVisitable + { + protected: + Element( Element* pParent ) + : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent ) + { + if( pParent ) + pParent->Children.push_back( this ); + } + + public: + virtual ~Element(); + + /// Apply visitor to all children + void applyToChildren( ElementTreeVisitor& ); + /// Union element geometry with given element + void updateGeometryWith( const Element* pMergeFrom ); + +#if OSL_DEBUG_LEVEL > 1 + // xxx refac TODO: move code to visitor + virtual void emitStructure( int nLevel ); +#endif + /** el must be a valid dereferencable iterator of el->Parent->Children + pNewParent must not be NULL + */ + static void setParent( std::list::iterator& el, Element* pNewParent ); + + double x, y, w, h; + sal_Int32 StyleId; + Element* Parent; + std::list Children; + }; + + struct ListElement : public Element + { + ListElement() : Element( NULL ) {} + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ); + }; + + struct HyperlinkElement : public Element + { + friend class ElementFactory; + protected: + HyperlinkElement( Element* pParent, const rtl::OUString& rURI ) + : Element( pParent ), URI( rURI ) {} + public: + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ); + + rtl::OUString URI; + }; + + struct GraphicalElement : public Element + { + protected: + GraphicalElement( Element* pParent, sal_Int32 nGCId ) + : Element( pParent ), GCId(nGCId ) {} + + public: + sal_Int32 GCId; + }; + + struct DrawElement : public GraphicalElement + { + protected: + DrawElement( Element* pParent, sal_Int32 nGCId ) + : GraphicalElement( pParent, nGCId ), isCharacter(false), ZOrder(0) {} + + public: + bool isCharacter; + sal_Int32 ZOrder; + }; + + struct FrameElement : public DrawElement + { + friend class ElementFactory; + protected: + FrameElement( Element* pParent, sal_Int32 nGCId ) + : DrawElement( pParent, nGCId ) {} + + public: + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ); + }; + + struct TextElement : public GraphicalElement + { + friend class ElementFactory; + protected: + TextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId ) + : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {} + + public: + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ); + + rtl::OUStringBuffer Text; + sal_Int32 FontId; + }; + + struct ParagraphElement : public Element + { + friend class ElementFactory; + protected: + ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ) {} + + public: + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ); + + // returns true only if only a single line is contained + bool isSingleLined( PDFIProcessor& rProc ) const; + // returns the highest line height of the contained textelements + // line height is font height if the text element is itself multilined + double getLineHeight( PDFIProcessor& rProc ) const; + // returns the first text element child; does not recurse through subparagraphs + TextElement* getFirstTextChild() const; + + enum ParagraphType { Normal, Headline }; + ParagraphType Type; + }; + + struct PolyPolyElement : public DrawElement + { + friend class ElementFactory; + protected: + PolyPolyElement( Element* pParent, sal_Int32 nGCId, + const basegfx::B2DPolyPolygon& rPolyPoly, + sal_Int8 nAction ); + public: + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ); + + void updateGeometry(); + +#if OSL_DEBUG_LEVEL > 1 + virtual void emitStructure( int nLevel ); +#endif + + basegfx::B2DPolyPolygon PolyPoly; + sal_Int8 Action; + }; + + struct ImageElement : public DrawElement + { + friend class ElementFactory; + protected: + ImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage ) + : DrawElement( pParent, nGCId ), Image( nImage ) {} + + public: + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ); + + ImageId Image; + }; + + struct PageElement : public Element + { + friend class ElementFactory; + protected: + PageElement( Element* pParent, sal_Int32 nPageNr ) + : Element( pParent ), PageNumber( nPageNr ), Hyperlinks(), + TopMargin( 0.0 ), BottomMargin( 0.0 ), LeftMargin( 0.0 ), RightMargin( 0.0 ), + HeaderElement( NULL ), FooterElement( NULL ) + {} + private: + // helper method for resolveHyperlinks + bool resolveHyperlink( std::list::iterator link_it, std::list& rElements ); + public: + virtual ~PageElement(); + + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ); + + void emitPageAnchoredElements( EmitContext& rEmitContext ); + static void updateParagraphGeometry( Element* pEle ); + void resolveHyperlinks(); + void resolveFontStyles( PDFIProcessor& rProc ); + void resolveUnderlines( PDFIProcessor& rProc ); + + sal_Int32 PageNumber; + ListElement Hyperlinks; // contains not yet realized links on this page + double TopMargin; + double BottomMargin; + double LeftMargin; + double RightMargin; + Element* HeaderElement; + Element* FooterElement; + }; + + struct DocumentElement : public Element + { + friend class ElementFactory; + protected: + DocumentElement() : Element( NULL ) {} + public: + virtual ~DocumentElement(); + + // ElementTreeVisitable + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ); + + }; + + // this class is the differentiator of document types: it will create + // Element objects with an optimize() method suitable for the document type + class ElementFactory + { + public: + ElementFactory() {} + virtual ~ElementFactory(); + + virtual HyperlinkElement* createHyperlinkElement( Element* pParent, const rtl::OUString& rURI ) + { return new HyperlinkElement( pParent, rURI ); } + + virtual TextElement* createTextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId ) + { return new TextElement( pParent, nGCId, nFontId ); } + virtual ParagraphElement* createParagraphElement( Element* pParent ) + { return new ParagraphElement( pParent ); } + + virtual FrameElement* createFrameElement( Element* pParent, sal_Int32 nGCId ) + { return new FrameElement( pParent, nGCId ); } + virtual PolyPolyElement* + createPolyPolyElement( Element* pParent, + sal_Int32 nGCId, + const basegfx::B2DPolyPolygon& rPolyPoly, + sal_Int8 nAction) + { return new PolyPolyElement( pParent, nGCId, rPolyPoly, nAction ); } + virtual ImageElement* createImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage ) + { return new ImageElement( pParent, nGCId, nImage ); } + + virtual PageElement* createPageElement( Element* pParent, + sal_Int32 nPageNr ) + { return new PageElement( pParent, nPageNr ); } + virtual DocumentElement* createDocumentElement() + { return new DocumentElement(); } + }; +} + +#endif diff --git a/sdext/source/pdfimport/tree/imagecontainer.hxx b/sdext/source/pdfimport/tree/imagecontainer.hxx new file mode 100644 index 000000000000..530bfe64b37c --- /dev/null +++ b/sdext/source/pdfimport/tree/imagecontainer.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: imagecontainer.hxx,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_PDFI_IMAGECONTAINER_HXX +#define INCLUDED_PDFI_IMAGECONTAINER_HXX + +#include "pdfihelper.hxx" + +#include +#include +#include +#include + +#include +#include + +namespace pdfi +{ + struct EmitContext; + + class ImageContainer + { + private: + std::vector< ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> > m_aImages; + + public: + ImageContainer(); + + ImageId addImage( const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue>& xBitmap ); + void writeBase64EncodedStream( ImageId nImageId, EmitContext& rContext ); + }; +} + +#endif + diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.hxx b/sdext/source/pdfimport/tree/pdfiprocessor.hxx new file mode 100644 index 000000000000..e8558386e0e0 --- /dev/null +++ b/sdext/source/pdfimport/tree/pdfiprocessor.hxx @@ -0,0 +1,295 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: pdfiprocessor.hxx,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#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 "imagecontainer.hxx" +#include "pdfihelper.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: + 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 >& ); + + /// 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 ); + void sortDocument( bool bDeep = false ); + void setWordSpace( double fWordSpace); + + private: + void processGlyphLine(); + void processGlyph( double fPreAvarageSpaceValue, + CharGlyph& rGlyph, + ParagraphElement* pPara, + FrameElement* pFrame, + bool bIsWhiteSpaceInLine ); + + void drawGlyphLine( const rtl::OUString& rGlyphs, + const ::com::sun::star::geometry::RealRectangle2D& rRect, + const ::com::sun::star::geometry::Matrix2D& rFontMatrix ); + + void drawCharGlyphs( rtl::OUString& rGlyphs, + ::com::sun::star::geometry::RealRectangle2D& rRect, + ::com::sun::star::geometry::Matrix2D& rFontMatrix, + GraphicsContext aGC, + Element* pCurElement, + ParagraphElement* pPara, + FrameElement* pFrame, + bool bSpaceFlag ); + + GraphicsContext& getTransformGlyphContex( 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 ::rtl::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 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 rtl::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 rtl::OUString& rText, sal_Int32 nElements = -1 ); + void endIndicator(); + + void setupImage(ImageId nImage); + + typedef std::hash_map IdToFontMap; + typedef std::hash_map FontToIdMap; + + typedef std::hash_map IdToGCMap; + typedef std::hash_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; + double m_fWordSpace; + bool m_bIsWhiteSpaceInLine; + com::sun::star::uno::Reference< + com::sun::star::task::XStatusIndicator > + m_xStatusIndicator; + + bool m_bHaveTextOnDocLevel; + }; + class CharGlyph + { + public: + CharGlyph(){}; + virtual ~CharGlyph(){}; + rtl::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; } + + void setGlyph (const rtl::OUString& rGlyphs ){ m_rGlyphs=rGlyphs; } + void setRect (const ::com::sun::star::geometry::RealRectangle2D& rRect ){ m_rRect=rRect; } + void setFontMatrix (const ::com::sun::star::geometry::Matrix2D& rFontMatrix ){ m_rFontMatrix= rFontMatrix; } + void setGraphicsContext (GraphicsContext& rCurrentContext ){ m_rCurrentContext= rCurrentContext; } + void setCurElement( Element* pCurElement ){ m_pCurElement= pCurElement; } + + double getYPrevGlyphPosition(){ return m_fYPrevGlyphPosition; } + double getXPrevGlyphPosition(){ return m_fXPrevGlyphPosition; } + double getPrevGlyphHeight (){ return m_fPrevGlyphHeight; } + double getPrevGlyphWidth (){ return m_fPrevGlyphWidth; } + double getPrevGlypthsSpace() { if( (m_rRect.X1-m_fXPrevGlyphPosition)<0 ) + return 0; + else + return m_rRect.X1-m_fXPrevGlyphPosition; + } + + void setYPrevGlyphPosition( double fYPrevTextPosition ){ m_fYPrevGlyphPosition= fYPrevTextPosition; } + void setXPrevGlyphPosition( double fXPrevTextPosition ){ m_fXPrevGlyphPosition= fXPrevTextPosition; } + void setPrevGlyphHeight ( double fPrevTextHeight ){ m_fPrevGlyphHeight= fPrevTextHeight; } + void setPrevGlyphWidth ( double fPrevTextWidth ){ m_fPrevGlyphWidth= fPrevTextWidth; } + + private: + + double m_fYPrevGlyphPosition ; + double m_fXPrevGlyphPosition ; + 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 ; + rtl::OUString m_rGlyphs ; + }; +} + +#define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) ) + +#endif diff --git a/sdext/source/pdfimport/tree/style.hxx b/sdext/source/pdfimport/tree/style.hxx new file mode 100644 index 000000000000..912f0707bcc1 --- /dev/null +++ b/sdext/source/pdfimport/tree/style.hxx @@ -0,0 +1,184 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: style.hxx,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_PDFI_STYLE_HXX +#define INCLUDED_PDFI_STYLE_HXX + +#include "pdfihelper.hxx" +#include +#include +#include +#include +#include "treevisiting.hxx" + +namespace pdfi +{ + struct Element; + struct EmitContext; + struct ElementTreeVisitable; + + class StyleContainer + { + public: + struct Style + { + rtl::OString Name; + PropertyMap Properties; + rtl::OUString Contents; + Element* ContainedElement; + std::vector< Style* > SubStyles; + + Style() : ContainedElement( NULL ) {} + Style( const rtl::OString& rName, const PropertyMap& rProps ) : + Name( rName ), + Properties( rProps ), + ContainedElement( NULL ) + {} + }; + + private: + struct HashedStyle + { + rtl::OString Name; + PropertyMap Properties; + rtl::OUString Contents; + Element* ContainedElement; + std::vector SubStyles; + + bool IsSubStyle; + sal_Int32 RefCount; + + HashedStyle() : ContainedElement( NULL ), IsSubStyle( true ), RefCount( 0 ) {} + + HashedStyle( const HashedStyle& rRight ) : + Name( rRight.Name ), + Properties( rRight.Properties ), + Contents( rRight.Contents ), + ContainedElement( rRight.ContainedElement ), + SubStyles( rRight.SubStyles ), + IsSubStyle( rRight.IsSubStyle ), + RefCount( 0 ) + {} + + size_t hashCode() const + { + size_t nRet = size_t(Name.hashCode()); + for( PropertyMap::const_iterator it = Properties.begin(); + it != Properties.end(); ++it ) + { + nRet ^= size_t(it->first.hashCode()); + nRet ^= size_t(it->second.hashCode()); + } + nRet = size_t(Contents.hashCode()); + nRet ^= size_t(ContainedElement); + for( unsigned int n = 0; n < SubStyles.size(); ++n ) + nRet ^= size_t(SubStyles[n]); + return nRet; + } + + bool operator==(const HashedStyle& rRight) const + { + if( Name != rRight.Name || + Properties != rRight.Properties || + Contents != rRight.Contents || + ContainedElement != rRight.ContainedElement || + SubStyles.size() != rRight.SubStyles.size() + ) + return false; + for( unsigned int n = 0; n < SubStyles.size(); ++n ) + { + if( SubStyles[n] != rRight.SubStyles[n] ) + return false; + } + return true; + } + }; + + struct StyleHash; + friend struct StyleHash; + struct StyleHash + { + size_t operator()( const StyleContainer::HashedStyle& rStyle ) const + { + return rStyle.hashCode(); + } + }; + + struct StyleIdNameSort; + friend struct StyleIdNameSort; + struct StyleIdNameSort + { + const std::hash_map< sal_Int32, HashedStyle >* m_pMap; + + StyleIdNameSort( const std::hash_map< sal_Int32, HashedStyle >* pMap ) : + m_pMap(pMap) + {} + bool operator()( sal_Int32 nLeft, sal_Int32 nRight ) + { + const std::hash_map< sal_Int32, HashedStyle >::const_iterator left_it = + m_pMap->find( nLeft ); + const std::hash_map< sal_Int32, HashedStyle >::const_iterator right_it = + m_pMap->find( nRight ); + if( left_it == m_pMap->end() ) + return false; + else if( right_it == m_pMap->end() ) + return true; + else + return left_it->second.Name < right_it->second.Name; + } + }; + + sal_Int32 m_nNextId; + std::hash_map< sal_Int32, HashedStyle > m_aIdToStyle; + std::hash_map< HashedStyle, sal_Int32, StyleHash > m_aStyleToId; + + void impl_emitStyle( sal_Int32 nStyleId, + EmitContext& rContext, + ElementTreeVisitor& rContainedElemVisitor ); + + public: + StyleContainer(); + + void emit( EmitContext& rContext, + ElementTreeVisitor& rContainedElemVisitor ); + + sal_Int32 impl_getStyleId( const Style& rStyle, bool bSubStyle ); + sal_Int32 getStyleId( const Style& rStyle ) + { return impl_getStyleId( rStyle, false ); } + + // returns NULL for an invalid style id + const PropertyMap* getProperties( sal_Int32 nStyleId ) const; + sal_Int32 setProperties( sal_Int32 nStyleId, const PropertyMap &rNewProps ); + rtl::OUString getStyleName( sal_Int32 nStyle ) const; + }; +} + +#endif diff --git a/sdext/source/pdfimport/tree/treevisiting.hxx b/sdext/source/pdfimport/tree/treevisiting.hxx new file mode 100644 index 000000000000..0aba4cd547cb --- /dev/null +++ b/sdext/source/pdfimport/tree/treevisiting.hxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: treevisiting.hxx,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_PDFI_TREEVISITING_HXX +#define INCLUDED_PDFI_TREEVISITING_HXX + +#include +#include + + +namespace pdfi +{ + class PDFIProcessor; + class StyleContainer; + struct HyperlinkElement; + struct TextElement; + struct ParagraphElement; + struct FrameElement; + struct PolyPolyElement; + struct ImageElement; + struct PageElement; + struct DocumentElement; + struct EmitContext; + struct Element; + + /** To be visited by all tree element types + + Visitor interface from the "visitor pattern". Implementor gets + called with actual tree node instances. + */ + struct ElementTreeVisitor + { + virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) = 0; + virtual void visit( TextElement&, const std::list< Element* >::const_iterator& ) = 0; + virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& ) = 0; + virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& ) = 0; + virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& ) = 0; + virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& ) = 0; + virtual void visit( PageElement&, const std::list< Element* >::const_iterator& ) = 0; + virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& ) = 0; + }; + typedef boost::shared_ptr ElementTreeVisitorSharedPtr; + + /** Visitee interface + + To be implemented by every tree node that needs to be + visitable. + */ + struct ElementTreeVisitable + { + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) = 0; + }; + typedef boost::shared_ptr ElementTreeVisitableSharedPtr; +} + +#endif diff --git a/sdext/source/pdfimport/tree/writertreevisiting.hxx b/sdext/source/pdfimport/tree/writertreevisiting.hxx new file mode 100644 index 000000000000..a02dcc6d6712 --- /dev/null +++ b/sdext/source/pdfimport/tree/writertreevisiting.hxx @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: writertreevisiting.hxx,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_PDFI_WRITERTREEVISITING_HXX +#define INCLUDED_PDFI_WRITERTREEVISITING_HXX + +#include "treevisiting.hxx" + +namespace pdfi +{ + struct DrawElement; + + class WriterXmlOptimizer : public ElementTreeVisitor + { + private: + PDFIProcessor& m_rProcessor; + void optimizeTextElements(Element& rParent); + void checkHeaderAndFooter( PageElement& rElem ); + + public: + explicit WriterXmlOptimizer(PDFIProcessor& rProcessor) : + m_rProcessor(rProcessor) + {} + virtual ~WriterXmlOptimizer() + {} + + virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( TextElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& ); + }; + + class WriterXmlFinalizer : public ElementTreeVisitor + { + private: + StyleContainer& m_rStyleContainer; + PDFIProcessor& m_rProcessor; + + void setFirstOnPage( ParagraphElement& rElem, + StyleContainer& rStyles, + const rtl::OUString& rMasterPageName ); + + public: + explicit WriterXmlFinalizer(StyleContainer& rStyleContainer, + PDFIProcessor& rProcessor) : + m_rStyleContainer(rStyleContainer), + m_rProcessor(rProcessor) + {} + virtual ~WriterXmlFinalizer() + {} + + virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( TextElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& ); + }; + + class WriterXmlEmitter : public ElementTreeVisitor + { + private: + EmitContext& m_rEmitContext ; + void fillFrameProps( DrawElement& rElem, + PropertyMap& rProps, + const EmitContext& rEmitContext ); + + public: + explicit WriterXmlEmitter(EmitContext& rEmitContext) : + m_rEmitContext(rEmitContext) + {} + virtual ~WriterXmlEmitter() + {} + + virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( TextElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( PageElement&, const std::list< Element* >::const_iterator& ); + virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& ); + }; +} + +#endif -- cgit v1.2.3