vcl/source/gdi/pdfwriter_impl.cxx | 36 +++++----- vcl/source/gdi/pdfwriter_impl.hxx | 128 +++++++++++++++++++------------------- 2 files changed, 84 insertions(+), 80 deletions(-)
New commits: commit 166390fdf1a09329b9b218fa7e5b8a142f87e728 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Dec 30 09:45:32 2019 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Dec 30 14:31:09 2019 +0100 pdf: move PDFPage out of PDFWriterImpl into vcl::pdf namespace Change-Id: Ia3a092d53b8c3cbbbbad785222868c5c259419c2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85993 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 4c02c41717af..7cb77f2f60c4 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -566,7 +566,7 @@ public: void translate( double tx, double ty ); void invert(); - void append( PDFWriterImpl::PDFPage const & rPage, OStringBuffer& rBuffer ); + void append( PDFPage const & rPage, OStringBuffer& rBuffer ); Point transform( const Point& rPoint ) const; }; @@ -670,7 +670,7 @@ void Matrix3::invert() set( fn ); } -void Matrix3::append( PDFWriterImpl::PDFPage const & rPage, OStringBuffer& rBuffer ) +void Matrix3::append( PDFPage const & rPage, OStringBuffer& rBuffer ) { appendDouble( f[0], rBuffer ); rBuffer.append( ' ' ); @@ -683,7 +683,7 @@ void Matrix3::append( PDFWriterImpl::PDFPage const & rPage, OStringBuffer& rBuff rPage.appendPoint( Point( static_cast<long>(f[4]), static_cast<long>(f[5]) ), rBuffer ); } -PDFWriterImpl::PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, double nPageHeight, PDFWriter::Orientation eOrientation ) +PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, double nPageHeight, PDFWriter::Orientation eOrientation ) : m_pWriter( pWriter ), m_nPageWidth( nPageWidth ), @@ -699,7 +699,7 @@ PDFWriterImpl::PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, doub m_nPageObject = m_pWriter->createObject(); } -void PDFWriterImpl::PDFPage::beginStream() +void PDFPage::beginStream() { if (g_bDebugDisableCompression) { @@ -731,7 +731,7 @@ void PDFWriterImpl::PDFPage::beginStream() m_pWriter->checkAndEnableStreamEncryption( m_aStreamObjects.back() ); } -void PDFWriterImpl::PDFPage::endStream() +void PDFPage::endStream() { if (!g_bDebugDisableCompression) m_pWriter->endCompression(); @@ -756,7 +756,7 @@ void PDFWriterImpl::PDFPage::endStream() m_pWriter->writeBuffer( aLine.getStr(), aLine.getLength() ); } -bool PDFWriterImpl::PDFPage::emit(sal_Int32 nParentObject ) +bool PDFPage::emit(sal_Int32 nParentObject ) { // emit page object if( ! m_pWriter->updateObject( m_nPageObject ) ) @@ -917,7 +917,7 @@ static GEOMETRY lcl_convert( const MapMode& _rSource, const MapMode& _rDest, Out } } -void PDFWriterImpl::PDFPage::appendPoint( const Point& rPoint, OStringBuffer& rBuffer ) const +void PDFPage::appendPoint( const Point& rPoint, OStringBuffer& rBuffer ) const { Point aPoint( lcl_convert( m_pWriter->m_aGraphicsStack.front().m_aMapMode, m_pWriter->m_aMapMode, @@ -935,7 +935,7 @@ void PDFWriterImpl::PDFPage::appendPoint( const Point& rPoint, OStringBuffer& rB appendFixedInt( nValue, rBuffer ); } -void PDFWriterImpl::PDFPage::appendPixelPoint( const basegfx::B2DPoint& rPoint, OStringBuffer& rBuffer ) const +void PDFPage::appendPixelPoint( const basegfx::B2DPoint& rPoint, OStringBuffer& rBuffer ) const { double fValue = pixelToPoint(rPoint.getX()); @@ -945,7 +945,7 @@ void PDFWriterImpl::PDFPage::appendPixelPoint( const basegfx::B2DPoint& rPoint, appendDouble( fValue, rBuffer, nLog10Divisor ); } -void PDFWriterImpl::PDFPage::appendRect( const tools::Rectangle& rRect, OStringBuffer& rBuffer ) const +void PDFPage::appendRect( const tools::Rectangle& rRect, OStringBuffer& rBuffer ) const { appendPoint( rRect.BottomLeft() + Point( 0, 1 ), rBuffer ); rBuffer.append( ' ' ); @@ -955,7 +955,7 @@ void PDFWriterImpl::PDFPage::appendRect( const tools::Rectangle& rRect, OStringB rBuffer.append( " re" ); } -void PDFWriterImpl::PDFPage::convertRect( tools::Rectangle& rRect ) const +void PDFPage::convertRect( tools::Rectangle& rRect ) const { Point aLL = lcl_convert( m_pWriter->m_aGraphicsStack.front().m_aMapMode, m_pWriter->m_aMapMode, @@ -972,7 +972,7 @@ void PDFWriterImpl::PDFPage::convertRect( tools::Rectangle& rRect ) const rRect.SetBottom( rRect.Top() + aSize.Height() ); } -void PDFWriterImpl::PDFPage::appendPolygon( const tools::Polygon& rPoly, OStringBuffer& rBuffer, bool bClose ) const +void PDFPage::appendPolygon( const tools::Polygon& rPoly, OStringBuffer& rBuffer, bool bClose ) const { sal_uInt16 nPoints = rPoly.GetSize(); /* @@ -1017,7 +1017,7 @@ void PDFWriterImpl::PDFPage::appendPolygon( const tools::Polygon& rPoly, OString } } -void PDFWriterImpl::PDFPage::appendPolygon( const basegfx::B2DPolygon& rPoly, OStringBuffer& rBuffer ) const +void PDFPage::appendPolygon( const basegfx::B2DPolygon& rPoly, OStringBuffer& rBuffer ) const { basegfx::B2DPolygon aPoly( lcl_convert( m_pWriter->m_aGraphicsStack.front().m_aMapMode, m_pWriter->m_aMapMode, @@ -1092,20 +1092,20 @@ void PDFWriterImpl::PDFPage::appendPolygon( const basegfx::B2DPolygon& rPoly, OS } } -void PDFWriterImpl::PDFPage::appendPolyPolygon( const tools::PolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const +void PDFPage::appendPolyPolygon( const tools::PolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const { sal_uInt16 nPolygons = rPolyPoly.Count(); for( sal_uInt16 n = 0; n < nPolygons; n++ ) appendPolygon( rPolyPoly[n], rBuffer ); } -void PDFWriterImpl::PDFPage::appendPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const +void PDFPage::appendPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const { for(auto const& rPolygon : rPolyPoly) appendPolygon( rPolygon, rBuffer ); } -void PDFWriterImpl::PDFPage::appendMappedLength( sal_Int32 nLength, OStringBuffer& rBuffer, bool bVertical, sal_Int32* pOutLength ) const +void PDFPage::appendMappedLength( sal_Int32 nLength, OStringBuffer& rBuffer, bool bVertical, sal_Int32* pOutLength ) const { sal_Int32 nValue = nLength; if ( nLength < 0 ) @@ -1124,7 +1124,7 @@ void PDFWriterImpl::PDFPage::appendMappedLength( sal_Int32 nLength, OStringBuffe appendFixedInt( nValue, rBuffer ); } -void PDFWriterImpl::PDFPage::appendMappedLength( double fLength, OStringBuffer& rBuffer, bool bVertical, sal_Int32 nPrecision ) const +void PDFPage::appendMappedLength( double fLength, OStringBuffer& rBuffer, bool bVertical, sal_Int32 nPrecision ) const { Size aSize( lcl_convert( m_pWriter->m_aGraphicsStack.front().m_aMapMode, m_pWriter->m_aMapMode, @@ -1134,7 +1134,7 @@ void PDFWriterImpl::PDFPage::appendMappedLength( double fLength, OStringBuffer& appendDouble( fLength, rBuffer, nPrecision ); } -bool PDFWriterImpl::PDFPage::appendLineInfo( const LineInfo& rInfo, OStringBuffer& rBuffer ) const +bool PDFPage::appendLineInfo( const LineInfo& rInfo, OStringBuffer& rBuffer ) const { if(LineStyle::Dash == rInfo.GetStyle() && rInfo.GetDashLen() != rInfo.GetDotLen()) { @@ -1203,7 +1203,7 @@ bool PDFWriterImpl::PDFPage::appendLineInfo( const LineInfo& rInfo, OStringBuffe return true; } -void PDFWriterImpl::PDFPage::appendWaveLine( sal_Int32 nWidth, sal_Int32 nY, sal_Int32 nDelta, OStringBuffer& rBuffer ) const +void PDFPage::appendWaveLine( sal_Int32 nWidth, sal_Int32 nY, sal_Int32 nDelta, OStringBuffer& rBuffer ) const { if( nWidth <= 0 ) return; diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx index 5cb0143d1969..d375d7842bd0 100644 --- a/vcl/source/gdi/pdfwriter_impl.hxx +++ b/vcl/source/gdi/pdfwriter_impl.hxx @@ -103,6 +103,65 @@ namespace pdf { constexpr sal_Int32 g_nInheritedPageWidth = 595; // default A4 in inch/72 constexpr sal_Int32 g_nInheritedPageHeight = 842; // default A4 in inch/72 + +struct PDFPage +{ + VclPtr<PDFWriterImpl> m_pWriter; + double const m_nPageWidth; // in inch/72 + double const m_nPageHeight; // in inch/72 + PDFWriter::Orientation const m_eOrientation; + sal_Int32 m_nPageObject; + std::vector<sal_Int32> m_aStreamObjects; + sal_Int32 m_nStreamLengthObject; + sal_uInt64 m_nBeginStreamPos; + std::vector<sal_Int32> m_aAnnotations; + std::vector<sal_Int32> m_aMCIDParents; + PDFWriter::PageTransition m_eTransition; + sal_uInt32 m_nTransTime; + + PDFPage( PDFWriterImpl* pWriter, double nPageWidth, double nPageHeight, PDFWriter::Orientation eOrientation ); + + void beginStream(); + void endStream(); + bool emit( sal_Int32 nParentPage ); + + // converts point from ref device coordinates to + // page coordinates and appends the point to the buffer + // if pOutPoint is set it will be updated to the emitted point + // (in PDF map mode, that is 10th of point) + void appendPoint( const Point& rPoint, OStringBuffer& rBuffer ) const; + // appends a B2DPoint without further transformation + void appendPixelPoint( const basegfx::B2DPoint& rPoint, OStringBuffer& rBuffer ) const; + // appends a rectangle + void appendRect( const tools::Rectangle& rRect, OStringBuffer& rBuffer ) const; + // converts a rectangle to 10th points page space + void convertRect( tools::Rectangle& rRect ) const; + // appends a polygon optionally closing it + void appendPolygon( const tools::Polygon& rPoly, OStringBuffer& rBuffer, bool bClose = true ) const; + // appends a polygon optionally closing it + void appendPolygon( const basegfx::B2DPolygon& rPoly, OStringBuffer& rBuffer ) const; + // appends a polypolygon optionally closing the subpaths + void appendPolyPolygon( const tools::PolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const; + // appends a polypolygon optionally closing the subpaths + void appendPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const; + // converts a length (either vertical or horizontal; this + // can be important if the source MapMode is not + // symmetrical) to page length and appends it to the buffer + // if pOutLength is set it will be updated to the emitted length + // (in PDF map mode, that is 10th of point) + void appendMappedLength( sal_Int32 nLength, OStringBuffer& rBuffer, bool bVertical = true, sal_Int32* pOutLength = nullptr ) const; + // the same for double values + void appendMappedLength( double fLength, OStringBuffer& rBuffer, bool bVertical = true, sal_Int32 nPrecision = 5 ) const; + // appends LineInfo + // returns false if too many dash array entry were created for + // the implementation limits of some PDF readers + bool appendLineInfo( const LineInfo& rInfo, OStringBuffer& rBuffer ) const; + // appends a horizontal waveline with vertical offset (helper for drawWaveLine) + void appendWaveLine( sal_Int32 nLength, sal_Int32 nYOffset, sal_Int32 nDelta, OStringBuffer& rBuffer ) const; + + double getHeight() const { return m_nPageHeight ? m_nPageHeight : vcl::pdf::g_nInheritedPageHeight; } +}; + } class PDFWriterImpl : public VirtualDevice @@ -110,66 +169,7 @@ class PDFWriterImpl : public VirtualDevice friend class PDFStreamIf; public: - - struct PDFPage - { - VclPtr<PDFWriterImpl> m_pWriter; - double const m_nPageWidth; // in inch/72 - double const m_nPageHeight; // in inch/72 - PDFWriter::Orientation const m_eOrientation; - sal_Int32 m_nPageObject; - std::vector<sal_Int32> m_aStreamObjects; - sal_Int32 m_nStreamLengthObject; - sal_uInt64 m_nBeginStreamPos; - std::vector<sal_Int32> m_aAnnotations; - std::vector<sal_Int32> m_aMCIDParents; - PDFWriter::PageTransition m_eTransition; - sal_uInt32 m_nTransTime; - - PDFPage( PDFWriterImpl* pWriter, double nPageWidth, double nPageHeight, PDFWriter::Orientation eOrientation ); - - void beginStream(); - void endStream(); - bool emit( sal_Int32 nParentPage ); - - // converts point from ref device coordinates to - // page coordinates and appends the point to the buffer - // if pOutPoint is set it will be updated to the emitted point - // (in PDF map mode, that is 10th of point) - void appendPoint( const Point& rPoint, OStringBuffer& rBuffer ) const; - // appends a B2DPoint without further transformation - void appendPixelPoint( const basegfx::B2DPoint& rPoint, OStringBuffer& rBuffer ) const; - // appends a rectangle - void appendRect( const tools::Rectangle& rRect, OStringBuffer& rBuffer ) const; - // converts a rectangle to 10th points page space - void convertRect( tools::Rectangle& rRect ) const; - // appends a polygon optionally closing it - void appendPolygon( const tools::Polygon& rPoly, OStringBuffer& rBuffer, bool bClose = true ) const; - // appends a polygon optionally closing it - void appendPolygon( const basegfx::B2DPolygon& rPoly, OStringBuffer& rBuffer ) const; - // appends a polypolygon optionally closing the subpaths - void appendPolyPolygon( const tools::PolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const; - // appends a polypolygon optionally closing the subpaths - void appendPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const; - // converts a length (either vertical or horizontal; this - // can be important if the source MapMode is not - // symmetrical) to page length and appends it to the buffer - // if pOutLength is set it will be updated to the emitted length - // (in PDF map mode, that is 10th of point) - void appendMappedLength( sal_Int32 nLength, OStringBuffer& rBuffer, bool bVertical = true, sal_Int32* pOutLength = nullptr ) const; - // the same for double values - void appendMappedLength( double fLength, OStringBuffer& rBuffer, bool bVertical = true, sal_Int32 nPrecision = 5 ) const; - // appends LineInfo - // returns false if too many dash array entry were created for - // the implementation limits of some PDF readers - bool appendLineInfo( const LineInfo& rInfo, OStringBuffer& rBuffer ) const; - // appends a horizontal waveline with vertical offset (helper for drawWaveLine) - void appendWaveLine( sal_Int32 nLength, sal_Int32 nYOffset, sal_Int32 nDelta, OStringBuffer& rBuffer ) const; - - double getHeight() const { return m_nPageHeight ? m_nPageHeight : vcl::pdf::g_nInheritedPageHeight; } - }; - - friend struct PDFPage; + friend struct vcl::pdf::PDFPage; /// Contains information to emit a reference XObject. struct ReferenceXObjectEmit commit 92832bb85616393afdb062a69974983c9d6e0a13 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Dec 30 09:35:42 2019 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Dec 30 14:30:53 2019 +0100 pdf: move g_nInheritedPage{Width,Height} consts from PDFWriterImpl g_nInheritedPageWidth and g_nInheritedPageHeight constants don't need to be inside PDFWriterImpl as they aren't necessary only used there. Move them out of class to vcl::pdf namespace. Change-Id: Ie6ef8c73cf0d52a0aa001bb3bab1ca709df8cab1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85992 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx index 9651f98801a5..5cb0143d1969 100644 --- a/vcl/source/gdi/pdfwriter_impl.hxx +++ b/vcl/source/gdi/pdfwriter_impl.hxx @@ -99,6 +99,12 @@ namespace filter class PDFObjectElement; } +namespace pdf +{ +constexpr sal_Int32 g_nInheritedPageWidth = 595; // default A4 in inch/72 +constexpr sal_Int32 g_nInheritedPageHeight = 842; // default A4 in inch/72 +} + class PDFWriterImpl : public VirtualDevice { friend class PDFStreamIf; @@ -160,7 +166,7 @@ public: // appends a horizontal waveline with vertical offset (helper for drawWaveLine) void appendWaveLine( sal_Int32 nLength, sal_Int32 nYOffset, sal_Int32 nDelta, OStringBuffer& rBuffer ) const; - double getHeight() const { return m_nPageHeight ? m_nPageHeight : PDFWriterImpl::g_nInheritedPageHeight; } + double getHeight() const { return m_nPageHeight ? m_nPageHeight : vcl::pdf::g_nInheritedPageHeight; } }; friend struct PDFPage; @@ -645,8 +651,6 @@ private: sal_Int32 m_nNextFID; PDFFontCache m_aFontCache; - static constexpr sal_Int32 g_nInheritedPageWidth = 595; // default A4 in inch/72 - static constexpr sal_Int32 g_nInheritedPageHeight = 842; // default A4 in inch/72 sal_Int32 m_nCurrentPage; sal_Int32 m_nCatalogObject; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits