summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@aliftype.com>2022-09-05 06:34:52 +0200
committerخالد حسني <khaled@aliftype.com>2022-09-05 09:55:11 +0200
commit28c8cddd4218905bca05778dcdbae5911132a096 (patch)
tree338f413302fa4b14bfdf9514e0a9e5803e76f931 /vcl
parent8b9e7617e967c4033d9853e6bc2e96334bf6b243 (diff)
vcl: Consolidate PhysicalFontFace::GetFontCapabilities()
All subclasses are doing the same thing in slightly different ways, so move it to the base class that we can now access font tables there. Change-Id: I1f8827dbc345aa852e1f7aaaa4cb4615593289c8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139395 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@aliftype.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/font/PhysicalFontFace.hxx6
-rw-r--r--vcl/inc/qt5/QtFontFace.hxx6
-rw-r--r--vcl/inc/quartz/salgdi.h4
-rw-r--r--vcl/inc/unx/freetype_glyphcache.hxx9
-rw-r--r--vcl/inc/win/salgdi.h8
-rw-r--r--vcl/qt5/QtFontFace.cxx27
-rw-r--r--vcl/quartz/AquaGraphicsBackend.cxx1
-rw-r--r--vcl/quartz/salgdi.cxx33
-rw-r--r--vcl/source/font/PhysicalFontFace.cxx21
-rw-r--r--vcl/unx/generic/gdi/freetypetextrender.cxx2
-rw-r--r--vcl/unx/generic/glyphs/freetype_glyphcache.cxx25
-rw-r--r--vcl/unx/generic/print/genpspgraphics.cxx2
-rw-r--r--vcl/win/gdi/salfont.cxx39
-rw-r--r--vcl/win/gdi/winlayout.cxx1
14 files changed, 30 insertions, 154 deletions
diff --git a/vcl/inc/font/PhysicalFontFace.hxx b/vcl/inc/font/PhysicalFontFace.hxx
index ee65766fadbd..396178c5e40d 100644
--- a/vcl/inc/font/PhysicalFontFace.hxx
+++ b/vcl/inc/font/PhysicalFontFace.hxx
@@ -25,6 +25,7 @@
#include <rtl/ref.hxx>
#include <tools/long.hxx>
#include <vcl/dllapi.h>
+#include <vcl/fontcapabilities.hxx>
#include <vcl/fontcharmap.hxx>
#include <fontattributes.hxx>
@@ -40,7 +41,6 @@ class FontSelectPattern;
namespace vcl
{
-struct FontCapabilities;
class PhysicalFontFamily;
}
@@ -76,7 +76,7 @@ public:
virtual sal_IntPtr GetFontId() const = 0;
virtual FontCharMapRef GetFontCharMap() const;
- virtual bool GetFontCapabilities(vcl::FontCapabilities&) const = 0;
+ virtual bool GetFontCapabilities(vcl::FontCapabilities&) const;
bool IsBetterMatch(const vcl::font::FontSelectPattern&, FontMatchStatus&) const;
sal_Int32 CompareIgnoreSize(const PhysicalFontFace&) const;
@@ -91,6 +91,8 @@ public:
protected:
mutable hb_face_t* mpHbFace;
mutable FontCharMapRef mxCharMap;
+ mutable vcl::FontCapabilities maFontCapabilities;
+ mutable bool mbFontCapabilitiesRead;
explicit PhysicalFontFace(const FontAttributes&);
};
diff --git a/vcl/inc/qt5/QtFontFace.hxx b/vcl/inc/qt5/QtFontFace.hxx
index 3db0c8a6eb5b..06260468cbdc 100644
--- a/vcl/inc/qt5/QtFontFace.hxx
+++ b/vcl/inc/qt5/QtFontFace.hxx
@@ -25,8 +25,6 @@
#include <font/PhysicalFontFace.hxx>
#include <tools/ref.hxx>
-#include <vcl/fontcapabilities.hxx>
-#include <vcl/fontcharmap.hxx>
#include <QtCore/QString>
#include <QtGui/QFont>
@@ -52,8 +50,6 @@ public:
QFont CreateFont() const;
- bool GetFontCapabilities(vcl::FontCapabilities&) const override;
-
rtl::Reference<LogicalFontInstance>
CreateFontInstance(const vcl::font::FontSelectPattern& rFSD) const override;
@@ -67,8 +63,6 @@ private:
const QString m_aFontId;
const FontIdType m_eFontIdType;
- mutable vcl::FontCapabilities m_aFontCapabilities;
- mutable bool m_bFontCapabilitiesRead;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index cbdffdeecc19..732587a09551 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -69,16 +69,12 @@ public:
int GetFontTable( uint32_t nTagCode, unsigned char* ) const;
int GetFontTable( const char pTagName[5], unsigned char* ) const;
- bool GetFontCapabilities(vcl::FontCapabilities&) const override;
-
rtl::Reference<LogicalFontInstance> CreateFontInstance(const vcl::font::FontSelectPattern&) const override;
virtual hb_blob_t* GetHbTable(hb_tag_t nTag) const override;
private:
const sal_IntPtr mnFontId;
- mutable vcl::FontCapabilities maFontCapabilities;
- mutable bool mbFontCapabilitiesRead;
};
class CoreTextStyle final : public LogicalFontInstance
diff --git a/vcl/inc/unx/freetype_glyphcache.hxx b/vcl/inc/unx/freetype_glyphcache.hxx
index b77978061d09..a5876344a055 100644
--- a/vcl/inc/unx/freetype_glyphcache.hxx
+++ b/vcl/inc/unx/freetype_glyphcache.hxx
@@ -72,8 +72,6 @@ public:
void AnnounceFont( vcl::font::PhysicalFontCollection* );
- bool GetFontCapabilities(vcl::FontCapabilities&) const;
-
private:
friend class FreetypeManager;
explicit FreetypeFontInfo(FontAttributes , FreetypeFontFile* const pFontFile,
@@ -100,17 +98,10 @@ public:
virtual rtl::Reference<LogicalFontInstance> CreateFontInstance(const vcl::font::FontSelectPattern&) const override;
virtual sal_IntPtr GetFontId() const override { return mpFreetypeFontInfo->GetFontId(); }
- inline bool GetFontCapabilities(vcl::FontCapabilities&) const override;
-
virtual hb_face_t* GetHbFace() const override;
virtual hb_blob_t* GetHbTable(hb_tag_t nTag) const override;
};
-bool FreetypeFontFace::GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const
-{
- return mpFreetypeFontInfo->GetFontCapabilities(rFontCapabilities);
-}
-
class SAL_DLLPUBLIC_RTTI FreetypeFontInstance final : public LogicalFontInstance
{
friend rtl::Reference<LogicalFontInstance> FreetypeFontFace::CreateFontInstance(const vcl::font::FontSelectPattern&) const;
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index 0faedda67585..74f5617d9156 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -71,24 +71,16 @@ public:
BYTE GetCharSet() const { return meWinCharSet; }
BYTE GetPitchAndFamily() const { return mnPitchAndFamily; }
- bool GetFontCapabilities(vcl::FontCapabilities&) const override;
-
virtual hb_blob_t* GetHbTable(hb_tag_t nTag) const override;
private:
sal_IntPtr mnId;
- // some members that are initialized lazily when the font gets selected into a HDC
- mutable bool mbFontCapabilitiesRead;
- mutable vcl::FontCapabilities maFontCapabilities;
-
BYTE meWinCharSet;
BYTE mnPitchAndFamily;
bool mbAliasSymbolsHigh;
bool mbAliasSymbolsLow;
HFONT mhFont;
-
- void GetFontCapabilities() const;
};
/** Class that creates (and destroys) a compatible Device Context.
diff --git a/vcl/qt5/QtFontFace.cxx b/vcl/qt5/QtFontFace.cxx
index c449cca690c3..5a0183bbc809 100644
--- a/vcl/qt5/QtFontFace.cxx
+++ b/vcl/qt5/QtFontFace.cxx
@@ -25,8 +25,6 @@
#include <QtFont.hxx>
#include <QtTools.hxx>
-#include <sft.hxx>
-#include <impfontcharmap.hxx>
#include <fontinstance.hxx>
#include <font/FontSelectPattern.hxx>
#include <font/PhysicalFontCollection.hxx>
@@ -163,7 +161,6 @@ QtFontFace::QtFontFace(const FontAttributes& rFA, QString aFontID, const FontIdT
: PhysicalFontFace(rFA)
, m_aFontId(std::move(aFontID))
, m_eFontIdType(eFontIdType)
- , m_bFontCapabilitiesRead(false)
{
}
@@ -205,30 +202,6 @@ QtFontFace::CreateFontInstance(const vcl::font::FontSelectPattern& rFSD) const
return new QtFont(*this, rFSD);
}
-bool QtFontFace::GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const
-{
- // read this only once per font
- if (m_bFontCapabilitiesRead)
- {
- rFontCapabilities = m_aFontCapabilities;
- return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
- }
- m_bFontCapabilitiesRead = true;
-
- QFont aFont = CreateFont();
- QRawFont aRawFont(QRawFont::fromFont(aFont));
- QByteArray aOS2Table = aRawFont.fontTable("OS/2");
- if (!aOS2Table.isEmpty())
- {
- vcl::getTTCoverage(m_aFontCapabilities.oUnicodeRange, m_aFontCapabilities.oCodePageRange,
- reinterpret_cast<const unsigned char*>(aOS2Table.data()),
- aOS2Table.size());
- }
-
- rFontCapabilities = m_aFontCapabilities;
- return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
-}
-
hb_blob_t* QtFontFace::GetHbTable(hb_tag_t nTag) const
{
char pTagName[5] = { '\0' };
diff --git a/vcl/quartz/AquaGraphicsBackend.cxx b/vcl/quartz/AquaGraphicsBackend.cxx
index 71b50037c02b..aef2e3bb0f21 100644
--- a/vcl/quartz/AquaGraphicsBackend.cxx
+++ b/vcl/quartz/AquaGraphicsBackend.cxx
@@ -43,7 +43,6 @@
#ifdef IOS
#include <svdata.hxx>
#endif
-#include <sft.hxx>
using namespace vcl;
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index f893fe20fae4..f7bc60904114 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -54,7 +54,6 @@
#include <svdata.hxx>
#endif
#include <sallayout.hxx>
-#include <sft.hxx>
#include <config_features.h>
#include <vcl/skia/SkiaHelper.hxx>
@@ -130,7 +129,6 @@ bool CoreTextGlyphFallbackSubstititution::FindFontSubstitute(vcl::font::FontSele
CoreTextFontFace::CoreTextFontFace( const FontAttributes& rDFA, sal_IntPtr nFontId )
: vcl::font::PhysicalFontFace( rDFA )
, mnFontId( nFontId )
- , mbFontCapabilitiesRead( false )
{
}
@@ -143,35 +141,6 @@ sal_IntPtr CoreTextFontFace::GetFontId() const
return mnFontId;
}
-bool CoreTextFontFace::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
-{
- // read this only once per font
- if( mbFontCapabilitiesRead )
- {
- rFontCapabilities = maFontCapabilities;
- return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
- }
- mbFontCapabilitiesRead = true;
-
- int nBufSize = GetFontTable( "OS/2", nullptr );
- if( nBufSize > 0 )
- {
- // allocate a buffer for the OS/2 raw data
- std::vector<unsigned char> aBuffer( nBufSize );
- // get the OS/2 raw data
- const int nRawLength = GetFontTable( "OS/2", aBuffer.data() );
- if( nRawLength > 0 )
- {
- const unsigned char* pOS2Table = aBuffer.data();
- vcl::getTTCoverage( maFontCapabilities.oUnicodeRange,
- maFontCapabilities.oCodePageRange,
- pOS2Table, nRawLength);
- }
- }
- rFontCapabilities = maFontCapabilities;
- return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
-}
-
AquaSalGraphics::AquaSalGraphics()
: mnRealDPIX( 0 )
, mnRealDPIY( 0 )
@@ -512,7 +481,7 @@ bool AquaSalGraphics::GetFontCapabilities(vcl::FontCapabilities &rFontCapabiliti
if (!mpTextStyle[0])
return false;
- return static_cast<const CoreTextFontFace*>(mpTextStyle[0]->GetFontFace())->GetFontCapabilities(rFontCapabilities);
+ return mpTextStyle[0]->GetFontFace()->GetFontCapabilities(rFontCapabilities);
}
// fake a SFNT font directory entry for a font table
diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx
index 2b095059de6b..e20b9fce1405 100644
--- a/vcl/source/font/PhysicalFontFace.cxx
+++ b/vcl/source/font/PhysicalFontFace.cxx
@@ -25,6 +25,7 @@
#include <fontattributes.hxx>
#include <impfontcharmap.hxx>
+#include <sft.hxx>
#include <font/FontSelectPattern.hxx>
#include <font/PhysicalFontFace.hxx>
@@ -245,6 +246,26 @@ FontCharMapRef PhysicalFontFace::GetFontCharMap() const
return mxCharMap;
}
+
+bool PhysicalFontFace::GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const
+{
+ if (!mbFontCapabilitiesRead)
+ {
+ mbFontCapabilitiesRead = true;
+
+ hb_blob_t* pBlob = GetHbTable(HB_TAG('O', 'S', '/', '2'));
+ if (pBlob)
+ {
+ unsigned int nSize = 0;
+ auto* pData = reinterpret_cast<const unsigned char*>(hb_blob_get_data(pBlob, &nSize));
+ vcl::getTTCoverage(maFontCapabilities.oUnicodeRange, maFontCapabilities.oCodePageRange,
+ pData, nSize);
+ }
+ }
+
+ rFontCapabilities = maFontCapabilities;
+ return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/vcl/unx/generic/gdi/freetypetextrender.cxx b/vcl/unx/generic/gdi/freetypetextrender.cxx
index 2e748bf85711..61782cf22462 100644
--- a/vcl/unx/generic/gdi/freetypetextrender.cxx
+++ b/vcl/unx/generic/gdi/freetypetextrender.cxx
@@ -80,7 +80,7 @@ bool FreeTypeTextRenderImpl::GetFontCapabilities(vcl::FontCapabilities &rGetImpl
{
if (!mpFreetypeFont[0])
return false;
- return mpFreetypeFont[0]->GetFreetypeFont().GetFontCapabilities(rGetImplFontCapabilities);
+ return mpFreetypeFont[0]->GetFontFace()->GetFontCapabilities(rGetImplFontCapabilities);
}
// SalGraphics
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index 5e55b502090b..adc7e3def9bb 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -39,7 +39,6 @@
#include <langboost.hxx>
#include <font/PhysicalFontCollection.hxx>
-#include <sft.hxx>
#include <ft2build.h>
#include FT_FREETYPE_H
@@ -663,30 +662,6 @@ bool FreetypeFont::GetAntialiasAdvice() const
return !mrFontInstance.GetFontSelectPattern().mbNonAntialiased && (mnPrioAntiAlias > 0);
}
-bool FreetypeFont::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
-{
- return mxFontInfo->GetFontCapabilities(rFontCapabilities);
-}
-
-bool FreetypeFontInfo::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
-{
- bool bRet = false;
-
- sal_uLong nLength = 0;
-
- // load OS/2 table
- const FT_Byte* pOS2 = GetTable("OS/2", &nLength);
- if (pOS2)
- {
- bRet = vcl::getTTCoverage(
- rFontCapabilities.oUnicodeRange,
- rFontCapabilities.oCodePageRange,
- pOS2, nLength);
- }
-
- return bRet;
-}
-
// outline stuff
namespace {
diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx
index 5b607b44610b..ff62b2860a93 100644
--- a/vcl/unx/generic/print/genpspgraphics.cxx
+++ b/vcl/unx/generic/print/genpspgraphics.cxx
@@ -150,7 +150,7 @@ bool GenPspGraphics::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilitie
if (!m_pFreetypeFont[0])
return false;
- return m_pFreetypeFont[0]->GetFreetypeFont().GetFontCapabilities(rFontCapabilities);
+ return m_pFreetypeFont[0]->GetFontFace()->GetFontCapabilities(rFontCapabilities);
}
void GenPspGraphics::SetFont(LogicalFontInstance *pFontInstance, int nFallbackLevel)
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 1c4ef2355f56..7614bbf4390c 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -582,7 +582,6 @@ void ImplSalLogFontToFontW( HDC hDC, const LOGFONTW& rLogFont, Font& rFont )
WinFontFace::WinFontFace(const ENUMLOGFONTEXW& rEnumFont, const NEWTEXTMETRICW& rMetric)
: vcl::font::PhysicalFontFace(WinFont2DevFontAttributes(rEnumFont, rMetric)),
mnId( 0 ),
- mbFontCapabilitiesRead( false ),
meWinCharSet(rEnumFont.elfLogFont.lfCharSet),
mnPitchAndFamily(rMetric.tmPitchAndFamily),
mbAliasSymbolsHigh( false ),
@@ -709,42 +708,6 @@ hb_blob_t* WinFontFace::GetHbTable(hb_tag_t nTag) const
return pBlob;
}
-static DWORD CalcTag( const char p[5]) { return (p[0]+(p[1]<<8)+(p[2]<<16)+(p[3]<<24)); }
-
-bool WinFontFace::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
-{
- if (!mbFontCapabilitiesRead)
- GetFontCapabilities();
- rFontCapabilities = maFontCapabilities;
- return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
-}
-
-void WinFontFace::GetFontCapabilities() const
-{
- // read this only once per font
- if( mbFontCapabilitiesRead )
- return;
-
- mbFontCapabilitiesRead = true;
-
- HDC hDC(::GetDC(nullptr));
- HFONT hOldFont = ::SelectFont(hDC, mhFont);
-
- // OS/2 table
- const DWORD OS2Tag = CalcTag( "OS/2" );
- DWORD nLength = ::GetFontData( hDC, OS2Tag, 0, nullptr, 0 );
- if( (nLength != GDI_ERROR) && nLength )
- {
- std::vector<unsigned char> aTable( nLength );
- unsigned char* pTable = aTable.data();
- ::GetFontData( hDC, OS2Tag, 0, pTable, nLength );
- vcl::getTTCoverage(maFontCapabilities.oUnicodeRange, maFontCapabilities.oCodePageRange, pTable, nLength);
- }
-
- ::SelectFont(hDC, hOldFont);
- ::ReleaseDC(nullptr, hDC);
-}
-
void WinSalGraphics::SetTextColor( Color nColor )
{
COLORREF aCol = PALETTERGB( nColor.GetRed(),
@@ -1557,6 +1520,8 @@ SFErrCodes ScopedTrueTypeFont::open(void const * pBuffer, sal_uInt32 nLen,
return OpenTTFontBuffer(pBuffer, nLen, nFaceNum, &m_pFont, xCharMap);
}
+static DWORD CalcTag( const char p[5]) { return (p[0]+(p[1]<<8)+(p[2]<<16)+(p[3]<<24)); }
+
bool WinSalGraphics::CreateFontSubset( const OUString& rToFile,
const vcl::font::PhysicalFontFace* pFont, const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding,
sal_Int32* pGlyphWidths, int nGlyphCount, FontSubsetInfo& rInfo )
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index b9134312bac1..748e5502ee73 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -38,7 +38,6 @@
#include <win/DWriteTextRenderer.hxx>
#include <win/scoped_gdi.hxx>
-#include <sft.hxx>
#include <sallayout.hxx>
#include <cstdio>