Kaydet (Commit) cb54bb89 authored tarafından Caolán McNamara's avatar Caolán McNamara

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: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst c094442f
...@@ -34,7 +34,7 @@ public: ...@@ -34,7 +34,7 @@ public:
mpPattern(pPattern) {} mpPattern(pPattern) {}
~FontConfigFontOptions(); ~FontConfigFontOptions();
void SyncPattern(const OString& rFileName, int nFontFace, bool bEmbolden); void SyncPattern(const OString& rFileName, sal_uInt32 nFontFace, sal_uInt32 nFontVariation, bool bEmbolden);
FcPattern* GetPattern() const; FcPattern* GetPattern() const;
static void cairo_font_options_substitute(FcPattern* pPattern); static void cairo_font_options_substitute(FcPattern* pPattern);
private: private:
......
...@@ -131,6 +131,7 @@ class VCL_PLUGIN_PUBLIC PrintFontManager ...@@ -131,6 +131,7 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
int m_nDirectory; // atom containing system dependent path int m_nDirectory; // atom containing system dependent path
OString m_aFontFile; // relative to directory OString m_aFontFile; // relative to directory
int m_nCollectionEntry; // 0 for regular fonts, 0 to ... for fonts stemming from collections int m_nCollectionEntry; // 0 for regular fonts, 0 to ... for fonts stemming from collections
int m_nVariationEntry; // 0 for regular fonts, 0 to ... for fonts stemming from font variations
explicit PrintFont(); explicit PrintFont();
}; };
...@@ -154,7 +155,7 @@ class VCL_PLUGIN_PUBLIC PrintFontManager ...@@ -154,7 +155,7 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
bool analyzeSfntFile(PrintFont* pFont) const; bool analyzeSfntFile(PrintFont* pFont) const;
// finds the font id for the nFaceIndex face in this font file // finds the font id for the nFaceIndex face in this font file
// There may be multiple font ids for font collections // There may be multiple font ids for font collections
fontID findFontFileID( int nDirID, const OString& rFile, int nFaceIndex ) const; fontID findFontFileID(int nDirID, const OString& rFile, int nFaceIndex, int nVariationIndex) const;
// There may be multiple font ids for font collections // There may be multiple font ids for font collections
std::vector<fontID> findFontFileIDs( int nDirID, const OString& rFile ) const; std::vector<fontID> findFontFileIDs( int nDirID, const OString& rFile ) const;
...@@ -242,6 +243,9 @@ public: ...@@ -242,6 +243,9 @@ public:
// get the ttc face number // get the ttc face number
int getFontFaceNumber( fontID nFontID ) const; int getFontFaceNumber( fontID nFontID ) const;
// get the ttc face variation
int getFontFaceVariation( fontID nFontID ) const;
// get a specific fonts ascend // get a specific fonts ascend
int getFontAscend( fontID nFontID ) const; int getFontAscend( fontID nFontID ) const;
......
...@@ -57,9 +57,8 @@ private: ...@@ -57,9 +57,8 @@ private:
class FreetypeFontInfo class FreetypeFontInfo
{ {
public: public:
FreetypeFontInfo( const FontAttributes&, FreetypeFontInfo(const FontAttributes&, const OString& rNativeFileName,
const OString& rNativeFileName, int nFaceNum, int nFaceVariation, sal_IntPtr nFontId);
int nFaceNum, sal_IntPtr nFontId);
~FreetypeFontInfo(); ~FreetypeFontInfo();
const unsigned char* GetTable( const char*, sal_uLong* pLength) const; const unsigned char* GetTable( const char*, sal_uLong* pLength) const;
...@@ -69,6 +68,7 @@ public: ...@@ -69,6 +68,7 @@ public:
const OString& GetFontFileName() const { return mpFontFile->GetFileName(); } const OString& GetFontFileName() const { return mpFontFile->GetFileName(); }
int GetFontFaceIndex() const { return mnFaceNum; } int GetFontFaceIndex() const { return mnFaceNum; }
int GetFontFaceVariation() const { return mnFaceVariation; }
sal_IntPtr GetFontId() const { return mnFontId; } sal_IntPtr GetFontId() const { return mnFontId; }
bool IsSymbolFont() const { return maDevFontAttributes.IsSymbolFont(); } bool IsSymbolFont() const { return maDevFontAttributes.IsSymbolFont(); }
const FontAttributes& GetFontAttributes() const { return maDevFontAttributes; } const FontAttributes& GetFontAttributes() const { return maDevFontAttributes; }
...@@ -82,6 +82,7 @@ private: ...@@ -82,6 +82,7 @@ private:
FT_FaceRec_* maFaceFT; FT_FaceRec_* maFaceFT;
FreetypeFontFile* const mpFontFile; FreetypeFontFile* const mpFontFile;
const int mnFaceNum; const int mnFaceNum;
const int mnFaceVariation;
int mnRefCount; int mnRefCount;
sal_IntPtr const mnFontId; sal_IntPtr const mnFontId;
FontAttributes maDevFontAttributes; FontAttributes maDevFontAttributes;
......
...@@ -58,9 +58,9 @@ public: ...@@ -58,9 +58,9 @@ public:
static GlyphCache& GetInstance(); static GlyphCache& GetInstance();
void AddFontFile( void AddFontFile(const OString& rNormalizedName,
const OString& rNormalizedName, int nFaceNum, int nVariantNum,
int nFaceNum, sal_IntPtr nFontId, sal_IntPtr nFontId,
const FontAttributes&); const FontAttributes&);
void AnnounceFonts( PhysicalFontCollection* ) const; void AnnounceFonts( PhysicalFontCollection* ) const;
...@@ -99,6 +99,7 @@ public: ...@@ -99,6 +99,7 @@ public:
const OString& GetFontFileName() const; const OString& GetFontFileName() const;
int GetFontFaceIndex() const; int GetFontFaceIndex() const;
int GetFontFaceVariation() const;
bool TestFont() const { return mbFaceOk;} bool TestFont() const { return mbFaceOk;}
FT_Face GetFtFace() const; FT_Face GetFtFace() const;
int GetLoadFlags() const { return (mnLoadFlags & ~FT_LOAD_IGNORE_TRANSFORM); } int GetLoadFlags() const { return (mnLoadFlags & ~FT_LOAD_IGNORE_TRANSFORM); }
...@@ -118,6 +119,7 @@ public: ...@@ -118,6 +119,7 @@ public:
FreetypeFontInstance* GetFontInstance() const { return mpFontInstance.get(); } FreetypeFontInstance* GetFontInstance() const { return mpFontInstance.get(); }
void SetFontVariationsOnHBFont(hb_font_t* pHbFace) const;
private: private:
friend class GlyphCache; friend class GlyphCache;
friend class FreetypeFontInstance; friend class FreetypeFontInstance;
......
...@@ -113,12 +113,13 @@ void Qt5Graphics::GetDevFontList(PhysicalFontCollection* pPFC) ...@@ -113,12 +113,13 @@ void Qt5Graphics::GetDevFontList(PhysicalFontCollection* pPFC)
// normalize face number to the GlyphCache // normalize face number to the GlyphCache
int nFaceNum = rMgr.getFontFaceNumber(aInfo.m_nID); int nFaceNum = rMgr.getFontFaceNumber(aInfo.m_nID);
int nVariantNum = rMgr.getFontFaceVariation(aInfo.m_nID);
// inform GlyphCache about this font provided by the PsPrint subsystem // inform GlyphCache about this font provided by the PsPrint subsystem
FontAttributes aDFA = GenPspGraphics::Info2FontAttributes(aInfo); FontAttributes aDFA = GenPspGraphics::Info2FontAttributes(aInfo);
aDFA.IncreaseQualityBy(4096); aDFA.IncreaseQualityBy(4096);
const OString& rFileName = rMgr.getFontFileSysPath(aInfo.m_nID); const OString& rFileName = rMgr.getFontFileSysPath(aInfo.m_nID);
rGC.AddFontFile(rFileName, nFaceNum, aInfo.m_nID, aDFA); rGC.AddFontFile(rFileName, nFaceNum, nVariantNum, aInfo.m_nID, aDFA);
// register font files unknown to Qt // register font files unknown to Qt
if (bUseFontconfig) if (bUseFontconfig)
......
...@@ -472,9 +472,14 @@ namespace ...@@ -472,9 +472,14 @@ namespace
// for variable fonts, FC_INDEX has been changed such that the lower half is now the // 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 // index of the font within the collection, and the upper half has been repurposed
// as the index within the variations // 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 ...@@ -498,7 +503,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o
int weight = 0; int weight = 0;
int width = 0; int width = 0;
int spacing = 0; int spacing = 0;
int nCollectionEntryId = -1; int nEntryId = -1;
FcBool outline = false; FcBool outline = false;
FcResult eFileRes = FcPatternGetString(pFSet->fonts[i], FC_FILE, 0, &file); FcResult eFileRes = FcPatternGetString(pFSet->fonts[i], FC_FILE, 0, &file);
...@@ -511,7 +516,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o ...@@ -511,7 +516,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o
FcResult eWidthRes = FcPatternGetInteger(pFSet->fonts[i], FC_WIDTH, 0, &width); FcResult eWidthRes = FcPatternGetInteger(pFSet->fonts[i], FC_WIDTH, 0, &width);
FcResult eSpacRes = FcPatternGetInteger(pFSet->fonts[i], FC_SPACING, 0, &spacing); FcResult eSpacRes = FcPatternGetInteger(pFSet->fonts[i], FC_SPACING, 0, &spacing);
FcResult eOutRes = FcPatternGetBool(pFSet->fonts[i], FC_OUTLINE, 0, &outline); 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); FcResult eFormatRes = FcPatternGetString(pFSet->fonts[i], FC_FONTFORMAT, 0, &format);
if( eFileRes != FcResultMatch || eFamilyRes != FcResultMatch || eOutRes != FcResultMatch ) if( eFileRes != FcResultMatch || eFamilyRes != FcResultMatch || eOutRes != FcResultMatch )
...@@ -576,9 +581,9 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o ...@@ -576,9 +581,9 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o
else // more than one font else // more than one font
{ {
// a collection entry, get the correct index // 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) for (auto & font : aFonts)
{ {
if( font->m_nCollectionEntry == nCollectionEntry ) if( font->m_nCollectionEntry == nCollectionEntry )
...@@ -595,14 +600,14 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o ...@@ -595,14 +600,14 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o
// additional entries will be created in the cache // additional entries will be created in the cache
// if this is a new index (that is if the loop above // if this is a new index (that is if the loop above
// ran to the end of the list) // ran to the end of the list)
xUpdate->m_nCollectionEntry = GetCollectionIndex(nCollectionEntryId); xUpdate->m_nCollectionEntry = GetCollectionIndex(nEntryId);
} }
else else
{ {
SAL_INFO( SAL_INFO(
"vcl.fonts", "vcl.fonts",
"multiple fonts for file, but no index in fontconfig pattern ! (index res =" "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"); << "; file will not be used");
// we have found more than one font in this file // we have found more than one font in this file
// but fontconfig will not tell us which index is meant // but fontconfig will not tell us which index is meant
...@@ -622,9 +627,9 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o ...@@ -622,9 +627,9 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o
if( eSlantRes == FcResultMatch ) if( eSlantRes == FcResultMatch )
xUpdate->m_eItalic = convertSlant(slant); xUpdate->m_eItalic = convertSlant(slant);
if( eStyleRes == FcResultMatch ) if( eStyleRes == FcResultMatch )
{
xUpdate->m_aStyleName = OStringToOUString( OString( reinterpret_cast<char*>(style) ), RTL_TEXTENCODING_UTF8 ); xUpdate->m_aStyleName = OStringToOUString( OString( reinterpret_cast<char*>(style) ), RTL_TEXTENCODING_UTF8 );
} if( eIndexRes == FcResultMatch )
xUpdate->m_nVariationEntry = GetVariationIndex(nEntryId);
// sort into known fonts // sort into known fonts
fontID aFont = m_nNextFontID++; fontID aFont = m_nNextFontID++;
...@@ -945,16 +950,16 @@ void PrintFontManager::Substitute(FontSelectPattern &rPattern, OUString& rMissin ...@@ -945,16 +950,16 @@ void PrintFontManager::Substitute(FontSelectPattern &rPattern, OUString& rMissin
//extract the closest match //extract the closest match
FcChar8* file = nullptr; FcChar8* file = nullptr;
FcResult eFileRes = FcPatternGetString(pSet->fonts[0], FC_FILE, 0, &file); FcResult eFileRes = FcPatternGetString(pSet->fonts[0], FC_FILE, 0, &file);
int nCollectionEntryId = 0; int nEntryId = 0;
FcResult eIndexRes = FcPatternGetInteger(pSet->fonts[0], FC_INDEX, 0, &nCollectionEntryId); FcResult eIndexRes = FcPatternGetInteger(pSet->fonts[0], FC_INDEX, 0, &nEntryId);
if (eIndexRes != FcResultMatch) if (eIndexRes != FcResultMatch)
nCollectionEntryId = 0; nEntryId = 0;
if( eFileRes == FcResultMatch ) if( eFileRes == FcResultMatch )
{ {
OString aDir, aBase, aOrgPath( reinterpret_cast<char*>(file) ); OString aDir, aBase, aOrgPath( reinterpret_cast<char*>(file) );
splitPath( aOrgPath, aDir, aBase ); splitPath( aOrgPath, aDir, aBase );
int nDirID = getDirectoryAtom( aDir ); int nDirID = getDirectoryAtom( aDir );
fontID aFont = findFontFileID( nDirID, aBase, GetCollectionIndex(nCollectionEntryId) ); fontID aFont = findFontFileID(nDirID, aBase, GetCollectionIndex(nEntryId), GetVariationIndex(nEntryId));
if( aFont > 0 ) if( aFont > 0 )
{ {
FastPrintFontInfo aInfo; FastPrintFontInfo aInfo;
...@@ -1076,12 +1081,13 @@ FcPattern *FontConfigFontOptions::GetPattern() const ...@@ -1076,12 +1081,13 @@ FcPattern *FontConfigFontOptions::GetPattern() const
return mpPattern; 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); FcPatternDel(mpPattern, FC_FILE);
FcPatternAddString(mpPattern, FC_FILE, reinterpret_cast<FcChar8 const *>(rFileName.getStr())); FcPatternAddString(mpPattern, FC_FILE, reinterpret_cast<FcChar8 const *>(rFileName.getStr()));
FcPatternDel(mpPattern, FC_INDEX); FcPatternDel(mpPattern, FC_INDEX);
FcPatternAddInteger(mpPattern, FC_INDEX, nIndex); sal_uInt32 nFcIndex = (nVariation << 16) | nIndex;
FcPatternAddInteger(mpPattern, FC_INDEX, nFcIndex);
FcPatternDel(mpPattern, FC_EMBOLDEN); FcPatternDel(mpPattern, FC_EMBOLDEN);
FcPatternAddBool(mpPattern, FC_EMBOLDEN, bEmbolden ? FcTrue : FcFalse); FcPatternAddBool(mpPattern, FC_EMBOLDEN, bEmbolden ? FcTrue : FcFalse);
} }
...@@ -1161,16 +1167,18 @@ void PrintFontManager::matchFont( FastPrintFontInfo& rInfo, const css::lang::Loc ...@@ -1161,16 +1167,18 @@ void PrintFontManager::matchFont( FastPrintFontInfo& rInfo, const css::lang::Loc
//extract the closest match //extract the closest match
FcChar8* file = nullptr; FcChar8* file = nullptr;
FcResult eFileRes = FcPatternGetString(pSet->fonts[0], FC_FILE, 0, &file); FcResult eFileRes = FcPatternGetString(pSet->fonts[0], FC_FILE, 0, &file);
int nCollectionEntry = 0; int nEntryId = 0;
FcResult eIndexRes = FcPatternGetInteger(pSet->fonts[0], FC_INDEX, 0, &nCollectionEntry); FcResult eIndexRes = FcPatternGetInteger(pSet->fonts[0], FC_INDEX, 0, &nEntryId);
if (eIndexRes != FcResultMatch) if (eIndexRes != FcResultMatch)
nCollectionEntry = 0; nEntryId = 0;
if( eFileRes == FcResultMatch ) if( eFileRes == FcResultMatch )
{ {
OString aDir, aBase, aOrgPath( reinterpret_cast<char*>(file) ); OString aDir, aBase, aOrgPath( reinterpret_cast<char*>(file) );
splitPath( aOrgPath, aDir, aBase ); splitPath( aOrgPath, aDir, aBase );
int nDirID = getDirectoryAtom( aDir ); int nDirID = getDirectoryAtom( aDir );
fontID aFont = findFontFileID( nDirID, aBase, nCollectionEntry ); fontID aFont = findFontFileID(nDirID, aBase,
GetCollectionIndex(nEntryId),
GetVariationIndex(nEntryId));
if( aFont > 0 ) if( aFont > 0 )
getFontFastInfo( aFont, rInfo ); getFontFastInfo( aFont, rInfo );
} }
......
...@@ -108,6 +108,7 @@ PrintFontManager::PrintFont::PrintFont() ...@@ -108,6 +108,7 @@ PrintFontManager::PrintFont::PrintFont()
, m_nYMax(0) , m_nYMax(0)
, m_nDirectory(0) , m_nDirectory(0)
, m_nCollectionEntry(0) , m_nCollectionEntry(0)
, m_nVariationEntry(0)
{ {
} }
...@@ -275,7 +276,7 @@ std::vector<std::unique_ptr<PrintFontManager::PrintFont>> PrintFontManager::anal ...@@ -275,7 +276,7 @@ std::vector<std::unique_ptr<PrintFontManager::PrintFont>> PrintFontManager::anal
return aNewFonts; return aNewFonts;
} }
fontID PrintFontManager::findFontFileID( int nDirID, const OString& rFontFile, int nFaceIndex ) const fontID PrintFontManager::findFontFileID(int nDirID, const OString& rFontFile, int nFaceIndex, int nVariationIndex) const
{ {
fontID nID = 0; fontID nID = 0;
...@@ -290,7 +291,9 @@ fontID PrintFontManager::findFontFileID( int nDirID, const OString& rFontFile, i ...@@ -290,7 +291,9 @@ fontID PrintFontManager::findFontFileID( int nDirID, const OString& rFontFile, i
continue; continue;
PrintFont* const pFont = (*it).second.get(); PrintFont* const pFont = (*it).second.get();
if (pFont->m_nDirectory == nDirID && if (pFont->m_nDirectory == nDirID &&
pFont->m_aFontFile == rFontFile && pFont->m_nCollectionEntry == nFaceIndex) pFont->m_aFontFile == rFontFile &&
pFont->m_nCollectionEntry == nFaceIndex &&
pFont->m_nVariationEntry == nVariationIndex)
{ {
nID = it->first; nID = it->first;
if (nID) if (nID)
...@@ -835,6 +838,19 @@ int PrintFontManager::getFontFaceNumber( fontID nFontID ) const ...@@ -835,6 +838,19 @@ int PrintFontManager::getFontFaceNumber( fontID nFontID ) const
return nRet; return nRet;
} }
int PrintFontManager::getFontFaceVariation( fontID nFontID ) const
{
int nRet = 0;
PrintFont* pFont = getFont( nFontID );
if (pFont)
{
nRet = pFont->m_nVariationEntry;
if (nRet < 0)
nRet = 0;
}
return nRet;
}
FontFamily PrintFontManager::matchFamilyName( const OUString& rFamily ) FontFamily PrintFontManager::matchFamilyName( const OUString& rFamily )
{ {
struct family_t { struct family_t {
......
...@@ -407,12 +407,13 @@ void CairoTextRender::GetDevFontList( PhysicalFontCollection* pFontCollection ) ...@@ -407,12 +407,13 @@ void CairoTextRender::GetDevFontList( PhysicalFontCollection* pFontCollection )
// normalize face number to the GlyphCache // normalize face number to the GlyphCache
int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID ); int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
int nVariantNum = rMgr.getFontFaceVariation( aInfo.m_nID );
// inform GlyphCache about this font provided by the PsPrint subsystem // inform GlyphCache about this font provided by the PsPrint subsystem
FontAttributes aDFA = GenPspGraphics::Info2FontAttributes( aInfo ); FontAttributes aDFA = GenPspGraphics::Info2FontAttributes( aInfo );
aDFA.IncreaseQualityBy( 4096 ); aDFA.IncreaseQualityBy( 4096 );
const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID ); const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID );
rGC.AddFontFile( rFileName, nFaceNum, aInfo.m_nID, aDFA ); rGC.AddFontFile( rFileName, nFaceNum, nVariantNum, aInfo.m_nID, aDFA );
} }
// announce glyphcache fonts // announce glyphcache fonts
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include FT_GLYPH_H #include FT_GLYPH_H
#include FT_MULTIPLE_MASTERS_H
#include FT_OUTLINE_H #include FT_OUTLINE_H
#include FT_SIZES_H #include FT_SIZES_H
#include FT_SYNTHESIS_H #include FT_SYNTHESIS_H
...@@ -60,6 +61,7 @@ ...@@ -60,6 +61,7 @@
// TODO: move file mapping stuff to OSL // TODO: move file mapping stuff to OSL
#include <unistd.h> #include <unistd.h>
#include <dlfcn.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mman.h> #include <sys/mman.h>
...@@ -162,11 +164,12 @@ void FreetypeFontFile::Unmap() ...@@ -162,11 +164,12 @@ void FreetypeFontFile::Unmap()
} }
FreetypeFontInfo::FreetypeFontInfo( const FontAttributes& rDevFontAttributes, FreetypeFontInfo::FreetypeFontInfo( const FontAttributes& rDevFontAttributes,
const OString& rNativeFileName, int nFaceNum, sal_IntPtr nFontId) const OString& rNativeFileName, int nFaceNum, int nFaceVariation, sal_IntPtr nFontId)
: :
maFaceFT( nullptr ), maFaceFT( nullptr ),
mpFontFile( FreetypeFontFile::FindFontFile( rNativeFileName ) ), mpFontFile( FreetypeFontFile::FindFontFile( rNativeFileName ) ),
mnFaceNum( nFaceNum ), mnFaceNum( nFaceNum ),
mnFaceVariation( nFaceVariation ),
mnRefCount( 0 ), mnRefCount( 0 ),
mnFontId( nFontId ), mnFontId( nFontId ),
maDevFontAttributes( rDevFontAttributes ) maDevFontAttributes( rDevFontAttributes )
...@@ -181,6 +184,18 @@ FreetypeFontInfo::~FreetypeFontInfo() ...@@ -181,6 +184,18 @@ FreetypeFontInfo::~FreetypeFontInfo()
{ {
} }
namespace
{
void dlFT_Done_MM_Var(FT_Library library, FT_MM_Var *amaster)
{
static auto func = reinterpret_cast<void(*)(FT_Library, FT_MM_Var*)>(dlsym(nullptr, "FT_Done_MM_Var"));
if (func)
func(library, amaster);
else
free(amaster);
}
}
FT_FaceRec_* FreetypeFontInfo::GetFaceFT() FT_FaceRec_* FreetypeFontInfo::GetFaceFT()
{ {
if (!maFaceFT && mpFontFile->Map()) if (!maFaceFT && mpFontFile->Map())
...@@ -190,12 +205,50 @@ FT_FaceRec_* FreetypeFontInfo::GetFaceFT() ...@@ -190,12 +205,50 @@ FT_FaceRec_* FreetypeFontInfo::GetFaceFT()
mpFontFile->GetFileSize(), mnFaceNum, &maFaceFT ); mpFontFile->GetFileSize(), mnFaceNum, &maFaceFT );
if( (rc != FT_Err_Ok) || (maFaceFT->num_glyphs <= 0) ) if( (rc != FT_Err_Ok) || (maFaceFT->num_glyphs <= 0) )
maFaceFT = nullptr; maFaceFT = nullptr;
if (maFaceFT && mnFaceVariation)
{
FT_MM_Var *pFtMMVar;
if (FT_Get_MM_Var(maFaceFT, &pFtMMVar) == 0)
{
if (static_cast<sal_uInt32>(mnFaceVariation) <= pFtMMVar->num_namedstyles)
{
FT_Var_Named_Style *instance = &pFtMMVar->namedstyle[mnFaceVariation - 1];
FT_Set_Var_Design_Coordinates(maFaceFT, pFtMMVar->num_axis, instance->coords);
}
dlFT_Done_MM_Var(aLibFT, pFtMMVar);
}
}
} }
++mnRefCount; ++mnRefCount;
return maFaceFT; return maFaceFT;
} }
void FreetypeFont::SetFontVariationsOnHBFont(hb_font_t* pHbFace) const
{
sal_uInt32 nFaceVariation = mpFontInfo->GetFontFaceVariation();
if (maFaceFT && nFaceVariation)
{
FT_MM_Var *pFtMMVar;
if (FT_Get_MM_Var(maFaceFT, &pFtMMVar) == 0)
{
if (nFaceVariation <= pFtMMVar->num_namedstyles)
{
FT_Var_Named_Style *instance = &pFtMMVar->namedstyle[nFaceVariation - 1];
std::vector<hb_variation_t> aVariations(pFtMMVar->num_axis);
for (FT_UInt i = 0; i < pFtMMVar->num_axis; ++i)
{
aVariations[i].tag = pFtMMVar->axis[i].tag;
aVariations[i].value = instance->coords[i] / 65536.0;
}
hb_font_set_variations(pHbFace, aVariations.data(), aVariations.size());
}
dlFT_Done_MM_Var(aLibFT, pFtMMVar);
}
}
}
void FreetypeFontInfo::ReleaseFaceFT() void FreetypeFontInfo::ReleaseFaceFT()
{ {
if (--mnRefCount <= 0) if (--mnRefCount <= 0)
...@@ -259,9 +312,6 @@ void GlyphCache::InitFreetype() ...@@ -259,9 +312,6 @@ void GlyphCache::InitFreetype()
{ {
/*FT_Error rcFT =*/ FT_Init_FreeType( &aLibFT ); /*FT_Error rcFT =*/ FT_Init_FreeType( &aLibFT );
FT_Int nMajor = 0, nMinor = 0, nPatch = 0;
FT_Library_Version(aLibFT, &nMajor, &nMinor, &nPatch);
// TODO: remove when the priorities are selected by UI // TODO: remove when the priorities are selected by UI
char* pEnv; char* pEnv;
pEnv = ::getenv( "SAL_EMBEDDED_BITMAP_PRIORITY" ); pEnv = ::getenv( "SAL_EMBEDDED_BITMAP_PRIORITY" );
...@@ -281,8 +331,8 @@ FT_Face FreetypeFont::GetFtFace() const ...@@ -281,8 +331,8 @@ FT_Face FreetypeFont::GetFtFace() const
return maFaceFT; return maFaceFT;
} }
void GlyphCache::AddFontFile( const OString& rNormalizedName, void GlyphCache::AddFontFile(const OString& rNormalizedName,
int nFaceNum, sal_IntPtr nFontId, const FontAttributes& rDevFontAttr) int nFaceNum, int nVariantNum, sal_IntPtr nFontId, const FontAttributes& rDevFontAttr)
{ {
if( rNormalizedName.isEmpty() ) if( rNormalizedName.isEmpty() )
return; return;
...@@ -291,7 +341,7 @@ void GlyphCache::AddFontFile( const OString& rNormalizedName, ...@@ -291,7 +341,7 @@ void GlyphCache::AddFontFile( const OString& rNormalizedName,
return; return;
FreetypeFontInfo* pFontInfo = new FreetypeFontInfo( rDevFontAttr, FreetypeFontInfo* pFontInfo = new FreetypeFontInfo( rDevFontAttr,
rNormalizedName, nFaceNum, nFontId); rNormalizedName, nFaceNum, nVariantNum, nFontId);
m_aFontInfoList[ nFontId ].reset(pFontInfo); m_aFontInfoList[ nFontId ].reset(pFontInfo);
if( m_nMaxFontId < nFontId ) if( m_nMaxFontId < nFontId )
m_nMaxFontId = nFontId; m_nMaxFontId = nFontId;
...@@ -433,7 +483,7 @@ const FontConfigFontOptions* FreetypeFont::GetFontOptions() const ...@@ -433,7 +483,7 @@ const FontConfigFontOptions* FreetypeFont::GetFontOptions() const
if (!mxFontOptions) if (!mxFontOptions)
{ {
mxFontOptions.reset(GetFCFontOptions(mpFontInfo->GetFontAttributes(), mpFontInstance->GetFontSelectPattern().mnHeight)); mxFontOptions.reset(GetFCFontOptions(mpFontInfo->GetFontAttributes(), mpFontInstance->GetFontSelectPattern().mnHeight));
mxFontOptions->SyncPattern(GetFontFileName(), GetFontFaceIndex(), NeedsArtificialBold()); mxFontOptions->SyncPattern(GetFontFileName(), GetFontFaceIndex(), GetFontFaceVariation(), NeedsArtificialBold());
} }
return mxFontOptions.get(); return mxFontOptions.get();
} }
...@@ -453,6 +503,11 @@ int FreetypeFont::GetFontFaceIndex() const ...@@ -453,6 +503,11 @@ int FreetypeFont::GetFontFaceIndex() const
return mpFontInfo->GetFontFaceIndex(); return mpFontInfo->GetFontFaceIndex();
} }
int FreetypeFont::GetFontFaceVariation() const
{
return mpFontInfo->GetFontFaceVariation();
}
FreetypeFont::~FreetypeFont() FreetypeFont::~FreetypeFont()
{ {
if( maSizeFT ) if( maSizeFT )
......
...@@ -298,7 +298,10 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU ...@@ -298,7 +298,10 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
hb_font_t* FreetypeFontInstance::ImplInitHbFont() hb_font_t* FreetypeFontInstance::ImplInitHbFont()
{ {
return InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr)); hb_font_t* pRet = InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr));
assert(mpFreetypeFont);
mpFreetypeFont->SetFontVariationsOnHBFont(pRet);
return pRet;
} }
bool FreetypeFontInstance::ImplGetGlyphBoundRect(sal_GlyphId nId, tools::Rectangle& rRect, bool bVertical) const bool FreetypeFontInstance::ImplGetGlyphBoundRect(sal_GlyphId nId, tools::Rectangle& rRect, bool bVertical) const
......
...@@ -693,9 +693,10 @@ bool GenPspGraphics::AddTempDevFontHelper( PhysicalFontCollection* pFontCollecti ...@@ -693,9 +693,10 @@ bool GenPspGraphics::AddTempDevFontHelper( PhysicalFontCollection* pFontCollecti
aDFA.IncreaseQualityBy( 5800 ); aDFA.IncreaseQualityBy( 5800 );
int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID ); int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
int nVariantNum = rMgr.getFontFaceVariation( aInfo.m_nID );
const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID ); const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID );
rGC.AddFontFile( rFileName, nFaceNum, aInfo.m_nID, aDFA ); rGC.AddFontFile( rFileName, nFaceNum, nVariantNum, aInfo.m_nID, aDFA );
} }
// announce new font to device's font list // announce new font to device's font list
......
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