[Libreoffice-commits] core.git: 2 commits - i18npool/inc i18npool/source vcl/generic
Eike Rathke
erack at redhat.com
Mon Feb 18 16:15:37 PST 2013
i18npool/inc/i18npool/languagetag.hxx | 5 +
i18npool/source/languagetag/languagetag.cxx | 83 ++++++++++++++++------------
vcl/generic/fontmanager/fontconfig.cxx | 33 ++++++-----
3 files changed, 73 insertions(+), 48 deletions(-)
New commits:
commit 6e6af9943ca72f0b2b27726b7051db2ddbf378dd
Author: Eike Rathke <erack at redhat.com>
Date: Tue Feb 19 01:14:31 2013 +0100
really, don't obtain the process locale 500 times
Twice for each font ...
Change-Id: Ib4589f8a11e0c14f0c5235e17d0c68e67d93b0b4
diff --git a/vcl/generic/fontmanager/fontconfig.cxx b/vcl/generic/fontmanager/fontconfig.cxx
index 9c6abe1..f5dda96 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;
}
/*
commit 555d88d003b8f0708fb5a1c1f3b3f7a8110dddf7
Author: Eike Rathke <erack at redhat.com>
Date: Tue Feb 19 00:45:07 2013 +0100
added reset(rtl_Locale)
Change-Id: I1bc83dd4e5286f7102513d8a4c7d5624952eb830
diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx
index 324fcd3..ff8266d 100644
--- a/i18npool/inc/i18npool/languagetag.hxx
+++ b/i18npool/inc/i18npool/languagetag.hxx
@@ -205,6 +205,9 @@ public:
/** Reset with LanguageType MS-LangID. */
void reset( LanguageType nLanguage );
+ /** Reset with rtl_Locale. */
+ void reset( const rtl_Locale & rLocale );
+
/** Fall back to a known locale.
@@ -275,6 +278,8 @@ private:
void convertLangToLocale();
void convertLangToBcp47();
+ void convertFromRtlLocale();
+
bool canonicalize();
rtl::OUString getLanguageFromLangtag();
diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx
index 2117771..c510962 100644
--- a/i18npool/source/languagetag/languagetag.cxx
+++ b/i18npool/source/languagetag/languagetag.cxx
@@ -248,41 +248,7 @@ LanguageTag::LanguageTag( const rtl_Locale & rLocale )
mbCachedCountry( false),
mbIsFallback( false)
{
- // The rtl_Locale follows the Open Group Base Specification,
- // 8.2 Internationalization Variables
- // language[_territory][.codeset][@modifier]
- // On GNU/Linux systems usually being glibc locales.
- // sal/osl/unx/nlsupport.c _parse_locale() parses them into
- // Language: language 2 or 3 alpha code
- // Country: [territory] 2 alpha code
- // Variant: [.codeset][@modifier]
- // Variant effectively contains anything that follows the territory, not
- // looking for '.' dot delimiter or '@' modifier content.
- if (!maLocale.Variant.isEmpty())
- {
- OString aStr = OUStringToOString( maLocale.Language + "_" + maLocale.Country + maLocale.Variant,
- RTL_TEXTENCODING_UTF8);
- /* FIXME: let liblangtag parse this entirely with
- * lt_tag_convert_from_locale() but that needs a patch to pass the
- * string. */
-#if 0
- myLtError aError;
- theDataRef::get().incRef();
- mpImplLangtag = lt_tag_convert_from_locale( aStr.getStr(), &aError.p);
- maBcp47 = OStringToOUString( lt_tag_get_string( MPLANGTAG), RTL_TEXTENCODING_UTF8);
- mbInitializedBcp47 = true;
-#else
- mnLangID = MsLangId::convertUnxByteStringToLanguage( aStr);
- if (mnLangID == LANGUAGE_DONTKNOW)
- {
- SAL_WARN( "i18npool.langtag", "LanguageTag(rtl_Locale) - unknown: " << aStr);
- mnLangID = LANGUAGE_ENGLISH_US; // we need _something_ here
- }
- mbInitializedLangID = true;
-#endif
- maLocale = lang::Locale();
- mbInitializedLocale = false;
- }
+ convertFromRtlLocale();
}
@@ -417,6 +383,13 @@ void LanguageTag::reset( LanguageType nLanguage )
}
+void LanguageTag::reset( const rtl_Locale & rLocale )
+{
+ reset( lang::Locale( rLocale.Language, rLocale.Country, rLocale.Variant));
+ convertFromRtlLocale();
+}
+
+
bool LanguageTag::canonicalize()
{
#ifdef erDEBUG
@@ -671,6 +644,46 @@ void LanguageTag::convertLangToBcp47()
}
+void LanguageTag::convertFromRtlLocale()
+{
+ // The rtl_Locale follows the Open Group Base Specification,
+ // 8.2 Internationalization Variables
+ // language[_territory][.codeset][@modifier]
+ // On GNU/Linux systems usually being glibc locales.
+ // sal/osl/unx/nlsupport.c _parse_locale() parses them into
+ // Language: language 2 or 3 alpha code
+ // Country: [territory] 2 alpha code
+ // Variant: [.codeset][@modifier]
+ // Variant effectively contains anything that follows the territory, not
+ // looking for '.' dot delimiter or '@' modifier content.
+ if (!maLocale.Variant.isEmpty())
+ {
+ OString aStr = OUStringToOString( maLocale.Language + "_" + maLocale.Country + maLocale.Variant,
+ RTL_TEXTENCODING_UTF8);
+ /* FIXME: let liblangtag parse this entirely with
+ * lt_tag_convert_from_locale() but that needs a patch to pass the
+ * string. */
+#if 0
+ myLtError aError;
+ theDataRef::get().incRef();
+ mpImplLangtag = lt_tag_convert_from_locale( aStr.getStr(), &aError.p);
+ maBcp47 = OStringToOUString( lt_tag_get_string( MPLANGTAG), RTL_TEXTENCODING_UTF8);
+ mbInitializedBcp47 = true;
+#else
+ mnLangID = MsLangId::convertUnxByteStringToLanguage( aStr);
+ if (mnLangID == LANGUAGE_DONTKNOW)
+ {
+ SAL_WARN( "i18npool.langtag", "LanguageTag(rtl_Locale) - unknown: " << aStr);
+ mnLangID = LANGUAGE_ENGLISH_US; // we need _something_ here
+ }
+ mbInitializedLangID = true;
+#endif
+ maLocale = lang::Locale();
+ mbInitializedLocale = false;
+ }
+}
+
+
const rtl::OUString & LanguageTag::getBcp47( bool bResolveSystem ) const
{
if (!bResolveSystem && mbSystemLocale)
More information about the Libreoffice-commits
mailing list