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
, m_aLinearPos(rLinearPos)
, m_pFontInstance(pFontInstance)
{
assert(pFontInstance);
}
enum
......
......@@ -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;
......
......@@ -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();
};
......
/* -*- 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 @@
#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;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
}
......
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