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

Rely on the font instance of the glyph

The FreetypeFont might already have released the font instance of
the glyph, but the glyphs font instance must still be valid, so
use this instead to cache glyph bound rect.

For whatever reason the Windows compiler doesn't accept inline
functions in the GlyphItem struct and wants to export them in
the DLL, even when declared VCL_DLLPRIVATE, so this just uses
static inlines as a workaround.

Change-Id: I4539d91a846a54a05f9648638494e1e99f704b0a
Reviewed-on: https://gerrit.libreoffice.org/62425
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst a4b60b78
...@@ -55,6 +55,7 @@ struct VCL_DLLPUBLIC GlyphItem ...@@ -55,6 +55,7 @@ struct VCL_DLLPUBLIC GlyphItem
, m_aLinearPos(rLinearPos) , m_aLinearPos(rLinearPos)
, m_pFontInstance(pFontInstance) , m_pFontInstance(pFontInstance)
{ {
assert(pFontInstance);
} }
enum enum
......
...@@ -70,8 +70,8 @@ public: // TODO: make data members private ...@@ -70,8 +70,8 @@ public: // TODO: make data members private
const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); } const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
const ImplFontCache* GetFontCache() const { return mpFontCache; } const ImplFontCache* GetFontCache() const { return mpFontCache; }
bool GetCachedGlyphBoundRect(sal_GlyphId, tools::Rectangle &); bool GetCachedGlyphBoundRect(sal_GlyphId, tools::Rectangle &) const;
void CacheGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &); void CacheGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &) const;
int GetKashidaWidth(); int GetKashidaWidth();
...@@ -92,7 +92,7 @@ private: ...@@ -92,7 +92,7 @@ private:
// TODO: at least the ones which just differ in orientation, stretching or height // TODO: at least the ones which just differ in orientation, stretching or height
typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList; typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList;
std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList; std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList;
ImplFontCache * mpFontCache; mutable ImplFontCache * mpFontCache;
const FontSelectPattern m_aFontSelData; const FontSelectPattern m_aFontSelData;
hb_font_t* m_pHbFont; hb_font_t* m_pHbFont;
double m_nAveWidthFactor; double m_nAveWidthFactor;
......
...@@ -88,8 +88,8 @@ public: ...@@ -88,8 +88,8 @@ public:
LogicalFontInstance* pLogicalFont, LogicalFontInstance* pLogicalFont,
int nFallbackLevel, OUString& rMissingCodes ); int nFallbackLevel, OUString& rMissingCodes );
bool GetCachedGlyphBoundRect(LogicalFontInstance *, sal_GlyphId, tools::Rectangle &); bool GetCachedGlyphBoundRect(const LogicalFontInstance *, sal_GlyphId, tools::Rectangle &);
void CacheGlyphBoundRect(LogicalFontInstance *, sal_GlyphId, tools::Rectangle &); void CacheGlyphBoundRect(const LogicalFontInstance *, sal_GlyphId, tools::Rectangle &);
void Invalidate(); void Invalidate();
}; };
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_VCL_IMPGLYPHITEM_HXX
#define INCLUDED_VCL_IMPGLYPHITEM_HXX
#include <vcl/glyphitem.hxx>
// for whatever reason MSVC tries to export these when declared class inline even
// when annotated with VCL_DLLPRIVATE, so keep them as seperate static inline.
static inline bool GetCachedGlyphBoundRect(const GlyphItem& rItem, tools::Rectangle& rRect)
{
return rItem.m_pFontInstance->GetCachedGlyphBoundRect(rItem.m_aGlyphId, rRect);
}
static inline void CacheGlyphBoundRect(const GlyphItem& rItem, tools::Rectangle& rRect)
{
rItem.m_pFontInstance->CacheGlyphBoundRect(rItem.m_aGlyphId, rRect);
}
#endif // INCLUDED_VCL_IMPGLYPHITEM_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#endif #endif
#include <fontinstance.hxx> #include <fontinstance.hxx>
#include <fontattributes.hxx> #include <fontattributes.hxx>
#include <impglyphitem.hxx>
#include <PhysicalFontCollection.hxx> #include <PhysicalFontCollection.hxx>
#include <quartz/salgdi.h> #include <quartz/salgdi.h>
#include <quartz/utils.h> #include <quartz/utils.h>
...@@ -139,7 +140,8 @@ void CoreTextStyle::GetFontMetric( ImplFontMetricDataRef const & rxFontMetric ) ...@@ -139,7 +140,8 @@ void CoreTextStyle::GetFontMetric( ImplFontMetricDataRef const & rxFontMetric )
bool CoreTextStyle::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect ) bool CoreTextStyle::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect )
{ {
if (GetCachedGlyphBoundRect(rGlyph.m_aGlyphId, rRect)) assert(this == rGlyph.m_pFontInstance);
if (::GetCachedGlyphBoundRect(rGlyph, rRect))
return true; return true;
CGGlyph nCGGlyph = rGlyph.m_aGlyphId; CGGlyph nCGGlyph = rGlyph.m_aGlyphId;
...@@ -159,7 +161,8 @@ bool CoreTextStyle::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& ...@@ -159,7 +161,8 @@ bool CoreTextStyle::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle&
long xMax = ceil(aCGRect.origin.x + aCGRect.size.width); long xMax = ceil(aCGRect.origin.x + aCGRect.size.width);
long yMax = ceil(aCGRect.origin.y + aCGRect.size.height); long yMax = ceil(aCGRect.origin.y + aCGRect.size.height);
rRect = tools::Rectangle(xMin, -yMax, xMax, -yMin); rRect = tools::Rectangle(xMin, -yMax, xMax, -yMin);
CacheGlyphBoundRect(rGlyph.m_aGlyphId, rRect);
::CacheGlyphBoundRect(rGlyph, rRect);
return true; return true;
} }
......
...@@ -243,7 +243,7 @@ void ImplFontCache::Invalidate() ...@@ -243,7 +243,7 @@ void ImplFontCache::Invalidate()
m_aBoundRectCache.clear(); m_aBoundRectCache.clear();
} }
bool ImplFontCache::GetCachedGlyphBoundRect(LogicalFontInstance *pFont, sal_GlyphId nID, tools::Rectangle &rRect) bool ImplFontCache::GetCachedGlyphBoundRect(const LogicalFontInstance *pFont, sal_GlyphId nID, tools::Rectangle &rRect)
{ {
if (!pFont->GetFontCache()) if (!pFont->GetFontCache())
return false; return false;
...@@ -260,7 +260,7 @@ bool ImplFontCache::GetCachedGlyphBoundRect(LogicalFontInstance *pFont, sal_Glyp ...@@ -260,7 +260,7 @@ bool ImplFontCache::GetCachedGlyphBoundRect(LogicalFontInstance *pFont, sal_Glyp
return false; return false;
} }
void ImplFontCache::CacheGlyphBoundRect(LogicalFontInstance *pFont, sal_GlyphId nID, tools::Rectangle &rRect) void ImplFontCache::CacheGlyphBoundRect(const LogicalFontInstance *pFont, sal_GlyphId nID, tools::Rectangle &rRect)
{ {
if (!pFont->GetFontCache()) if (!pFont->GetFontCache())
return; return;
......
...@@ -142,14 +142,14 @@ void LogicalFontInstance::IgnoreFallbackForUnicode( sal_UCS4 cChar, FontWeight e ...@@ -142,14 +142,14 @@ void LogicalFontInstance::IgnoreFallbackForUnicode( sal_UCS4 cChar, FontWeight e
mpUnicodeFallbackList->erase( it ); mpUnicodeFallbackList->erase( it );
} }
bool LogicalFontInstance::GetCachedGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect) bool LogicalFontInstance::GetCachedGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect) const
{ {
if (!mpFontCache) if (!mpFontCache)
return false; return false;
return mpFontCache->GetCachedGlyphBoundRect(this, nID, rRect); return mpFontCache->GetCachedGlyphBoundRect(this, nID, rRect);
} }
void LogicalFontInstance::CacheGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect) void LogicalFontInstance::CacheGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect) const
{ {
if (!mpFontCache) if (!mpFontCache)
return; return;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <fontinstance.hxx> #include <fontinstance.hxx>
#include <impglyphitem.hxx>
#include <impfont.hxx> #include <impfont.hxx>
#include <fontattributes.hxx> #include <fontattributes.hxx>
...@@ -590,8 +591,7 @@ void FreetypeFont::ApplyGlyphTransform(bool bVertical, FT_Glyph pGlyphFT ) const ...@@ -590,8 +591,7 @@ void FreetypeFont::ApplyGlyphTransform(bool bVertical, FT_Glyph pGlyphFT ) const
bool FreetypeFont::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect) bool FreetypeFont::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect)
{ {
assert(mpFontInstance.is()); if (::GetCachedGlyphBoundRect(rGlyph, rRect))
if (mpFontInstance.is() && mpFontInstance->GetCachedGlyphBoundRect(rGlyph.m_aGlyphId, rRect))
return true; return true;
FT_Activate_Size( maSizeFT ); FT_Activate_Size( maSizeFT );
...@@ -613,13 +613,10 @@ bool FreetypeFont::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& ...@@ -613,13 +613,10 @@ bool FreetypeFont::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle&
FT_BBox aBbox; FT_BBox aBbox;
FT_Glyph_Get_CBox( pGlyphFT, FT_GLYPH_BBOX_PIXELS, &aBbox ); FT_Glyph_Get_CBox( pGlyphFT, FT_GLYPH_BBOX_PIXELS, &aBbox );
rRect = tools::Rectangle(aBbox.xMin, -aBbox.yMax, aBbox.xMax, -aBbox.yMin);
if (mpFontInstance.is())
mpFontInstance->CacheGlyphBoundRect(rGlyph.m_aGlyphId, rRect);
FT_Done_Glyph( pGlyphFT ); FT_Done_Glyph( pGlyphFT );
rRect = tools::Rectangle(aBbox.xMin, -aBbox.yMax, aBbox.xMax, -aBbox.yMin);
::CacheGlyphBoundRect(rGlyph, rRect);
return true; return true;
} }
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <win/winlayout.hxx> #include <win/winlayout.hxx>
#include <impfontcharmap.hxx> #include <impfontcharmap.hxx>
#include <impfontmetricdata.hxx> #include <impfontmetricdata.hxx>
#include <impglyphitem.hxx>
using namespace vcl; using namespace vcl;
...@@ -1327,21 +1328,17 @@ void WinSalGraphics::ClearDevFontCache() ...@@ -1327,21 +1328,17 @@ void WinSalGraphics::ClearDevFontCache()
bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect) bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect)
{ {
rtl::Reference<WinFontInstance> pFont = static_cast<WinFontInstance*>(rGlyph.m_pFontInstance); if (::GetCachedGlyphBoundRect(rGlyph, rRect))
assert(pFont.is());
if (pFont.is() && pFont->GetCachedGlyphBoundRect(rGlyph.m_aGlyphId, rRect))
return true; return true;
WinFontInstance* pFont = static_cast<WinFontInstance*>(rGlyph.m_pFontInstance);
HDC hDC = getHDC(); HDC hDC = getHDC();
HFONT hFont = static_cast<HFONT>(GetCurrentObject(hDC, OBJ_FONT)); HFONT hFont = static_cast<HFONT>(GetCurrentObject(hDC, OBJ_FONT));
float fFontScale = 1.0; float fFontScale = 1.0;
if (pFont.is())
{
if (hFont != pFont->GetHFONT()) if (hFont != pFont->GetHFONT())
SelectObject(hDC, pFont->GetHFONT()); SelectObject(hDC, pFont->GetHFONT());
fFontScale = pFont->GetScale(); fFontScale = pFont->GetScale();
}
// use unity matrix // use unity matrix
MAT2 aMat; MAT2 aMat;
...@@ -1355,9 +1352,9 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle ...@@ -1355,9 +1352,9 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle
aGM.gmptGlyphOrigin.x = aGM.gmptGlyphOrigin.y = 0; aGM.gmptGlyphOrigin.x = aGM.gmptGlyphOrigin.y = 0;
aGM.gmBlackBoxX = aGM.gmBlackBoxY = 0; aGM.gmBlackBoxX = aGM.gmBlackBoxY = 0;
DWORD nSize = ::GetGlyphOutlineW(hDC, rGlyph.m_aGlyphId, nGGOFlags, &aGM, 0, nullptr, &aMat); DWORD nSize = ::GetGlyphOutlineW(hDC, rGlyph.m_aGlyphId, nGGOFlags, &aGM, 0, nullptr, &aMat);
if (pFont.is() && hFont != pFont->GetHFONT()) if (hFont != pFont->GetHFONT())
SelectObject(hDC, hFont); SelectObject(hDC, hFont);
if( nSize == GDI_ERROR ) if (nSize == GDI_ERROR)
return false; return false;
rRect = tools::Rectangle( Point( +aGM.gmptGlyphOrigin.x, -aGM.gmptGlyphOrigin.y ), rRect = tools::Rectangle( Point( +aGM.gmptGlyphOrigin.x, -aGM.gmptGlyphOrigin.y ),
...@@ -1367,8 +1364,7 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle ...@@ -1367,8 +1364,7 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle
rRect.SetTop(static_cast<int>( fFontScale * rRect.Top() )); rRect.SetTop(static_cast<int>( fFontScale * rRect.Top() ));
rRect.SetBottom(static_cast<int>( fFontScale * rRect.Bottom() ) + 1); rRect.SetBottom(static_cast<int>( fFontScale * rRect.Bottom() ) + 1);
pFont->CacheGlyphBoundRect(rGlyph.m_aGlyphId, rRect); ::CacheGlyphBoundRect(rGlyph, rRect);
return true; return true;
} }
......
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