update credits
[LibreOffice.git] / include / unotools / fontcfg.hxx
blob23ea55140655d73029d1745e5f02551c2e9ceaf8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _UNOTOOLS_FONTCFG_HXX
20 #define _UNOTOOLS_FONTCFG_HXX
22 #include <unotools/unotoolsdllapi.h>
23 #include <tools/string.hxx>
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>
29 #include <boost/unordered_map.hpp>
30 #include <boost/unordered_set.hpp>
31 #include <vector>
33 namespace com {
34 namespace sun {
35 namespace star {
36 namespace lang {
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 inline bool operator==( const com::sun::star::lang::Locale& rLeft, const com::sun::star::lang::Locale& rRight )
42 return
43 rLeft.Language.equals( rRight.Language ) &&
44 rLeft.Country.equals( rRight.Country ) &&
45 rLeft.Variant.equals( rRight.Variant )
48 }}}}
50 namespace utl
53 struct LocaleHash
55 size_t operator()( const com::sun::star::lang::Locale& rLocale ) const
57 return
58 (size_t)rLocale.Language.hashCode() ^
59 (size_t)rLocale.Country.hashCode() ^
60 (size_t)rLocale.Variant.hashCode();
64 class UNOTOOLS_DLLPUBLIC DefaultFontConfiguration
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;
71 struct LocaleAccess
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;
80 boost::unordered_map< com::sun::star::lang::Locale,
81 LocaleAccess,
82 utl::LocaleHash >
83 m_aConfig;
85 OUString tryLocale( const com::sun::star::lang::Locale& rLocale, const OUString& rType ) const;
87 public:
88 DefaultFontConfiguration();
89 ~DefaultFontConfiguration();
91 static DefaultFontConfiguration& get();
93 OUString getDefaultFont( const com::sun::star::lang::Locale& rLocale, int nType ) const;
94 OUString getUserInterfaceFont( const com::sun::star::lang::Locale& rLocale ) const;
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)
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)
155 struct UNOTOOLS_DLLPUBLIC FontNameAttr
157 String Name;
158 ::std::vector< String > Substitutions;
159 ::std::vector< String > MSSubstitutions;
160 ::std::vector< String > PSSubstitutions;
161 ::std::vector< String > HTMLSubstitutions;
162 FontWeight Weight;
163 FontWidth Width;
164 unsigned long Type; // bitfield of IMPL_FONT_ATTR_*
167 class UNOTOOLS_DLLPUBLIC FontSubstConfiguration
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 struct LocaleSubst
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;
184 LocaleSubst() : bConfigRead( false ) {}
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;
191 void fillSubstVector( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xFont,
192 const OUString& rType,
193 std::vector< String >& 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();
205 static FontSubstConfiguration& get();
207 const FontNameAttr* getSubstInfo(
208 const String& 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 String& rOrgName, String& rShortName, String& rFamilyName, FontWeight& rWeight, FontWidth& rWidth, sal_uLong& rType );
217 } // namespace utl
219 #endif // _UNOTOOLS_FONTCFG_HXX
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */