[Libreoffice-commits] core.git: Branch 'libreoffice-7-1' - vcl/win

Regina Henschel (via logerrit) logerrit at kemper.freedesktop.org
Wed Dec 9 16:33:40 UTC 2020


 vcl/win/gdi/gdiimpl.cxx |   35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

New commits:
commit d41d6768a17c65460565265f41a590f8e6982ad9
Author:     Regina Henschel <rb.henschel at t-online.de>
AuthorDate: Thu Dec 3 23:53:43 2020 +0100
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Wed Dec 9 17:33:09 2020 +0100

    tdf#134128 Use Gdiplus::DashCapRound for round dash or dot.
    
    If Skia and OpenGL are disabled, rendering in edit mode shows no round
    dashes and dots on Windows. This becomes especially visible, when
    importing OOXML documents. In that case it looks as if dots are lost.
    The patch uses now Gdiplus::DashCapRound instead of the previously
    used Gdiplus::DashCapFlat, and it adds a similar tweak as in OOXML
    import and increases the dash length by the cap size for rendering.
    
    Change-Id: I98a258809ef253a2cacb7c5c94f2b26b89ee2488
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107181
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    (cherry picked from commit 24d770799660d3ec94ee7add435645794426042b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107201
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/vcl/win/gdi/gdiimpl.cxx b/vcl/win/gdi/gdiimpl.cxx
index de022280c4b2..b3b70320dd05 100644
--- a/vcl/win/gdi/gdiimpl.cxx
+++ b/vcl/win/gdi/gdiimpl.cxx
@@ -2343,12 +2343,39 @@ bool WinSalGraphicsImpl::drawPolyLine(
         std::vector<Gdiplus::REAL> aDashArray(pStroke->size());
         const double fFactor(fLineWidth == 0 ? 1.0 : 1.0 / fLineWidth);
 
-        for(size_t a(0); a < pStroke->size(); a++)
+        // tdf#134128. ODF adds caps to the dashes and dots, but GDI makes caps from the
+        // dash or dot themselve. We tweak aDashArray to look the same in GDI (e.g. Impress edit mode)
+        // and other renderes (e.g. Impress slide show), while keeping the total length of the
+        // pattern.
+        // Patterns are always a sequence dash space dash space ...
+        if (eLineCap != css::drawing::LineCap_BUTT)
         {
-            aDashArray[a] = Gdiplus::REAL((*pStroke)[a] * fFactor);
+            size_t nSize = pStroke->size();
+            // We want to treat dash and space in pairs. There should be no odd size. If so, we ignore
+            // last item.
+            nSize /= 2;
+            for(size_t a(0); a < nSize; a++)
+            {
+                double fDashLengthRel = (*pStroke)[2 * a] * fFactor;
+                double fSpaceLengthRel = (*pStroke)[2 * a + 1] * fFactor;
+                // GDI allows only positive lengths for space, Skia negative lengths too. Thus the
+                // appearance is different, in case space is too small.
+                double fCorrect = fSpaceLengthRel - 1.0 <= 0 ? fSpaceLengthRel - 0.01 : 1.0;
+                aDashArray[2 * a] = Gdiplus::REAL(fDashLengthRel + fCorrect);
+                aDashArray[2 * a + 1] = Gdiplus::REAL(fSpaceLengthRel - fCorrect);
+            }
         }
-
-        aPen.SetDashCap(Gdiplus::DashCapFlat);
+        else
+        {
+            for(size_t a(0); a < pStroke->size(); a++)
+            {
+                aDashArray[a] = Gdiplus::REAL((*pStroke)[a] * fFactor);
+            }
+        }
+        if (eLineCap == css::drawing::LineCap_ROUND)
+            aPen.SetDashCap(Gdiplus::DashCapRound);
+        else
+            aPen.SetDashCap(Gdiplus::DashCapFlat); // "square" doesn't exist in Gdiplus
         aPen.SetDashOffset(Gdiplus::REAL(0.0));
         aPen.SetDashPattern(aDashArray.data(), aDashArray.size());
     }


More information about the Libreoffice-commits mailing list