diff options
Diffstat (limited to 'cppcanvas/source/mtfrenderer/textaction.cxx')
-rw-r--r-- | cppcanvas/source/mtfrenderer/textaction.cxx | 131 |
1 files changed, 110 insertions, 21 deletions
diff --git a/cppcanvas/source/mtfrenderer/textaction.cxx b/cppcanvas/source/mtfrenderer/textaction.cxx index 8292935e976f..41c2f4ac3557 100644 --- a/cppcanvas/source/mtfrenderer/textaction.cxx +++ b/cppcanvas/source/mtfrenderer/textaction.cxx @@ -470,7 +470,7 @@ namespace cppcanvas virtual ~TextRenderer() {} /// Render text with given RenderState - virtual bool operator()( const rendering::RenderState& rRenderState ) const = 0; + virtual bool operator()( const rendering::RenderState& rRenderState, const ::Color& rTextFillColor ) const = 0; }; /** Render effect text. @@ -486,7 +486,8 @@ namespace cppcanvas const ::Color& rShadowColor, const ::basegfx::B2DSize& rShadowOffset, const ::Color& rReliefColor, - const ::basegfx::B2DSize& rReliefOffset ) + const ::basegfx::B2DSize& rReliefOffset, + const ::Color& rTextFillColor ) { ::Color aEmptyColor( COL_AUTO ); uno::Reference<rendering::XColorSpace> xColorSpace( @@ -507,7 +508,7 @@ namespace cppcanvas vcl::unotools::colorToDoubleSequence( rShadowColor, xColorSpace ); - rRenderer( aShadowState ); + rRenderer( aShadowState, rTextFillColor ); } // draw relief text, if enabled @@ -525,11 +526,11 @@ namespace cppcanvas vcl::unotools::colorToDoubleSequence( rReliefColor, xColorSpace ); - rRenderer( aReliefState ); + rRenderer( aReliefState, rTextFillColor ); } // draw normal text - rRenderer( rRenderState ); + rRenderer( rRenderState, rTextFillColor ); return true; } @@ -800,7 +801,10 @@ namespace cppcanvas private: /// Interface TextRenderer - virtual bool operator()( const rendering::RenderState& rRenderState ) const override; + virtual bool operator()( const rendering::RenderState& rRenderState, const ::Color& rTextFillColor ) const override; + + geometry::RealRectangle2D queryTextBounds() const; + css::uno::Reference<css::rendering::XPolyPolygon2D> queryTextBounds(const uno::Reference<rendering::XCanvas>& rCanvas) const; // TODO(P2): This is potentially a real mass object // (every character might be a separate TextAction), @@ -820,6 +824,7 @@ namespace cppcanvas const ::Color maReliefColor; const ::basegfx::B2DSize maShadowOffset; const ::Color maShadowColor; + const ::Color maTextFillColor; const sal_Int8 maTextDirection; }; @@ -902,7 +907,7 @@ namespace cppcanvas "::cppcanvas::internal::EffectTextAction(): Invalid font or lines" ); } - bool EffectTextAction::operator()( const rendering::RenderState& rRenderState ) const + bool EffectTextAction::operator()( const rendering::RenderState& rRenderState, const ::Color& rTextFillColor ) const { const rendering::ViewState& rViewState( mpCanvas->getViewState() ); const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() ); @@ -911,6 +916,18 @@ namespace cppcanvas rViewState, rRenderState ); + //rhbz#1589029 non-transparent text fill background support + ::Color aEmptyColor( COL_AUTO ); + if (rTextFillColor != aEmptyColor) + { + rendering::RenderState aLocalState( rRenderState ); + aLocalState.DeviceColor = vcl::unotools::colorToDoubleSequence( + rTextFillColor, rCanvas->getDevice()->getDeviceColorSpace()); + auto xTextBounds = queryTextBounds(rCanvas); + // background of text + rCanvas->fillPolyPolygon(xTextBounds, rViewState, aLocalState); + } + rCanvas->drawText( maStringContext, mxFont, rViewState, rRenderState, @@ -933,7 +950,8 @@ namespace cppcanvas maShadowColor, maShadowOffset, maReliefColor, - maReliefOffset ); + maReliefOffset, + maTextFillColor); } bool EffectTextAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation, @@ -948,7 +966,7 @@ namespace cppcanvas return render( rTransformation ); } - ::basegfx::B2DRange EffectTextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const + geometry::RealRectangle2D EffectTextAction::queryTextBounds() const { // create XTextLayout, to have the // XTextLayout::queryTextBounds() method available @@ -958,11 +976,24 @@ namespace cppcanvas maTextDirection, 0 ) ); + return xTextLayout->queryTextBounds(); + } + + css::uno::Reference<css::rendering::XPolyPolygon2D> EffectTextAction::queryTextBounds(const uno::Reference<rendering::XCanvas>& rCanvas) const + { + auto aTextBounds = queryTextBounds(); + auto aB2DBounds = ::basegfx::unotools::b2DRectangleFromRealRectangle2D(aTextBounds); + auto aTextBoundsPoly = ::basegfx::utils::createPolygonFromRect(aB2DBounds); + return ::basegfx::unotools::xPolyPolygonFromB2DPolygon(rCanvas->getDevice(), aTextBoundsPoly); + } + + ::basegfx::B2DRange EffectTextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const + { rendering::RenderState aLocalState( maState ); ::canvas::tools::prependToRenderState(aLocalState, rTransformation); return calcEffectTextBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D( - xTextLayout->queryTextBounds() ), + queryTextBounds() ), ::basegfx::B2DRange( 0,0, maLinesOverallSize.getX(), maLinesOverallSize.getY() ), @@ -1183,6 +1214,7 @@ namespace cppcanvas const ::Color& rReliefColor, const ::basegfx::B2DSize& rShadowOffset, const ::Color& rShadowColor, + const ::Color& rTextFillColor, const OUString& rText, sal_Int32 nStartPos, sal_Int32 nLen, @@ -1195,6 +1227,7 @@ namespace cppcanvas const ::Color& rReliefColor, const ::basegfx::B2DSize& rShadowOffset, const ::Color& rShadowColor, + const ::Color& rTextFillColor, const OUString& rText, sal_Int32 nStartPos, sal_Int32 nLen, @@ -1219,7 +1252,9 @@ namespace cppcanvas private: // TextRenderer interface - virtual bool operator()( const rendering::RenderState& rRenderState ) const override; + virtual bool operator()( const rendering::RenderState& rRenderState, const ::Color& rTextFillColor ) const override; + + css::uno::Reference<css::rendering::XPolyPolygon2D> queryTextBounds(const uno::Reference<rendering::XCanvas>& rCanvas) const; // TODO(P2): This is potentially a real mass object // (every character might be a separate TextAction), @@ -1238,6 +1273,7 @@ namespace cppcanvas const ::Color maReliefColor; const ::basegfx::B2DSize maShadowOffset; const ::Color maShadowColor; + const ::Color maTextFillColor; }; EffectTextArrayAction::EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint, @@ -1245,6 +1281,7 @@ namespace cppcanvas const ::Color& rReliefColor, const ::basegfx::B2DSize& rShadowOffset, const ::Color& rShadowColor, + const ::Color& rTextFillColor, const OUString& rText, sal_Int32 nStartPos, sal_Int32 nLen, @@ -1261,7 +1298,8 @@ namespace cppcanvas maReliefOffset( rReliefOffset ), maReliefColor( rReliefColor ), maShadowOffset( rShadowOffset ), - maShadowColor( rShadowColor ) + maShadowColor( rShadowColor ), + maTextFillColor( rTextFillColor ) { initEffectLinePolyPolygon( maLinesOverallSize, mxTextLines, @@ -1285,6 +1323,7 @@ namespace cppcanvas const ::Color& rReliefColor, const ::basegfx::B2DSize& rShadowOffset, const ::Color& rShadowColor, + const ::Color& rTextFillColor, const OUString& rText, sal_Int32 nStartPos, sal_Int32 nLen, @@ -1302,7 +1341,8 @@ namespace cppcanvas maReliefOffset( rReliefOffset ), maReliefColor( rReliefColor ), maShadowOffset( rShadowOffset ), - maShadowColor( rShadowColor ) + maShadowColor( rShadowColor ), + maTextFillColor( rTextFillColor ) { initEffectLinePolyPolygon( maLinesOverallSize, mxTextLines, @@ -1322,7 +1362,15 @@ namespace cppcanvas &rTextTransform ); } - bool EffectTextArrayAction::operator()( const rendering::RenderState& rRenderState ) const + css::uno::Reference<css::rendering::XPolyPolygon2D> EffectTextArrayAction::queryTextBounds(const uno::Reference<rendering::XCanvas>& rCanvas) const + { + const geometry::RealRectangle2D aTextBounds(mxTextLayout->queryTextBounds()); + auto aB2DBounds = ::basegfx::unotools::b2DRectangleFromRealRectangle2D(aTextBounds); + auto aTextBoundsPoly = ::basegfx::utils::createPolygonFromRect(aB2DBounds); + return ::basegfx::unotools::xPolyPolygonFromB2DPolygon(rCanvas->getDevice(), aTextBoundsPoly); + } + + bool EffectTextArrayAction::operator()( const rendering::RenderState& rRenderState, const ::Color& rTextFillColor ) const { const rendering::ViewState& rViewState( mpCanvas->getViewState() ); const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() ); @@ -1331,6 +1379,18 @@ namespace cppcanvas rViewState, rRenderState ); + //rhbz#1589029 non-transparent text fill background support + ::Color aEmptyColor( COL_AUTO ); + if (rTextFillColor != aEmptyColor) + { + rendering::RenderState aLocalState(rRenderState); + aLocalState.DeviceColor = vcl::unotools::colorToDoubleSequence( + rTextFillColor, rCanvas->getDevice()->getDeviceColorSpace()); + auto xTextBounds = queryTextBounds(rCanvas); + // background of text + rCanvas->fillPolyPolygon(xTextBounds, rViewState, aLocalState); + } + rCanvas->drawTextLayout( mxTextLayout, rViewState, rRenderState ); @@ -1352,7 +1412,8 @@ namespace cppcanvas maShadowColor, maShadowOffset, maReliefColor, - maReliefOffset ); + maReliefOffset, + maTextFillColor); } class EffectTextArrayRenderHelper : public TextRenderer @@ -1370,12 +1431,24 @@ namespace cppcanvas } // TextRenderer interface - virtual bool operator()( const rendering::RenderState& rRenderState ) const override + virtual bool operator()( const rendering::RenderState& rRenderState, const ::Color& rTextFillColor ) const override { mrCanvas->fillPolyPolygon( mrLinePolygon, mrViewState, rRenderState ); + //rhbz#1589029 non-transparent text fill background support + ::Color aEmptyColor( COL_AUTO ); + if (rTextFillColor != aEmptyColor) + { + rendering::RenderState aLocalState(rRenderState); + aLocalState.DeviceColor = vcl::unotools::colorToDoubleSequence( + rTextFillColor, mrCanvas->getDevice()->getDeviceColorSpace()); + auto xTextBounds = queryTextBounds(); + // background of text + mrCanvas->fillPolyPolygon(xTextBounds, mrViewState, aLocalState); + } + mrCanvas->drawTextLayout( mrTextLayout, mrViewState, rRenderState ); @@ -1384,6 +1457,15 @@ namespace cppcanvas } private: + + css::uno::Reference<css::rendering::XPolyPolygon2D> queryTextBounds() const + { + const geometry::RealRectangle2D aTextBounds(mrTextLayout->queryTextBounds()); + auto aB2DBounds = ::basegfx::unotools::b2DRectangleFromRealRectangle2D(aTextBounds); + auto aTextBoundsPoly = ::basegfx::utils::createPolygonFromRect(aB2DBounds); + return ::basegfx::unotools::xPolyPolygonFromB2DPolygon(mrCanvas->getDevice(), aTextBoundsPoly); + } + const uno::Reference< rendering::XCanvas >& mrCanvas; const uno::Reference< rendering::XTextLayout >& mrTextLayout; const uno::Reference< rendering::XPolyPolygon2D >& mrLinePolygon; @@ -1441,7 +1523,8 @@ namespace cppcanvas maShadowColor, maShadowOffset, maReliefColor, - maReliefOffset ); + maReliefOffset, + maTextFillColor); } ::basegfx::B2DRange EffectTextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const @@ -1553,7 +1636,7 @@ namespace cppcanvas private: // TextRenderer interface - virtual bool operator()( const rendering::RenderState& rRenderState ) const override; + virtual bool operator()( const rendering::RenderState& rRenderState, const ::Color& rTextFillColor ) const override; // TODO(P2): This is potentially a real mass object // (every character might be a separate TextAction), @@ -1577,6 +1660,7 @@ namespace cppcanvas const ::Color maReliefColor; const ::basegfx::B2DSize maShadowOffset; const ::Color maShadowColor; + const ::Color maTextFillColor; }; double calcOutlineWidth( const OutDevState& rState, @@ -1675,7 +1759,7 @@ namespace cppcanvas rTextTransform ); } - bool OutlineAction::operator()( const rendering::RenderState& rRenderState ) const + bool OutlineAction::operator()( const rendering::RenderState& rRenderState, const ::Color& /*rTextFillColor*/ ) const { const rendering::ViewState& rViewState( mpCanvas->getViewState() ); const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() ); @@ -1731,7 +1815,8 @@ namespace cppcanvas maShadowColor, maShadowOffset, maReliefColor, - maReliefOffset ); + maReliefOffset, + maTextFillColor); } #if 0 // see #if'ed out use in OutlineAction::renderSubset below: @@ -2040,6 +2125,7 @@ namespace cppcanvas const ::Color& rReliefColor, const ::Size& rShadowOffset, const ::Color& rShadowColor, + const ::Color& rTextFillColor, const OUString& rText, sal_Int32 nStartPos, sal_Int32 nLen, @@ -2173,7 +2259,8 @@ namespace cppcanvas !rState.textUnderlineStyle && !rState.textStrikeoutStyle && rReliefColor == aEmptyColor && - rShadowColor == aEmptyColor ) + rShadowColor == aEmptyColor && + rTextFillColor == aEmptyColor ) { // nope if( rParms.maTextTransformation.is_initialized() ) @@ -2206,6 +2293,7 @@ namespace cppcanvas rReliefColor, aShadowOffset, rShadowColor, + rTextFillColor, rText, nStartPos, nLen, @@ -2221,6 +2309,7 @@ namespace cppcanvas rReliefColor, aShadowOffset, rShadowColor, + rTextFillColor, rText, nStartPos, nLen, |