diff options
-rw-r--r-- | include/unotools/fontcfg.hxx | 39 | ||||
-rw-r--r-- | unotools/source/config/fontcfg.cxx | 36 |
2 files changed, 21 insertions, 54 deletions
diff --git a/include/unotools/fontcfg.hxx b/include/unotools/fontcfg.hxx index 3e7f0ac95200..5e63ddb7fbdf 100644 --- a/include/unotools/fontcfg.hxx +++ b/include/unotools/fontcfg.hxx @@ -30,37 +30,9 @@ #include <boost/unordered_set.hpp> #include <vector> -namespace com { -namespace sun { -namespace star { -namespace lang { - -// equality operator needed for hash_map; -// (-> why does this need to be in the namespace of Locale ? g++ fails to compile else) -inline bool operator==( const com::sun::star::lang::Locale& rLeft, const com::sun::star::lang::Locale& rRight ) -{ - return - rLeft.Language.equals( rRight.Language ) && - rLeft.Country.equals( rRight.Country ) && - rLeft.Variant.equals( rRight.Variant ) - ; -} -}}}} - namespace utl { -struct LocaleHash -{ - size_t operator()( const com::sun::star::lang::Locale& rLocale ) const - { - return - (size_t)rLocale.Language.hashCode() ^ - (size_t)rLocale.Country.hashCode() ^ - (size_t)rLocale.Variant.hashCode(); - } -}; - class UNOTOOLS_DLLPUBLIC DefaultFontConfiguration { com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > @@ -77,12 +49,9 @@ class UNOTOOLS_DLLPUBLIC DefaultFontConfiguration mutable com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xAccess; }; - boost::unordered_map< com::sun::star::lang::Locale, - LocaleAccess, - utl::LocaleHash > - m_aConfig; + boost::unordered_map< OUString, LocaleAccess, OUStringHash > m_aConfig; - OUString tryLocale( const com::sun::star::lang::Locale& rLocale, const OUString& rType ) const; + OUString tryLocale( const OUString& rBcp47, const OUString& rType ) const; public: DefaultFontConfiguration(); @@ -183,7 +152,7 @@ private: LocaleSubst() : bConfigRead( false ) {} }; - boost::unordered_map< com::sun::star::lang::Locale, LocaleSubst, utl::LocaleHash > m_aSubst; + boost::unordered_map< OUString, LocaleSubst, OUStringHash > m_aSubst; typedef boost::unordered_set< OUString, OUStringHash > UniqueSubstHash; mutable UniqueSubstHash maSubstHash; @@ -197,7 +166,7 @@ private: const OUString& rType ) const; unsigned long getSubstType( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont, const OUString& rType ) const; - void readLocaleSubst( const com::sun::star::lang::Locale& rLocale ) const; + void readLocaleSubst( const OUString& rBcp47 ) const; public: FontSubstConfiguration(); ~FontSubstConfiguration(); diff --git a/unotools/source/config/fontcfg.cxx b/unotools/source/config/fontcfg.cxx index e9cec6c952f5..b61de13b7b2b 100644 --- a/unotools/source/config/fontcfg.cxx +++ b/unotools/source/config/fontcfg.cxx @@ -126,7 +126,8 @@ DefaultFontConfiguration::DefaultFontConfiguration() const OUString* pLocaleStrings = aLocales.getConstArray(); for( int i = 0; i < nLocales; i++ ) { - Locale aLoc( LanguageTag( pLocaleStrings[i]).getLocale( false)); + // Feed through LanguageTag for casing. + OUString aLoc( LanguageTag( pLocaleStrings[i], true).getBcp47( false)); m_aConfig[ aLoc ] = LocaleAccess(); m_aConfig[ aLoc ].aConfigLocaleString = pLocaleStrings[i]; } @@ -160,12 +161,11 @@ DefaultFontConfiguration::~DefaultFontConfiguration() m_xConfigProvider.clear(); } -OUString DefaultFontConfiguration::tryLocale( const Locale& rLocale, const OUString& rType ) const +OUString DefaultFontConfiguration::tryLocale( const OUString& rBcp47, const OUString& rType ) const { OUString aRet; - boost::unordered_map< Locale, LocaleAccess, LocaleHash >::const_iterator it = - m_aConfig.find( rLocale ); + boost::unordered_map< OUString, LocaleAccess, OUStringHash >::const_iterator it = m_aConfig.find( rBcp47 ); if( it != m_aConfig.end() ) { if( !it->second.xAccess.is() ) @@ -212,33 +212,32 @@ OUString DefaultFontConfiguration::tryLocale( const Locale& rLocale, const OUStr OUString DefaultFontConfiguration::getDefaultFont( const Locale& rLocale, int nType ) const { OUString aType = OUString::createFromAscii( getKeyType( nType ) ); - OUString aRet = tryLocale( rLocale, aType ); + LanguageTag aLanguageTag( rLocale); + // Try the simple cases first without constructing fallbacks. + OUString aRet = tryLocale( aLanguageTag.getBcp47(), aType ); if (aRet.isEmpty()) { if (rLocale.Variant.isEmpty()) { if (!rLocale.Country.isEmpty()) { - Locale aLocale( rLocale.Language, "", ""); - aRet = tryLocale( aLocale, aType ); + aRet = tryLocale( rLocale.Language, aType ); } } else { - ::std::vector< OUString > aFallbacks( LanguageTag( rLocale).getFallbackStrings()); + ::std::vector< OUString > aFallbacks( aLanguageTag.getFallbackStrings()); aFallbacks.erase( aFallbacks.begin()); // first is full BCP47, we already checked that for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end() && aRet.isEmpty(); ++it) { - Locale aLocale( LanguageTag( *it).getLocale( false)); - aRet = tryLocale( aLocale, aType ); + aRet = tryLocale( *it, aType ); } } } if( aRet.isEmpty() ) { - Locale aLocale("en","",""); - aRet = tryLocale( aLocale, aType ); + aRet = tryLocale( "en", aType ); } return aRet; } @@ -388,7 +387,8 @@ FontSubstConfiguration::FontSubstConfiguration() : const OUString* pLocaleStrings = aLocales.getConstArray(); for( int i = 0; i < nLocales; i++ ) { - Locale aLoc( LanguageTag( pLocaleStrings[i]).getLocale( false)); + // Feed through LanguageTag for casing. + OUString aLoc( LanguageTag( pLocaleStrings[i], true).getBcp47( false)); m_aSubst[ aLoc ] = LocaleSubst(); m_aSubst[ aLoc ].aConfigLocaleString = pLocaleStrings[i]; } @@ -1046,10 +1046,9 @@ unsigned long FontSubstConfiguration::getSubstType( const com::sun::star::uno::R return type; } -void FontSubstConfiguration::readLocaleSubst( const com::sun::star::lang::Locale& rLocale ) const +void FontSubstConfiguration::readLocaleSubst( const OUString& rBcp47 ) const { - boost::unordered_map< Locale, LocaleSubst, LocaleHash >::const_iterator it = - m_aSubst.find( rLocale ); + boost::unordered_map< OUString, LocaleSubst, OUStringHash >::const_iterator it = m_aSubst.find( rBcp47 ); if( it != m_aSubst.end() ) { if( ! it->second.bConfigRead ) @@ -1148,12 +1147,11 @@ const FontNameAttr* FontSubstConfiguration::getSubstInfo( const OUString& rFontN for (::std::vector< OUString >::const_iterator fb( aFallbacks.begin()); fb != aFallbacks.end(); ++fb) { - Locale aLocale( LanguageTag( *fb).getLocale()); - boost::unordered_map< Locale, LocaleSubst, LocaleHash >::const_iterator lang = m_aSubst.find( aLocale ); + boost::unordered_map< OUString, LocaleSubst, OUStringHash >::const_iterator lang = m_aSubst.find( *fb ); if( lang != m_aSubst.end() ) { if( ! lang->second.bConfigRead ) - readLocaleSubst( aLocale ); + readLocaleSubst( *fb ); // try to find an exact match // because the list is sorted this will also find fontnames of the form searchfontname* std::vector< FontNameAttr >::const_iterator it = ::std::lower_bound( lang->second.aSubstAttributes.begin(), lang->second.aSubstAttributes.end(), aSearchAttr, StrictStringSort() ); |