diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-03-21 12:12:49 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-03-22 11:15:27 +0100 |
commit | cb54bb89494218589227246f1923d8a24ab1676a (patch) | |
tree | 8702b630c767233c4a8850d68c982c18811f09da /vcl/unx/generic/fontmanager/fontconfig.cxx | |
parent | c094442f997054bbfdacc0d9f213dc218453d29c (diff) |
rhbz#1690732 basic font variation support
on the fontconfig/harfbuzz/cairo drawing path for preset variations
Change-Id: I95ef68aecfd59687ae9aae58e01e394c83c6ea9e
Reviewed-on: https://gerrit.libreoffice.org/69505
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx/generic/fontmanager/fontconfig.cxx')
-rw-r--r-- | vcl/unx/generic/fontmanager/fontconfig.cxx | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx index 374321bc1eb3..003e163d8777 100644 --- a/vcl/unx/generic/fontmanager/fontconfig.cxx +++ b/vcl/unx/generic/fontmanager/fontconfig.cxx @@ -472,9 +472,14 @@ namespace // for variable fonts, FC_INDEX has been changed such that the lower half is now the // index of the font within the collection, and the upper half has been repurposed // as the index within the variations - unsigned int GetCollectionIndex(unsigned int nCollectionEntryId) + unsigned int GetCollectionIndex(unsigned int nEntryId) { - return nCollectionEntryId & 0xFFFF; + return nEntryId & 0xFFFF; + } + + unsigned int GetVariationIndex(unsigned int nEntryId) + { + return nEntryId >> 16; } } @@ -498,7 +503,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o int weight = 0; int width = 0; int spacing = 0; - int nCollectionEntryId = -1; + int nEntryId = -1; FcBool outline = false; FcResult eFileRes = FcPatternGetString(pFSet->fonts[i], FC_FILE, 0, &file); @@ -511,7 +516,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o FcResult eWidthRes = FcPatternGetInteger(pFSet->fonts[i], FC_WIDTH, 0, &width); FcResult eSpacRes = FcPatternGetInteger(pFSet->fonts[i], FC_SPACING, 0, &spacing); FcResult eOutRes = FcPatternGetBool(pFSet->fonts[i], FC_OUTLINE, 0, &outline); - FcResult eIndexRes = FcPatternGetInteger(pFSet->fonts[i], FC_INDEX, 0, &nCollectionEntryId); + FcResult eIndexRes = FcPatternGetInteger(pFSet->fonts[i], FC_INDEX, 0, &nEntryId); FcResult eFormatRes = FcPatternGetString(pFSet->fonts[i], FC_FONTFORMAT, 0, &format); if( eFileRes != FcResultMatch || eFamilyRes != FcResultMatch || eOutRes != FcResultMatch ) @@ -576,9 +581,9 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o else // more than one font { // a collection entry, get the correct index - if( eIndexRes == FcResultMatch && nCollectionEntryId != -1 ) + if( eIndexRes == FcResultMatch && nEntryId != -1 ) { - int nCollectionEntry = GetCollectionIndex(nCollectionEntryId); + int nCollectionEntry = GetCollectionIndex(nEntryId); for (auto & font : aFonts) { if( font->m_nCollectionEntry == nCollectionEntry ) @@ -595,14 +600,14 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o // additional entries will be created in the cache // if this is a new index (that is if the loop above // ran to the end of the list) - xUpdate->m_nCollectionEntry = GetCollectionIndex(nCollectionEntryId); + xUpdate->m_nCollectionEntry = GetCollectionIndex(nEntryId); } else { SAL_INFO( "vcl.fonts", "multiple fonts for file, but no index in fontconfig pattern ! (index res =" - << eIndexRes << " collection entry = " << nCollectionEntryId + << eIndexRes << " collection entry = " << nEntryId << "; file will not be used"); // we have found more than one font in this file // but fontconfig will not tell us which index is meant @@ -622,9 +627,9 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o if( eSlantRes == FcResultMatch ) xUpdate->m_eItalic = convertSlant(slant); if( eStyleRes == FcResultMatch ) - { xUpdate->m_aStyleName = OStringToOUString( OString( reinterpret_cast<char*>(style) ), RTL_TEXTENCODING_UTF8 ); - } + if( eIndexRes == FcResultMatch ) + xUpdate->m_nVariationEntry = GetVariationIndex(nEntryId); // sort into known fonts fontID aFont = m_nNextFontID++; @@ -945,16 +950,16 @@ void PrintFontManager::Substitute(FontSelectPattern &rPattern, OUString& rMissin //extract the closest match FcChar8* file = nullptr; FcResult eFileRes = FcPatternGetString(pSet->fonts[0], FC_FILE, 0, &file); - int nCollectionEntryId = 0; - FcResult eIndexRes = FcPatternGetInteger(pSet->fonts[0], FC_INDEX, 0, &nCollectionEntryId); + int nEntryId = 0; + FcResult eIndexRes = FcPatternGetInteger(pSet->fonts[0], FC_INDEX, 0, &nEntryId); if (eIndexRes != FcResultMatch) - nCollectionEntryId = 0; + nEntryId = 0; if( eFileRes == FcResultMatch ) { OString aDir, aBase, aOrgPath( reinterpret_cast<char*>(file) ); splitPath( aOrgPath, aDir, aBase ); int nDirID = getDirectoryAtom( aDir ); - fontID aFont = findFontFileID( nDirID, aBase, GetCollectionIndex(nCollectionEntryId) ); + fontID aFont = findFontFileID(nDirID, aBase, GetCollectionIndex(nEntryId), GetVariationIndex(nEntryId)); if( aFont > 0 ) { FastPrintFontInfo aInfo; @@ -1076,12 +1081,13 @@ FcPattern *FontConfigFontOptions::GetPattern() const return mpPattern; } -void FontConfigFontOptions::SyncPattern(const OString& rFileName, int nIndex, bool bEmbolden) +void FontConfigFontOptions::SyncPattern(const OString& rFileName, sal_uInt32 nIndex, sal_uInt32 nVariation, bool bEmbolden) { FcPatternDel(mpPattern, FC_FILE); FcPatternAddString(mpPattern, FC_FILE, reinterpret_cast<FcChar8 const *>(rFileName.getStr())); FcPatternDel(mpPattern, FC_INDEX); - FcPatternAddInteger(mpPattern, FC_INDEX, nIndex); + sal_uInt32 nFcIndex = (nVariation << 16) | nIndex; + FcPatternAddInteger(mpPattern, FC_INDEX, nFcIndex); FcPatternDel(mpPattern, FC_EMBOLDEN); FcPatternAddBool(mpPattern, FC_EMBOLDEN, bEmbolden ? FcTrue : FcFalse); } @@ -1161,16 +1167,18 @@ void PrintFontManager::matchFont( FastPrintFontInfo& rInfo, const css::lang::Loc //extract the closest match FcChar8* file = nullptr; FcResult eFileRes = FcPatternGetString(pSet->fonts[0], FC_FILE, 0, &file); - int nCollectionEntry = 0; - FcResult eIndexRes = FcPatternGetInteger(pSet->fonts[0], FC_INDEX, 0, &nCollectionEntry); + int nEntryId = 0; + FcResult eIndexRes = FcPatternGetInteger(pSet->fonts[0], FC_INDEX, 0, &nEntryId); if (eIndexRes != FcResultMatch) - nCollectionEntry = 0; + nEntryId = 0; if( eFileRes == FcResultMatch ) { OString aDir, aBase, aOrgPath( reinterpret_cast<char*>(file) ); splitPath( aOrgPath, aDir, aBase ); int nDirID = getDirectoryAtom( aDir ); - fontID aFont = findFontFileID( nDirID, aBase, nCollectionEntry ); + fontID aFont = findFontFileID(nDirID, aBase, + GetCollectionIndex(nEntryId), + GetVariationIndex(nEntryId)); if( aFont > 0 ) getFontFastInfo( aFont, rInfo ); } |