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