diff options
author | Eike Rathke <erack@redhat.com> | 2013-02-19 01:14:31 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-02-19 01:15:07 +0100 |
commit | 6e6af9943ca72f0b2b27726b7051db2ddbf378dd (patch) | |
tree | df8c74f7bc1df210644874af479000c110418085 /vcl | |
parent | 555d88d003b8f0708fb5a1c1f3b3f7a8110dddf7 (diff) |
really, don't obtain the process locale 500 times
Twice for each font ...
Change-Id: Ib4589f8a11e0c14f0c5235e17d0c68e67d93b0b4
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/generic/fontmanager/fontconfig.cxx | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/vcl/generic/fontmanager/fontconfig.cxx b/vcl/generic/fontmanager/fontconfig.cxx index 9c6abe16beee..f5dda96627d7 100644 --- a/vcl/generic/fontmanager/fontconfig.cxx +++ b/vcl/generic/fontmanager/fontconfig.cxx @@ -128,10 +128,14 @@ public: boost::unordered_map< rtl::OString, rtl::OString, rtl::OStringHash > m_aLocalizedToCanonical; private: void cacheLocalizedFontNames(const FcChar8 *origfontname, const FcChar8 *bestfontname, const std::vector< lang_and_element > &lang_and_elements); + + LanguageTag* m_pLanguageTag; }; FontCfgWrapper::FontCfgWrapper() - : m_pOutlineSet( NULL ) + : + m_pOutlineSet( NULL ), + m_pLanguageTag( NULL ) { FcInit(); } @@ -282,22 +286,21 @@ namespace { class localizedsorter { - LanguageTag maLoc; public: - localizedsorter(const LanguageTag& rLanguageTag) : maLoc(rLanguageTag) {} - FcChar8* bestname(const std::vector<lang_and_element> &elements); + localizedsorter() {}; + FcChar8* bestname(const std::vector<lang_and_element> &elements, const LanguageTag & rLangTag); }; - FcChar8* localizedsorter::bestname(const std::vector<lang_and_element> &elements) + FcChar8* localizedsorter::bestname(const std::vector<lang_and_element> &elements, const LanguageTag & rLangTag) { FcChar8* candidate = elements.begin()->second; /* FIXME-BCP47: once fontconfig supports language tags this * language-territory stuff needs to be changed! */ - SAL_INFO_IF( !maLoc.isIsoLocale(), "i18n", "localizedsorter::bestname - not an ISO locale"); - rtl::OString sLangMatch(rtl::OUStringToOString(maLoc.getLanguage().toAsciiLowerCase(), RTL_TEXTENCODING_UTF8)); + SAL_INFO_IF( !rLangTag.isIsoLocale(), "i18n", "localizedsorter::bestname - not an ISO locale"); + rtl::OString sLangMatch(rtl::OUStringToOString(rLangTag.getLanguage().toAsciiLowerCase(), RTL_TEXTENCODING_UTF8)); rtl::OString sFullMatch = sLangMatch; sFullMatch += OString('-'); - sFullMatch += rtl::OUStringToOString(maLoc.getCountry().toAsciiLowerCase(), RTL_TEXTENCODING_UTF8); + sFullMatch += rtl::OUStringToOString(rLangTag.getCountry().toAsciiLowerCase(), RTL_TEXTENCODING_UTF8); std::vector<lang_and_element>::const_iterator aEnd = elements.end(); bool alreadyclosematch = false; @@ -382,11 +385,13 @@ FcResult FontCfgWrapper::LocalizedElementFromPattern(FcPattern* pPattern, FcChar } //possible to-do, sort by UILocale instead of process locale - rtl_Locale* pLoc = NULL; - osl_getProcessLocale(&pLoc); - LanguageTag aTag(*pLoc); - localizedsorter aSorter(aTag); - *element = aSorter.bestname(lang_and_elements); + if (!m_pLanguageTag) + { + rtl_Locale* pLoc = NULL; + osl_getProcessLocale(&pLoc); + m_pLanguageTag = new LanguageTag(*pLoc); + } + *element = localizedsorter().bestname(lang_and_elements, *m_pLanguageTag); //if this element is a fontname, map the other names to this best-name if (rtl_str_compare(elementtype, FC_FAMILY) == 0) @@ -406,6 +411,8 @@ void FontCfgWrapper::clear() FcFontSetDestroy( m_pOutlineSet ); m_pOutlineSet = NULL; } + delete m_pLanguageTag; + m_pLanguageTag = NULL; } /* |