Kaydet (Commit) fb823544 authored tarafından Khaled Hosny's avatar Khaled Hosny

Font features are not a Graphite-only feature

We parse features appended to font names in CommonSalLayout as well, so
code that takes care of their presence (striping them when searching,
hashing, etc.) should not be dependent on the old Graphite support or it
will not work when old Graphite is disabled (e.g. on macOS).

Change-Id: If040782a86ec76d3743baf4d2b1d7a194e8e13f2
üst a6ce5d39
...@@ -49,6 +49,9 @@ public: ...@@ -49,6 +49,9 @@ public:
return !(*this == rOther); return !(*this == rOther);
} }
static const char FEAT_PREFIX;
static const char FEAT_SEPARATOR;
public: public:
OUString maTargetName; // name of the font name token that is chosen OUString maTargetName; // name of the font name token that is chosen
OUString maSearchName; // name of the font that matches best OUString maSearchName; // name of the font that matches best
......
...@@ -42,8 +42,6 @@ namespace grutils ...@@ -42,8 +42,6 @@ namespace grutils
{ {
public: public:
enum { MAX_FEATURES = 64 }; enum { MAX_FEATURES = 64 };
static const char FEAT_PREFIX;
static const char FEAT_SEPARATOR;
static const char FEAT_ID_VALUE_SEPARATOR; static const char FEAT_ID_VALUE_SEPARATOR;
GrFeatureParser(const gr_face * face, const OString& features, const OString& lang); GrFeatureParser(const gr_face * face, const OString& features, const OString& lang);
GrFeatureParser(const gr_face * face, const OString& lang); GrFeatureParser(const gr_face * face, const OString& lang);
......
...@@ -18,9 +18,6 @@ ...@@ -18,9 +18,6 @@
*/ */
#include <config_graphite.h> #include <config_graphite.h>
#if ENABLE_GRAPHITE
#include "graphite_features.hxx"
#endif
#include <i18nlangtag/mslangid.hxx> #include <i18nlangtag/mslangid.hxx>
#include <unotools/configmgr.hxx> #include <unotools/configmgr.hxx>
#include <unotools/fontdefs.hxx> #include <unotools/fontdefs.hxx>
...@@ -989,22 +986,18 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r ...@@ -989,22 +986,18 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r
rFSD.maTargetName = GetNextFontToken( rFSD.GetFamilyName(), nTokenPos ); rFSD.maTargetName = GetNextFontToken( rFSD.GetFamilyName(), nTokenPos );
aSearchName = rFSD.maTargetName; aSearchName = rFSD.maTargetName;
#if ENABLE_GRAPHITE
// Until features are properly supported, they are appended to the // Until features are properly supported, they are appended to the
// font name, so we need to strip them off so the font is found. // font name, so we need to strip them off so the font is found.
sal_Int32 nFeat = aSearchName.indexOf(grutils::GrFeatureParser::FEAT_PREFIX); sal_Int32 nFeat = aSearchName.indexOf(FontSelectPatternAttributes::FEAT_PREFIX);
OUString aOrigName = rFSD.maTargetName; OUString aOrigName = rFSD.maTargetName;
OUString aBaseFontName = aSearchName.copy( 0, (nFeat != -1) ? nFeat : aSearchName.getLength() ); OUString aBaseFontName = aSearchName.copy( 0, (nFeat != -1) ? nFeat : aSearchName.getLength() );
if (nFeat != -1 && if (nFeat != -1)
-1 != aSearchName.indexOf(grutils::GrFeatureParser::FEAT_ID_VALUE_SEPARATOR, nFeat))
{ {
aSearchName = aBaseFontName; aSearchName = aBaseFontName;
rFSD.maTargetName = aBaseFontName; rFSD.maTargetName = aBaseFontName;
} }
#endif
aSearchName = GetEnglishSearchFontName( aSearchName ); aSearchName = GetEnglishSearchFontName( aSearchName );
ImplFontSubstitute( aSearchName ); ImplFontSubstitute( aSearchName );
// #114999# special emboldening for Ricoh fonts // #114999# special emboldening for Ricoh fonts
...@@ -1035,10 +1028,9 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r ...@@ -1035,10 +1028,9 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r
} }
} }
#if ENABLE_GRAPHITE
// restore the features to make the font selection data unique // restore the features to make the font selection data unique
rFSD.maTargetName = aOrigName; rFSD.maTargetName = aOrigName;
#endif
// check if the current font name token or its substitute is valid // check if the current font name token or its substitute is valid
PhysicalFontFamily* pFoundData = ImplFindFontFamilyBySearchName( aSearchName ); PhysicalFontFamily* pFoundData = ImplFindFontFamilyBySearchName( aSearchName );
if( pFoundData ) if( pFoundData )
...@@ -1047,10 +1039,9 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r ...@@ -1047,10 +1039,9 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r
// some systems provide special customization // some systems provide special customization
// e.g. they suggest "serif" as UI-font, but this name cannot be used directly // e.g. they suggest "serif" as UI-font, but this name cannot be used directly
// because the system wants to map it to another font first, e.g. "Helvetica" // because the system wants to map it to another font first, e.g. "Helvetica"
#if ENABLE_GRAPHITE
// use the target name to search in the prematch hook // use the target name to search in the prematch hook
rFSD.maTargetName = aBaseFontName; rFSD.maTargetName = aBaseFontName;
#endif
// Related: fdo#49271 RTF files often contain weird-ass // Related: fdo#49271 RTF files often contain weird-ass
// Win 3.1/Win95 style fontnames which attempt to put the // Win 3.1/Win95 style fontnames which attempt to put the
...@@ -1071,11 +1062,11 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r ...@@ -1071,11 +1062,11 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamily( FontSelectPattern& r
if( mpPreMatchHook->FindFontSubstitute( rFSD ) ) if( mpPreMatchHook->FindFontSubstitute( rFSD ) )
aSearchName = GetEnglishSearchFontName( aSearchName ); aSearchName = GetEnglishSearchFontName( aSearchName );
} }
#if ENABLE_GRAPHITE
// the prematch hook uses the target name to search, but we now need // the prematch hook uses the target name to search, but we now need
// to restore the features to make the font selection data unique // to restore the features to make the font selection data unique
rFSD.maTargetName = aOrigName; rFSD.maTargetName = aOrigName;
#endif
pFoundData = ImplFindFontFamilyBySearchName( aSearchName ); pFoundData = ImplFindFontFamilyBySearchName( aSearchName );
if( pFoundData ) if( pFoundData )
return pFoundData; return pFoundData;
......
...@@ -24,11 +24,6 @@ ...@@ -24,11 +24,6 @@
#include "PhysicalFontFace.hxx" #include "PhysicalFontFace.hxx"
#include "PhysicalFontFamily.hxx" #include "PhysicalFontFamily.hxx"
#include <config_graphite.h>
#if ENABLE_GRAPHITE
#include "graphite_features.hxx"
#endif
size_t ImplFontCache::IFSD_Hash::operator()( const FontSelectPattern& rFSD ) const size_t ImplFontCache::IFSD_Hash::operator()( const FontSelectPattern& rFSD ) const
{ {
return rFSD.hashCode(); return rFSD.hashCode();
...@@ -73,14 +68,12 @@ bool ImplFontCache::IFSD_Equal::operator()(const FontSelectPattern& rA, const Fo ...@@ -73,14 +68,12 @@ bool ImplFontCache::IFSD_Equal::operator()(const FontSelectPattern& rA, const Fo
return false; return false;
} }
#if ENABLE_GRAPHITE
// check for features // check for features
if ((rA.maTargetName.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) if ((rA.maTargetName.indexOf(FontSelectPatternAttributes::FEAT_PREFIX)
!= -1 || != -1 ||
rB.maTargetName.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) rB.maTargetName.indexOf(FontSelectPatternAttributes::FEAT_PREFIX)
!= -1) && rA.maTargetName != rB.maTargetName) != -1) && rA.maTargetName != rB.maTargetName)
return false; return false;
#endif
if (rA.mbEmbolden != rB.mbEmbolden) if (rA.mbEmbolden != rB.mbEmbolden)
return false; return false;
......
...@@ -22,10 +22,9 @@ ...@@ -22,10 +22,9 @@
#include <PhysicalFontFace.hxx> #include <PhysicalFontFace.hxx>
#include "svdata.hxx" #include "svdata.hxx"
#include <config_graphite.h> // These mustn't conflict with font name lists which use ; and ,
#if ENABLE_GRAPHITE const char FontSelectPatternAttributes::FEAT_PREFIX = ':';
#include "graphite_features.hxx" const char FontSelectPatternAttributes::FEAT_SEPARATOR = '&';
#endif
FontSelectPattern::FontSelectPattern( const vcl::Font& rFont, FontSelectPattern::FontSelectPattern( const vcl::Font& rFont,
const OUString& rSearchName, const Size& rSize, float fExactHeight) const OUString& rSearchName, const Size& rSize, float fExactHeight)
...@@ -105,15 +104,13 @@ size_t FontSelectPatternAttributes::hashCode() const ...@@ -105,15 +104,13 @@ size_t FontSelectPatternAttributes::hashCode() const
{ {
// TODO: does it pay off to improve this hash function? // TODO: does it pay off to improve this hash function?
size_t nHash; size_t nHash;
#if ENABLE_GRAPHITE
// check for features and generate a unique hash if necessary // check for features and generate a unique hash if necessary
if (maTargetName.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) if (maTargetName.indexOf(FontSelectPatternAttributes::FEAT_PREFIX)
!= -1) != -1)
{ {
nHash = maTargetName.hashCode(); nHash = maTargetName.hashCode();
} }
else else
#endif
{ {
nHash = maSearchName.hashCode(); nHash = maSearchName.hashCode();
} }
......
...@@ -125,15 +125,15 @@ static hb_unicode_funcs_t* getUnicodeFuncs() ...@@ -125,15 +125,15 @@ static hb_unicode_funcs_t* getUnicodeFuncs()
void CommonSalLayout::ParseFeatures(const OUString& name) void CommonSalLayout::ParseFeatures(const OUString& name)
{ {
int nFeatures = 0; int nFeatures = 0;
int nStart = name.indexOf(':'); int nStart = name.indexOf(FontSelectPatternAttributes::FEAT_PREFIX);
if (nStart < 0) if (nStart < 0)
return; return;
OString oName = OUStringToOString(name, RTL_TEXTENCODING_ASCII_US); OString oName = OUStringToOString(name, RTL_TEXTENCODING_ASCII_US);
for (int nNext = nStart; nNext > 0; nNext = name.indexOf('&', nNext + 1)) for (int nNext = nStart; nNext > 0; nNext = name.indexOf(FontSelectPatternAttributes::FEAT_SEPARATOR, nNext + 1))
{ {
if (name.match("lang=", nNext + 1)) if (name.match("lang=", nNext + 1))
{ {
int endamp = name.indexOf('&', nNext+1); int endamp = name.indexOf(FontSelectPatternAttributes::FEAT_SEPARATOR, nNext+1);
int enddelim = name.indexOf(' ', nNext+1); int enddelim = name.indexOf(' ', nNext+1);
int end = name.getLength(); int end = name.getLength();
if (endamp < 0) if (endamp < 0)
...@@ -154,7 +154,9 @@ void CommonSalLayout::ParseFeatures(const OUString& name) ...@@ -154,7 +154,9 @@ void CommonSalLayout::ParseFeatures(const OUString& name)
return; return;
maFeatures.reserve(nFeatures); maFeatures.reserve(nFeatures);
for (int nThis = nStart, nNext = name.indexOf('&', nStart + 1); nThis > 0; nThis = nNext, nNext = name.indexOf('&', nNext + 1)) for (int nThis = nStart, nNext = name.indexOf(FontSelectPatternAttributes::FEAT_SEPARATOR, nStart + 1);
nThis > 0;
nThis = nNext, nNext = name.indexOf(FontSelectPatternAttributes::FEAT_SEPARATOR, nNext + 1))
{ {
if (!name.match("lang=", nThis + 1)) if (!name.match("lang=", nThis + 1))
{ {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
#include <fontselect.hxx>
#include <graphite_features.hxx> #include <graphite_features.hxx>
using namespace grutils; using namespace grutils;
...@@ -74,9 +75,6 @@ short getIntValue(const OString & id, size_t offset, size_t length) ...@@ -74,9 +75,6 @@ short getIntValue(const OString & id, size_t offset, size_t length)
} }
// These mustn't conflict with font name lists which use ; and ,
const char GrFeatureParser::FEAT_PREFIX = ':';
const char GrFeatureParser::FEAT_SEPARATOR = '&';
const char GrFeatureParser::FEAT_ID_VALUE_SEPARATOR = '='; const char GrFeatureParser::FEAT_ID_VALUE_SEPARATOR = '=';
GrFeatureParser::GrFeatureParser(const gr_face * pFace, const OString& lang) GrFeatureParser::GrFeatureParser(const gr_face * pFace, const OString& lang)
...@@ -106,7 +104,7 @@ GrFeatureParser::GrFeatureParser(const gr_face * pFace, const OString& features, ...@@ -106,7 +104,7 @@ GrFeatureParser::GrFeatureParser(const gr_face * pFace, const OString& features,
if (features.match(aLangPrefix, pos )) if (features.match(aLangPrefix, pos ))
{ {
pos = nEquals + 1; pos = nEquals + 1;
nFeatEnd = features.indexOf(FEAT_SEPARATOR, pos); nFeatEnd = features.indexOf(FontSelectPatternAttributes::FEAT_SEPARATOR, pos);
if (nFeatEnd == -1) if (nFeatEnd == -1)
{ {
nFeatEnd = features.getLength(); nFeatEnd = features.getLength();
...@@ -164,7 +162,7 @@ GrFeatureParser::GrFeatureParser(const gr_face * pFace, const OString& features, ...@@ -164,7 +162,7 @@ GrFeatureParser::GrFeatureParser(const gr_face * pFace, const OString& features,
} }
const gr_feature_ref * pFref = gr_face_find_fref(pFace, featId); const gr_feature_ref * pFref = gr_face_find_fref(pFace, featId);
pos = nEquals + 1; pos = nEquals + 1;
nFeatEnd = features.indexOf(FEAT_SEPARATOR, pos); nFeatEnd = features.indexOf(FontSelectPatternAttributes::FEAT_SEPARATOR, pos);
if (nFeatEnd == -1) if (nFeatEnd == -1)
{ {
nFeatEnd = features.getLength(); nFeatEnd = features.getLength();
......
...@@ -26,11 +26,6 @@ ...@@ -26,11 +26,6 @@
#include <fontinstance.hxx> #include <fontinstance.hxx>
#include <fontattributes.hxx> #include <fontattributes.hxx>
#include <config_graphite.h>
#if ENABLE_GRAPHITE
#include <graphite_features.hxx>
#endif
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <tools/debug.hxx> #include <tools/debug.hxx>
...@@ -74,23 +69,22 @@ size_t GlyphCache::IFSD_Hash::operator()( const FontSelectPattern& rFontSelData ...@@ -74,23 +69,22 @@ size_t GlyphCache::IFSD_Hash::operator()( const FontSelectPattern& rFontSelData
{ {
// TODO: is it worth to improve this hash function? // TODO: is it worth to improve this hash function?
sal_IntPtr nFontId = reinterpret_cast<sal_IntPtr>( rFontSelData.mpFontData ); sal_IntPtr nFontId = reinterpret_cast<sal_IntPtr>( rFontSelData.mpFontData );
#if ENABLE_GRAPHITE
if (rFontSelData.maTargetName.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) if (rFontSelData.maTargetName.indexOf(FontSelectPatternAttributes::FEAT_PREFIX)
!= -1) != -1)
{ {
OString aFeatName = OUStringToOString( rFontSelData.maTargetName, RTL_TEXTENCODING_UTF8 ); OString aFeatName = OUStringToOString( rFontSelData.maTargetName, RTL_TEXTENCODING_UTF8 );
nFontId ^= aFeatName.hashCode(); nFontId ^= aFeatName.hashCode();
} }
#endif
size_t nHash = nFontId << 8; size_t nHash = nFontId << 8;
nHash += rFontSelData.mnHeight; nHash += rFontSelData.mnHeight;
nHash += rFontSelData.mnOrientation; nHash += rFontSelData.mnOrientation;
nHash += size_t(rFontSelData.mbVertical); nHash += size_t(rFontSelData.mbVertical);
nHash += rFontSelData.GetItalic(); nHash += rFontSelData.GetItalic();
nHash += rFontSelData.GetWeight(); nHash += rFontSelData.GetWeight();
#if ENABLE_GRAPHITE
nHash += rFontSelData.meLanguage; nHash += rFontSelData.meLanguage;
#endif
return nHash; return nHash;
} }
...@@ -121,16 +115,14 @@ bool GlyphCache::IFSD_Equal::operator()( const FontSelectPattern& rA, const Font ...@@ -121,16 +115,14 @@ bool GlyphCache::IFSD_Equal::operator()( const FontSelectPattern& rA, const Font
if( nAWidth != nBWidth ) if( nAWidth != nBWidth )
return false; return false;
#if ENABLE_GRAPHITE
if (rA.meLanguage != rB.meLanguage) if (rA.meLanguage != rB.meLanguage)
return false; return false;
// check for features // check for features
if ((rA.maTargetName.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) if ((rA.maTargetName.indexOf(FontSelectPatternAttributes::FEAT_PREFIX)
!= -1 || != -1 ||
rB.maTargetName.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) rB.maTargetName.indexOf(FontSelectPatternAttributes::FEAT_PREFIX)
!= -1) && rA.maTargetName != rB.maTargetName) != -1) && rA.maTargetName != rB.maTargetName)
return false; return false;
#endif
if (rA.mbEmbolden != rB.mbEmbolden) if (rA.mbEmbolden != rB.mbEmbolden)
return false; return false;
......
...@@ -72,7 +72,7 @@ GraphiteServerFontLayout::GraphiteServerFontLayout(FreetypeFont& rFreetypeFont) ...@@ -72,7 +72,7 @@ GraphiteServerFontLayout::GraphiteServerFontLayout(FreetypeFont& rFreetypeFont)
rFreetypeFont.GetFtFace()->size->metrics.x_ppem, rFreetypeFont.GetFtFace()->size->metrics.x_ppem,
rFreetypeFont.GetFontSelData().mfExactHeight); rFreetypeFont.GetFontSelData().mfExactHeight);
#endif #endif
sal_Int32 nFeat = name.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) + 1; sal_Int32 nFeat = name.indexOf(FontSelectPatternAttributes::FEAT_PREFIX) + 1;
if (nFeat > 0) if (nFeat > 0)
{ {
OString aFeat = name.copy(nFeat, name.getLength() - nFeat); OString aFeat = name.copy(nFeat, name.getLength() - nFeat);
......
...@@ -3735,7 +3735,7 @@ GraphiteWinLayout::GraphiteWinLayout(HDC hDC, const WinFontFace& rWFD, WinFontIn ...@@ -3735,7 +3735,7 @@ GraphiteWinLayout::GraphiteWinLayout(HDC hDC, const WinFontFace& rWFD, WinFontIn
RTL_TEXTENCODING_ASCII_US); RTL_TEXTENCODING_ASCII_US);
OString name = OUStringToOString( OString name = OUStringToOString(
rWFE.maFontSelData.maTargetName, RTL_TEXTENCODING_UTF8 ); rWFE.maFontSelData.maTargetName, RTL_TEXTENCODING_UTF8 );
sal_Int32 nFeat = name.indexOf(grutils::GrFeatureParser::FEAT_PREFIX) + 1; sal_Int32 nFeat = name.indexOf(FontSelectPatternAttributes::FEAT_PREFIX) + 1;
if (nFeat > 0) if (nFeat > 0)
{ {
OString aFeat = name.copy(nFeat, name.getLength() - nFeat); OString aFeat = name.copy(nFeat, name.getLength() - nFeat);
......
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