summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-03-31 10:57:43 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2024-06-17 21:05:50 +0500
commit032520d04ff73e831e0a4379de0792ae8d809ba3 (patch)
tree810e122250ecb165c09d9e7677f775f0a64366f3
parentf09f039997f5be5ca6ca8286fa9037b05d4278b9 (diff)
Simplify a bit
And make font size calculations consistent between SkiaTextRender (x11) and WinSkiaSalGraphicsImpl (win). They already did ~the same, the win case just used an intermediate 'getHScale' coefficient. Change-Id: I90ad4d9c49427465ef3263843b34bd9bc0d762eb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165488 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--vcl/skia/win/gdiimpl.cxx34
-rw-r--r--vcl/skia/x11/textrender.cxx10
2 files changed, 19 insertions, 25 deletions
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index 39294bc2b372..0451307b7bdf 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -216,21 +216,22 @@ catch (const sal::systools::ComError& e)
bool WinSkiaSalGraphicsImpl::DrawTextLayout(const GenericSalLayout& rLayout)
{
- assert(dynamic_cast<const SkiaWinFontInstance*>(&rLayout.GetFont()));
- const SkiaWinFontInstance* pWinFont
- = static_cast<const SkiaWinFontInstance*>(&rLayout.GetFont());
- const HFONT hLayoutFont = pWinFont->GetHFONT();
- double hScale = pWinFont->getHScale();
+ assert(dynamic_cast<SkiaWinFontInstance*>(&rLayout.GetFont()));
+ SkiaWinFontInstance& rWinFont = static_cast<SkiaWinFontInstance&>(rLayout.GetFont());
+ const vcl::font::FontSelectPattern& rFSD = rWinFont.GetFontSelectPattern();
+ if (rFSD.mnHeight == 0)
+ return false;
+ const HFONT hLayoutFont = rWinFont.GetHFONT();
LOGFONTW logFont;
if (GetObjectW(hLayoutFont, sizeof(logFont), &logFont) == 0)
{
assert(false);
return false;
}
- sk_sp<SkTypeface> typeface = pWinFont->GetSkiaTypeface();
+ sk_sp<SkTypeface> typeface = rWinFont.GetSkiaTypeface();
if (!typeface)
{
- typeface = createDirectWriteTypeface(pWinFont);
+ typeface = createDirectWriteTypeface(&rWinFont);
bool dwrite = true;
if (!typeface) // fall back to GDI text rendering
{
@@ -251,7 +252,7 @@ bool WinSkiaSalGraphicsImpl::DrawTextLayout(const GenericSalLayout& rLayout)
return false;
}
// Cache the typeface.
- const_cast<SkiaWinFontInstance*>(pWinFont)->SetSkiaTypeface(typeface, dwrite);
+ rWinFont.SetSkiaTypeface(typeface, dwrite);
}
SkFont font(typeface);
@@ -268,21 +269,14 @@ bool WinSkiaSalGraphicsImpl::DrawTextLayout(const GenericSalLayout& rLayout)
font.setEdging(logFont.lfQuality == NONANTIALIASED_QUALITY ? SkFont::Edging::kAlias
: ePreferredAliasing);
- const vcl::font::FontSelectPattern& rFSD = pWinFont->GetFontSelectPattern();
- int nHeight = rFSD.mnHeight;
- int nWidth = rFSD.mnWidth ? rFSD.mnWidth : nHeight;
- if (nWidth == 0 || nHeight == 0)
- return false;
+ double nHeight = rFSD.mnHeight;
+ double nWidth = rFSD.mnWidth ? rFSD.mnWidth * rWinFont.GetAverageWidthFactor() : nHeight;
font.setSize(nHeight);
- font.setScaleX(hScale);
+ font.setScaleX(nWidth / nHeight);
- // Unlike with Freetype-based font handling, use height even in vertical mode,
- // additionally multiply it by horizontal scale to get the proper
- // size and then scale the width back, otherwise the height would
- // not be correct. I don't know why this is inconsistent.
SkFont verticalFont(font);
- verticalFont.setSize(nHeight * hScale);
- verticalFont.setScaleX(1.0 / hScale);
+ verticalFont.setSize(nWidth);
+ verticalFont.setScaleX(nHeight / nWidth);
assert(dynamic_cast<SkiaSalGraphicsImpl*>(mWinParent.GetImpl()));
SkiaSalGraphicsImpl* impl = static_cast<SkiaSalGraphicsImpl*>(mWinParent.GetImpl());
diff --git a/vcl/skia/x11/textrender.cxx b/vcl/skia/x11/textrender.cxx
index acc930e070e5..425710626fb5 100644
--- a/vcl/skia/x11/textrender.cxx
+++ b/vcl/skia/x11/textrender.cxx
@@ -51,10 +51,10 @@ void SkiaTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalGr
const FreetypeFontInstance& rInstance = static_cast<FreetypeFontInstance&>(rLayout.GetFont());
const FreetypeFont& rFont = rInstance.GetFreetypeFont();
const vcl::font::FontSelectPattern& rFSD = rInstance.GetFontSelectPattern();
- int nHeight = rFSD.mnHeight;
- int nWidth = rFSD.mnWidth ? rFSD.mnWidth : nHeight;
- if (nWidth == 0 || nHeight == 0)
+ if (rFSD.mnHeight == 0)
return;
+ double nHeight = rFSD.mnHeight;
+ double nWidth = rFSD.mnWidth ? rFSD.mnWidth : nHeight;
if (!fontManager)
{
@@ -65,7 +65,7 @@ void SkiaTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalGr
= SkFontMgr_createTypefaceFromFcPattern(fontManager, rFont.GetFontOptions()->GetPattern());
SkFont font(typeface);
font.setSize(nHeight);
- font.setScaleX(1.0 * nWidth / nHeight);
+ font.setScaleX(nWidth / nHeight);
if (rInstance.NeedsArtificialItalic())
font.setSkewX(-1.0 * ARTIFICIAL_ITALIC_SKEW);
if (rInstance.NeedsArtificialBold())
@@ -94,7 +94,7 @@ void SkiaTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalGr
// Vertical font, use width as "height".
SkFont verticalFont(font);
verticalFont.setSize(nWidth);
- verticalFont.setScaleX(1.0 * nHeight / nWidth);
+ verticalFont.setScaleX(nHeight / nWidth);
assert(dynamic_cast<SkiaSalGraphicsImpl*>(rGraphics.GetImpl()));
SkiaSalGraphicsImpl* impl = static_cast<SkiaSalGraphicsImpl*>(rGraphics.GetImpl());