From b8c6a3486bb11c61539a19ae72fc938f67e9470e Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 16 Oct 2017 22:46:05 +0200 Subject: Move sdext/source/pdfimport/tree include files to common include directory ...that are included from various source directories. Change done in preparation of loplugin:includeform. Change-Id: Ie46f4b940ceeb34fd8883dc17f56a072f625ee3a Reviewed-on: https://gerrit.libreoffice.org/43442 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- sdext/source/pdfimport/inc/genericelements.hxx | 320 ++++++++++++++++++++++++ sdext/source/pdfimport/inc/imagecontainer.hxx | 52 ++++ sdext/source/pdfimport/inc/pdfiprocessor.hxx | 221 ++++++++++++++++ sdext/source/pdfimport/inc/treevisiting.hxx | 62 +++++ sdext/source/pdfimport/pdfiadaptor.cxx | 2 +- sdext/source/pdfimport/tree/genericelements.hxx | 320 ------------------------ sdext/source/pdfimport/tree/imagecontainer.hxx | 52 ---- sdext/source/pdfimport/tree/pdfiprocessor.hxx | 221 ---------------- sdext/source/pdfimport/tree/treevisiting.hxx | 62 ----- 9 files changed, 656 insertions(+), 656 deletions(-) create mode 100644 sdext/source/pdfimport/inc/genericelements.hxx create mode 100644 sdext/source/pdfimport/inc/imagecontainer.hxx create mode 100644 sdext/source/pdfimport/inc/pdfiprocessor.hxx create mode 100644 sdext/source/pdfimport/inc/treevisiting.hxx delete mode 100644 sdext/source/pdfimport/tree/genericelements.hxx delete mode 100644 sdext/source/pdfimport/tree/imagecontainer.hxx delete mode 100644 sdext/source/pdfimport/tree/pdfiprocessor.hxx delete mode 100644 sdext/source/pdfimport/tree/treevisiting.hxx (limited to 'sdext') diff --git a/sdext/source/pdfimport/inc/genericelements.hxx b/sdext/source/pdfimport/inc/genericelements.hxx new file mode 100644 index 000000000000..9a5db64016fd --- /dev/null +++ b/sdext/source/pdfimport/inc/genericelements.hxx @@ -0,0 +1,320 @@ +/* -*- 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_SDEXT_SOURCE_PDFIMPORT_INC_GENERICELEMENTS_HXX +#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_GENERICELEMENTS_HXX + +#include "pdfihelper.hxx" +#include "treevisiting.hxx" + +#include +#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 css::uno::Reference< + css::task::XStatusIndicator>& _xStatusIndicator, + css::uno::Reference< css::uno::XComponentContext > const & xContext) + : + rEmitter(_rEmitter), + rStyles(_rStyles), + rImages(_rImages), + rProcessor(_rProcessor), + xStatusIndicator(_xStatusIndicator), + m_xContext(xContext) + {} + + XmlEmitter& rEmitter; + StyleContainer& rStyles; + ImageContainer& rImages; + PDFIProcessor& rProcessor; + css::uno::Reference< + css::task::XStatusIndicator> xStatusIndicator; + css::uno::Reference< + css::uno::XComponentContext > m_xContext; + }; + + struct Element + { + protected: + explicit 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(); + + /** + To be implemented by every tree node that needs to be + visitable. + */ + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) = 0; + /// Apply visitor to all children + void applyToChildren( ElementTreeVisitor& ); + /// Union element geometry with given element + void updateGeometryWith( const Element* pMergeFrom ); + +#if OSL_DEBUG_LEVEL > 0 + // xxx refac TODO: move code to visitor + virtual void emitStructure( int nLevel ); +#endif + /** el must be a valid dereferenceable iterator of el->Parent->Children + pNewParent must not be NULL + */ + static void setParent( std::list::iterator const & el, Element* pNewParent ); + + double x, y, w, h; + sal_Int32 StyleId; + Element* Parent; + std::list Children; + }; + + struct ListElement : public Element + { + ListElement() : Element( nullptr ) {} + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; + }; + + struct HyperlinkElement : public Element + { + friend class ElementFactory; + protected: + HyperlinkElement( Element* pParent, const OUString& rURI ) + : Element( pParent ), URI( rURI ) {} + public: + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; + + OUString URI; + }; + + struct GraphicalElement : public Element + { + protected: + GraphicalElement(Element* pParent, sal_Int32 nGCId) + : Element(pParent) + , GCId(nGCId) + , MirrorVertical(false) + , IsForText(false) + , FontSize(0.0) + , TextStyleId(0) + { + } + + public: + sal_Int32 GCId; + bool MirrorVertical; + bool IsForText; + double FontSize; + sal_Int32 TextStyleId; + }; + + 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: + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; + }; + + struct TextElement : public GraphicalElement + { + friend class ElementFactory; + protected: + TextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId ) + : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {} + + public: + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; + + OUStringBuffer Text; + sal_Int32 FontId; + }; + + struct ParagraphElement : public Element + { + friend class ElementFactory; + protected: + explicit ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ), bRtl( false ) {} + + public: + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override; + + // returns true only if only a single line is contained + bool isSingleLined( PDFIProcessor const & 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; + bool bRtl; + }; + + struct PolyPolyElement : public DrawElement + { + friend class ElementFactory; + protected: + PolyPolyElement( Element* pParent, sal_Int32 nGCId, + const basegfx::B2DPolyPolygon& rPolyPoly, + sal_Int8 nAction ); + public: + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override; + + void updateGeometry(); + +#if OSL_DEBUG_LEVEL > 0 + virtual void emitStructure( int nLevel ) override; +#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: + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; + + 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( nullptr ), FooterElement( nullptr ) + {} + private: + // helper method for resolveHyperlinks + bool resolveHyperlink( const std::list::iterator& link_it, std::list& rElements ); + public: + virtual ~PageElement() override; + + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override; + + static void updateParagraphGeometry( Element* pEle ); + void resolveHyperlinks(); + void resolveFontStyles( PDFIProcessor const & rProc ); + void resolveUnderlines( PDFIProcessor const & 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( nullptr ) {} + public: + virtual ~DocumentElement() override; + + virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; + }; + + // 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() = delete; + + static HyperlinkElement* createHyperlinkElement( Element* pParent, const OUString& rURI ) + { return new HyperlinkElement( pParent, rURI ); } + + static TextElement* createTextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId ) + { return new TextElement( pParent, nGCId, nFontId ); } + static ParagraphElement* createParagraphElement( Element* pParent ) + { return new ParagraphElement( pParent ); } + + static FrameElement* createFrameElement( Element* pParent, sal_Int32 nGCId ) + { return new FrameElement( pParent, nGCId ); } + static PolyPolyElement* + createPolyPolyElement( Element* pParent, + sal_Int32 nGCId, + const basegfx::B2DPolyPolygon& rPolyPoly, + sal_Int8 nAction) + { return new PolyPolyElement( pParent, nGCId, rPolyPoly, nAction ); } + static ImageElement* createImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage ) + { return new ImageElement( pParent, nGCId, nImage ); } + + static PageElement* createPageElement( Element* pParent, + sal_Int32 nPageNr ) + { return new PageElement( pParent, nPageNr ); } + static DocumentElement* createDocumentElement() + { return new DocumentElement(); } + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/source/pdfimport/inc/imagecontainer.hxx b/sdext/source/pdfimport/inc/imagecontainer.hxx new file mode 100644 index 000000000000..2c7af596f441 --- /dev/null +++ b/sdext/source/pdfimport/inc/imagecontainer.hxx @@ -0,0 +1,52 @@ +/* -*- 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_SDEXT_SOURCE_PDFIMPORT_INC_IMAGECONTAINER_HXX +#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_IMAGECONTAINER_HXX + +#include "pdfihelper.hxx" + +#include +#include +#include + +#include + +namespace pdfi +{ + struct EmitContext; + + class ImageContainer + { + private: + std::vector< css::uno::Sequence< + css::beans::PropertyValue> > m_aImages; + + public: + ImageContainer(); + + ImageId addImage( const css::uno::Sequence< + css::beans::PropertyValue>& xBitmap ); + void writeBase64EncodedStream( ImageId nImageId, EmitContext& rContext ); + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/source/pdfimport/inc/pdfiprocessor.hxx b/sdext/source/pdfimport/inc/pdfiprocessor.hxx new file mode 100644 index 000000000000..fae6c0fc5382 --- /dev/null +++ b/sdext/source/pdfimport/inc/pdfiprocessor.hxx @@ -0,0 +1,221 @@ +/* -*- 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_SDEXT_SOURCE_PDFIMPORT_INC_PDFIPROCESSOR_HXX +#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIPROCESSOR_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: + css::uno::Reference< + css::uno::XComponentContext > m_xContext; + basegfx::B2DHomMatrix prevTextMatrix; + double prevCharWidth; + enum DocumentTextDirecion { LrTb, RlTb, TbLr }; + + explicit PDFIProcessor( const css::uno::Reference< css::task::XStatusIndicator >& xStat, + css::uno::Reference< css::uno::XComponentContext > const & xContext) ; + + 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(); } + + const css::uno::Reference< css::task::XStatusIndicator >& getStatusIndicator() const + { return m_xStatusIndicator; } + + const FontAttributes& getFont( sal_Int32 nFontId ) const; + sal_Int32 getFontId( const FontAttributes& rAttr ) const; + + void sortElements( Element* pElement, bool bDeep = false ); + + static OUString mirrorString( const OUString& i_rInString ); + + private: + void processGlyphLine(); + + // ContentSink interface implementation + + virtual void setPageNum( sal_Int32 nNumPages ) override; + virtual void startPage( const css::geometry::RealSize2D& rSize ) override; + virtual void endPage() override; + + virtual void hyperLink( const css::geometry::RealRectangle2D& rBounds, + const OUString& rURI ) override; + virtual void pushState() override; + virtual void popState() override; + virtual void setFlatness( double ) override; + virtual void setTransformation( const css::geometry::AffineMatrix2D& rMatrix ) override; + virtual void setLineDash( const css::uno::Sequence& dashes, + double start ) override; + virtual void setLineJoin(sal_Int8) override; + virtual void setLineCap(sal_Int8) override; + virtual void setMiterLimit(double) override; + virtual void setLineWidth(double) override; + virtual void setFillColor( const css::rendering::ARGBColor& rColor ) override; + virtual void setStrokeColor( const css::rendering::ARGBColor& rColor ) override; + virtual void setFont( const FontAttributes& rFont ) override; + virtual void setTextRenderMode( sal_Int32 ) override; + + virtual void strokePath( const css::uno::Reference< + css::rendering::XPolyPolygon2D >& rPath ) override; + virtual void fillPath( const css::uno::Reference< + css::rendering::XPolyPolygon2D >& rPath ) override; + virtual void eoFillPath( const css::uno::Reference< + css::rendering::XPolyPolygon2D >& rPath ) override; + + virtual void intersectClip(const css::uno::Reference< + css::rendering::XPolyPolygon2D >& rPath) override; + virtual void intersectEoClip(const css::uno::Reference< + css::rendering::XPolyPolygon2D >& rPath) override; + + virtual void drawGlyphs( const OUString& rGlyphs, + const css::geometry::RealRectangle2D& rRect, + const css::geometry::Matrix2D& rFontMatrix, + double fontSize) override; + virtual void endText() override; + + virtual void drawMask(const css::uno::Sequence< + css::beans::PropertyValue>& xBitmap, + bool bInvert ) override; + /// Given image must already be color-mapped and normalized to sRGB. + virtual void drawImage(const css::uno::Sequence< + css::beans::PropertyValue>& xBitmap ) override; + /** Given image must already be color-mapped and normalized to sRGB. + + maskColors must contain two sequences of color components + */ + virtual void drawColorMaskedImage(const css::uno::Sequence< + css::beans::PropertyValue>& xBitmap, + const css::uno::Sequence< + css::uno::Any>& xMaskColors ) override; + virtual void drawMaskedImage(const css::uno::Sequence< + css::beans::PropertyValue>& xBitmap, + const css::uno::Sequence< + css::beans::PropertyValue>& xMask, + bool bInvertMask) override; + virtual void drawAlphaMaskedImage(const css::uno::Sequence< + css::beans::PropertyValue>& xImage, + const css::uno::Sequence< + css::beans::PropertyValue>& xMask) override; + + void startIndicator( const OUString& rText ); + void endIndicator(); + + void setupImage(ImageId nImage); + + typedef std::unordered_map IdToFontMap; + typedef std::unordered_map FontToIdMap; + + typedef std::unordered_map IdToGCMap; + typedef std::unordered_map GCToIdMap; + + typedef std::vector GraphicsContextStack; + + std::vector m_GlyphsList; + + std::shared_ptr m_pDocument; + PageElement* m_pCurPage; + Element* m_pCurElement; + sal_Int32 m_nNextFontId; + IdToFontMap m_aIdToFont; + FontToIdMap m_aFontToId; + + GraphicsContextStack m_aGCStack; + sal_Int32 m_nNextGCId; + IdToGCMap m_aIdToGC; + GCToIdMap m_aGCToId; + + ImageContainer m_aImages; + + sal_Int32 m_nPages; + sal_Int32 m_nNextZOrder; + css::uno::Reference< css::task::XStatusIndicator > + m_xStatusIndicator; + }; + class CharGlyph final + { + public: + CharGlyph(Element* pCurElement, const GraphicsContext& rCurrentContext, + double width, double prevSpaceWidth, const OUString& rGlyphs ) + : m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext), + m_Width(width), m_PrevSpaceWidth(prevSpaceWidth), m_rGlyphs(rGlyphs) {}; + + OUString& getGlyph(){ return m_rGlyphs; } + double getWidth(){ return m_Width; } + double getPrevSpaceWidth(){ return m_PrevSpaceWidth; } + GraphicsContext& getGC(){ return m_rCurrentContext; } + Element* getCurElement(){ return m_pCurElement; } + + private: + Element* m_pCurElement ; + GraphicsContext m_rCurrentContext ; + double m_Width ; + double m_PrevSpaceWidth ; + OUString m_rGlyphs ; + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/source/pdfimport/inc/treevisiting.hxx b/sdext/source/pdfimport/inc/treevisiting.hxx new file mode 100644 index 000000000000..ec6d429d2ab9 --- /dev/null +++ b/sdext/source/pdfimport/inc/treevisiting.hxx @@ -0,0 +1,62 @@ +/* -*- 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_SDEXT_SOURCE_PDFIMPORT_INC_TREEVISITING_HXX +#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_TREEVISITING_HXX + +#include +#include + + +namespace pdfi +{ + struct HyperlinkElement; + struct TextElement; + struct ParagraphElement; + struct FrameElement; + struct PolyPolyElement; + struct ImageElement; + struct PageElement; + struct DocumentElement; + 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; + virtual ~ElementTreeVisitor() {} + }; + typedef std::shared_ptr ElementTreeVisitorSharedPtr; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/source/pdfimport/pdfiadaptor.cxx b/sdext/source/pdfimport/pdfiadaptor.cxx index 7553aafc914f..badcb5a3f67b 100644 --- a/sdext/source/pdfimport/pdfiadaptor.cxx +++ b/sdext/source/pdfimport/pdfiadaptor.cxx @@ -24,7 +24,7 @@ #include "odfemitter.hxx" #include "inc/wrapper.hxx" #include "inc/contentsink.hxx" -#include "tree/pdfiprocessor.hxx" +#include "pdfiprocessor.hxx" #include #include diff --git a/sdext/source/pdfimport/tree/genericelements.hxx b/sdext/source/pdfimport/tree/genericelements.hxx deleted file mode 100644 index 3d2703768ae1..000000000000 --- a/sdext/source/pdfimport/tree/genericelements.hxx +++ /dev/null @@ -1,320 +0,0 @@ -/* -*- 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_SDEXT_SOURCE_PDFIMPORT_TREE_GENERICELEMENTS_HXX -#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_GENERICELEMENTS_HXX - -#include "pdfihelper.hxx" -#include "treevisiting.hxx" - -#include -#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 css::uno::Reference< - css::task::XStatusIndicator>& _xStatusIndicator, - css::uno::Reference< css::uno::XComponentContext > const & xContext) - : - rEmitter(_rEmitter), - rStyles(_rStyles), - rImages(_rImages), - rProcessor(_rProcessor), - xStatusIndicator(_xStatusIndicator), - m_xContext(xContext) - {} - - XmlEmitter& rEmitter; - StyleContainer& rStyles; - ImageContainer& rImages; - PDFIProcessor& rProcessor; - css::uno::Reference< - css::task::XStatusIndicator> xStatusIndicator; - css::uno::Reference< - css::uno::XComponentContext > m_xContext; - }; - - struct Element - { - protected: - explicit 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(); - - /** - To be implemented by every tree node that needs to be - visitable. - */ - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) = 0; - /// Apply visitor to all children - void applyToChildren( ElementTreeVisitor& ); - /// Union element geometry with given element - void updateGeometryWith( const Element* pMergeFrom ); - -#if OSL_DEBUG_LEVEL > 0 - // xxx refac TODO: move code to visitor - virtual void emitStructure( int nLevel ); -#endif - /** el must be a valid dereferenceable iterator of el->Parent->Children - pNewParent must not be NULL - */ - static void setParent( std::list::iterator const & el, Element* pNewParent ); - - double x, y, w, h; - sal_Int32 StyleId; - Element* Parent; - std::list Children; - }; - - struct ListElement : public Element - { - ListElement() : Element( nullptr ) {} - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; - }; - - struct HyperlinkElement : public Element - { - friend class ElementFactory; - protected: - HyperlinkElement( Element* pParent, const OUString& rURI ) - : Element( pParent ), URI( rURI ) {} - public: - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; - - OUString URI; - }; - - struct GraphicalElement : public Element - { - protected: - GraphicalElement(Element* pParent, sal_Int32 nGCId) - : Element(pParent) - , GCId(nGCId) - , MirrorVertical(false) - , IsForText(false) - , FontSize(0.0) - , TextStyleId(0) - { - } - - public: - sal_Int32 GCId; - bool MirrorVertical; - bool IsForText; - double FontSize; - sal_Int32 TextStyleId; - }; - - 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: - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; - }; - - struct TextElement : public GraphicalElement - { - friend class ElementFactory; - protected: - TextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId ) - : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {} - - public: - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; - - OUStringBuffer Text; - sal_Int32 FontId; - }; - - struct ParagraphElement : public Element - { - friend class ElementFactory; - protected: - explicit ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ), bRtl( false ) {} - - public: - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override; - - // returns true only if only a single line is contained - bool isSingleLined( PDFIProcessor const & 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; - bool bRtl; - }; - - struct PolyPolyElement : public DrawElement - { - friend class ElementFactory; - protected: - PolyPolyElement( Element* pParent, sal_Int32 nGCId, - const basegfx::B2DPolyPolygon& rPolyPoly, - sal_Int8 nAction ); - public: - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override; - - void updateGeometry(); - -#if OSL_DEBUG_LEVEL > 0 - virtual void emitStructure( int nLevel ) override; -#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: - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; - - 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( nullptr ), FooterElement( nullptr ) - {} - private: - // helper method for resolveHyperlinks - bool resolveHyperlink( const std::list::iterator& link_it, std::list& rElements ); - public: - virtual ~PageElement() override; - - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override; - - static void updateParagraphGeometry( Element* pEle ); - void resolveHyperlinks(); - void resolveFontStyles( PDFIProcessor const & rProc ); - void resolveUnderlines( PDFIProcessor const & 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( nullptr ) {} - public: - virtual ~DocumentElement() override; - - virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override; - }; - - // 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() = delete; - - static HyperlinkElement* createHyperlinkElement( Element* pParent, const OUString& rURI ) - { return new HyperlinkElement( pParent, rURI ); } - - static TextElement* createTextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId ) - { return new TextElement( pParent, nGCId, nFontId ); } - static ParagraphElement* createParagraphElement( Element* pParent ) - { return new ParagraphElement( pParent ); } - - static FrameElement* createFrameElement( Element* pParent, sal_Int32 nGCId ) - { return new FrameElement( pParent, nGCId ); } - static PolyPolyElement* - createPolyPolyElement( Element* pParent, - sal_Int32 nGCId, - const basegfx::B2DPolyPolygon& rPolyPoly, - sal_Int8 nAction) - { return new PolyPolyElement( pParent, nGCId, rPolyPoly, nAction ); } - static ImageElement* createImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage ) - { return new ImageElement( pParent, nGCId, nImage ); } - - static PageElement* createPageElement( Element* pParent, - sal_Int32 nPageNr ) - { return new PageElement( pParent, nPageNr ); } - static DocumentElement* createDocumentElement() - { return new DocumentElement(); } - }; -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/source/pdfimport/tree/imagecontainer.hxx b/sdext/source/pdfimport/tree/imagecontainer.hxx deleted file mode 100644 index a24b2f9a02b5..000000000000 --- a/sdext/source/pdfimport/tree/imagecontainer.hxx +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- 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_SDEXT_SOURCE_PDFIMPORT_TREE_IMAGECONTAINER_HXX -#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_IMAGECONTAINER_HXX - -#include "pdfihelper.hxx" - -#include -#include -#include - -#include - -namespace pdfi -{ - struct EmitContext; - - class ImageContainer - { - private: - std::vector< css::uno::Sequence< - css::beans::PropertyValue> > m_aImages; - - public: - ImageContainer(); - - ImageId addImage( const css::uno::Sequence< - css::beans::PropertyValue>& xBitmap ); - void writeBase64EncodedStream( ImageId nImageId, EmitContext& rContext ); - }; -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.hxx b/sdext/source/pdfimport/tree/pdfiprocessor.hxx deleted file mode 100644 index 81facadfd9fd..000000000000 --- a/sdext/source/pdfimport/tree/pdfiprocessor.hxx +++ /dev/null @@ -1,221 +0,0 @@ -/* -*- 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_SDEXT_SOURCE_PDFIMPORT_TREE_PDFIPROCESSOR_HXX -#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_PDFIPROCESSOR_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: - css::uno::Reference< - css::uno::XComponentContext > m_xContext; - basegfx::B2DHomMatrix prevTextMatrix; - double prevCharWidth; - enum DocumentTextDirecion { LrTb, RlTb, TbLr }; - - explicit PDFIProcessor( const css::uno::Reference< css::task::XStatusIndicator >& xStat, - css::uno::Reference< css::uno::XComponentContext > const & xContext) ; - - 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(); } - - const css::uno::Reference< css::task::XStatusIndicator >& getStatusIndicator() const - { return m_xStatusIndicator; } - - const FontAttributes& getFont( sal_Int32 nFontId ) const; - sal_Int32 getFontId( const FontAttributes& rAttr ) const; - - void sortElements( Element* pElement, bool bDeep = false ); - - static OUString mirrorString( const OUString& i_rInString ); - - private: - void processGlyphLine(); - - // ContentSink interface implementation - - virtual void setPageNum( sal_Int32 nNumPages ) override; - virtual void startPage( const css::geometry::RealSize2D& rSize ) override; - virtual void endPage() override; - - virtual void hyperLink( const css::geometry::RealRectangle2D& rBounds, - const OUString& rURI ) override; - virtual void pushState() override; - virtual void popState() override; - virtual void setFlatness( double ) override; - virtual void setTransformation( const css::geometry::AffineMatrix2D& rMatrix ) override; - virtual void setLineDash( const css::uno::Sequence& dashes, - double start ) override; - virtual void setLineJoin(sal_Int8) override; - virtual void setLineCap(sal_Int8) override; - virtual void setMiterLimit(double) override; - virtual void setLineWidth(double) override; - virtual void setFillColor( const css::rendering::ARGBColor& rColor ) override; - virtual void setStrokeColor( const css::rendering::ARGBColor& rColor ) override; - virtual void setFont( const FontAttributes& rFont ) override; - virtual void setTextRenderMode( sal_Int32 ) override; - - virtual void strokePath( const css::uno::Reference< - css::rendering::XPolyPolygon2D >& rPath ) override; - virtual void fillPath( const css::uno::Reference< - css::rendering::XPolyPolygon2D >& rPath ) override; - virtual void eoFillPath( const css::uno::Reference< - css::rendering::XPolyPolygon2D >& rPath ) override; - - virtual void intersectClip(const css::uno::Reference< - css::rendering::XPolyPolygon2D >& rPath) override; - virtual void intersectEoClip(const css::uno::Reference< - css::rendering::XPolyPolygon2D >& rPath) override; - - virtual void drawGlyphs( const OUString& rGlyphs, - const css::geometry::RealRectangle2D& rRect, - const css::geometry::Matrix2D& rFontMatrix, - double fontSize) override; - virtual void endText() override; - - virtual void drawMask(const css::uno::Sequence< - css::beans::PropertyValue>& xBitmap, - bool bInvert ) override; - /// Given image must already be color-mapped and normalized to sRGB. - virtual void drawImage(const css::uno::Sequence< - css::beans::PropertyValue>& xBitmap ) override; - /** Given image must already be color-mapped and normalized to sRGB. - - maskColors must contain two sequences of color components - */ - virtual void drawColorMaskedImage(const css::uno::Sequence< - css::beans::PropertyValue>& xBitmap, - const css::uno::Sequence< - css::uno::Any>& xMaskColors ) override; - virtual void drawMaskedImage(const css::uno::Sequence< - css::beans::PropertyValue>& xBitmap, - const css::uno::Sequence< - css::beans::PropertyValue>& xMask, - bool bInvertMask) override; - virtual void drawAlphaMaskedImage(const css::uno::Sequence< - css::beans::PropertyValue>& xImage, - const css::uno::Sequence< - css::beans::PropertyValue>& xMask) override; - - void startIndicator( const OUString& rText ); - void endIndicator(); - - void setupImage(ImageId nImage); - - typedef std::unordered_map IdToFontMap; - typedef std::unordered_map FontToIdMap; - - typedef std::unordered_map IdToGCMap; - typedef std::unordered_map GCToIdMap; - - typedef std::vector GraphicsContextStack; - - std::vector m_GlyphsList; - - std::shared_ptr m_pDocument; - PageElement* m_pCurPage; - Element* m_pCurElement; - sal_Int32 m_nNextFontId; - IdToFontMap m_aIdToFont; - FontToIdMap m_aFontToId; - - GraphicsContextStack m_aGCStack; - sal_Int32 m_nNextGCId; - IdToGCMap m_aIdToGC; - GCToIdMap m_aGCToId; - - ImageContainer m_aImages; - - sal_Int32 m_nPages; - sal_Int32 m_nNextZOrder; - css::uno::Reference< css::task::XStatusIndicator > - m_xStatusIndicator; - }; - class CharGlyph final - { - public: - CharGlyph(Element* pCurElement, const GraphicsContext& rCurrentContext, - double width, double prevSpaceWidth, const OUString& rGlyphs ) - : m_pCurElement(pCurElement), m_rCurrentContext(rCurrentContext), - m_Width(width), m_PrevSpaceWidth(prevSpaceWidth), m_rGlyphs(rGlyphs) {}; - - OUString& getGlyph(){ return m_rGlyphs; } - double getWidth(){ return m_Width; } - double getPrevSpaceWidth(){ return m_PrevSpaceWidth; } - GraphicsContext& getGC(){ return m_rCurrentContext; } - Element* getCurElement(){ return m_pCurElement; } - - private: - Element* m_pCurElement ; - GraphicsContext m_rCurrentContext ; - double m_Width ; - double m_PrevSpaceWidth ; - OUString m_rGlyphs ; - }; -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/source/pdfimport/tree/treevisiting.hxx b/sdext/source/pdfimport/tree/treevisiting.hxx deleted file mode 100644 index 97a3f18f6f58..000000000000 --- a/sdext/source/pdfimport/tree/treevisiting.hxx +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- 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_SDEXT_SOURCE_PDFIMPORT_TREE_TREEVISITING_HXX -#define INCLUDED_SDEXT_SOURCE_PDFIMPORT_TREE_TREEVISITING_HXX - -#include -#include - - -namespace pdfi -{ - struct HyperlinkElement; - struct TextElement; - struct ParagraphElement; - struct FrameElement; - struct PolyPolyElement; - struct ImageElement; - struct PageElement; - struct DocumentElement; - 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; - virtual ~ElementTreeVisitor() {} - }; - typedef std::shared_ptr ElementTreeVisitorSharedPtr; - -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3