summaryrefslogtreecommitdiff
path: root/vcl/win
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2018-09-06 14:04:25 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2018-09-07 20:27:01 +0200
commit7cb3e475f2fb0162c7290414509de4fb8fe57e30 (patch)
treeecd3e4dedd2c171991700a4294c410d17782179c /vcl/win
parent334df91c6e464fe6434500f63e2fb12438722845 (diff)
WIN add SalGraphics* to WinFontInstance
HFONT lookup in ImplDoSetFont depends on the mbVirDev of the WinSalGraphics. Since we need too look up HFONTs for SalLayout without changing the corresponding SalGraphics, add a pointer to the WinFontInstance. Change-Id: Idb6573ce7267f0019c2183be47621d0eaef8e57b Reviewed-on: https://gerrit.libreoffice.org/60093 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/win')
-rw-r--r--vcl/win/gdi/salfont.cxx11
-rw-r--r--vcl/win/gdi/winlayout.cxx26
2 files changed, 21 insertions, 16 deletions
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index e2734052c9c0..15a95ee98668 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -934,13 +934,10 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, int nFallbackLevel)
HFONT hNewFont = pFontInstance->GetHFONT();
if (!hNewFont)
{
- float fFontScale = 1.0;
- hNewFont = ImplDoSetFont(pFont->GetFontSelectPattern(), pFont->GetFontFace(), fFontScale, hOldFont);
- mpWinFontEntry[ nFallbackLevel ]->SetHFONT(hNewFont);
- mpWinFontEntry[ nFallbackLevel ]->SetScale(fFontScale);
+ pFontInstance->SetGraphics(this);
+ hNewFont = pFontInstance->GetHFONT();
}
- else
- hOldFont = ::SelectFont( getHDC(), hNewFont );
+ hOldFont = ::SelectFont(getHDC(), hNewFont);
// keep default font
if( !mhDefFont )
@@ -1588,7 +1585,7 @@ ScopedFont::ScopedFont(WinSalGraphics & rData): m_rData(rData), m_hOrigFont(null
if (m_rData.mpWinFontEntry[0])
{
m_hOrigFont = m_rData.mpWinFontEntry[0]->GetHFONT();
- m_rData.mpWinFontEntry[0]->UnsetHFONT();
+ m_rData.mpWinFontEntry[0]->SetHFONT(nullptr);
}
}
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 3800fcd9adc3..a1d76c8026a4 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -307,13 +307,16 @@ std::unique_ptr<SalLayout> WinSalGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs
assert(mpWinFontEntry[nFallbackLevel]->GetFontFace());
+ mpWinFontEntry[nFallbackLevel]->SetGraphics(this);
GenericSalLayout *aLayout = new GenericSalLayout(*mpWinFontEntry[nFallbackLevel]);
return std::unique_ptr<SalLayout>(aLayout);
}
WinFontInstance::WinFontInstance(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP)
: LogicalFontInstance(rPFF, rFSP)
+ , m_pGraphics(nullptr)
, m_hFont(nullptr)
+ , m_fScale(1.0f)
{
}
@@ -335,8 +338,12 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
{
sal_uLong nLength = 0;
unsigned char* pBuffer = nullptr;
- HFONT hFont = static_cast<HFONT>(pUserData);
- HDC hDC = GetDC(nullptr);
+ WinFontInstance* pFont = static_cast<WinFontInstance*>(pUserData);
+ HDC hDC = pFont->GetGraphics()->getHDC();
+ HFONT hFont = pFont->GetHFONT();
+ assert(hDC);
+ assert(hFont);
+
HGDIOBJ hOrigFont = SelectObject(hDC, hFont);
nLength = ::GetFontData(hDC, OSL_NETDWORD(nTableTag), 0, nullptr, 0);
if (nLength > 0 && nLength != GDI_ERROR)
@@ -345,7 +352,6 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
::GetFontData(hDC, OSL_NETDWORD(nTableTag), 0, pBuffer, nLength);
}
SelectObject(hDC, hOrigFont);
- ReleaseDC(nullptr, hDC);
hb_blob_t* pBlob = nullptr;
if (pBuffer != nullptr)
@@ -356,8 +362,8 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
hb_font_t* WinFontInstance::ImplInitHbFont()
{
- assert(m_hFont);
- hb_font_t* pHbFont = InitHbFont(hb_face_create_for_tables(getFontTable, m_hFont, nullptr));
+ assert(m_pGraphics);
+ hb_font_t* pHbFont = InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr));
// Calculate the AverageWidthFactor, see LogicalFontInstance::GetScale().
if (GetFontSelectPattern().mnWidth)
@@ -373,14 +379,13 @@ hb_font_t* WinFontInstance::ImplInitHbFont()
aLogFont.lfWidth = 0;
// Get the font metrics.
+ HDC hDC = m_pGraphics->getHDC();
HFONT hNewFont = CreateFontIndirectW(&aLogFont);
- HDC hDC = GetDC(nullptr);
HGDIOBJ hOrigFont = SelectObject(hDC, hNewFont);
TEXTMETRICW aFontMetric;
GetTextMetricsW(hDC, &aFontMetric);
SelectObject(hDC, hOrigFont);
DeleteObject(hNewFont);
- ReleaseDC(nullptr, hDC);
SetAverageWidthFactor(nUPEM / aFontMetric.tmAveCharWidth);
}
@@ -388,12 +393,15 @@ hb_font_t* WinFontInstance::ImplInitHbFont()
return pHbFont;
}
-void WinFontInstance::SetHFONT(const HFONT hFont)
+void WinFontInstance::SetGraphics(WinSalGraphics *pGraphics)
{
ReleaseHbFont();
if (m_hFont)
::DeleteFont(m_hFont);
- m_hFont = hFont;
+ m_pGraphics = pGraphics;
+ HFONT hOrigFont;
+ m_hFont = m_pGraphics->ImplDoSetFont(GetFontSelectPattern(), GetFontFace(), m_fScale, hOrigFont);
+ SelectObject(m_pGraphics->getHDC(), hOrigFont);
}
bool WinSalGraphics::CacheGlyphs(const GenericSalLayout& rLayout)