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 368bc2b821dde56379c9a4c3acfcc3143efbdf6d
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri May 17 20:40:37 2024 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sat May 18 14:46:38 2024 +0500

    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

diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx 
b/drawinglayer/source/processor2d/vclprocessor2d.cxx
index 109be5cd40f9..f401c220f170 100644
--- a/drawinglayer/source/processor2d/vclprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx
@@ -428,17 +428,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 098a5ccc5ef0..7142fee006df 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -21,6 +21,7 @@
 
 #include <sal/config.h>
 
+#include <comphelper/flagguard.hxx>
 #include <o3tl/span.hxx>
 #include <tools/gen.hxx>
 #include <tools/ref.hxx>
@@ -258,6 +259,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;
@@ -340,6 +343,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 887480ce3ee9..a70fdaaddc1c 100644
--- a/include/vcl/vcllayout.hxx
+++ b/include/vcl/vcllayout.hxx
@@ -21,6 +21,7 @@
 
 #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>
@@ -110,6 +111,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();
@@ -118,6 +122,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 0ff3ac91f177..ce652f4506dd 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -468,7 +468,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 f8c8c93958d7..57bd0ff62b83 100644
--- a/vcl/win/gdi/DWriteTextRenderer.cxx
+++ b/vcl/win/gdi/DWriteTextRenderer.cxx
@@ -332,12 +332,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