summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vcl/inc/PhysicalFontFace.hxx9
-rw-r--r--vcl/inc/fontinstance.hxx11
-rw-r--r--vcl/inc/qt5/Qt5FontFace.hxx2
-rw-r--r--vcl/inc/quartz/salgdi.h2
-rw-r--r--vcl/inc/unx/freetype_glyphcache.hxx3
-rw-r--r--vcl/inc/win/salgdi.h4
-rw-r--r--vcl/qt5/Qt5Font.cxx21
-rw-r--r--vcl/qt5/Qt5FontFace.cxx21
-rw-r--r--vcl/quartz/ctfonts.cxx11
-rw-r--r--vcl/source/font/PhysicalFontFace.cxx22
-rw-r--r--vcl/source/font/fontinstance.cxx2
-rw-r--r--vcl/source/gdi/pdfbuildin_fonts.hxx6
-rw-r--r--vcl/unx/generic/glyphs/freetype_glyphcache.cxx21
-rw-r--r--vcl/unx/generic/glyphs/glyphcache.cxx20
-rw-r--r--vcl/win/gdi/salfont.cxx24
-rw-r--r--vcl/win/gdi/winlayout.cxx31
16 files changed, 121 insertions, 89 deletions
diff --git a/vcl/inc/PhysicalFontFace.hxx b/vcl/inc/PhysicalFontFace.hxx
index 23af5be9169e..d827c7a10987 100644
--- a/vcl/inc/PhysicalFontFace.hxx
+++ b/vcl/inc/PhysicalFontFace.hxx
@@ -20,6 +20,8 @@
#ifndef INCLUDED_VCL_INC_PHYSICALFONTFACE_HXX
#define INCLUDED_VCL_INC_PHYSICALFONTFACE_HXX
+#include <hb.h>
+
#include <salhelper/simplereferenceobject.hxx>
#include <rtl/ref.hxx>
#include <vcl/dllapi.h>
@@ -54,6 +56,8 @@ public:
class VCL_PLUGIN_PUBLIC PhysicalFontFace : public FontAttributes, public salhelper::SimpleReferenceObject
{
public:
+ ~PhysicalFontFace();
+
virtual rtl::Reference<LogicalFontInstance> CreateFontInstance(const FontSelectPattern&) const = 0;
int GetHeight() const { return mnHeight; }
@@ -64,12 +68,17 @@ public:
sal_Int32 CompareWithSize( const PhysicalFontFace& ) const;
sal_Int32 CompareIgnoreSize( const PhysicalFontFace& ) const;
+ hb_face_t* GetHbFace() const;
+ virtual hb_blob_t* GetHbTable(hb_tag_t nTag) const = 0;
+
protected:
explicit PhysicalFontFace(const FontAttributes&);
void SetBitmapSize( int nW, int nH ) { mnWidth=nW; mnHeight=nH; }
long mnWidth; // Width (in pixels)
long mnHeight; // Height (in pixels)
+
+ mutable hb_face_t* mpHbFace;
};
#endif // INCLUDED_VCL_INC_PHYSICALFONTFACE_HXX
diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx
index b57955f82a9e..5e234df72e0c 100644
--- a/vcl/inc/fontinstance.hxx
+++ b/vcl/inc/fontinstance.hxx
@@ -77,14 +77,12 @@ public: // TODO: make data members private
int GetKashidaWidth();
void GetScale(double* nXScale, double* nYScale);
- static inline void DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName);
protected:
explicit LogicalFontInstance(const PhysicalFontFace&, const FontSelectPattern&);
virtual bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const = 0;
- // Takes ownership of pHbFace.
static hb_font_t* InitHbFont(hb_face_t* pHbFace);
virtual hb_font_t* ImplInitHbFont() { assert(false); return hb_font_get_empty(); }
inline void ReleaseHbFont();
@@ -117,15 +115,6 @@ inline void LogicalFontInstance::ReleaseHbFont()
m_pHbFont = nullptr;
}
-inline void LogicalFontInstance::DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName)
-{
- pTagName[0] = static_cast<char>(nTableTag >> 24);
- pTagName[1] = static_cast<char>(nTableTag >> 16);
- pTagName[2] = static_cast<char>(nTableTag >> 8);
- pTagName[3] = static_cast<char>(nTableTag);
- pTagName[4] = 0;
-}
-
#endif // INCLUDED_VCL_INC_FONTINSTANCE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/Qt5FontFace.hxx b/vcl/inc/qt5/Qt5FontFace.hxx
index c427a85445c3..1ecf01545f45 100644
--- a/vcl/inc/qt5/Qt5FontFace.hxx
+++ b/vcl/inc/qt5/Qt5FontFace.hxx
@@ -49,6 +49,8 @@ public:
rtl::Reference<LogicalFontInstance>
CreateFontInstance(const FontSelectPattern& rFSD) const override;
+ hb_blob_t* GetHbTable(hb_tag_t nTag) const override;
+
protected:
Qt5FontFace(const Qt5FontFace&);
Qt5FontFace(const FontAttributes& rFA, const QString& rFontID);
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index 338878e79529..051585648f19 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -73,6 +73,8 @@ public:
rtl::Reference<LogicalFontInstance> CreateFontInstance(const FontSelectPattern&) const override;
+ hb_blob_t* GetHbTable(hb_tag_t nTag) const override;
+
private:
const sal_IntPtr mnFontId;
mutable FontCharMapRef mxCharMap;
diff --git a/vcl/inc/unx/freetype_glyphcache.hxx b/vcl/inc/unx/freetype_glyphcache.hxx
index 17084fcf5a75..9873fa38059d 100644
--- a/vcl/inc/unx/freetype_glyphcache.hxx
+++ b/vcl/inc/unx/freetype_glyphcache.hxx
@@ -61,6 +61,7 @@ public:
int nFaceNum, int nFaceVariation, sal_IntPtr nFontId);
~FreetypeFontInfo();
+ const unsigned char* GetTable( uint32_t, sal_uLong* pLength) const;
const unsigned char* GetTable( const char*, sal_uLong* pLength) const;
FT_FaceRec_* GetFaceFT();
@@ -99,6 +100,8 @@ public:
virtual rtl::Reference<LogicalFontInstance> CreateFontInstance( const FontSelectPattern& ) const override;
virtual sal_IntPtr GetFontId() const override { return mpFreetypeFontInfo->GetFontId(); }
+
+ hb_blob_t* GetHbTable(hb_tag_t nTag) const override;
};
// a class for cache entries for physical font instances that are based on serverfonts
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index d6d8dea14c24..503b8f3aa062 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -76,6 +76,8 @@ public:
FontCharMapRef GetFontCharMap() const;
bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const;
+ hb_blob_t* GetHbTable(hb_tag_t nTag) const override;
+
private:
sal_IntPtr mnId;
@@ -91,6 +93,8 @@ private:
void ReadCmapTable( HDC ) const;
void GetFontCapabilities( HDC hDC ) const;
+
+ mutable HDC mhDC;
};
/** Class that creates (and destroys) a compatible Device Context.
diff --git a/vcl/qt5/Qt5Font.cxx b/vcl/qt5/Qt5Font.cxx
index ee9d339266b2..ffa7e0a78415 100644
--- a/vcl/qt5/Qt5Font.cxx
+++ b/vcl/qt5/Qt5Font.cxx
@@ -80,26 +80,7 @@ Qt5Font::Qt5Font(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP)
}
}
-static hb_blob_t* getFontTable(hb_face_t*, hb_tag_t nTableTag, void* pUserData)
-{
- char pTagName[5];
- LogicalFontInstance::DecodeOpenTypeTag(nTableTag, pTagName);
-
- Qt5Font* pFont = static_cast<Qt5Font*>(pUserData);
- QRawFont aRawFont(QRawFont::fromFont(*pFont));
- QByteArray aTable = aRawFont.fontTable(pTagName);
- const sal_uInt32 nLength = aTable.size();
-
- hb_blob_t* pBlob = nullptr;
- if (nLength > 0)
- pBlob = hb_blob_create(aTable.data(), nLength, HB_MEMORY_MODE_DUPLICATE, nullptr, nullptr);
- return pBlob;
-}
-
-hb_font_t* Qt5Font::ImplInitHbFont()
-{
- return InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr));
-}
+hb_font_t* Qt5Font::ImplInitHbFont() { return InitHbFont(GetFontFace()->GetHbFace()); }
bool Qt5Font::GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const { return false; }
diff --git a/vcl/qt5/Qt5FontFace.cxx b/vcl/qt5/Qt5FontFace.cxx
index a7837667f1dd..2523f3424284 100644
--- a/vcl/qt5/Qt5FontFace.cxx
+++ b/vcl/qt5/Qt5FontFace.cxx
@@ -191,4 +191,25 @@ bool Qt5FontFace::GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities)
return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
}
+hb_blob_t* Qt5FontFace::GetHbTable(hb_tag_t nTag) const
+{
+ char pName[5];
+ pName[0] = static_cast<char>(nTag >> 24);
+ pName[1] = static_cast<char>(nTag >> 16);
+ pName[2] = static_cast<char>(nTag >> 8);
+ pName[3] = static_cast<char>(nTag);
+ pName[4] = 0;
+
+ QFont aFont;
+ aFont.fromString(m_aFontId);
+ QRawFont aRawFont(QRawFont::fromFont(aFont));
+ QByteArray aTable = aRawFont.fontTable(pName);
+ const sal_uInt32 nLength = aTable.size();
+
+ hb_blob_t* pBlob = nullptr;
+ if (nLength > 0)
+ pBlob = hb_blob_create(aTable.data(), nLength, HB_MEMORY_MODE_DUPLICATE, nullptr, nullptr);
+ return pBlob;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx
index 252720a0aa4e..4bb749a7d11a 100644
--- a/vcl/quartz/ctfonts.cxx
+++ b/vcl/quartz/ctfonts.cxx
@@ -232,16 +232,15 @@ bool CoreTextStyle::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& rR
return true;
}
-static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pUserData)
+hb_blob_t* CoreTextFontFace::GetHbTable(hb_tag_t nTag) const
{
sal_uLong nLength = 0;
unsigned char* pBuffer = nullptr;
- CoreTextFontFace* pFont = static_cast<CoreTextFontFace*>(pUserData);
- nLength = pFont->GetFontTable(nTableTag, nullptr);
+ nLength = GetFontTable(nTag, nullptr);
if (nLength > 0)
{
pBuffer = new unsigned char[nLength];
- pFont->GetFontTable(nTableTag, pBuffer);
+ GetFontTable(nTag, pBuffer);
}
hb_blob_t* pBlob = nullptr;
@@ -253,9 +252,7 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
hb_font_t* CoreTextStyle::ImplInitHbFont()
{
- hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, const_cast<PhysicalFontFace*>(GetFontFace()), nullptr);
-
- return InitHbFont(pHbFace);
+ return InitHbFont(GetFontFace()->GetHbFace());
}
rtl::Reference<LogicalFontInstance> CoreTextFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx
index b16488ddc88d..a8ca4dabbfd7 100644
--- a/vcl/source/font/PhysicalFontFace.cxx
+++ b/vcl/source/font/PhysicalFontFace.cxx
@@ -30,6 +30,7 @@ PhysicalFontFace::PhysicalFontFace( const FontAttributes& rDFA )
: FontAttributes( rDFA )
, mnWidth(0)
, mnHeight(0)
+ , mpHbFace(nullptr)
{
// StarSymbol is a unicode font, but it still deserves the symbol flag
if( !IsSymbolFont() )
@@ -37,6 +38,12 @@ PhysicalFontFace::PhysicalFontFace( const FontAttributes& rDFA )
SetSymbolFlag( true );
}
+PhysicalFontFace::~PhysicalFontFace()
+{
+ if (mpHbFace)
+ hb_face_destroy(mpHbFace);
+}
+
sal_Int32 PhysicalFontFace::CompareIgnoreSize( const PhysicalFontFace& rOther ) const
{
// compare their width, weight, italic, style name and family name
@@ -196,4 +203,19 @@ bool PhysicalFontFace::IsBetterMatch( const FontSelectPattern& rFSD, FontMatchSt
return true;
}
+static hb_blob_t* getTable(hb_face_t*, hb_tag_t nTag, void* pUserData)
+{
+ return static_cast<const PhysicalFontFace*>(pUserData)->GetHbTable(nTag);
+}
+
+hb_face_t* PhysicalFontFace::GetHbFace() const
+{
+ if (mpHbFace == nullptr)
+ {
+ const void* pUserData = this;
+ mpHbFace = hb_face_create_for_tables(getTable, const_cast<void*>(pUserData), nullptr);
+ }
+ return mpHbFace;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/font/fontinstance.cxx b/vcl/source/font/fontinstance.cxx
index 808f2d0a5c27..07aab6c38618 100644
--- a/vcl/source/font/fontinstance.cxx
+++ b/vcl/source/font/fontinstance.cxx
@@ -74,8 +74,6 @@ hb_font_t* LogicalFontInstance::InitHbFont(hb_face_t* pHbFace)
unsigned int nUPEM = hb_face_get_upem(pHbFace);
hb_font_set_scale(pHbFont, nUPEM, nUPEM);
hb_ot_font_set_funcs(pHbFont);
- // hb_font_t keeps a reference to hb_face_t, so destroy this one.
- hb_face_destroy(pHbFace);
return pHbFont;
}
diff --git a/vcl/source/gdi/pdfbuildin_fonts.hxx b/vcl/source/gdi/pdfbuildin_fonts.hxx
index 69bdee5dcb9c..1a372c58ba69 100644
--- a/vcl/source/gdi/pdfbuildin_fonts.hxx
+++ b/vcl/source/gdi/pdfbuildin_fonts.hxx
@@ -71,6 +71,12 @@ public:
sal_IntPtr GetFontId() const override { return reinterpret_cast<sal_IntPtr>(&mrBuildin); }
static const BuildinFont& Get(int nId) { return m_aBuildinFonts[nId]; }
+
+ hb_blob_t* GetHbTable(hb_tag_t /*nTag*/) const override
+ {
+ assert(false);
+ return hb_blob_get_empty();
+ }
};
} // namespace pdf
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index d58c5bedc097..8dbeab94013f 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -268,6 +268,12 @@ static const sal_uInt32 T_otto = 0x4f54544f; /* 'OTTO' */
const unsigned char* FreetypeFontInfo::GetTable( const char* pTag, sal_uLong* pLength ) const
{
+ uint32_t nTag = HB_TAG(pTag[0], pTag[1], pTag[2], pTag[3]);
+ return GetTable(nTag, pLength);
+}
+
+const unsigned char* FreetypeFontInfo::GetTable( uint32_t nTag, sal_uLong* pLength ) const
+{
const unsigned char* pBuffer = mpFontFile->GetBuffer();
int nFileSize = mpFontFile->GetFileSize();
if( !pBuffer || nFileSize<1024 )
@@ -288,7 +294,7 @@ const unsigned char* FreetypeFontInfo::GetTable( const char* pTag, sal_uLong* pL
return nullptr;
for( int i = 0; i < nTables; ++i, p+=16 )
{
- if( p[0]==pTag[0] && p[1]==pTag[1] && p[2]==pTag[2] && p[3]==pTag[3] )
+ if( HB_TAG(p[0], p[1], p[2], p[3]) == nTag )
{
sal_uLong nLength = GetUInt( p + 12 );
if( pLength != nullptr )
@@ -407,6 +413,19 @@ rtl::Reference<LogicalFontInstance> FreetypeFontFace::CreateFontInstance(const F
return new FreetypeFontInstance(*this, rFSD);
}
+hb_blob_t* FreetypeFontFace::GetHbTable(hb_tag_t nTag) const
+{
+ sal_uLong nLength = 0;
+ const char* pBuffer = reinterpret_cast<const char*>(
+ mpFreetypeFontInfo->GetTable(nTag, &nLength));
+
+ hb_blob_t* pBlob = nullptr;
+ if (pBuffer != nullptr)
+ pBlob = hb_blob_create(pBuffer, nLength, HB_MEMORY_MODE_READONLY, nullptr, nullptr);
+
+ return pBlob;
+}
+
// FreetypeFont
FreetypeFont::FreetypeFont(LogicalFontInstance* pFontInstance, FreetypeFontInfo* pFI )
diff --git a/vcl/unx/generic/glyphs/glyphcache.cxx b/vcl/unx/generic/glyphs/glyphcache.cxx
index 558e3d8c3323..156cde1f0232 100644
--- a/vcl/unx/generic/glyphs/glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/glyphcache.cxx
@@ -278,27 +278,9 @@ FreetypeFontInstance::~FreetypeFontInstance()
{
}
-static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pUserData)
-{
- char pTagName[5];
- LogicalFontInstance::DecodeOpenTypeTag( nTableTag, pTagName );
-
- sal_uLong nLength = 0;
- FreetypeFontInstance* pFontInstance = static_cast<FreetypeFontInstance*>( pUserData );
- FreetypeFont* pFont = pFontInstance->GetFreetypeFont();
- const char* pBuffer = reinterpret_cast<const char*>(
- pFont->GetTable(pTagName, &nLength) );
-
- hb_blob_t* pBlob = nullptr;
- if (pBuffer != nullptr)
- pBlob = hb_blob_create(pBuffer, nLength, HB_MEMORY_MODE_READONLY, nullptr, nullptr);
-
- return pBlob;
-}
-
hb_font_t* FreetypeFontInstance::ImplInitHbFont()
{
- hb_font_t* pRet = InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr));
+ hb_font_t* pRet = InitHbFont(GetFontFace()->GetHbFace());
assert(mpFreetypeFont);
mpFreetypeFont->SetFontVariationsOnHBFont(pRet);
return pRet;
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 343e3f8b6208..c87e00fb3405 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -615,7 +615,8 @@ WinFontFace::WinFontFace( const FontAttributes& rDFS,
meWinCharSet( eWinCharSet ),
mnPitchAndFamily( nPitchAndFamily ),
mbAliasSymbolsHigh( false ),
- mbAliasSymbolsLow( false )
+ mbAliasSymbolsLow( false ),
+ mhDC( nullptr )
{
if( eWinCharSet == SYMBOL_CHARSET )
{
@@ -649,6 +650,25 @@ sal_IntPtr WinFontFace::GetFontId() const
return mnId;
}
+hb_blob_t* WinFontFace::GetHbTable(hb_tag_t nTag) const
+{
+ sal_uLong nLength = 0;
+ unsigned char* pBuffer = nullptr;
+
+ nLength = ::GetFontData(mhDC, nTag, 0, nullptr, 0);
+ if (nLength > 0 && nLength != GDI_ERROR)
+ {
+ pBuffer = new unsigned char[nLength];
+ ::GetFontData(mhDC, nTag, 0, pBuffer, nLength);
+ }
+
+ hb_blob_t* pBlob = nullptr;
+ if (pBuffer != nullptr)
+ pBlob = hb_blob_create(reinterpret_cast<const char*>(pBuffer), nLength, HB_MEMORY_MODE_READONLY,
+ pBuffer, [](void* data){ delete[] static_cast<unsigned char*>(data); });
+ return pBlob;
+}
+
rtl::Reference<LogicalFontInstance> WinFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
{
return new WinFontInstance(*this, rFSD);
@@ -662,6 +682,8 @@ void WinFontFace::UpdateFromHDC( HDC hDC ) const
if( mxUnicodeMap.is() )
return;
+ mhDC = hDC;
+
ReadCmapTable( hDC );
GetFontCapabilities( hDC );
}
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 25949dc0692e..d82c2e89722f 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -327,41 +327,16 @@ float WinFontInstance::getHScale() const
return nWidth / nHeight;
}
-static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pUserData)
-{
- sal_uLong nLength = 0;
- unsigned char* pBuffer = 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)
- {
- pBuffer = new unsigned char[nLength];
- ::GetFontData(hDC, OSL_NETDWORD(nTableTag), 0, pBuffer, nLength);
- }
- SelectObject(hDC, hOrigFont);
-
- hb_blob_t* pBlob = nullptr;
- if (pBuffer != nullptr)
- pBlob = hb_blob_create(reinterpret_cast<const char*>(pBuffer), nLength, HB_MEMORY_MODE_READONLY,
- pBuffer, [](void* data){ delete[] static_cast<unsigned char*>(data); });
- return pBlob;
-}
-
hb_font_t* WinFontInstance::ImplInitHbFont()
{
assert(m_pGraphics);
- hb_font_t* pHbFont = InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr));
+ hb_face_t* pHbFace = GetFontFace()->GetHbFace();
+ hb_font_t* pHbFont = InitHbFont(pHbFace);
// Calculate the AverageWidthFactor, see LogicalFontInstance::GetScale().
if (GetFontSelectPattern().mnWidth)
{
- double nUPEM = hb_face_get_upem(hb_font_get_face(pHbFont));
+ double nUPEM = hb_face_get_upem(pHbFace);
LOGFONTW aLogFont;
GetObjectW(m_hFont, sizeof(LOGFONTW), &aLogFont);