2002-02-06 10:36:30 +00:00
/*************************************************************************
*
2005-09-09 10:57:35 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2002-02-06 10:36:30 +00:00
*
2005-09-09 10:57:35 +00:00
* $ RCSfile : fontcfg . cxx , v $
2002-02-06 10:36:30 +00:00
*
2006-12-04 15:35:50 +00:00
* $ Revision : 1.44 $
2002-02-06 10:36:30 +00:00
*
2006-12-04 15:35:50 +00:00
* last change : $ Author : rt $ $ Date : 2006 - 12 - 04 16 : 35 : 50 $
2002-02-06 10:36:30 +00:00
*
2005-09-09 10:57:35 +00:00
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1 .
2002-02-06 10:36:30 +00:00
*
*
2005-09-09 10:57:35 +00:00
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2005 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
2002-02-06 10:36:30 +00:00
*
2005-09-09 10:57:35 +00:00
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 , as published by the Free Software Foundation .
2002-02-06 10:36:30 +00:00
*
2005-09-09 10:57:35 +00:00
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
2002-02-06 10:36:30 +00:00
*
2005-09-09 10:57:35 +00:00
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston ,
* MA 02111 - 1307 USA
2002-02-06 10:36:30 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-17 11:00:10 +00:00
// MARKER(update_precomp.py): autogen include statement, do not remove
# include "precompiled_vcl.hxx"
2002-02-06 10:36:30 +00:00
# ifndef _VCL_FONTCFG_HXX
# include <fontcfg.hxx>
# endif
2005-02-24 14:23:31 +00:00
# ifndef VCL_INC_CONFIGSETTINGS_HXX
# include <configsettings.hxx>
# endif
2002-02-06 10:36:30 +00:00
# ifndef _SV_OUTDEV_HXX
# include <outdev.hxx>
# endif
# ifndef _SV_SVDATA_HXX
# include <svdata.hxx>
# endif
2002-05-29 12:41:06 +00:00
# ifndef _SV_SVAPP_HXX
# include <svapp.hxx>
# endif
2006-05-04 14:11:41 +00:00
# ifndef _VCL_UNOHELP_HXX
# include <unohelp.hxx>
# endif
2002-02-06 10:36:30 +00:00
# ifndef _COM_SUN_STAR_UNO_ANY_HXX_
# include <com/sun/star/uno/Any.hxx>
# endif
# ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
# include <com/sun/star/uno/Sequence.hxx>
# endif
# ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
# include <com/sun/star/beans/PropertyValue.hpp>
# endif
2003-06-30 13:29:06 +00:00
# ifndef UNOTOOLS_CONFIGPATHES_HXX_INCLUDED
# include <unotools/configpathes.hxx>
# endif
2002-02-06 10:36:30 +00:00
2004-06-25 14:16:03 +00:00
# ifndef _RTL_USTRBUF_HXX_
# include <rtl/ustrbuf.hxx>
# endif
2003-04-15 15:05:18 +00:00
# if OSL_DEBUG_LEVEL > 1
2002-02-06 10:36:30 +00:00
# include <stdio.h>
# endif
2002-02-21 13:56:14 +00:00
# include <string.h>
2002-02-06 10:36:30 +00:00
# include <list>
# include <algorithm>
# define DEFAULTFONT_CONFIGNODE "VCL / DefaultFonts"
# define SUBSTFONT_CONFIGNODE "VCL / FontSubstitutions"
2002-05-07 14:47:26 +00:00
# define SETTINGS_CONFIGNODE "VCL / Settings"
2002-02-06 10:36:30 +00:00
using namespace vcl ;
using namespace rtl ;
using namespace utl ;
using namespace com : : sun : : star : : uno ;
2004-06-25 14:16:03 +00:00
using namespace com : : sun : : star : : lang ;
2002-02-06 10:36:30 +00:00
using namespace com : : sun : : star : : beans ;
2006-05-04 14:11:41 +00:00
using namespace com : : sun : : star : : container ;
2002-02-06 10:36:30 +00:00
2006-05-04 14:11:41 +00:00
/*
* DefaultFontConfiguration
*/
2002-02-06 10:36:30 +00:00
2006-05-04 14:11:41 +00:00
static const char * getKeyType ( int nKeyType )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
switch ( nKeyType )
2002-02-06 10:36:30 +00:00
{
2006-06-19 18:22:47 +00:00
case DEFAULTFONT_CJK_DISPLAY : return " CJK_DISPLAY " ;
case DEFAULTFONT_CJK_HEADING : return " CJK_HEADING " ;
case DEFAULTFONT_CJK_PRESENTATION : return " CJK_PRESENTATION " ;
case DEFAULTFONT_CJK_SPREADSHEET : return " CJK_SPREADSHEET " ;
case DEFAULTFONT_CJK_TEXT : return " CJK_TEXT " ;
case DEFAULTFONT_CTL_DISPLAY : return " CTL_DISPLAY " ;
case DEFAULTFONT_CTL_HEADING : return " CTL_HEADING " ;
case DEFAULTFONT_CTL_PRESENTATION : return " CTL_PRESENTATION " ;
case DEFAULTFONT_CTL_SPREADSHEET : return " CTL_SPREADSHEET " ;
case DEFAULTFONT_CTL_TEXT : return " CTL_TEXT " ;
case DEFAULTFONT_FIXED : return " FIXED " ;
case DEFAULTFONT_LATIN_DISPLAY : return " LATIN_DISPLAY " ;
case DEFAULTFONT_LATIN_FIXED : return " LATIN_FIXED " ;
case DEFAULTFONT_LATIN_HEADING : return " LATIN_HEADING " ;
case DEFAULTFONT_LATIN_PRESENTATION : return " LATIN_PRESENTATION " ;
case DEFAULTFONT_LATIN_SPREADSHEET : return " LATIN_SPREADSHEET " ;
case DEFAULTFONT_LATIN_TEXT : return " LATIN_TEXT " ;
case DEFAULTFONT_SANS : return " SANS " ;
case DEFAULTFONT_SANS_UNICODE : return " SANS_UNICODE " ;
case DEFAULTFONT_SERIF : return " SERIF " ;
case DEFAULTFONT_SYMBOL : return " SYMBOL " ;
case DEFAULTFONT_UI_FIXED : return " UI_FIXED " ;
case DEFAULTFONT_UI_SANS : return " UI_SANS " ;
2006-05-04 14:11:41 +00:00
default :
DBG_ERROR ( " unmatched type " ) ;
return " " ;
2002-02-06 10:36:30 +00:00
}
}
2006-05-04 14:11:41 +00:00
DefaultFontConfiguration * DefaultFontConfiguration : : get ( )
2002-02-06 10:36:30 +00:00
{
ImplSVData * pSVData = ImplGetSVData ( ) ;
2006-05-04 14:11:41 +00:00
if ( ! pSVData - > maGDIData . mpDefaultFontConfiguration )
pSVData - > maGDIData . mpDefaultFontConfiguration = new DefaultFontConfiguration ( ) ;
return pSVData - > maGDIData . mpDefaultFontConfiguration ;
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
DefaultFontConfiguration : : DefaultFontConfiguration ( )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
try
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
// get service provider
Reference < XMultiServiceFactory > xSMgr ( unohelper : : GetMultiServiceFactory ( ) ) ;
// create configuration hierachical access name
if ( xSMgr . is ( ) )
2004-06-25 14:16:03 +00:00
{
2006-07-20 15:08:23 +00:00
try
2004-06-25 14:16:03 +00:00
{
2006-07-20 15:08:23 +00:00
m_xConfigProvider =
Reference < XMultiServiceFactory > (
xSMgr - > createInstance ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM (
" com.sun.star.configuration.ConfigurationProvider " ) ) ) ,
2006-05-04 14:11:41 +00:00
UNO_QUERY ) ;
2006-07-20 15:08:23 +00:00
if ( m_xConfigProvider . is ( ) )
2006-05-04 14:11:41 +00:00
{
2006-07-20 15:08:23 +00:00
Sequence < Any > aArgs ( 1 ) ;
PropertyValue aVal ;
aVal . Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( " nodepath " ) ) ;
aVal . Value < < = OUString ( RTL_CONSTASCII_USTRINGPARAM ( " /org.openoffice.VCL/DefaultFonts " ) ) ;
aArgs . getArray ( ) [ 0 ] < < = aVal ;
m_xConfigAccess =
Reference < XNameAccess > (
m_xConfigProvider - > createInstanceWithArguments ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM (
" com.sun.star.configuration.ConfigurationAccess " ) ) ,
aArgs ) ,
UNO_QUERY ) ;
if ( m_xConfigAccess . is ( ) )
2006-05-04 14:11:41 +00:00
{
2006-07-20 15:08:23 +00:00
Sequence < OUString > aLocales = m_xConfigAccess - > getElementNames ( ) ;
// fill config hash with empty interfaces
int nLocales = aLocales . getLength ( ) ;
const OUString * pLocaleStrings = aLocales . getConstArray ( ) ;
Locale aLoc ;
for ( int i = 0 ; i < nLocales ; i + + )
{
sal_Int32 nIndex = 0 ;
aLoc . Language = pLocaleStrings [ i ] . getToken ( 0 , sal_Unicode ( ' - ' ) , nIndex ) . toAsciiLowerCase ( ) ;
if ( nIndex ! = - 1 )
aLoc . Country = pLocaleStrings [ i ] . getToken ( 0 , sal_Unicode ( ' - ' ) , nIndex ) . toAsciiUpperCase ( ) ;
else
aLoc . Country = OUString ( ) ;
if ( nIndex ! = - 1 )
aLoc . Variant = pLocaleStrings [ i ] . getToken ( 0 , sal_Unicode ( ' - ' ) , nIndex ) . toAsciiUpperCase ( ) ;
else
aLoc . Variant = OUString ( ) ;
m_aConfig [ aLoc ] = LocaleAccess ( ) ;
m_aConfig [ aLoc ] . aConfigLocaleString = pLocaleStrings [ i ] ;
}
2006-05-04 14:11:41 +00:00
}
}
2004-06-25 14:16:03 +00:00
}
2006-07-20 15:08:23 +00:00
catch ( Exception & )
{
// configuration is awry
m_xConfigProvider . clear ( ) ;
m_xConfigAccess . clear ( ) ;
}
2004-06-25 14:16:03 +00:00
}
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
catch ( WrappedTargetException & )
{
}
# if OSL_DEBUG_LEVEL > 1
fprintf ( stderr , " config provider: %s, config access: %s \n " ,
m_xConfigProvider . is ( ) ? " true " : " false " ,
m_xConfigAccess . is ( ) ? " true " : " false "
) ;
# endif
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
DefaultFontConfiguration : : ~ DefaultFontConfiguration ( )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
// release all nodes
m_aConfig . clear ( ) ;
// release top node
m_xConfigAccess . clear ( ) ;
// release config provider
m_xConfigProvider . clear ( ) ;
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
OUString DefaultFontConfiguration : : tryLocale ( const Locale & rLocale , const OUString & rType ) const
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
OUString aRet ;
2002-02-06 10:36:30 +00:00
2006-05-04 14:11:41 +00:00
std : : hash_map < Locale , LocaleAccess , LocaleHash > : : const_iterator it =
m_aConfig . find ( rLocale ) ;
if ( it ! = m_aConfig . end ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
if ( ! it - > second . xAccess . is ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
try
{
Reference < XNameAccess > xNode ;
Any aAny = m_xConfigAccess - > getByName ( it - > second . aConfigLocaleString ) ;
if ( aAny > > = xNode )
it - > second . xAccess = xNode ;
}
catch ( NoSuchElementException )
{
}
catch ( WrappedTargetException )
{
}
2004-06-25 14:16:03 +00:00
}
2006-05-04 14:11:41 +00:00
if ( it - > second . xAccess . is ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
try
{
Any aAny = it - > second . xAccess - > getByName ( rType ) ;
aAny > > = aRet ;
}
catch ( NoSuchElementException & )
{
}
catch ( WrappedTargetException & )
2002-02-06 10:36:30 +00:00
{
}
}
}
2006-05-04 14:11:41 +00:00
return aRet ;
}
2002-02-06 10:36:30 +00:00
2006-05-04 14:11:41 +00:00
OUString DefaultFontConfiguration : : getDefaultFont ( const Locale & rLocale , int nType ) const
2002-02-06 10:36:30 +00:00
{
2004-06-25 14:16:03 +00:00
Locale aLocale ;
aLocale . Language = rLocale . Language . toAsciiLowerCase ( ) ;
2006-05-04 14:11:41 +00:00
aLocale . Country = rLocale . Country . toAsciiUpperCase ( ) ;
aLocale . Variant = rLocale . Variant . toAsciiUpperCase ( ) ;
OUString aType = OUString : : createFromAscii ( getKeyType ( nType ) ) ;
OUString aRet = tryLocale ( aLocale , aType ) ;
if ( ! aRet . getLength ( ) & & aLocale . Variant . getLength ( ) )
2002-02-06 10:36:30 +00:00
{
2004-06-25 14:16:03 +00:00
aLocale . Variant = OUString ( ) ;
2006-05-04 14:11:41 +00:00
aRet = tryLocale ( aLocale , aType ) ;
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
if ( ! aRet . getLength ( ) & & aLocale . Country . getLength ( ) )
{
aLocale . Country = OUString ( ) ;
aRet = tryLocale ( aLocale , aType ) ;
}
if ( ! aRet . getLength ( ) )
{
aLocale . Language = OUString ( RTL_CONSTASCII_USTRINGPARAM ( " en " ) ) ;
aRet = tryLocale ( aLocale , aType ) ;
}
return aRet ;
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
OUString DefaultFontConfiguration : : getUserInterfaceFont ( const Locale & rLocale ) const
2002-05-29 12:41:06 +00:00
{
2006-05-04 14:11:41 +00:00
Locale aLocale = rLocale ;
2004-06-25 14:16:03 +00:00
if ( ! aLocale . Language . getLength ( ) )
aLocale = Application : : GetSettings ( ) . GetUILocale ( ) ;
2006-05-04 14:11:41 +00:00
OUString aUIFont = getDefaultFont ( aLocale , DEFAULTFONT_UI_SANS ) ;
2002-05-29 12:41:06 +00:00
if ( aUIFont . getLength ( ) )
return aUIFont ;
2003-08-18 14:13:39 +00:00
// fallback mechanism (either no configuration or no entry in configuration
2006-08-14 15:32:57 +00:00
# define FALLBACKFONT_UI_SANS "Andale Sans UI;Albany;Albany AMT;Tahoma;Arial Unicode MS;Arial;Nimbus Sans L;Bitstream Vera Sans;gnu-unifont;Interface User;Geneva;WarpSans;Dialog;Swiss;Lucida;Helvetica;Charcoal;Chicago;MS Sans Serif;Helv;Times;Times New Roman;Interface System"
# define FALLBACKFONT_UI_SANS_LATIN2 "Andale Sans UI;Albany;Albany AMT;Tahoma;Arial Unicode MS;Arial;Nimbus Sans L;Luxi Sans;Bitstream Vera Sans;Interface User;Geneva;WarpSans;Dialog;Swiss;Lucida;Helvetica;Charcoal;Chicago;MS Sans Serif;Helv;Times;Times New Roman;Interface System"
2003-08-18 14:13:39 +00:00
# define FALLBACKFONT_UI_SANS_ARABIC "Tahoma;Traditional Arabic;Simplified Arabic;Lucidasans;Lucida Sans;Supplement;Andale Sans UI;clearlyU;Interface User;Arial Unicode MS;Lucida Sans Unicode;WarpSans;Geneva;MS Sans Serif;Helv;Dialog;Albany;Lucida;Helvetica;Charcoal;Chicago;Arial;Helmet;Interface System;Sans Serif"
# define FALLBACKFONT_UI_SANS_THAI "OONaksit;Tahoma;Lucidasans;Arial Unicode MS"
2004-02-20 07:51:00 +00:00
# define FALLBACKFONT_UI_SANS_KOREAN "SunGulim;BaekmukGulim;Gulim;Roundgothic;Arial Unicode MS;Lucida Sans Unicode;gnu-unifont;Andale Sans UI"
2004-07-23 11:18:25 +00:00
# define FALLBACKFONT_UI_SANS_JAPANESE1 "HG-GothicB-Sun;Andale Sans UI;HG MhinchoLightJ"
# define FALLBACKFONT_UI_SANS_JAPANESE2 "Kochi Gothic;Gothic"
2004-02-20 07:51:00 +00:00
# define FALLBACKFONT_UI_SANS_CHINSIM "Andale Sans UI;Arial Unicode MS;ZYSong18030;AR PL SungtiL GB;AR PL KaitiM GB;SimSun;Lucida Sans Unicode;Fangsong;Hei;Song;Kai;Ming;gnu-unifont;Interface User;"
# define FALLBACKFONT_UI_SANS_CHINTRD "Andale Sans UI;Arial Unicode MS;AR PL Mingti2L Big5;AR PL KaitiM Big5;Kai;PMingLiU;MingLiU;Ming;Lucida Sans Unicode;gnu-unifont;Interface User;"
2003-08-18 14:13:39 +00:00
// we need localized names for japanese fonts
static sal_Unicode const aMSGothic [ ] = { 0xFF2D , 0xFF33 , ' ' , 0x30B4 , 0x30B7 , 0x30C3 , 0x30AF , 0 , 0 } ;
2004-02-20 07:51:00 +00:00
static sal_Unicode const aMSPGothic [ ] = { 0xFF2D , 0xFF33 , ' ' , 0xFF30 , 0x30B4 , 0x30B7 , 0x30C3 , 0x30AF , 0 , 0 } ;
static sal_Unicode const aTLPGothic [ ] = { 0x0054 , 0x004C , 0x0050 , 0x30B4 , 0x30B7 , 0x30C3 , 0x30AF , 0 , 0 } ;
static sal_Unicode const aLXGothic [ ] = { 0x004C , 0x0058 , 0x30B4 , 0x30B7 , 0x30C3 , 0x30AF , 0 , 0 } ;
static sal_Unicode const aKochiGothic [ ] = { 0x6771 , 0x98A8 , 0x30B4 , 0x30B7 , 0x30C3 , 0x30AF , 0 , 0 } ;
String aFallBackJapaneseLocalized ( RTL_CONSTASCII_USTRINGPARAM ( " MS UI Gothic; " ) ) ;
aFallBackJapaneseLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS_JAPANESE1 ) ) ;
aFallBackJapaneseLocalized + = String ( aMSPGothic ) ;
aFallBackJapaneseLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( " ; " ) ) ;
aFallBackJapaneseLocalized + = String ( aMSGothic ) ;
aFallBackJapaneseLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( " ; " ) ) ;
aFallBackJapaneseLocalized + = String ( aTLPGothic ) ;
aFallBackJapaneseLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( " ; " ) ) ;
aFallBackJapaneseLocalized + = String ( aLXGothic ) ;
aFallBackJapaneseLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( " ; " ) ) ;
aFallBackJapaneseLocalized + = String ( aKochiGothic ) ;
aFallBackJapaneseLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( " ; " ) ) ;
aFallBackJapaneseLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS_JAPANESE2 ) ) ;
static const OUString aFallBackJapanese ( aFallBackJapaneseLocalized ) ;
static const OUString aFallback ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS ) ) ;
static const OUString aFallbackLatin2 ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS_LATIN2 ) ) ;
static const OUString aFallBackArabic ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS_ARABIC ) ) ;
static const OUString aFallBackThai ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS_THAI ) ) ;
static const OUString aFallBackChineseSIM ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS_CHINSIM ) ) ;
static const OUString aFallBackChineseTRD ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS_CHINTRD ) ) ;
// we need localized names for korean fonts
static sal_Unicode const aSunGulim [ ] = { 0xC36C , 0xAD74 , 0xB9BC , 0 } ;
static sal_Unicode const aBaekmukGulim [ ] = { 0xBC31 , 0xBC35 , 0xAD74 , 0xB9BC , 0 } ;
String aFallBackKoreanLocalized ( aSunGulim ) ;
aFallBackKoreanLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( " ; " ) ) ;
aFallBackKoreanLocalized + = String ( aBaekmukGulim ) ;
aFallBackKoreanLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( " ; " ) ) ;
aFallBackKoreanLocalized + = String ( RTL_CONSTASCII_USTRINGPARAM ( FALLBACKFONT_UI_SANS_KOREAN ) ) ;
static const OUString aFallBackKorean ( aFallBackKoreanLocalized ) ;
// optimize font list for some locales, as long as Andale Sans UI does not support them
2004-06-25 14:16:03 +00:00
if ( aLocale . Language . equalsAscii ( " ar " ) | |
aLocale . Language . equalsAscii ( " he " ) | |
aLocale . Language . equalsAscii ( " iw " ) )
{
return aFallBackArabic ;
}
else if ( aLocale . Language . equalsAscii ( " th " ) )
{
return aFallBackThai ;
}
else if ( aLocale . Language . equalsAscii ( " ko " ) )
{
return aFallBackKorean ;
}
else if ( aLocale . Language . equalsAscii ( " cs " ) | |
aLocale . Language . equalsAscii ( " hu " ) | |
aLocale . Language . equalsAscii ( " pl " ) | |
aLocale . Language . equalsAscii ( " ro " ) | |
aLocale . Language . equalsAscii ( " rm " ) | |
aLocale . Language . equalsAscii ( " hr " ) | |
aLocale . Language . equalsAscii ( " sk " ) | |
aLocale . Language . equalsAscii ( " sl " ) | |
aLocale . Language . equalsAscii ( " sb " ) )
{
return aFallbackLatin2 ;
}
else if ( aLocale . Language . equalsAscii ( " zh " ) )
2004-02-20 07:51:00 +00:00
{
2004-06-25 14:16:03 +00:00
if ( ! aLocale . Country . equalsAscii ( " cn " ) )
return aFallBackChineseTRD ;
else
2003-09-19 09:46:08 +00:00
return aFallBackChineseSIM ;
2004-06-25 14:16:03 +00:00
}
else if ( aLocale . Language . equalsAscii ( " ja " ) )
{
return aFallBackJapanese ;
}
2003-09-19 09:46:08 +00:00
return aFallback ;
2002-05-29 12:41:06 +00:00
}
2002-02-06 10:36:30 +00:00
// ------------------------------------------------------------------------------------
/*
* FontSubstConfigItem : : get
*/
2006-05-04 14:11:41 +00:00
FontSubstConfiguration * FontSubstConfiguration : : get ( )
2002-02-06 10:36:30 +00:00
{
ImplSVData * pSVData = ImplGetSVData ( ) ;
2006-05-04 14:11:41 +00:00
if ( ! pSVData - > maGDIData . mpFontSubstConfiguration )
pSVData - > maGDIData . mpFontSubstConfiguration = new FontSubstConfiguration ( ) ;
return pSVData - > maGDIData . mpFontSubstConfiguration ;
2002-02-06 10:36:30 +00:00
}
/*
* FontSubstConfigItem : : FontSubstConfigItem
*/
2006-10-13 07:31:07 +00:00
FontSubstConfiguration : : FontSubstConfiguration ( ) :
maSubstHash ( 300 )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
try
{
// get service provider
Reference < XMultiServiceFactory > xSMgr ( unohelper : : GetMultiServiceFactory ( ) ) ;
// create configuration hierachical access name
if ( xSMgr . is ( ) )
{
2006-07-20 15:08:23 +00:00
try
2006-05-04 14:11:41 +00:00
{
2006-07-20 15:08:23 +00:00
m_xConfigProvider =
Reference < XMultiServiceFactory > (
xSMgr - > createInstance ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM (
" com.sun.star.configuration.ConfigurationProvider " ) ) ) ,
2006-05-04 14:11:41 +00:00
UNO_QUERY ) ;
2006-07-20 15:08:23 +00:00
if ( m_xConfigProvider . is ( ) )
2006-05-04 14:11:41 +00:00
{
2006-07-20 15:08:23 +00:00
Sequence < Any > aArgs ( 1 ) ;
PropertyValue aVal ;
aVal . Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( " nodepath " ) ) ;
aVal . Value < < = OUString ( RTL_CONSTASCII_USTRINGPARAM ( " /org.openoffice.VCL/FontSubstitutions " ) ) ;
aArgs . getArray ( ) [ 0 ] < < = aVal ;
m_xConfigAccess =
Reference < XNameAccess > (
m_xConfigProvider - > createInstanceWithArguments ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM (
" com.sun.star.configuration.ConfigurationAccess " ) ) ,
aArgs ) ,
UNO_QUERY ) ;
if ( m_xConfigAccess . is ( ) )
2006-05-04 14:11:41 +00:00
{
2006-07-20 15:08:23 +00:00
Sequence < OUString > aLocales = m_xConfigAccess - > getElementNames ( ) ;
// fill config hash with empty interfaces
int nLocales = aLocales . getLength ( ) ;
const OUString * pLocaleStrings = aLocales . getConstArray ( ) ;
Locale aLoc ;
for ( int i = 0 ; i < nLocales ; i + + )
{
sal_Int32 nIndex = 0 ;
aLoc . Language = pLocaleStrings [ i ] . getToken ( 0 , sal_Unicode ( ' - ' ) , nIndex ) . toAsciiLowerCase ( ) ;
if ( nIndex ! = - 1 )
aLoc . Country = pLocaleStrings [ i ] . getToken ( 0 , sal_Unicode ( ' - ' ) , nIndex ) . toAsciiUpperCase ( ) ;
else
aLoc . Country = OUString ( ) ;
if ( nIndex ! = - 1 )
aLoc . Variant = pLocaleStrings [ i ] . getToken ( 0 , sal_Unicode ( ' - ' ) , nIndex ) . toAsciiUpperCase ( ) ;
else
aLoc . Variant = OUString ( ) ;
m_aSubst [ aLoc ] = LocaleSubst ( ) ;
m_aSubst [ aLoc ] . aConfigLocaleString = pLocaleStrings [ i ] ;
}
2006-05-04 14:11:41 +00:00
}
}
}
2006-07-20 15:08:23 +00:00
catch ( Exception & )
{
// configuration is awry
m_xConfigProvider . clear ( ) ;
m_xConfigAccess . clear ( ) ;
}
2006-05-04 14:11:41 +00:00
}
}
catch ( WrappedTargetException & )
{
}
# if OSL_DEBUG_LEVEL > 1
fprintf ( stderr , " config provider: %s, config access: %s \n " ,
m_xConfigProvider . is ( ) ? " true " : " false " ,
m_xConfigAccess . is ( ) ? " true " : " false "
) ;
# endif
2002-02-06 10:36:30 +00:00
}
/*
* FontSubstConfigItem : : ~ FontSubstConfigItem
*/
2006-05-04 14:11:41 +00:00
FontSubstConfiguration : : ~ FontSubstConfiguration ( )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
// release config access
m_xConfigAccess . clear ( ) ;
// release config provider
m_xConfigProvider . clear ( ) ;
2002-02-06 10:36:30 +00:00
}
/*
* FontSubstConfigItem : : getMapName
*/
// =======================================================================
static const char * const aImplKillLeadingList [ ] =
{
" microsoft " ,
" monotype " ,
" linotype " ,
2003-09-19 09:46:08 +00:00
" baekmuk " ,
2002-02-06 10:36:30 +00:00
" adobe " ,
" nimbus " ,
" zycjk " ,
" itc " ,
" sun " ,
" amt " ,
" ms " ,
" mt " ,
" cg " ,
" hg " ,
" fz " ,
2005-03-18 16:51:38 +00:00
" ipa " ,
" sazanami " ,
" kochi " ,
2002-02-06 10:36:30 +00:00
NULL
} ;
// -----------------------------------------------------------------------
static const char * const aImplKillTrailingList [ ] =
{
" microsoft " ,
" monotype " ,
" linotype " ,
" adobe " ,
" nimbus " ,
" itc " ,
" sun " ,
" amt " ,
" ms " ,
" mt " ,
2005-01-31 08:17:41 +00:00
" clm " ,
2002-02-06 10:36:30 +00:00
// Scripts, for compatibility with older versions
" we " ,
" cyr " ,
" tur " ,
" wt " ,
" greek " ,
" wl " ,
// CJK extensions
" gb " ,
" big5 " ,
" pro " ,
" z01 " ,
" z02 " ,
" z03 " ,
" z13 " ,
" b01 " ,
" w3x12 " ,
// Old Printer Fontnames
" 5cpi " ,
" 6cpi " ,
" 7cpi " ,
" 8cpi " ,
" 9cpi " ,
" 10cpi " ,
" 11cpi " ,
" 12cpi " ,
" 13cpi " ,
" 14cpi " ,
" 15cpi " ,
" 16cpi " ,
" 18cpi " ,
" 24cpi " ,
" scale " ,
" pc " ,
NULL
} ;
// -----------------------------------------------------------------------
static const char * const aImplKillTrailingWithExceptionsList [ ] =
{
2004-10-13 07:49:50 +00:00
" ce " , " monospace " , " oldface " , NULL ,
" ps " , " caps " , NULL ,
2002-02-06 10:36:30 +00:00
NULL
} ;
// -----------------------------------------------------------------------
struct ImplFontAttrWeightSearchData
{
const char * mpStr ;
FontWeight meWeight ;
} ;
static ImplFontAttrWeightSearchData const aImplWeightAttrSearchList [ ] =
{
2006-10-13 07:31:07 +00:00
// the attribute names are ordered by "first match wins"
// e.g. "semilight" should wins over "semi"
2002-02-06 10:36:30 +00:00
{ " extrablack " , WEIGHT_BLACK } ,
{ " ultrablack " , WEIGHT_BLACK } ,
{ " ultrabold " , WEIGHT_ULTRABOLD } ,
{ " semibold " , WEIGHT_SEMIBOLD } ,
2006-10-13 07:31:07 +00:00
{ " semilight " , WEIGHT_SEMILIGHT } ,
{ " semi " , WEIGHT_SEMIBOLD } ,
{ " demi " , WEIGHT_SEMIBOLD } ,
{ " black " , WEIGHT_BLACK } ,
2002-02-06 10:36:30 +00:00
{ " bold " , WEIGHT_BOLD } ,
2006-12-04 15:35:50 +00:00
{ " heavy " , WEIGHT_BLACK } ,
2002-02-06 10:36:30 +00:00
{ " ultralight " , WEIGHT_ULTRALIGHT } ,
{ " light " , WEIGHT_LIGHT } ,
{ " medium " , WEIGHT_MEDIUM } ,
{ NULL , WEIGHT_DONTKNOW } ,
} ;
// -----------------------------------------------------------------------
struct ImplFontAttrWidthSearchData
{
const char * mpStr ;
FontWidth meWidth ;
} ;
static ImplFontAttrWidthSearchData const aImplWidthAttrSearchList [ ] =
{
{ " narrow " , WIDTH_CONDENSED } ,
{ " semicondensed " , WIDTH_SEMI_CONDENSED } ,
{ " ultracondensed " , WIDTH_ULTRA_CONDENSED } ,
{ " semiexpanded " , WIDTH_SEMI_EXPANDED } ,
{ " ultraexpanded " , WIDTH_ULTRA_EXPANDED } ,
{ " expanded " , WIDTH_EXPANDED } ,
{ " wide " , WIDTH_ULTRA_EXPANDED } ,
{ " condensed " , WIDTH_CONDENSED } ,
{ " cond " , WIDTH_CONDENSED } ,
{ " cn " , WIDTH_CONDENSED } ,
{ NULL , WIDTH_DONTKNOW } ,
} ;
struct ImplFontAttrTypeSearchData
{
const char * mpStr ;
ULONG mnType ;
} ;
static ImplFontAttrTypeSearchData const aImplTypeAttrSearchList [ ] =
{
{ " monotype " , 0 } ,
{ " linotype " , 0 } ,
{ " titling " , IMPL_FONT_ATTR_TITLING } ,
{ " captitals " , IMPL_FONT_ATTR_CAPITALS } ,
{ " captital " , IMPL_FONT_ATTR_CAPITALS } ,
{ " caps " , IMPL_FONT_ATTR_CAPITALS } ,
{ " italic " , IMPL_FONT_ATTR_ITALIC } ,
{ " oblique " , IMPL_FONT_ATTR_ITALIC } ,
{ " rounded " , IMPL_FONT_ATTR_ROUNDED } ,
{ " outline " , IMPL_FONT_ATTR_OUTLINE } ,
{ " shadow " , IMPL_FONT_ATTR_SHADOW } ,
{ " handwriting " , IMPL_FONT_ATTR_HANDWRITING | IMPL_FONT_ATTR_SCRIPT } ,
{ " hand " , IMPL_FONT_ATTR_HANDWRITING | IMPL_FONT_ATTR_SCRIPT } ,
{ " signet " , IMPL_FONT_ATTR_HANDWRITING | IMPL_FONT_ATTR_SCRIPT } ,
{ " script " , IMPL_FONT_ATTR_BRUSHSCRIPT | IMPL_FONT_ATTR_SCRIPT } ,
{ " calligraphy " , IMPL_FONT_ATTR_CHANCERY | IMPL_FONT_ATTR_SCRIPT } ,
{ " chancery " , IMPL_FONT_ATTR_CHANCERY | IMPL_FONT_ATTR_SCRIPT } ,
{ " corsiva " , IMPL_FONT_ATTR_CHANCERY | IMPL_FONT_ATTR_SCRIPT } ,
{ " gothic " , IMPL_FONT_ATTR_SANSSERIF | IMPL_FONT_ATTR_GOTHIC } ,
{ " schoolbook " , IMPL_FONT_ATTR_SERIF | IMPL_FONT_ATTR_SCHOOLBOOK } ,
{ " schlbk " , IMPL_FONT_ATTR_SERIF | IMPL_FONT_ATTR_SCHOOLBOOK } ,
{ " typewriter " , IMPL_FONT_ATTR_TYPEWRITER | IMPL_FONT_ATTR_FIXED } ,
{ " lineprinter " , IMPL_FONT_ATTR_TYPEWRITER | IMPL_FONT_ATTR_FIXED } ,
{ " monospaced " , IMPL_FONT_ATTR_FIXED } ,
{ " monospace " , IMPL_FONT_ATTR_FIXED } ,
{ " mono " , IMPL_FONT_ATTR_FIXED } ,
{ " fixed " , IMPL_FONT_ATTR_FIXED } ,
{ " sansserif " , IMPL_FONT_ATTR_SANSSERIF } ,
{ " sans " , IMPL_FONT_ATTR_SANSSERIF } ,
{ " swiss " , IMPL_FONT_ATTR_SANSSERIF } ,
{ " serif " , IMPL_FONT_ATTR_SERIF } ,
{ " bright " , IMPL_FONT_ATTR_SERIF } ,
{ " symbols " , IMPL_FONT_ATTR_SYMBOL } ,
{ " symbol " , IMPL_FONT_ATTR_SYMBOL } ,
{ " dingbats " , IMPL_FONT_ATTR_SYMBOL } ,
{ " dings " , IMPL_FONT_ATTR_SYMBOL } ,
{ " ding " , IMPL_FONT_ATTR_SYMBOL } ,
{ " bats " , IMPL_FONT_ATTR_SYMBOL } ,
{ " math " , IMPL_FONT_ATTR_SYMBOL } ,
{ " oldstyle " , IMPL_FONT_ATTR_OTHERSTYLE } ,
{ " oldface " , IMPL_FONT_ATTR_OTHERSTYLE } ,
{ " old " , IMPL_FONT_ATTR_OTHERSTYLE } ,
{ " new " , 0 } ,
{ " modern " , 0 } ,
{ " lucida " , 0 } ,
{ " regular " , 0 } ,
{ " extended " , 0 } ,
{ " extra " , IMPL_FONT_ATTR_OTHERSTYLE } ,
{ " ext " , 0 } ,
{ " scalable " , 0 } ,
{ " scale " , 0 } ,
{ " nimbus " , 0 } ,
{ " adobe " , 0 } ,
{ " itc " , 0 } ,
{ " amt " , 0 } ,
{ " mt " , 0 } ,
{ " ms " , 0 } ,
{ " cpi " , 0 } ,
{ " no " , 0 } ,
{ NULL , 0 } ,
} ;
// -----------------------------------------------------------------------
2004-02-20 07:51:00 +00:00
static bool ImplKillLeading ( String & rName , const char * const * ppStr )
2002-02-06 10:36:30 +00:00
{
2004-02-20 07:51:00 +00:00
for ( ; * ppStr ; + + ppStr )
2002-02-06 10:36:30 +00:00
{
const char * pStr = * ppStr ;
const xub_Unicode * pNameStr = rName . GetBuffer ( ) ;
while ( ( * pNameStr = = ( xub_Unicode ) ( unsigned char ) * pStr ) & & * pStr )
{
pNameStr + + ;
pStr + + ;
}
if ( ! * pStr )
{
2006-06-19 18:22:47 +00:00
xub_StrLen nLen = sal : : static_int_cast < xub_StrLen > ( pNameStr - rName . GetBuffer ( ) ) ;
2004-02-20 07:51:00 +00:00
rName . Erase ( 0 , nLen ) ;
return true ;
2002-02-06 10:36:30 +00:00
}
}
2003-09-19 09:46:08 +00:00
// special case for Baekmuk
// TODO: allow non-ASCII KillLeading list
const xub_Unicode * pNameStr = rName . GetBuffer ( ) ;
2004-02-20 07:51:00 +00:00
if ( ( pNameStr [ 0 ] = = 0xBC31 ) & & ( pNameStr [ 1 ] = = 0xBC35 ) )
2003-09-19 09:46:08 +00:00
{
2004-02-20 07:51:00 +00:00
xub_StrLen nLen = ( pNameStr [ 2 ] = = 0x0020 ) ? 3 : 2 ;
rName . Erase ( 0 , nLen ) ;
return true ;
2003-09-19 09:46:08 +00:00
}
2004-02-20 07:51:00 +00:00
return false ;
2002-02-06 10:36:30 +00:00
}
// -----------------------------------------------------------------------
2004-10-13 07:49:50 +00:00
static xub_StrLen ImplIsTrailing ( const String & rName , const char * pStr )
2002-02-06 10:36:30 +00:00
{
2004-10-13 07:49:50 +00:00
xub_StrLen nStrLen = static_cast < xub_StrLen > ( strlen ( pStr ) ) ;
if ( nStrLen > = rName . Len ( ) )
return 0 ;
2002-02-06 10:36:30 +00:00
2004-10-13 07:49:50 +00:00
const xub_Unicode * pEndName = rName . GetBuffer ( ) + rName . Len ( ) ;
const sal_Unicode * pNameStr = pEndName - nStrLen ;
do if ( * ( pNameStr + + ) ! = * ( pStr + + ) )
2002-02-06 10:36:30 +00:00
return 0 ;
2004-10-13 07:49:50 +00:00
while ( * pStr ) ;
return nStrLen ;
2002-02-06 10:36:30 +00:00
}
// -----------------------------------------------------------------------
2004-10-13 07:49:50 +00:00
static bool ImplKillTrailing ( String & rName , const char * const * ppStr )
2002-02-06 10:36:30 +00:00
{
2004-10-13 07:49:50 +00:00
for ( ; * ppStr ; + + ppStr )
2002-02-06 10:36:30 +00:00
{
2004-10-13 07:49:50 +00:00
xub_StrLen nTrailLen = ImplIsTrailing ( rName , * ppStr ) ;
if ( nTrailLen )
2002-02-06 10:36:30 +00:00
{
rName . Erase ( rName . Len ( ) - nTrailLen ) ;
2004-10-13 07:49:50 +00:00
return true ;
2002-02-06 10:36:30 +00:00
}
}
2004-10-13 07:49:50 +00:00
return false ;
2002-02-06 10:36:30 +00:00
}
// -----------------------------------------------------------------------
2004-10-13 07:49:50 +00:00
static bool ImplKillTrailingWithExceptions ( String & rName , const char * const * ppStr )
2002-02-06 10:36:30 +00:00
{
2004-10-13 07:49:50 +00:00
for ( ; * ppStr ; + + ppStr )
2002-02-06 10:36:30 +00:00
{
2004-10-13 07:49:50 +00:00
xub_StrLen nTrailLen = ImplIsTrailing ( rName , * ppStr ) ;
if ( nTrailLen )
2002-02-06 10:36:30 +00:00
{
2004-10-13 07:49:50 +00:00
// check string match against string exceptions
while ( * + + ppStr )
if ( ImplIsTrailing ( rName , * ppStr ) )
return false ;
2002-02-06 10:36:30 +00:00
rName . Erase ( rName . Len ( ) - nTrailLen ) ;
2004-10-13 07:49:50 +00:00
return true ;
2002-02-06 10:36:30 +00:00
}
else
{
2004-10-13 07:49:50 +00:00
// skip exception strings
while ( * + + ppStr ) ;
2002-02-06 10:36:30 +00:00
}
}
2004-10-13 07:49:50 +00:00
return false ;
2002-02-06 10:36:30 +00:00
}
// -----------------------------------------------------------------------
static BOOL ImplFindAndErase ( String & rName , const char * pStr )
{
xub_StrLen nPos = rName . SearchAscii ( pStr ) ;
if ( nPos = = STRING_NOTFOUND )
return FALSE ;
const char * pTempStr = pStr ;
while ( * pTempStr )
pTempStr + + ;
rName . Erase ( nPos , ( xub_StrLen ) ( pTempStr - pStr ) ) ;
return TRUE ;
}
// =======================================================================
2006-05-04 14:11:41 +00:00
void FontSubstConfiguration : : getMapName ( const String & rOrgName , String & rShortName ,
2004-06-17 11:16:14 +00:00
String & rFamilyName , FontWeight & rWeight , FontWidth & rWidth , ULONG & rType )
2002-02-06 10:36:30 +00:00
{
rShortName = rOrgName ;
2004-08-30 15:20:50 +00:00
// TODO: get rid of the crazy O(N*strlen) searches below
// they should be possible in O(strlen)
2002-02-06 10:36:30 +00:00
// Kill leading vendor names and other unimportant data
ImplKillLeading ( rShortName , aImplKillLeadingList ) ;
// Kill trailing vendor names and other unimportant data
ImplKillTrailing ( rShortName , aImplKillTrailingList ) ;
ImplKillTrailingWithExceptions ( rShortName , aImplKillTrailingWithExceptionsList ) ;
rFamilyName = rShortName ;
// Kill attributes from the name and update the data
// Weight
const ImplFontAttrWeightSearchData * pWeightList = aImplWeightAttrSearchList ;
while ( pWeightList - > mpStr )
{
if ( ImplFindAndErase ( rFamilyName , pWeightList - > mpStr ) )
{
if ( ( rWeight = = WEIGHT_DONTKNOW ) | | ( rWeight = = WEIGHT_NORMAL ) )
rWeight = pWeightList - > meWeight ;
break ;
}
pWeightList + + ;
}
// Width
const ImplFontAttrWidthSearchData * pWidthList = aImplWidthAttrSearchList ;
while ( pWidthList - > mpStr )
{
if ( ImplFindAndErase ( rFamilyName , pWidthList - > mpStr ) )
{
if ( ( rWidth = = WIDTH_DONTKNOW ) | | ( rWidth = = WIDTH_NORMAL ) )
rWidth = pWidthList - > meWidth ;
break ;
}
pWidthList + + ;
}
// Type
rType = 0 ;
const ImplFontAttrTypeSearchData * pTypeList = aImplTypeAttrSearchList ;
while ( pTypeList - > mpStr )
{
if ( ImplFindAndErase ( rFamilyName , pTypeList - > mpStr ) )
rType | = pTypeList - > mnType ;
pTypeList + + ;
}
// Remove numbers
2004-08-30 15:20:50 +00:00
// TODO: also remove localized and fullwidth digits
2002-02-06 10:36:30 +00:00
xub_StrLen i = 0 ;
while ( i < rFamilyName . Len ( ) )
{
sal_Unicode c = rFamilyName . GetChar ( i ) ;
if ( ( c > = 0x0030 ) & & ( c < = 0x0039 ) )
rFamilyName . Erase ( i , 1 ) ;
else
i + + ;
}
}
2004-07-13 08:27:57 +00:00
struct StrictStringSort : public : : std : : binary_function < const FontNameAttr & , const FontNameAttr & , bool >
2002-02-06 10:36:30 +00:00
{
2004-07-13 08:27:57 +00:00
bool operator ( ) ( const FontNameAttr & rLeft , const FontNameAttr & rRight )
2002-02-06 10:36:30 +00:00
{ return rLeft . Name . CompareTo ( rRight . Name ) = = COMPARE_LESS ; }
} ;
static const char * const pAttribNames [ ] =
{
" default " ,
" standard " ,
" normal " ,
" symbol " ,
" fixed " ,
" sansserif " ,
" serif " ,
" decorative " ,
" special " ,
" italic " ,
" title " ,
" capitals " ,
" cjk " ,
" cjk_jp " ,
" cjk_sc " ,
" cjk_tc " ,
" cjk_kr " ,
" ctl " ,
" nonelatin " ,
" full " ,
" outline " ,
" shadow " ,
" rounded " ,
" typewriter " ,
" script " ,
" handwriting " ,
" chancery " ,
" comic " ,
" brushscript " ,
" gothic " ,
" schoolbook " ,
" other "
} ;
struct enum_convert
{
const char * pName ;
int nEnum ;
} ;
static const enum_convert pWeightNames [ ] =
{
{ " normal " , WEIGHT_NORMAL } ,
{ " medium " , WEIGHT_MEDIUM } ,
{ " bold " , WEIGHT_BOLD } ,
{ " black " , WEIGHT_BLACK } ,
{ " semibold " , WEIGHT_SEMIBOLD } ,
{ " light " , WEIGHT_LIGHT } ,
{ " semilight " , WEIGHT_SEMILIGHT } ,
{ " ultrabold " , WEIGHT_ULTRABOLD } ,
2006-10-13 07:31:07 +00:00
{ " semi " , WEIGHT_SEMIBOLD } ,
{ " demi " , WEIGHT_SEMIBOLD } ,
2006-12-04 15:35:50 +00:00
{ " heavy " , WEIGHT_BLACK } ,
2002-02-06 10:36:30 +00:00
{ " unknown " , WEIGHT_DONTKNOW } ,
{ " thin " , WEIGHT_THIN } ,
{ " ultralight " , WEIGHT_ULTRALIGHT }
} ;
static const enum_convert pWidthNames [ ] =
{
{ " normal " , WIDTH_NORMAL } ,
{ " condensed " , WIDTH_CONDENSED } ,
{ " expanded " , WIDTH_EXPANDED } ,
{ " unknown " , WIDTH_DONTKNOW } ,
{ " ultracondensed " , WIDTH_ULTRA_CONDENSED } ,
{ " extracondensed " , WIDTH_EXTRA_CONDENSED } ,
{ " semicondensed " , WIDTH_SEMI_CONDENSED } ,
{ " semiexpanded " , WIDTH_SEMI_EXPANDED } ,
{ " extraexpanded " , WIDTH_EXTRA_EXPANDED } ,
{ " ultraexpanded " , WIDTH_ULTRA_EXPANDED }
} ;
2006-05-04 14:11:41 +00:00
void FontSubstConfiguration : : fillSubstVector ( const com : : sun : : star : : uno : : Reference < XNameAccess > xFont ,
const rtl : : OUString & rType ,
std : : vector < String > & rSubstVector ) const
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
try
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
Any aAny = xFont - > getByName ( rType ) ;
if ( aAny . getValueTypeClass ( ) = = TypeClass_STRING )
2004-06-25 14:16:03 +00:00
{
2006-05-04 14:11:41 +00:00
const OUString * pLine = ( const OUString * ) aAny . getValue ( ) ;
sal_Int32 nIndex = 0 ;
if ( pLine - > getLength ( ) )
while ( nIndex ! = - 1 )
{
OUString aSubst ( pLine - > getToken ( 0 , ' ; ' , nIndex ) ) ;
if ( aSubst . getLength ( ) )
2006-10-13 07:31:07 +00:00
{
UniqueSubstHash : : iterator aEntry = maSubstHash . find ( aSubst ) ;
if ( aEntry ! = maSubstHash . end ( ) )
aSubst = * aEntry ;
else
maSubstHash . insert ( aSubst ) ;
2006-05-04 14:11:41 +00:00
rSubstVector . push_back ( aSubst ) ;
2006-10-13 07:31:07 +00:00
}
2006-05-04 14:11:41 +00:00
}
2004-06-25 14:16:03 +00:00
}
2006-05-04 14:11:41 +00:00
}
catch ( NoSuchElementException )
{
}
catch ( WrappedTargetException )
{
}
}
FontWeight FontSubstConfiguration : : getSubstWeight ( const com : : sun : : star : : uno : : Reference < XNameAccess > xFont ,
const rtl : : OUString & rType ) const
{
int weight = - 1 ;
try
{
Any aAny = xFont - > getByName ( rType ) ;
if ( aAny . getValueTypeClass ( ) = = TypeClass_STRING )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
const OUString * pLine = ( const OUString * ) aAny . getValue ( ) ;
if ( pLine - > getLength ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
for ( weight = sizeof ( pWeightNames ) / sizeof ( pWeightNames [ 0 ] ) - 1 ; weight > = 0 ; weight - - )
if ( pLine - > equalsIgnoreAsciiCaseAscii ( pWeightNames [ weight ] . pName ) )
break ;
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
# if OSL_DEBUG_LEVEL > 1
if ( weight < 0 )
fprintf ( stderr , " Error: invalid weight %s \n " ,
OUStringToOString ( * pLine , RTL_TEXTENCODING_ASCII_US ) . getStr ( ) ) ;
# endif
}
}
catch ( NoSuchElementException )
{
}
catch ( WrappedTargetException )
{
}
return ( FontWeight ) ( weight > = 0 ? pWeightNames [ weight ] . nEnum : WEIGHT_DONTKNOW ) ;
}
FontWidth FontSubstConfiguration : : getSubstWidth ( const com : : sun : : star : : uno : : Reference < XNameAccess > xFont ,
const rtl : : OUString & rType ) const
{
int width = - 1 ;
try
{
Any aAny = xFont - > getByName ( rType ) ;
if ( aAny . getValueTypeClass ( ) = = TypeClass_STRING )
{
const OUString * pLine = ( const OUString * ) aAny . getValue ( ) ;
if ( pLine - > getLength ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
for ( width = sizeof ( pWidthNames ) / sizeof ( pWidthNames [ 0 ] ) - 1 ; width > = 0 ; width - - )
if ( pLine - > equalsIgnoreAsciiCaseAscii ( pWidthNames [ width ] . pName ) )
break ;
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
# if OSL_DEBUG_LEVEL > 1
if ( width < 0 )
fprintf ( stderr , " Error: invalid width %s \n " ,
OUStringToOString ( * pLine , RTL_TEXTENCODING_ASCII_US ) . getStr ( ) ) ;
# endif
}
}
catch ( NoSuchElementException )
{
}
catch ( WrappedTargetException )
{
}
return ( FontWidth ) ( width > = 0 ? pWidthNames [ width ] . nEnum : WIDTH_DONTKNOW ) ;
}
unsigned long FontSubstConfiguration : : getSubstType ( const com : : sun : : star : : uno : : Reference < XNameAccess > xFont ,
const rtl : : OUString & rType ) const
{
unsigned long type = 0 ;
try
{
Any aAny = xFont - > getByName ( rType ) ;
if ( aAny . getValueTypeClass ( ) = = TypeClass_STRING )
{
const OUString * pLine = ( const OUString * ) aAny . getValue ( ) ;
if ( pLine - > getLength ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
sal_Int32 nIndex = 0 ;
while ( nIndex ! = - 1 )
{
String aToken ( pLine - > getToken ( 0 , ' , ' , nIndex ) ) ;
for ( int k = 0 ; k < 32 ; k + + )
if ( aToken . EqualsIgnoreCaseAscii ( pAttribNames [ k ] ) )
{
type | = 1 < < k ;
break ;
}
}
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
}
}
catch ( NoSuchElementException )
{
}
catch ( WrappedTargetException )
{
}
return type ;
}
void FontSubstConfiguration : : readLocaleSubst ( const com : : sun : : star : : lang : : Locale & rLocale ) const
{
std : : hash_map < Locale , LocaleSubst , LocaleHash > : : const_iterator it =
m_aSubst . find ( rLocale ) ;
if ( it ! = m_aSubst . end ( ) )
{
if ( ! it - > second . bConfigRead )
{
it - > second . bConfigRead = true ;
Reference < XNameAccess > xNode ;
try
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
Any aAny = m_xConfigAccess - > getByName ( it - > second . aConfigLocaleString ) ;
aAny > > = xNode ;
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
catch ( NoSuchElementException )
2002-02-06 10:36:30 +00:00
{
}
2006-05-04 14:11:41 +00:00
catch ( WrappedTargetException )
2002-02-06 10:36:30 +00:00
{
}
2006-05-04 14:11:41 +00:00
if ( xNode . is ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
Sequence < OUString > aFonts = xNode - > getElementNames ( ) ;
int nFonts = aFonts . getLength ( ) ;
const OUString * pFontNames = aFonts . getConstArray ( ) ;
// strings for subst retrieval, construct only once
OUString aSubstFontsStr ( RTL_CONSTASCII_USTRINGPARAM ( " SubstFonts " ) ) ;
OUString aSubstFontsMSStr ( RTL_CONSTASCII_USTRINGPARAM ( " SubstFontsMS " ) ) ;
OUString aSubstFontsPSStr ( RTL_CONSTASCII_USTRINGPARAM ( " SubstFontsPS " ) ) ;
OUString aSubstFontsHTMLStr ( RTL_CONSTASCII_USTRINGPARAM ( " SubstFontsHTML " ) ) ;
OUString aSubstWeightStr ( RTL_CONSTASCII_USTRINGPARAM ( " FontWeight " ) ) ;
OUString aSubstWidthStr ( RTL_CONSTASCII_USTRINGPARAM ( " FontWidth " ) ) ;
OUString aSubstTypeStr ( RTL_CONSTASCII_USTRINGPARAM ( " FontType " ) ) ;
for ( int i = 0 ; i < nFonts ; i + + )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
Reference < XNameAccess > xFont ;
try
{
Any aAny = xNode - > getByName ( pFontNames [ i ] ) ;
aAny > > = xFont ;
}
catch ( NoSuchElementException )
2002-02-06 10:36:30 +00:00
{
}
2006-05-04 14:11:41 +00:00
catch ( WrappedTargetException )
{
}
if ( ! xFont . is ( ) )
{
# if OSL_DEBUG_LEVEL > 1
fprintf ( stderr , " did not get font attributes for %s \n " ,
OUStringToOString ( pFontNames [ i ] , RTL_TEXTENCODING_UTF8 ) . getStr ( ) ) ;
# endif
continue ;
}
FontNameAttr aAttr ;
// read subst attributes from config
aAttr . Name = pFontNames [ i ] ;
fillSubstVector ( xFont , aSubstFontsStr , aAttr . Substitutions ) ;
fillSubstVector ( xFont , aSubstFontsMSStr , aAttr . MSSubstitutions ) ;
fillSubstVector ( xFont , aSubstFontsPSStr , aAttr . PSSubstitutions ) ;
fillSubstVector ( xFont , aSubstFontsHTMLStr , aAttr . HTMLSubstitutions ) ;
aAttr . Weight = getSubstWeight ( xFont , aSubstWeightStr ) ;
aAttr . Width = getSubstWidth ( xFont , aSubstWidthStr ) ;
aAttr . Type = getSubstType ( xFont , aSubstTypeStr ) ;
// finally insert this entry
it - > second . aSubstAttributes . push_back ( aAttr ) ;
2002-02-06 10:36:30 +00:00
}
2006-05-04 14:11:41 +00:00
std : : sort ( it - > second . aSubstAttributes . begin ( ) , it - > second . aSubstAttributes . end ( ) , StrictStringSort ( ) ) ;
2002-02-06 10:36:30 +00:00
}
}
}
}
2006-05-04 14:11:41 +00:00
const FontNameAttr * FontSubstConfiguration : : getSubstInfo ( const String & rFontName , const Locale & rLocale ) const
2002-02-06 10:36:30 +00:00
{
2003-06-30 13:29:06 +00:00
if ( ! rFontName . Len ( ) )
return NULL ;
2003-06-16 10:35:10 +00:00
// search if a (language dep.) replacement table for the given font exists
// fallback is english
2002-02-06 10:36:30 +00:00
String aSearchFont ( rFontName ) ;
aSearchFont . ToLowerAscii ( ) ;
FontNameAttr aSearchAttr ;
aSearchAttr . Name = aSearchFont ;
2004-06-25 14:16:03 +00:00
Locale aLocale ;
aLocale . Language = rLocale . Language . toAsciiLowerCase ( ) ;
2006-05-04 14:11:41 +00:00
aLocale . Country = rLocale . Country . toAsciiUpperCase ( ) ;
aLocale . Variant = rLocale . Variant . toAsciiUpperCase ( ) ;
2004-06-25 14:16:03 +00:00
if ( ! aLocale . Language . getLength ( ) )
aLocale = Application : : GetSettings ( ) . GetUILocale ( ) ;
while ( aLocale . Language . getLength ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
std : : hash_map < Locale , LocaleSubst , LocaleHash > : : const_iterator lang = m_aSubst . find ( aLocale ) ;
if ( lang ! = m_aSubst . end ( ) )
2002-02-06 10:36:30 +00:00
{
2006-05-04 14:11:41 +00:00
if ( ! lang - > second . bConfigRead )
readLocaleSubst ( aLocale ) ;
2003-06-30 13:29:06 +00:00
// try to find an exact match
// because the list is sorted this will also find fontnames of the form searchfontname*
2006-05-04 14:11:41 +00:00
std : : vector < FontNameAttr > : : const_iterator it = : : std : : lower_bound ( lang - > second . aSubstAttributes . begin ( ) , lang - > second . aSubstAttributes . end ( ) , aSearchAttr , StrictStringSort ( ) ) ;
if ( it ! = lang - > second . aSubstAttributes . end ( ) & & aSearchFont . CompareTo ( it - > Name , aSearchFont . Len ( ) ) = = COMPARE_EQUAL )
2002-02-06 10:36:30 +00:00
return & ( * it ) ;
}
2004-06-25 14:16:03 +00:00
// gradually become more unspecific
if ( aLocale . Variant . getLength ( ) )
aLocale . Variant = OUString ( ) ;
else if ( aLocale . Country . getLength ( ) )
aLocale . Country = OUString ( ) ;
else if ( ! aLocale . Language . equalsAscii ( " en " ) )
aLocale . Language = OUString ( RTL_CONSTASCII_USTRINGPARAM ( " en " ) ) ;
else
aLocale . Language = OUString ( ) ;
2002-02-06 10:36:30 +00:00
}
return NULL ;
}
2002-05-07 14:47:26 +00:00
/*
* SettingsConfigItem : : get
*/
SettingsConfigItem * SettingsConfigItem : : get ( )
{
ImplSVData * pSVData = ImplGetSVData ( ) ;
if ( ! pSVData - > mpSettingsConfigItem )
pSVData - > mpSettingsConfigItem = new SettingsConfigItem ( ) ;
return pSVData - > mpSettingsConfigItem ;
}
/*
* SettignsConfigItem constructor
*/
SettingsConfigItem : : SettingsConfigItem ( )
:
ConfigItem ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( SETTINGS_CONFIGNODE ) ) ,
2006-10-13 07:31:07 +00:00
CONFIG_MODE_DELAYED_UPDATE ) ,
m_aSettings ( 0 )
2002-05-07 14:47:26 +00:00
{
getValues ( ) ;
}
/*
* SettingsConfigItem destructor
*/
SettingsConfigItem : : ~ SettingsConfigItem ( )
{
if ( IsModified ( ) )
Commit ( ) ;
}
/*
* SettingsConfigItem : : Commit
*/
void SettingsConfigItem : : Commit ( )
{
2002-08-29 06:55:13 +00:00
if ( ! IsValidConfigMgr ( ) )
return ;
2006-10-13 07:31:07 +00:00
std : : hash_map < OUString , SmallOUStrMap , rtl : : OUStringHash > : : const_iterator group ;
2002-05-07 14:47:26 +00:00
for ( group = m_aSettings . begin ( ) ; group ! = m_aSettings . end ( ) ; + + group )
{
String aKeyName ( group - > first ) ;
2006-06-19 18:22:47 +00:00
/*sal_Bool bAdded =*/ AddNode ( OUString ( ) , aKeyName ) ;
2002-05-07 14:47:26 +00:00
Sequence < PropertyValue > aValues ( group - > second . size ( ) ) ;
PropertyValue * pValues = aValues . getArray ( ) ;
int nIndex = 0 ;
2006-10-13 07:31:07 +00:00
SmallOUStrMap : : const_iterator it ;
2002-05-07 14:47:26 +00:00
for ( it = group - > second . begin ( ) ; it ! = group - > second . end ( ) ; + + it )
{
String aName ( aKeyName ) ;
aName . Append ( ' / ' ) ;
aName . Append ( String ( it - > first ) ) ;
pValues [ nIndex ] . Name = aName ;
pValues [ nIndex ] . Handle = 0 ;
pValues [ nIndex ] . Value < < = it - > second ;
pValues [ nIndex ] . State = PropertyState_DIRECT_VALUE ;
nIndex + + ;
}
ReplaceSetProperties ( aKeyName , aValues ) ;
}
}
/*
* SettingsConfigItem : : Notify
*/
2006-06-19 18:22:47 +00:00
void SettingsConfigItem : : Notify ( const Sequence < OUString > & )
2002-05-07 14:47:26 +00:00
{
getValues ( ) ;
}
/*
* SettingsConfigItem : : getValues
*/
void SettingsConfigItem : : getValues ( )
{
2002-08-29 06:55:13 +00:00
if ( ! IsValidConfigMgr ( ) )
return ;
2002-05-07 14:47:26 +00:00
m_aSettings . clear ( ) ;
Sequence < OUString > aNames ( GetNodeNames ( OUString ( ) ) ) ;
2006-10-13 07:31:07 +00:00
m_aSettings . resize ( aNames . getLength ( ) ) ;
for ( int j = 0 ; j < aNames . getLength ( ) ; j + + )
2002-05-07 14:47:26 +00:00
{
2004-05-10 14:48:23 +00:00
# if OSL_DEBUG_LEVEL > 2
2002-05-07 14:47:26 +00:00
fprintf ( stderr , " found settings data for \" %s \" \n " ,
OUStringToOString ( aNames . getConstArray ( ) [ j ] , RTL_TEXTENCODING_ASCII_US ) . getStr ( )
) ;
# endif
String aKeyName ( aNames . getConstArray ( ) [ j ] ) ;
Sequence < OUString > aKeys ( GetNodeNames ( aKeyName ) ) ;
Sequence < OUString > aSettingsKeys ( aKeys . getLength ( ) ) ;
const OUString * pFrom = aKeys . getConstArray ( ) ;
OUString * pTo = aSettingsKeys . getArray ( ) ;
for ( int m = 0 ; m < aKeys . getLength ( ) ; m + + )
{
String aName ( aKeyName ) ;
aName . Append ( ' / ' ) ;
aName . Append ( String ( pFrom [ m ] ) ) ;
pTo [ m ] = aName ;
}
Sequence < Any > aValues ( GetProperties ( aSettingsKeys ) ) ;
const Any * pValue = aValues . getConstArray ( ) ;
2006-10-13 07:31:07 +00:00
for ( int i = 0 ; i < aValues . getLength ( ) ; i + + , pValue + + )
2002-05-07 14:47:26 +00:00
{
if ( pValue - > getValueTypeClass ( ) = = TypeClass_STRING )
{
const OUString * pLine = ( const OUString * ) pValue - > getValue ( ) ;
if ( pLine - > getLength ( ) )
m_aSettings [ aKeyName ] [ pFrom [ i ] ] = * pLine ;
2004-05-10 14:48:23 +00:00
# if OSL_DEBUG_LEVEL > 2
2002-05-07 14:47:26 +00:00
fprintf ( stderr , " \" %s \" = \" %.30s \" \n " ,
OUStringToOString ( aKeys . getConstArray ( ) [ i ] , RTL_TEXTENCODING_ASCII_US ) . getStr ( ) ,
OUStringToOString ( * pLine , RTL_TEXTENCODING_ASCII_US ) . getStr ( )
) ;
# endif
}
}
}
}
/*
* SettingsConfigItem : : getDefaultFont
*/
const OUString & SettingsConfigItem : : getValue ( const OUString & rGroup , const OUString & rKey ) const
{
2006-10-13 07:31:07 +00:00
: : std : : hash_map < OUString , SmallOUStrMap , rtl : : OUStringHash > : : const_iterator group = m_aSettings . find ( rGroup ) ;
2002-05-07 14:47:26 +00:00
if ( group = = m_aSettings . end ( ) | | group - > second . find ( rKey ) = = group - > second . end ( ) )
{
static OUString aEmpty ;
return aEmpty ;
}
return group - > second . find ( rKey ) - > second ;
}
/*
* SettingsConfigItem : : setDefaultFont
*/
void SettingsConfigItem : : setValue ( const OUString & rGroup , const OUString & rKey , const OUString & rValue )
{
bool bModified = m_aSettings [ rGroup ] [ rKey ] ! = rValue ;
if ( bModified )
{
m_aSettings [ rGroup ] [ rKey ] = rValue ;
SetModified ( ) ;
}
}