1*bae3752eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*bae3752eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*bae3752eSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*bae3752eSAndrew Rist * distributed with this work for additional information
6*bae3752eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*bae3752eSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*bae3752eSAndrew Rist * "License"); you may not use this file except in compliance
9*bae3752eSAndrew Rist * with the License. You may obtain a copy of the License at
10*bae3752eSAndrew Rist *
11*bae3752eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*bae3752eSAndrew Rist *
13*bae3752eSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*bae3752eSAndrew Rist * software distributed under the License is distributed on an
15*bae3752eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*bae3752eSAndrew Rist * KIND, either express or implied. See the License for the
17*bae3752eSAndrew Rist * specific language governing permissions and limitations
18*bae3752eSAndrew Rist * under the License.
19*bae3752eSAndrew Rist *
20*bae3752eSAndrew Rist *************************************************************/
21*bae3752eSAndrew Rist
22*bae3752eSAndrew Rist
23cdf0e10cSrcweir #ifndef _UNOTOOLS_FONTCFG_HXX
24cdf0e10cSrcweir #define _UNOTOOLS_FONTCFG_HXX
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <unotools/unotoolsdllapi.h>
27cdf0e10cSrcweir #include <tools/string.hxx>
28cdf0e10cSrcweir #include <tools/fontenum.hxx>
29cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <hash_map>
34cdf0e10cSrcweir #include <hash_set>
35cdf0e10cSrcweir #include <vector>
36cdf0e10cSrcweir
37cdf0e10cSrcweir namespace com {
38cdf0e10cSrcweir namespace sun {
39cdf0e10cSrcweir namespace star {
40cdf0e10cSrcweir namespace lang {
41cdf0e10cSrcweir
42cdf0e10cSrcweir // equality operator needed for hash_map;
43cdf0e10cSrcweir // (-> why does this need to be in the namespace of Locale ? g++ fails to compile else)
operator ==(const com::sun::star::lang::Locale & rLeft,const com::sun::star::lang::Locale & rRight)44cdf0e10cSrcweir inline bool operator==( const com::sun::star::lang::Locale& rLeft, const com::sun::star::lang::Locale& rRight )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir return
47cdf0e10cSrcweir rLeft.Language.equals( rRight.Language ) &&
48cdf0e10cSrcweir rLeft.Country.equals( rRight.Country ) &&
49cdf0e10cSrcweir rLeft.Variant.equals( rRight.Variant )
50cdf0e10cSrcweir ;
51cdf0e10cSrcweir }
52cdf0e10cSrcweir }}}}
53cdf0e10cSrcweir
54cdf0e10cSrcweir namespace utl
55cdf0e10cSrcweir {
56cdf0e10cSrcweir
57cdf0e10cSrcweir struct LocaleHash
58cdf0e10cSrcweir {
operator ()utl::LocaleHash59cdf0e10cSrcweir size_t operator()( const com::sun::star::lang::Locale& rLocale ) const
60cdf0e10cSrcweir {
61cdf0e10cSrcweir return
62cdf0e10cSrcweir (size_t)rLocale.Language.hashCode() ^
63cdf0e10cSrcweir (size_t)rLocale.Country.hashCode() ^
64cdf0e10cSrcweir (size_t)rLocale.Variant.hashCode();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir };
67cdf0e10cSrcweir
68cdf0e10cSrcweir class UNOTOOLS_DLLPUBLIC DefaultFontConfiguration
69cdf0e10cSrcweir {
70cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
71cdf0e10cSrcweir m_xConfigProvider;
72cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
73cdf0e10cSrcweir m_xConfigAccess;
74cdf0e10cSrcweir
75cdf0e10cSrcweir struct LocaleAccess
76cdf0e10cSrcweir {
77cdf0e10cSrcweir // the real string used in the configuration
78cdf0e10cSrcweir // used to get rid of upper/lower case problems
79cdf0e10cSrcweir rtl::OUString aConfigLocaleString;
80cdf0e10cSrcweir // xAccess is mutable to be able to be filled on demand
81cdf0e10cSrcweir mutable com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xAccess;
82cdf0e10cSrcweir };
83cdf0e10cSrcweir
84cdf0e10cSrcweir std::hash_map< com::sun::star::lang::Locale,
85cdf0e10cSrcweir LocaleAccess,
86cdf0e10cSrcweir utl::LocaleHash >
87cdf0e10cSrcweir m_aConfig;
88cdf0e10cSrcweir
89cdf0e10cSrcweir rtl::OUString tryLocale( const com::sun::star::lang::Locale& rLocale, const rtl::OUString& rType ) const;
90cdf0e10cSrcweir
91cdf0e10cSrcweir DefaultFontConfiguration();
92cdf0e10cSrcweir public:
93cdf0e10cSrcweir ~DefaultFontConfiguration();
94cdf0e10cSrcweir
95cdf0e10cSrcweir static DefaultFontConfiguration* get();
96cdf0e10cSrcweir
97cdf0e10cSrcweir rtl::OUString getDefaultFont( const com::sun::star::lang::Locale& rLocale, int nType ) const;
98cdf0e10cSrcweir rtl::OUString getUserInterfaceFont( const com::sun::star::lang::Locale& rLocale ) const;
99cdf0e10cSrcweir };
100cdf0e10cSrcweir
101cdf0e10cSrcweir // IMPL_FONT_ATTR_DEFAULT - Default-Font like Andale Sans UI, Palace Script, Albany, Thorndale, Cumberland, ...
102cdf0e10cSrcweir // IMPL_FONT_ATTR_STANDARD - Standard-Font like Arial, Times, Courier, ...
103cdf0e10cSrcweir // IMPL_FONT_ATTR_NORMAL - normal Font for writing text like Arial, Verdana, Arial Narrow, Trebuchet, Times, Courier, ...
104cdf0e10cSrcweir // IMPL_FONT_ATTR_SYMBOL - Font with symbols
105cdf0e10cSrcweir // IMPL_FONT_ATTR_DECORATIVE - Readable and normally used for drawings
106cdf0e10cSrcweir // IMPL_FONT_ATTR_SPECIAL - very special design
107cdf0e10cSrcweir // IMPL_FONT_ATTR_TITLING - only uppercase characters
108cdf0e10cSrcweir // IMPL_FONT_ATTR_FULL - Font with normally all characters
109cdf0e10cSrcweir // IMPL_FONT_ATTR_CAPITALS - only uppercase characters, but lowercase characters smaller as the uppercase characters
110cdf0e10cSrcweir // IMPL_FONT_ATTR_TYPEWRITER - like a typewriter: Courier, ...
111cdf0e10cSrcweir // IMPL_FONT_ATTR_SCRIPT - Handwriting or Script
112cdf0e10cSrcweir // IMPL_FONT_ATTR_HANDWRITING - More Handwriting with normal letters
113cdf0e10cSrcweir // IMPL_FONT_ATTR_CHANCERY - Like Zapf Chancery
114cdf0e10cSrcweir // IMPL_FONT_ATTR_COMIC - Like Comic Sans MS
115cdf0e10cSrcweir // IMPL_FONT_ATTR_BRUSHSCRIPT - More Script
116cdf0e10cSrcweir // IMPL_FONT_ATTR_OTHERSTYLE - OldStyle, ... so negativ points
117cdf0e10cSrcweir #define IMPL_FONT_ATTR_DEFAULT ((sal_uLong)0x00000001)
118cdf0e10cSrcweir #define IMPL_FONT_ATTR_STANDARD ((sal_uLong)0x00000002)
119cdf0e10cSrcweir #define IMPL_FONT_ATTR_NORMAL ((sal_uLong)0x00000004)
120cdf0e10cSrcweir #define IMPL_FONT_ATTR_SYMBOL ((sal_uLong)0x00000008)
121cdf0e10cSrcweir #define IMPL_FONT_ATTR_FIXED ((sal_uLong)0x00000010)
122cdf0e10cSrcweir #define IMPL_FONT_ATTR_SANSSERIF ((sal_uLong)0x00000020)
123cdf0e10cSrcweir #define IMPL_FONT_ATTR_SERIF ((sal_uLong)0x00000040)
124cdf0e10cSrcweir #define IMPL_FONT_ATTR_DECORATIVE ((sal_uLong)0x00000080)
125cdf0e10cSrcweir #define IMPL_FONT_ATTR_SPECIAL ((sal_uLong)0x00000100)
126cdf0e10cSrcweir #define IMPL_FONT_ATTR_ITALIC ((sal_uLong)0x00000200)
127cdf0e10cSrcweir #define IMPL_FONT_ATTR_TITLING ((sal_uLong)0x00000400)
128cdf0e10cSrcweir #define IMPL_FONT_ATTR_CAPITALS ((sal_uLong)0x00000800)
129cdf0e10cSrcweir #define IMPL_FONT_ATTR_CJK ((sal_uLong)0x00001000)
130cdf0e10cSrcweir #define IMPL_FONT_ATTR_CJK_JP ((sal_uLong)0x00002000)
131cdf0e10cSrcweir #define IMPL_FONT_ATTR_CJK_SC ((sal_uLong)0x00004000)
132cdf0e10cSrcweir #define IMPL_FONT_ATTR_CJK_TC ((sal_uLong)0x00008000)
133cdf0e10cSrcweir #define IMPL_FONT_ATTR_CJK_KR ((sal_uLong)0x00010000)
134cdf0e10cSrcweir #define IMPL_FONT_ATTR_CTL ((sal_uLong)0x00020000)
135cdf0e10cSrcweir #define IMPL_FONT_ATTR_NONELATIN ((sal_uLong)0x00040000)
136cdf0e10cSrcweir #define IMPL_FONT_ATTR_FULL ((sal_uLong)0x00080000)
137cdf0e10cSrcweir #define IMPL_FONT_ATTR_OUTLINE ((sal_uLong)0x00100000)
138cdf0e10cSrcweir #define IMPL_FONT_ATTR_SHADOW ((sal_uLong)0x00200000)
139cdf0e10cSrcweir #define IMPL_FONT_ATTR_ROUNDED ((sal_uLong)0x00400000)
140cdf0e10cSrcweir #define IMPL_FONT_ATTR_TYPEWRITER ((sal_uLong)0x00800000)
141cdf0e10cSrcweir #define IMPL_FONT_ATTR_SCRIPT ((sal_uLong)0x01000000)
142cdf0e10cSrcweir #define IMPL_FONT_ATTR_HANDWRITING ((sal_uLong)0x02000000)
143cdf0e10cSrcweir #define IMPL_FONT_ATTR_CHANCERY ((sal_uLong)0x04000000)
144cdf0e10cSrcweir #define IMPL_FONT_ATTR_COMIC ((sal_uLong)0x08000000)
145cdf0e10cSrcweir #define IMPL_FONT_ATTR_BRUSHSCRIPT ((sal_uLong)0x10000000)
146cdf0e10cSrcweir #define IMPL_FONT_ATTR_GOTHIC ((sal_uLong)0x20000000)
147cdf0e10cSrcweir #define IMPL_FONT_ATTR_SCHOOLBOOK ((sal_uLong)0x40000000)
148cdf0e10cSrcweir #define IMPL_FONT_ATTR_OTHERSTYLE ((sal_uLong)0x80000000)
149cdf0e10cSrcweir
150cdf0e10cSrcweir #define IMPL_FONT_ATTR_CJK_ALLLANG (IMPL_FONT_ATTR_CJK_JP | IMPL_FONT_ATTR_CJK_SC | IMPL_FONT_ATTR_CJK_TC | IMPL_FONT_ATTR_CJK_KR)
151cdf0e10cSrcweir #define IMPL_FONT_ATTR_ALLSCRIPT (IMPL_FONT_ATTR_SCRIPT | IMPL_FONT_ATTR_HANDWRITING | IMPL_FONT_ATTR_CHANCERY | IMPL_FONT_ATTR_COMIC | IMPL_FONT_ATTR_BRUSHSCRIPT)
152cdf0e10cSrcweir #define IMPL_FONT_ATTR_ALLSUBSCRIPT (IMPL_FONT_ATTR_HANDWRITING | IMPL_FONT_ATTR_CHANCERY | IMPL_FONT_ATTR_COMIC | IMPL_FONT_ATTR_BRUSHSCRIPT)
153cdf0e10cSrcweir #define IMPL_FONT_ATTR_ALLSERIFSTYLE (IMPL_FONT_ATTR_ALLSCRIPT |\
154cdf0e10cSrcweir IMPL_FONT_ATTR_SANSSERIF | IMPL_FONT_ATTR_SERIF |\
155cdf0e10cSrcweir IMPL_FONT_ATTR_FIXED | IMPL_FONT_ATTR_ITALIC |\
156cdf0e10cSrcweir IMPL_FONT_ATTR_GOTHIC | IMPL_FONT_ATTR_SCHOOLBOOK |\
157cdf0e10cSrcweir IMPL_FONT_ATTR_SHADOW | IMPL_FONT_ATTR_OUTLINE)
158cdf0e10cSrcweir
159cdf0e10cSrcweir struct UNOTOOLS_DLLPUBLIC FontNameAttr
160cdf0e10cSrcweir {
161cdf0e10cSrcweir String Name;
162cdf0e10cSrcweir ::std::vector< String > Substitutions;
163cdf0e10cSrcweir ::std::vector< String > MSSubstitutions;
164cdf0e10cSrcweir ::std::vector< String > PSSubstitutions;
165cdf0e10cSrcweir ::std::vector< String > HTMLSubstitutions;
166cdf0e10cSrcweir FontWeight Weight;
167cdf0e10cSrcweir FontWidth Width;
168cdf0e10cSrcweir unsigned long Type; // bitfield of IMPL_FONT_ATTR_*
169cdf0e10cSrcweir };
170cdf0e10cSrcweir
171cdf0e10cSrcweir class UNOTOOLS_DLLPUBLIC FontSubstConfiguration
172cdf0e10cSrcweir {
173cdf0e10cSrcweir private:
174cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
175cdf0e10cSrcweir m_xConfigProvider;
176cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
177cdf0e10cSrcweir m_xConfigAccess;
178cdf0e10cSrcweir struct LocaleSubst
179cdf0e10cSrcweir {
180cdf0e10cSrcweir rtl::OUString aConfigLocaleString;
181cdf0e10cSrcweir mutable bool bConfigRead;
182cdf0e10cSrcweir // note: aSubstAttributes must be sorted alphabetically by Name
183cdf0e10cSrcweir // searches on the substitutes are done with Name as key, where
184cdf0e10cSrcweir // a minimal match is sufficient (that is e.g. "Thorndale" will match
185cdf0e10cSrcweir // "Thorndale BlaBlub"). Also names must be lower case.
186cdf0e10cSrcweir mutable std::vector< FontNameAttr > aSubstAttributes;
187cdf0e10cSrcweir
LocaleSubstutl::FontSubstConfiguration::LocaleSubst188cdf0e10cSrcweir LocaleSubst() : bConfigRead( false ) {}
189cdf0e10cSrcweir };
190cdf0e10cSrcweir std::hash_map< com::sun::star::lang::Locale, LocaleSubst, utl::LocaleHash > m_aSubst;
191cdf0e10cSrcweir typedef std::hash_set< rtl::OUString, rtl::OUStringHash > UniqueSubstHash;
192cdf0e10cSrcweir mutable UniqueSubstHash maSubstHash;
193cdf0e10cSrcweir
194cdf0e10cSrcweir
195cdf0e10cSrcweir void fillSubstVector( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
196cdf0e10cSrcweir const rtl::OUString& rType,
197cdf0e10cSrcweir std::vector< String >& rSubstVector ) const;
198cdf0e10cSrcweir FontWeight getSubstWeight( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
199cdf0e10cSrcweir const rtl::OUString& rType ) const;
200cdf0e10cSrcweir FontWidth getSubstWidth( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
201cdf0e10cSrcweir const rtl::OUString& rType ) const;
202cdf0e10cSrcweir unsigned long getSubstType( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
203cdf0e10cSrcweir const rtl::OUString& rType ) const;
204cdf0e10cSrcweir void readLocaleSubst( const com::sun::star::lang::Locale& rLocale ) const;
205cdf0e10cSrcweir FontSubstConfiguration();
206cdf0e10cSrcweir public:
207cdf0e10cSrcweir ~FontSubstConfiguration();
208cdf0e10cSrcweir
209cdf0e10cSrcweir static FontSubstConfiguration* get();
210cdf0e10cSrcweir
211cdf0e10cSrcweir const FontNameAttr* getSubstInfo(
212cdf0e10cSrcweir const String& rFontName,
213cdf0e10cSrcweir const com::sun::star::lang::Locale& rLocale =
214cdf0e10cSrcweir com::sun::star::lang::Locale( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "en" ) ),
215cdf0e10cSrcweir rtl::OUString(),
216cdf0e10cSrcweir rtl::OUString() )
217cdf0e10cSrcweir ) const;
218cdf0e10cSrcweir static void getMapName( const String& rOrgName, String& rShortName, String& rFamilyName, FontWeight& rWeight, FontWidth& rWidth, sal_uLong& rType );
219cdf0e10cSrcweir };
220cdf0e10cSrcweir
221cdf0e10cSrcweir } // namespace utl
222cdf0e10cSrcweir
223cdf0e10cSrcweir #endif // _UNOTOOLS_FONTCFG_HXX
224