summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-05-17 20:40:37 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-06-18 03:22:43 +0500
commitdba44b488c46cd9d1cc512628ef110486b96aac3 (patch)
tree077d45dff45aa9d0f4fccaa02c8c4528340960e3
parentf085903137c40f3714b9e82c8180abdce95d2549 (diff)
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 <mike.kaganski@collabora.com> Tested-by: Jenkins
-rw-r--r--drawinglayer/source/processor2d/vclprocessor2d.cxx24
-rw-r--r--include/vcl/outdev.hxx5
-rw-r--r--include/vcl/vcllayout.hxx6
-rw-r--r--vcl/source/outdev/text.cxx2
-rw-r--r--vcl/win/gdi/DWriteTextRenderer.cxx8
5 files changed, 31 insertions, 14 deletions
diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx b/drawinglayer/source/processor2d/vclprocessor2d.cxx
index f7a21a8e698c..f6b8dbc8f953 100644
--- a/drawinglayer/source/processor2d/vclprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx
@@ -441,17 +441,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 bdbb2ecd1847..15c6cd130f71 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>
@@ -259,6 +260,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;
@@ -341,6 +344,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 c946f6f67884..b37e8ff6e45b 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>
@@ -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 b68602e9e90c..edd215943a3c 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 ff39275b36b9..6a28cb4b4d98 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();