diff options
author | Caolán McNamara <caolanm@redhat.com> | 2023-01-04 19:43:20 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-01-05 10:50:07 +0000 |
commit | d6ded494dbb781d5539ab44fa8765eaf16275688 (patch) | |
tree | 955cd5e72fb7e837de9fc805a03282892d808b94 | |
parent | 4818e7d8d5b99cc9f74985572c113a10f0bbae3b (diff) |
move drawLine into CairoCommon and reuse from X11CairoSalGraphicsImpl
Change-Id: I6c667b4aa64c49ad18b7e9a2cd6cc43228369bd6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145050
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | vcl/headless/CairoCommon.cxx | 31 | ||||
-rw-r--r-- | vcl/headless/SvpGraphicsBackend.cxx | 25 | ||||
-rw-r--r-- | vcl/inc/headless/CairoCommon.hxx | 4 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx | 11 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx | 2 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/gdiimpl.cxx | 6 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/gdiimpl.hxx | 4 |
7 files changed, 56 insertions, 27 deletions
diff --git a/vcl/headless/CairoCommon.cxx b/vcl/headless/CairoCommon.cxx index 1b83e20adefa..9f890067b7e9 100644 --- a/vcl/headless/CairoCommon.cxx +++ b/vcl/headless/CairoCommon.cxx @@ -609,6 +609,37 @@ void CairoCommon::clipRegion(cairo_t* cr, const vcl::Region& rClipRegion) void CairoCommon::clipRegion(cairo_t* cr) { CairoCommon::clipRegion(cr, m_aClipRegion); } +void CairoCommon::drawLine(cairo_t* cr, basegfx::B2DRange* pExtents, const Color& rLineColor, + bool bAntiAlias, tools::Long nX1, tools::Long nY1, tools::Long nX2, + tools::Long nY2) +{ + basegfx::B2DPolygon aPoly; + + // PixelOffset used: To not mix with possible PixelSnap, cannot do + // directly on coordinates as tried before - despite being already 'snapped' + // due to being integer. If it would be directly added here, it would be + // 'snapped' again when !getAntiAlias(), losing the (0.5, 0.5) offset + aPoly.append(basegfx::B2DPoint(nX1, nY1)); + aPoly.append(basegfx::B2DPoint(nX2, nY2)); + + // PixelOffset used: Set PixelOffset as linear transformation + cairo_matrix_t aMatrix; + cairo_matrix_init_translate(&aMatrix, 0.5, 0.5); + cairo_set_matrix(cr, &aMatrix); + + AddPolygonToPath(cr, aPoly, basegfx::B2DHomMatrix(), !bAntiAlias, false); + + CairoCommon::applyColor(cr, rLineColor); + + if (pExtents) + { + *pExtents = getClippedStrokeDamage(cr); + pExtents->transform(basegfx::utils::createTranslateB2DHomMatrix(0.5, 0.5)); + } + + cairo_stroke(cr); +} + bool CairoCommon::drawPolyLine(cairo_t* cr, basegfx::B2DRange* pExtents, const Color& rLineColor, bool bAntiAlias, const basegfx::B2DHomMatrix& rObjectToDevice, const basegfx::B2DPolygon& rPolyLine, double fTransparency, diff --git a/vcl/headless/SvpGraphicsBackend.cxx b/vcl/headless/SvpGraphicsBackend.cxx index c41c31f4d360..b1920f576d81 100644 --- a/vcl/headless/SvpGraphicsBackend.cxx +++ b/vcl/headless/SvpGraphicsBackend.cxx @@ -122,31 +122,12 @@ void SvpGraphicsBackend::drawPixel(tools::Long nX, tools::Long nY, Color aColor) void SvpGraphicsBackend::drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) { - basegfx::B2DPolygon aPoly; - - // PixelOffset used: To not mix with possible PixelSnap, cannot do - // directly on coordinates as tried before - despite being already 'snapped' - // due to being integer. If it would be directly added here, it would be - // 'snapped' again when !getAntiAlias(), losing the (0.5, 0.5) offset - aPoly.append(basegfx::B2DPoint(nX1, nY1)); - aPoly.append(basegfx::B2DPoint(nX2, nY2)); - cairo_t* cr = m_rCairoCommon.getCairoContext(false, getAntiAlias()); + basegfx::B2DRange extents; m_rCairoCommon.clipRegion(cr); - // PixelOffset used: Set PixelOffset as linear transformation - cairo_matrix_t aMatrix; - cairo_matrix_init_translate(&aMatrix, 0.5, 0.5); - cairo_set_matrix(cr, &aMatrix); - - AddPolygonToPath(cr, aPoly, basegfx::B2DHomMatrix(), !getAntiAlias(), false); - - CairoCommon::applyColor(cr, m_rCairoCommon.m_aLineColor); - - basegfx::B2DRange extents = getClippedStrokeDamage(cr); - extents.transform(basegfx::utils::createTranslateB2DHomMatrix(0.5, 0.5)); - - cairo_stroke(cr); + CairoCommon::drawLine(cr, &extents, m_rCairoCommon.m_aLineColor, getAntiAlias(), nX1, nY1, nX2, + nY2); m_rCairoCommon.releaseCairoContext(cr, false, extents); } diff --git a/vcl/inc/headless/CairoCommon.hxx b/vcl/inc/headless/CairoCommon.hxx index 35d33e2fd24e..029060c31962 100644 --- a/vcl/inc/headless/CairoCommon.hxx +++ b/vcl/inc/headless/CairoCommon.hxx @@ -152,6 +152,10 @@ struct VCL_DLLPUBLIC CairoCommon void clipRegion(cairo_t* cr); static void clipRegion(cairo_t* cr, const vcl::Region& rClipRegion); + static void drawLine(cairo_t* cr, basegfx::B2DRange* pExtents, const Color& rLineColor, + bool bAntiAlias, tools::Long nX1, tools::Long nY1, tools::Long nX2, + tools::Long nY2); + // need this static version of ::drawPolyLine for usage from // vcl/unx/generic/gdi/salgdi.cxx. It gets wrapped by // ::drawPolyLine with some added parameters (see there) diff --git a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx index 799327684e85..13156fc13295 100644 --- a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx +++ b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx @@ -125,6 +125,17 @@ bool X11CairoSalGraphicsImpl::drawPolyPolygon(const basegfx::B2DHomMatrix& rObje return true; } +void X11CairoSalGraphicsImpl::drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, + tools::Long nY2) +{ + cairo_t* cr = mrX11Common.getCairoContext(); + clipRegion(cr); + + CairoCommon::drawLine(cr, nullptr, mnPenColor, getAntiAlias(), nX1, nY1, nX2, nY2); + + X11Common::releaseCairoContext(cr); +} + bool X11CairoSalGraphicsImpl::drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice, const basegfx::B2DPolygon& rPolyLine, double fTransparency, double fLineWidth, diff --git a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx index d450b919d551..0b7bb51e2333 100644 --- a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx +++ b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx @@ -76,6 +76,8 @@ public: void clipRegion(cairo_t* cr) { CairoCommon::clipRegion(cr, maClipRegion); } + void drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) override; + bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice, const basegfx::B2DPolyPolygon& rPolyPolygon, double fTransparency) override; diff --git a/vcl/unx/generic/gdi/gdiimpl.cxx b/vcl/unx/generic/gdi/gdiimpl.cxx index d95d65f8d98e..b75a78fc002f 100644 --- a/vcl/unx/generic/gdi/gdiimpl.cxx +++ b/vcl/unx/generic/gdi/gdiimpl.cxx @@ -437,7 +437,7 @@ void X11SalGraphicsImpl::DrawLines(sal_uInt32 nPoints, if( bClose ) { if( rPoints[nPoints-1].x != rPoints[0].x || rPoints[nPoints-1].y != rPoints[0].y ) - drawLine( rPoints[nPoints-1].x, rPoints[nPoints-1].y, rPoints[0].x, rPoints[0].y ); + internalDrawLine( rPoints[nPoints-1].x, rPoints[nPoints-1].y, rPoints[0].x, rPoints[0].y ); } } @@ -1121,7 +1121,7 @@ void X11SalGraphicsImpl::drawPixel( tools::Long nX, tools::Long nY, Color nColor } } -void X11SalGraphicsImpl::drawLine( tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 ) +void X11SalGraphicsImpl::internalDrawLine( tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 ) { if( mnPenColor != SALCOLOR_NONE ) { @@ -1174,7 +1174,7 @@ void X11SalGraphicsImpl::drawPolygon( sal_uInt32 nPoints, const Point* pPtAry ) if( 1 == nPoints ) drawPixel( pPtAry[0].getX(), pPtAry[0].getY() ); else - drawLine( pPtAry[0].getX(), pPtAry[0].getY(), + internalDrawLine( pPtAry[0].getX(), pPtAry[0].getY(), pPtAry[1].getX(), pPtAry[1].getY() ); } return; diff --git a/vcl/unx/generic/gdi/gdiimpl.hxx b/vcl/unx/generic/gdi/gdiimpl.hxx index 6858f582b1bf..033247685beb 100644 --- a/vcl/unx/generic/gdi/gdiimpl.hxx +++ b/vcl/unx/generic/gdi/gdiimpl.hxx @@ -103,6 +103,8 @@ private: void internalDrawPolyLine( sal_uInt32 nPoints, const Point* pPtAry, bool bClose ); + void internalDrawLine( tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 ); + public: explicit X11SalGraphicsImpl(X11SalGraphics& rParent); @@ -151,8 +153,6 @@ public: virtual void drawPixel( tools::Long nX, tools::Long nY ) override; virtual void drawPixel( tools::Long nX, tools::Long nY, Color nColor ) override; - virtual void drawLine( tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 ) override; - virtual void drawRect( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight ) override; virtual void drawPolyLine( sal_uInt32 nPoints, const Point* pPtAry ) override; |