diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-10-27 16:37:28 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-10-27 16:39:33 +0100 |
commit | c90728896ae050014357f89c4ab93f7e92afb2ee (patch) | |
tree | 81835c7f422381aacdafa9916ce36ef8df55f996 /vcl/generic | |
parent | bea5e37dd32f30d301aca89ba4875657de7c1025 (diff) |
make FontManager work directly on FontSelectPattern
This disentangles another layer of intermediate substitution and assignment
which we can do now after Christina's work and aligns this a step closer to the
FcPattern concept and a few more percent more readable and maintainable I hope.
Diffstat (limited to 'vcl/generic')
-rw-r--r-- | vcl/generic/fontmanager/fontconfig.cxx | 50 | ||||
-rw-r--r-- | vcl/generic/fontmanager/fontsubst.cxx | 25 |
2 files changed, 30 insertions, 45 deletions
diff --git a/vcl/generic/fontmanager/fontconfig.cxx b/vcl/generic/fontmanager/fontconfig.cxx index a4f5f7fd5bfa..2f2398c7b051 100644 --- a/vcl/generic/fontmanager/fontconfig.cxx +++ b/vcl/generic/fontmanager/fontconfig.cxx @@ -33,6 +33,8 @@ #include "impfont.hxx" #include "vcl/fontmanager.hxx" #include "vcl/vclenum.hxx" +#include "outfont.hxx" +#include <i18npool/mslangid.hxx> using namespace psp; @@ -747,12 +749,10 @@ static void addtopattern(FcPattern *pPattern, } } -rtl::OUString PrintFontManager::Substitute(const rtl::OUString& rFontName, - rtl::OUString& rMissingCodes, const rtl::OString &rLangAttrib, - FontItalic &rItalic, FontWeight &rWeight, - FontWidth &rWidth, FontPitch &rPitch, bool &rEmbolden, ItalicMatrix &rMatrix) const +bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& rMissingCodes ) const { - rtl::OUString aName; + bool bRet = false; + FontCfgWrapper& rWrapper = FontCfgWrapper::get(); // build pattern argument for fontconfig query @@ -761,17 +761,18 @@ rtl::OUString PrintFontManager::Substitute(const rtl::OUString& rFontName, // Prefer scalable fonts FcPatternAddBool(pPattern, FC_SCALABLE, FcTrue); - const rtl::OString aTargetName = rtl::OUStringToOString( rFontName, RTL_TEXTENCODING_UTF8 ); + const rtl::OString aTargetName = rtl::OUStringToOString( rPattern.maTargetName, RTL_TEXTENCODING_UTF8 ); const FcChar8* pTargetNameUtf8 = (FcChar8*)aTargetName.getStr(); FcPatternAddString(pPattern, FC_FAMILY, pTargetNameUtf8); - if( rLangAttrib.getLength() ) + const rtl::OString aLangAttrib = MsLangId::convertLanguageToIsoByteString(rPattern.meLanguage); + if( aLangAttrib.getLength() ) { const FcChar8* pLangAttribUtf8; - if (rLangAttrib.equalsIgnoreAsciiCase(OString(RTL_CONSTASCII_STRINGPARAM("pa-in")))) + if (aLangAttrib.equalsIgnoreAsciiCase(OString(RTL_CONSTASCII_STRINGPARAM("pa-in")))) pLangAttribUtf8 = (FcChar8*)"pa"; else - pLangAttribUtf8 = (FcChar8*)rLangAttrib.getStr(); + pLangAttribUtf8 = (FcChar8*)aLangAttrib.getStr(); FcPatternAddString(pPattern, FC_LANG, pLangAttribUtf8); } @@ -789,7 +790,8 @@ rtl::OUString PrintFontManager::Substitute(const rtl::OUString& rFontName, FcCharSetDestroy(unicodes); } - addtopattern(pPattern, rItalic, rWeight, rWidth, rPitch); + addtopattern(pPattern, rPattern.meItalic, rPattern.meWeight, + rPattern.meWidthType, rPattern.mePitch); // query fontconfig for a substitute FcConfigSubstitute(FcConfigGetCurrent(), pPattern, FcMatchPattern); @@ -821,32 +823,34 @@ rtl::OUString PrintFontManager::Substitute(const rtl::OUString& rFontName, // get the family name if( eFileRes == FcResultMatch ) { + bRet = true; + OString sFamily((sal_Char*)family); - boost::unordered_map< rtl::OString, rtl::OString, rtl::OStringHash >::const_iterator aI = rWrapper.m_aFontNameToLocalized.find(sFamily); + boost::unordered_map< rtl::OString, rtl::OString, rtl::OStringHash >::const_iterator aI = + rWrapper.m_aFontNameToLocalized.find(sFamily); if (aI != rWrapper.m_aFontNameToLocalized.end()) sFamily = aI->second; - aName = rtl::OStringToOUString( sFamily, RTL_TEXTENCODING_UTF8 ); - + rPattern.maSearchName = rtl::OStringToOUString( sFamily, RTL_TEXTENCODING_UTF8 ); int val = 0; if (FcResultMatch == FcPatternGetInteger(pSet->fonts[0], FC_WEIGHT, 0, &val)) - rWeight = convertWeight(val); + rPattern.meWeight = convertWeight(val); if (FcResultMatch == FcPatternGetInteger(pSet->fonts[0], FC_SLANT, 0, &val)) - rItalic = convertSlant(val); + rPattern.meItalic = convertSlant(val); if (FcResultMatch == FcPatternGetInteger(pSet->fonts[0], FC_SPACING, 0, &val)) - rPitch = convertSpacing(val); + rPattern.mePitch = convertSpacing(val); if (FcResultMatch == FcPatternGetInteger(pSet->fonts[0], FC_WIDTH, 0, &val)) - rWidth = convertWidth(val); + rPattern.meWidthType = convertWidth(val); FcBool bEmbolden; if (FcResultMatch == FcPatternGetBool(pSet->fonts[0], FC_EMBOLDEN, 0, &bEmbolden)) - rEmbolden = bEmbolden; + rPattern.mbEmbolden = bEmbolden; FcMatrix *pMatrix = 0; if (FcResultMatch == FcPatternGetMatrix(pSet->fonts[0], FC_MATRIX, 0, &pMatrix)) { - rMatrix.xx = pMatrix->xx; - rMatrix.xy = pMatrix->xy; - rMatrix.yx = pMatrix->yx; - rMatrix.yy = pMatrix->yy; + rPattern.maItalicMatrix.xx = pMatrix->xx; + rPattern.maItalicMatrix.xy = pMatrix->xy; + rPattern.maItalicMatrix.yx = pMatrix->yx; + rPattern.maItalicMatrix.yy = pMatrix->yy; } } @@ -873,7 +877,7 @@ rtl::OUString PrintFontManager::Substitute(const rtl::OUString& rFontName, FcFontSetDestroy( pSet ); } - return aName; + return bRet; } class FontConfigFontOptions : public ImplFontOptions diff --git a/vcl/generic/fontmanager/fontsubst.cxx b/vcl/generic/fontmanager/fontsubst.cxx index 6ad4ff157f1f..9d286fb18948 100644 --- a/vcl/generic/fontmanager/fontsubst.cxx +++ b/vcl/generic/fontmanager/fontsubst.cxx @@ -34,7 +34,6 @@ #include "vcl/sysdata.hxx" #include "outfont.hxx" -#include <i18npool/mslangid.hxx> #include "generic/printergfx.hxx" #include "salbmp.hxx" @@ -119,28 +118,10 @@ void SalGenericInstance::RegisterFontSubstitutors( ImplDevFontList* pList ) static FontSelectPattern GetFcSubstitute(const FontSelectPattern &rFontSelData, rtl::OUString& rMissingCodes ) { - FontSelectPattern aRet(rFontSelData); - - const rtl::OString aLangAttrib = MsLangId::convertLanguageToIsoByteString( rFontSelData.meLanguage ); - - FontItalic eItalic = rFontSelData.GetSlant(); - FontWeight eWeight = rFontSelData.GetWeight(); - FontWidth eWidth = rFontSelData.GetWidthType(); - FontPitch ePitch = rFontSelData.GetPitch(); - bool bEmbolden = rFontSelData.mbEmbolden; - ItalicMatrix aMatrix = rFontSelData.maItalicMatrix; - + FontSelectPattern aSubstituted(rFontSelData); const psp::PrintFontManager& rMgr = psp::PrintFontManager::get(); - aRet.maSearchName = rMgr.Substitute( rFontSelData.maTargetName, rMissingCodes, aLangAttrib, eItalic, eWeight, eWidth, ePitch, bEmbolden, aMatrix ); - - aRet.maItalicMatrix = aMatrix; - aRet.mbEmbolden = bEmbolden; - aRet.meItalic = eItalic; - aRet.meWeight = eWeight; - aRet.meWidthType = eWidth; - aRet.mePitch = ePitch; - - return aRet; + rMgr.Substitute(aSubstituted, rMissingCodes); + return aSubstituted; } namespace |