summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2018-10-27 15:37:39 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2018-10-30 11:42:49 +0100
commit7b0f2ee441b0cbcb88f3020df40c49e7cd6f9fb1 (patch)
tree2382b66e9a92907934e891cded6497c8ea7186ef /vcl
parenta4b60b78ea36d55a2abf0e5efccd8530568d2209 (diff)
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: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/fontinstance.hxx6
-rw-r--r--vcl/inc/impfontcache.hxx4
-rw-r--r--vcl/inc/impglyphitem.hxx40
-rw-r--r--vcl/quartz/ctfonts.cxx7
-rw-r--r--vcl/source/font/fontcache.cxx4
-rw-r--r--vcl/source/font/fontinstance.cxx4
-rw-r--r--vcl/unx/generic/glyphs/freetype_glyphcache.cxx11
-rw-r--r--vcl/win/gdi/salfont.cxx24
8 files changed, 68 insertions, 32 deletions
diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx
index eaad4d3d1f42..6f171ce72e49 100644
--- a/vcl/inc/fontinstance.hxx
+++ b/vcl/inc/fontinstance.hxx
@@ -70,8 +70,8 @@ public: // TODO: make data members private
const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
const ImplFontCache* GetFontCache() const { return mpFontCache; }
- bool GetCachedGlyphBoundRect(sal_GlyphId, tools::Rectangle &);
- void CacheGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &);
+ bool GetCachedGlyphBoundRect(sal_GlyphId, tools::Rectangle &) const;
+ void CacheGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &) const;
int GetKashidaWidth();
@@ -92,7 +92,7 @@ private:
// TODO: at least the ones which just differ in orientation, stretching or height
typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList;
std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList;
- ImplFontCache * mpFontCache;
+ mutable ImplFontCache * mpFontCache;
const FontSelectPattern m_aFontSelData;
hb_font_t* m_pHbFont;
double m_nAveWidthFactor;
diff --git a/vcl/inc/impfontcache.hxx b/vcl/inc/impfontcache.hxx
index 25bc970c97a9..df0dc0c61344 100644
--- a/vcl/inc/impfontcache.hxx
+++ b/vcl/inc/impfontcache.hxx
@@ -88,8 +88,8 @@ public:
LogicalFontInstance* pLogicalFont,
int nFallbackLevel, OUString& rMissingCodes );
- bool GetCachedGlyphBoundRect(LogicalFontInstance *, sal_GlyphId, tools::Rectangle &);
- void CacheGlyphBoundRect(LogicalFontInstance *, sal_GlyphId, tools::Rectangle &);
+ bool GetCachedGlyphBoundRect(const LogicalFontInstance *, sal_GlyphId, tools::Rectangle &);
+ void CacheGlyphBoundRect(const LogicalFontInstance *, sal_GlyphId, tools::Rectangle &);
void Invalidate();
};
diff --git a/vcl/inc/impglyphitem.hxx b/vcl/inc/impglyphitem.hxx
new file mode 100644
index 000000000000..a4843be677fb
--- /dev/null
+++ b/vcl/inc/impglyphitem.hxx
@@ -0,0 +1,40 @@
+/* -*- 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: */
diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx
index 5d3ca2c8e083..1425f7d1617b 100644
--- a/vcl/quartz/ctfonts.cxx
+++ b/vcl/quartz/ctfonts.cxx
@@ -34,6 +34,7 @@
#endif
#include <fontinstance.hxx>
#include <fontattributes.hxx>
+#include <impglyphitem.hxx>
#include <PhysicalFontCollection.hxx>
#include <quartz/salgdi.h>
#include <quartz/utils.h>
@@ -139,7 +140,8 @@ void CoreTextStyle::GetFontMetric( ImplFontMetricDataRef const & rxFontMetric )
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;
CGGlyph nCGGlyph = rGlyph.m_aGlyphId;
@@ -159,7 +161,8 @@ bool CoreTextStyle::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle&
long xMax = ceil(aCGRect.origin.x + aCGRect.size.width);
long yMax = ceil(aCGRect.origin.y + aCGRect.size.height);
rRect = tools::Rectangle(xMin, -yMax, xMax, -yMin);
- CacheGlyphBoundRect(rGlyph.m_aGlyphId, rRect);
+
+ ::CacheGlyphBoundRect(rGlyph, rRect);
return true;
}
diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx
index 51a04a34b769..abcee2358c4b 100644
--- a/vcl/source/font/fontcache.cxx
+++ b/vcl/source/font/fontcache.cxx
@@ -243,7 +243,7 @@ void ImplFontCache::Invalidate()
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())
return false;
@@ -260,7 +260,7 @@ bool ImplFontCache::GetCachedGlyphBoundRect(LogicalFontInstance *pFont, sal_Glyp
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())
return;
diff --git a/vcl/source/font/fontinstance.cxx b/vcl/source/font/fontinstance.cxx
index 0a7bc91c57af..7cdf4b931978 100644
--- a/vcl/source/font/fontinstance.cxx
+++ b/vcl/source/font/fontinstance.cxx
@@ -142,14 +142,14 @@ void LogicalFontInstance::IgnoreFallbackForUnicode( sal_UCS4 cChar, FontWeight e
mpUnicodeFallbackList->erase( it );
}
-bool LogicalFontInstance::GetCachedGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect)
+bool LogicalFontInstance::GetCachedGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect) const
{
if (!mpFontCache)
return false;
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)
return;
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index 74bbd7093411..ce04e4f68b55 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -24,6 +24,7 @@
#include <vcl/svapp.hxx>
#include <fontinstance.hxx>
+#include <impglyphitem.hxx>
#include <impfont.hxx>
#include <fontattributes.hxx>
@@ -590,8 +591,7 @@ void FreetypeFont::ApplyGlyphTransform(bool bVertical, FT_Glyph pGlyphFT ) const
bool FreetypeFont::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect)
{
- assert(mpFontInstance.is());
- if (mpFontInstance.is() && mpFontInstance->GetCachedGlyphBoundRect(rGlyph.m_aGlyphId, rRect))
+ if (::GetCachedGlyphBoundRect(rGlyph, rRect))
return true;
FT_Activate_Size( maSizeFT );
@@ -613,13 +613,10 @@ bool FreetypeFont::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle&
FT_BBox 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 );
+ rRect = tools::Rectangle(aBbox.xMin, -aBbox.yMax, aBbox.xMax, -aBbox.yMin);
+ ::CacheGlyphBoundRect(rGlyph, rRect);
return true;
}
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 4409effd789f..0e74be70f5a8 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -57,6 +57,7 @@
#include <win/winlayout.hxx>
#include <impfontcharmap.hxx>
#include <impfontmetricdata.hxx>
+#include <impglyphitem.hxx>
using namespace vcl;
@@ -1327,21 +1328,17 @@ void WinSalGraphics::ClearDevFontCache()
bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect)
{
- rtl::Reference<WinFontInstance> pFont = static_cast<WinFontInstance*>(rGlyph.m_pFontInstance);
- assert(pFont.is());
-
- if (pFont.is() && pFont->GetCachedGlyphBoundRect(rGlyph.m_aGlyphId, rRect))
+ if (::GetCachedGlyphBoundRect(rGlyph, rRect))
return true;
+ WinFontInstance* pFont = static_cast<WinFontInstance*>(rGlyph.m_pFontInstance);
+
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();
- }
+ if (hFont != pFont->GetHFONT())
+ SelectObject(hDC, pFont->GetHFONT());
+ fFontScale = pFont->GetScale();
// use unity matrix
MAT2 aMat;
@@ -1355,9 +1352,9 @@ 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.m_aGlyphId, nGGOFlags, &aGM, 0, nullptr, &aMat);
- if (pFont.is() && hFont != pFont->GetHFONT())
+ if (hFont != pFont->GetHFONT())
SelectObject(hDC, hFont);
- if( nSize == GDI_ERROR )
+ if (nSize == GDI_ERROR)
return false;
rRect = tools::Rectangle( Point( +aGM.gmptGlyphOrigin.x, -aGM.gmptGlyphOrigin.y ),
@@ -1367,8 +1364,7 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle
rRect.SetTop(static_cast<int>( fFontScale * rRect.Top() ));
rRect.SetBottom(static_cast<int>( fFontScale * rRect.Bottom() ) + 1);
- pFont->CacheGlyphBoundRect(rGlyph.m_aGlyphId, rRect);
-
+ ::CacheGlyphBoundRect(rGlyph, rRect);
return true;
}