summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2018-09-06 13:46:28 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2018-09-06 18:46:06 +0200
commitc177c305fc839e7a64d228ec56209d133588572b (patch)
treee0281793695a4f2e95b6a6d9614ded20a95eb8d7
parent2c704832567d0948595ebe1b239314890a01da4e (diff)
tdf#119302 WIN better font scale handling
Moves the scale factor into the LogicalFontInstance and uses the Glyphs font fallback level to use the correct font and scale. Probably the glyphs should be using a rtl::Reference to the LogcalFontInstance instead of the fallback level. I don't know if glyphs are evicted from the cache, if the fallback changes. There is now an assert and all places will use 1.0 as the default scaling factor, so LO should at least not crash. Change-Id: I9dd4fc3a5b5924fc379b48a7f71c9eed26b4779d Reviewed-on: https://gerrit.libreoffice.org/60091 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
-rw-r--r--vcl/inc/win/salgdi.h2
-rw-r--r--vcl/inc/win/winlayout.hxx3
-rw-r--r--vcl/win/gdi/salfont.cxx46
-rw-r--r--vcl/win/gdi/salgdi.cxx2
4 files changed, 33 insertions, 20 deletions
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index 51d14cb7ddda..32a104bef88e 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -171,8 +171,6 @@ private:
HFONT mhFonts[ MAX_FALLBACK ]; // Font + Fallbacks
rtl::Reference<WinFontInstance>
mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance
- float mfFontScale[ MAX_FALLBACK ]; // allows metrics emulation of huge font sizes
- float mfCurrentFontScale;
HRGN mhRegion; // vcl::Region Handle
HPEN mhDefPen; // DefaultPen
HBRUSH mhDefBrush; // DefaultBrush
diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index 598d90c60588..066f7b587f6d 100644
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -156,6 +156,8 @@ public:
void SetHFONT(const HFONT);
HFONT GetHFONT() const { return m_hFont; }
+ void SetScale(float fScale) { m_fScale = fScale; }
+ float GetScale() const { return m_fScale; }
// Prevent deletion of the HFONT in the WinFontInstance destructor
// Used for the ScopedFont handling
@@ -167,6 +169,7 @@ private:
virtual hb_font_t* ImplInitHbFont() override;
HFONT m_hFont;
+ float m_fScale;
GlyphCache maGlyphCache;
};
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 8c1a6651bbd5..bed9c7a22376 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -919,7 +919,6 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, int nFallbackLevel)
::SelectFont(getHDC(), mhDefFont);
mhDefFont = nullptr;
}
- mfCurrentFontScale = mfFontScale[nFallbackLevel];
// release no longer referenced font handles
for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
{
@@ -933,25 +932,24 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, int nFallbackLevel)
return;
}
- mpWinFontEntry[ nFallbackLevel ] = static_cast<WinFontInstance*>(pFont);
+ WinFontInstance *pFontInstance = static_cast<WinFontInstance*>(pFont);
+ mpWinFontEntry[ nFallbackLevel ] = pFontInstance;
HFONT hOldFont = nullptr;
- HFONT hNewFont = mpWinFontEntry[ nFallbackLevel ]->GetHFONT();
+ HFONT hNewFont = pFontInstance->GetHFONT();
if (!hNewFont)
{
- hNewFont = ImplDoSetFont(pFont->GetFontSelectPattern(), pFont->GetFontFace(), mfFontScale[ nFallbackLevel ], hOldFont);
+ float fFontScale = 1.0;
+ hNewFont = ImplDoSetFont(pFont->GetFontSelectPattern(), pFont->GetFontFace(), fFontScale, hOldFont);
mpWinFontEntry[ nFallbackLevel ]->SetHFONT(hNewFont);
+ mpWinFontEntry[ nFallbackLevel ]->SetScale(fFontScale);
}
else
hOldFont = ::SelectFont( getHDC(), hNewFont );
- mfCurrentFontScale = mfFontScale[nFallbackLevel];
-
+ // keep default font
if( !mhDefFont )
- {
- // keep default font
mhDefFont = hOldFont;
- }
else
{
// release no longer referenced font handles
@@ -968,7 +966,7 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, int nFallbackLevel)
}
// now the font is live => update font face
- const WinFontFace* pFontFace = static_cast<const WinFontFace*>(mpWinFontEntry[nFallbackLevel]->GetFontFace());
+ const WinFontFace* pFontFace = static_cast<const WinFontFace*>(pFontInstance->GetFontFace());
pFontFace->UpdateFromHDC(getHDC());
}
@@ -1008,7 +1006,7 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int nFa
rxFontMetric->SetSlant( 0 );
// transformation dependent font metrics
- rxFontMetric->SetWidth(static_cast<int>( mfFontScale[nFallbackLevel] * aWinMetric.tmAveCharWidth ));
+ rxFontMetric->SetWidth(static_cast<int>(mpWinFontEntry[nFallbackLevel]->GetScale() * aWinMetric.tmAveCharWidth));
const std::vector<uint8_t> rHhea(aHheaRawData.get(), aHheaRawData.get() + aHheaRawData.size());
const std::vector<uint8_t> rOS2(aOS2RawData.get(), aOS2RawData.get() + aOS2RawData.size());
@@ -1361,7 +1359,18 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle
return true;
}
+ rtl::Reference<WinFontInstance> pFont = mpWinFontEntry[rGlyph.mnFallbackLevel];
+ assert(pFont.is());
+
HDC hDC = getHDC();
+ HFONT hFont = static_cast<HFONT>(GetCurrentObject(hDC, OBJ_FONT));
+ float fFontScale = 1.0;
+ if (pFont.is())
+ {
+ if (hFont != pFont->GetHFONT())
+ SelectObject(hDC, pFont->GetHFONT());
+ fFontScale = pFont->GetScale();
+ }
// use unity matrix
MAT2 aMat;
@@ -1375,15 +1384,17 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle
aGM.gmptGlyphOrigin.x = aGM.gmptGlyphOrigin.y = 0;
aGM.gmBlackBoxX = aGM.gmBlackBoxY = 0;
DWORD nSize = ::GetGlyphOutlineW(hDC, rGlyph.maGlyphId, nGGOFlags, &aGM, 0, nullptr, &aMat);
+ if (pFont.is() && hFont != pFont->GetHFONT())
+ SelectObject(hDC, hFont);
if( nSize == GDI_ERROR )
return false;
rRect = tools::Rectangle( Point( +aGM.gmptGlyphOrigin.x, -aGM.gmptGlyphOrigin.y ),
Size( aGM.gmBlackBoxX, aGM.gmBlackBoxY ) );
- rRect.SetLeft(static_cast<int>( mfCurrentFontScale * rRect.Left() ));
- rRect.SetRight(static_cast<int>( mfCurrentFontScale * rRect.Right() ) + 1);
- rRect.SetTop(static_cast<int>( mfCurrentFontScale * rRect.Top() ));
- rRect.SetBottom(static_cast<int>( mfCurrentFontScale * rRect.Bottom() ) + 1);
+ rRect.SetLeft(static_cast<int>( fFontScale * rRect.Left() ));
+ rRect.SetRight(static_cast<int>( fFontScale * rRect.Right() ) + 1);
+ rRect.SetTop(static_cast<int>( fFontScale * rRect.Top() ));
+ rRect.SetBottom(static_cast<int>( fFontScale * rRect.Bottom() ) + 1);
g_BoundRectCache.insert({rGlyph.maGlyphId, rRect});
@@ -1563,7 +1574,10 @@ bool WinSalGraphics::GetGlyphOutline(const GlyphItem& rGlyph,
// rescaling needed for the tools::PolyPolygon conversion
if( rB2DPolyPoly.count() )
{
- const double fFactor(mfCurrentFontScale/256);
+ rtl::Reference<WinFontInstance> pFont = mpWinFontEntry[rGlyph.mnFallbackLevel];
+ assert(pFont.is());
+ float fFontScale = pFont.is() ? pFont->GetScale() : 1.0;
+ const double fFactor(fFontScale/256);
rB2DPolyPoly.transform(basegfx::utils::createScaleB2DHomMatrix(fFactor, fFactor));
}
diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx
index 78961ddaa8ba..46155bbef3dc 100644
--- a/vcl/win/gdi/salgdi.cxx
+++ b/vcl/win/gdi/salgdi.cxx
@@ -608,7 +608,6 @@ WinSalGraphics::WinSalGraphics(WinSalGraphics::Type eType, bool bScreen, HWND hW
mbWindow(eType == WinSalGraphics::WINDOW),
mbScreen(bScreen),
mhWnd(hWnd),
- mfCurrentFontScale(1.0),
mhRegion(nullptr),
mhDefPen(nullptr),
mhDefBrush(nullptr),
@@ -626,7 +625,6 @@ WinSalGraphics::WinSalGraphics(WinSalGraphics::Type eType, bool bScreen, HWND hW
{
mhFonts[ i ] = nullptr;
mpWinFontEntry[ i ] = nullptr;
- mfFontScale[ i ] = 1.0;
}
}