Kaydet (Commit) 7cb3e475 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

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: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst 334df91c
......@@ -170,9 +170,10 @@ private:
bool CacheGlyphs(const GenericSalLayout& rLayout);
bool DrawCachedGlyphs(const GenericSalLayout& rLayout);
HFONT ImplDoSetFont(FontSelectPattern const & i_rFont, const PhysicalFontFace * i_pFontFace, float& o_rFontScale, HFONT& o_rOldFont);
public:
HFONT ImplDoSetFont(FontSelectPattern const & i_rFont, const PhysicalFontFace * i_pFontFace, float& o_rFontScale, HFONT& o_rOldFont);
HDC getHDC() const { return mhLocalDC; }
void setHDC(HDC aNew) { mhLocalDC = aNew; }
......
......@@ -154,20 +154,22 @@ public:
GlyphCache& GetGlyphCache() { return maGlyphCache; }
bool hasHScale() const;
void SetHFONT(const HFONT);
void SetGraphics(WinSalGraphics*);
WinSalGraphics* GetGraphics() const { return m_pGraphics; }
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
void UnsetHFONT() { m_hFont = nullptr; }
void SetHFONT(HFONT hFont) { m_hFont = hFont; }
private:
explicit WinFontInstance(const PhysicalFontFace&, const FontSelectPattern&);
virtual hb_font_t* ImplInitHbFont() override;
WinSalGraphics *m_pGraphics;
HFONT m_hFont;
float m_fScale;
GlyphCache maGlyphCache;
......
......@@ -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);
}
}
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment