diff options
author | Caolán McNamara <caolanm@redhat.com> | 2023-01-06 09:43:21 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-01-07 10:56:03 +0000 |
commit | b3566864db77effddb243717dd0d9a1c791383e6 (patch) | |
tree | 88fa65fd2f20a171cf1937968e1eda2f065a40d4 /vcl/headless | |
parent | b348b9467111d47b0e995dcbec4951cd1c249e4a (diff) |
move drawRect into CairoCommon and reuse from X11CairoSalGraphicsImpl
Change-Id: I1d9f1dc96788530eb6a226a53a67764918348100
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145139
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/headless')
-rw-r--r-- | vcl/headless/CairoCommon.cxx | 49 | ||||
-rw-r--r-- | vcl/headless/SvpGraphicsBackend.cxx | 79 |
2 files changed, 55 insertions, 73 deletions
diff --git a/vcl/headless/CairoCommon.cxx b/vcl/headless/CairoCommon.cxx index 56293738d508..8ea358cbdc34 100644 --- a/vcl/headless/CairoCommon.cxx +++ b/vcl/headless/CairoCommon.cxx @@ -687,6 +687,55 @@ void CairoCommon::drawLine(cairo_t* cr, basegfx::B2DRange* pExtents, const Color cairo_stroke(cr); } +void CairoCommon::drawRect(cairo_t* cr, basegfx::B2DRange* pExtents, + const std::optional<Color>& rLineColor, + const std::optional<Color>& rFillColor, bool bAntiAlias, double nX, + double nY, double nWidth, double nHeight) +{ + // fast path for the common case of simply creating a solid block of color + if (rFillColor && rLineColor && rFillColor == rLineColor) + { + double fTransparency = 0; + // don't bother trying to draw stuff which is effectively invisible + if (nWidth < 0.1 || nHeight < 0.1) + return; + bool bPixelSnap = !bAntiAlias; + if (bPixelSnap) + { + // snap by rounding + nX = basegfx::fround(nX); + nY = basegfx::fround(nY); + nWidth = basegfx::fround(nWidth); + nHeight = basegfx::fround(nHeight); + } + cairo_rectangle(cr, nX, nY, nWidth, nHeight); + CairoCommon::applyColor(cr, *rFillColor, fTransparency); + if (pExtents) + { + // Get FillDamage + *pExtents = getClippedFillDamage(cr); + } + cairo_fill(cr); + return; + } + // because of the -1 hack we have to do fill and draw separately + if (rFillColor) + { + basegfx::B2DPolygon aRect = basegfx::utils::createPolygonFromRect( + basegfx::B2DRectangle(nX, nY, nX + nWidth, nY + nHeight)); + drawPolyPolygon(cr, pExtents, std::nullopt, rFillColor, bAntiAlias, basegfx::B2DHomMatrix(), + basegfx::B2DPolyPolygon(aRect), 0.0); + } + if (rLineColor) + { + // need same -1 hack as X11SalGraphicsImpl::drawRect + basegfx::B2DPolygon aRect = basegfx::utils::createPolygonFromRect( + basegfx::B2DRectangle(nX, nY, nX + nWidth - 1, nY + nHeight - 1)); + drawPolyPolygon(cr, pExtents, rLineColor, std::nullopt, bAntiAlias, basegfx::B2DHomMatrix(), + basegfx::B2DPolyPolygon(aRect), 0.0); + } +} + void CairoCommon::drawPolygon(cairo_t* cr, basegfx::B2DRange* pExtents, const std::optional<Color>& rLineColor, const std::optional<Color>& rFillColor, bool bAntiAlias, diff --git a/vcl/headless/SvpGraphicsBackend.cxx b/vcl/headless/SvpGraphicsBackend.cxx index 87a5a14debd8..1d2f17c44747 100644 --- a/vcl/headless/SvpGraphicsBackend.cxx +++ b/vcl/headless/SvpGraphicsBackend.cxx @@ -130,81 +130,14 @@ void SvpGraphicsBackend::drawLine(tools::Long nX1, tools::Long nY1, tools::Long void SvpGraphicsBackend::drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) { - implDrawRect(nX, nY, nWidth, nHeight); -} - -void SvpGraphicsBackend::implDrawRect(double nX, double nY, double nWidth, double nHeight) -{ - // fast path for the common case of simply creating a solid block of color - if (m_rCairoCommon.m_oFillColor && m_rCairoCommon.m_oLineColor - && m_rCairoCommon.m_oFillColor == m_rCairoCommon.m_oLineColor) - { - double fTransparency = 0; - - // don't bother trying to draw stuff which is effectively invisible - if (nWidth < 0.1 || nHeight < 0.1) - return; - - cairo_t* cr = m_rCairoCommon.getCairoContext(true, getAntiAlias()); - m_rCairoCommon.clipRegion(cr); - - // To make releaseCairoContext work, use empty extents - basegfx::B2DRange extents; - - bool bPixelSnap = !getAntiAlias(); - if (bPixelSnap) - { - // snap by rounding - nX = basegfx::fround(nX); - nY = basegfx::fround(nY); - nWidth = basegfx::fround(nWidth); - nHeight = basegfx::fround(nHeight); - } - - cairo_rectangle(cr, nX, nY, nWidth, nHeight); - - CairoCommon::applyColor(cr, *m_rCairoCommon.m_oFillColor, fTransparency); - // Get FillDamage (will be extended for LineDamage below) - extents = getClippedFillDamage(cr); - - cairo_fill(cr); - - m_rCairoCommon.releaseCairoContext(cr, true, extents); - - return; - } - - // because of the -1 hack we have to do fill and draw separately - std::optional<Color> aOrigFillColor = m_rCairoCommon.m_oFillColor; - std::optional<Color> aOrigLineColor = m_rCairoCommon.m_oLineColor; - m_rCairoCommon.m_oFillColor = std::nullopt; - m_rCairoCommon.m_oLineColor = std::nullopt; - - if (aOrigFillColor) - { - basegfx::B2DPolygon aRect = basegfx::utils::createPolygonFromRect( - basegfx::B2DRectangle(nX, nY, nX + nWidth, nY + nHeight)); - m_rCairoCommon.m_oFillColor = aOrigFillColor; - - drawPolyPolygon(basegfx::B2DHomMatrix(), basegfx::B2DPolyPolygon(aRect), 0.0); - - m_rCairoCommon.m_oFillColor = std::nullopt; - } - - if (aOrigLineColor) - { - // need same -1 hack as X11SalGraphicsImpl::drawRect - basegfx::B2DPolygon aRect = basegfx::utils::createPolygonFromRect( - basegfx::B2DRectangle(nX, nY, nX + nWidth - 1, nY + nHeight - 1)); - m_rCairoCommon.m_oLineColor = aOrigLineColor; - - drawPolyPolygon(basegfx::B2DHomMatrix(), basegfx::B2DPolyPolygon(aRect), 0.0); + cairo_t* cr = m_rCairoCommon.getCairoContext(true, getAntiAlias()); + basegfx::B2DRange extents; + m_rCairoCommon.clipRegion(cr); - m_rCairoCommon.m_oLineColor = std::nullopt; - } + CairoCommon::drawRect(cr, &extents, m_rCairoCommon.m_oLineColor, m_rCairoCommon.m_oFillColor, + getAntiAlias(), nX, nY, nWidth, nHeight); - m_rCairoCommon.m_oFillColor = aOrigFillColor; - m_rCairoCommon.m_oLineColor = aOrigLineColor; + m_rCairoCommon.releaseCairoContext(cr, true, extents); } void SvpGraphicsBackend::drawPolyLine(sal_uInt32 nPoints, const Point* pPtAry) |