drawinglayer/source/processor2d/vclprocessor2d.cxx |   24 ++++++++++++---------
 include/vcl/outdev.hxx                             |    5 ++++
 include/vcl/vcllayout.hxx                          |    6 +++++
 vcl/source/outdev/text.cxx                         |    2 -
 vcl/win/gdi/DWriteTextRenderer.cxx                 |    8 ++++---
 5 files changed, 31 insertions(+), 14 deletions(-)

New commits:
commit 2092df2a9044f1c2ae4379f48a3201e5867575a8
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri May 17 20:40:37 2024 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sat May 18 11:03:58 2024 +0200

    tdf#161154: pass "scaling is done externally" information down the stack
    
    VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D does the
    scaling, taking into account the font scaling. Before commit
    8557ea84c9336ba8061246f1f46ddb6e02f413a1, D2DWriteTextOutRenderer was
    doing own scaling in addition, but it seems that it somehow didn't
    affect the result much. The said commit removed the scalng from
    D2DWriteTextOutRenderer. As tdf#160901 demonstrated, the scaling is
    necessary in different code paths - and it turns out, that we need to
    know, if the caller does its own scaling or not, to make a decision,
    if the scaling should be fone in D2DWriteTextOutRenderer.
    
    This hack passes this from VclProcessor2D to D2DWriteTextOutRenderer
    through OutputDevice. Thanks to Miklos for the isea. I still don't
    understand, why all this seemingly doesn't affect other renderers.
    
    Change-Id: I001036f4574898b8e7606652525638df43c35240
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167786
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx 
b/drawinglayer/source/processor2d/vclprocessor2d.cxx
index 3cfec4af8b8d..c245389fdcb5 100644
--- a/drawinglayer/source/processor2d/vclprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx
@@ -439,17 +439,21 @@ void 
VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D(
             mpOutputDevice->SetFont(aFont);
             mpOutputDevice->SetTextColor(Color(aRGBFontColor));
 
-            if (!aDXArray.empty())
             {
-                const SalLayoutGlyphs* pGlyphs = 
SalLayoutGlyphsCache::self()->GetLayoutGlyphs(
-                    mpOutputDevice, aText, nPos, nLen);
-                mpOutputDevice->DrawTextArray(aStartPoint, aText, aDXArray,
-                                              
rTextCandidate.getKashidaArray(), nPos, nLen,
-                                              SalLayoutFlags::NONE, pGlyphs);
-            }
-            else
-            {
-                mpOutputDevice->DrawText(aStartPoint, aText, nPos, nLen);
+                // For D2DWriteTextOutRenderer, we must pass a flag to not use 
font scaling
+                auto guard = mpOutputDevice->ScopedNoFontScaling();
+                if (!aDXArray.empty())
+                {
+                    const SalLayoutGlyphs* pGlyphs = 
SalLayoutGlyphsCache::self()->GetLayoutGlyphs(
+                        mpOutputDevice, aText, nPos, nLen);
+                    mpOutputDevice->DrawTextArray(aStartPoint, aText, aDXArray,
+                                                  
rTextCandidate.getKashidaArray(), nPos, nLen,
+                                                  SalLayoutFlags::NONE, 
pGlyphs);
+                }
+                else
+                {
+                    mpOutputDevice->DrawText(aStartPoint, aText, nPos, nLen);
+                }
             }
 
             if (rTextCandidate.getFontAttribute().getRTL())
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index ab1758835ce1..6dbb9acf7f32 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -21,6 +21,7 @@
 
 #include <sal/config.h>
 
+#include <comphelper/flagguard.hxx>
 #include <tools/gen.hxx>
 #include <tools/ref.hxx>
 #include <tools/solar.h>
@@ -260,6 +261,8 @@ private:
     mutable bool                    mbRefPoint : 1;
     mutable bool                    mbEnableRTL : 1;
 
+    bool mbNoFontScaling = false; // Used only by D2DWriteTextOutRenderer
+
 protected:
     mutable std::shared_ptr<vcl::font::PhysicalFontCollection> 
mxFontCollection;
     mutable std::shared_ptr<ImplFontCache> mxFontCache;
@@ -342,6 +345,8 @@ public:
     /// request XSpriteCanvas render interface
     css::uno::Reference< css::rendering::XSpriteCanvas > GetSpriteCanvas() 
const;
 
+    auto ScopedNoFontScaling() { return 
comphelper::FlagRestorationGuard(mbNoFontScaling, true); }
+
 protected:
 
     /** Acquire a graphics device that the output device uses to draw on.
diff --git a/include/vcl/vcllayout.hxx b/include/vcl/vcllayout.hxx
index dd0747eae3ec..9370c69ded2e 100644
--- a/include/vcl/vcllayout.hxx
+++ b/include/vcl/vcllayout.hxx
@@ -22,6 +22,7 @@
 #include <basegfx/point/b2dpoint.hxx>
 #include <basegfx/polygon/b2dpolypolygon.hxx>
 #include <basegfx/range/b2drectangle.hxx>
+#include <comphelper/flagguard.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <tools/gen.hxx>
 #include <tools/degree.hxx>
@@ -120,6 +121,9 @@ public:
 
     virtual SalLayoutGlyphs GetGlyphs() const;
 
+    auto ScopedFontScaling(bool v) { return 
comphelper::FlagRestorationGuard(mbScaleFont, v); }
+    bool ScaleFont() const { return mbScaleFont; }
+
 protected:
     // used by layout engines
     SalLayout();
@@ -128,6 +132,8 @@ private:
     SalLayout(const SalLayout&) = delete;
     SalLayout& operator=(const SalLayout&) = delete;
 
+    bool mbScaleFont = true; // Used only by D2DWriteTextOutRenderer
+
 protected:
     int             mnMinCharPos;
     int             mnEndCharPos;
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index e42ca6cdc0e7..7d29256953fd 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -449,7 +449,7 @@ void OutputDevice::ImplDrawSpecialText( SalLayout& 
rSalLayout )
 
 void OutputDevice::ImplDrawText( SalLayout& rSalLayout )
 {
-
+    auto guard = rSalLayout.ScopedFontScaling(!mbNoFontScaling);
     if( mbInitClipRegion )
         InitClipRegion();
     if( mbOutputClipped )
diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx 
b/vcl/win/gdi/DWriteTextRenderer.cxx
index 8a62f2d73fd9..1731a1e4c379 100644
--- a/vcl/win/gdi/DWriteTextRenderer.cxx
+++ b/vcl/win/gdi/DWriteTextRenderer.cxx
@@ -311,12 +311,14 @@ 
WinFontTransformGuard::WinFontTransformGuard(ID2D1RenderTarget* pRenderTarget,
                                              bool bIsVertical)
     : mpRenderTarget(pRenderTarget)
 {
-    const float hscale = [&font = rLayout.GetFont()]
+    const float hscale = [&rLayout]
     {
-        const auto& rPattern = font.GetFontSelectPattern();
+        if (!rLayout.ScaleFont())
+            return 1.0;
+        const auto& rPattern = rLayout.GetFont().GetFontSelectPattern();
         if (!rPattern.mnHeight || !rPattern.mnWidth)
             return 1.0;
-        return rPattern.mnWidth * font.GetAverageWidthFactor() / 
rPattern.mnHeight;
+        return rPattern.mnWidth * rLayout.GetFont().GetAverageWidthFactor() / 
rPattern.mnHeight;
     }();
 
     Degree10 angle = rLayout.GetOrientation();

Reply via email to