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 INCLUDED_UNOTOOLS_FONTCFG_HXX
20 : #define INCLUDED_UNOTOOLS_FONTCFG_HXX
21 :
22 : #include <i18nlangtag/languagetag.hxx>
23 : #include <unotools/unotoolsdllapi.h>
24 : #include <tools/solar.h>
25 : #include <tools/fontenum.hxx>
26 : #include <com/sun/star/lang/Locale.hpp>
27 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 : #include <com/sun/star/container/XNameAccess.hpp>
29 : #include <o3tl/typed_flags_set.hxx>
30 :
31 : #include <unordered_map>
32 : #include <unordered_set>
33 : #include <vector>
34 :
35 : enum class DefaultFontType;
36 :
37 : // If you think the below concept of classifying a font (typeface) as possibly being one or several
38 : // of "Default", "Standard", and "Normal", etc, is madness, you are probably right. On the other
39 : // hand we have in officecfg/registry/data/org/openoffice/VCL.xcu carefully (or not) assigned to
40 : // each font mentioned in that file what its attributes are, so it is quite possible that touching
41 : // this would cause a regression that nobody would notice until after many years.
42 :
43 : // Note that the bit flags must match the entries in the pAttribNames array in
44 : // unotools/source/config/fontcfg.cxx.
45 :
46 : enum class ImplFontAttrs : sal_uLong
47 : {
48 : None = 0x00000000,
49 : Default = 0x00000001, ///< Default-Font like Andale Sans UI, Palace Script, Albany, Thorndale, Cumberland, ...
50 : Standard = 0x00000002, ///< Standard-Font like Arial, Times, Courier, ...
51 : Normal = 0x00000004, ///< Normal Font for writing text like Arial, Verdana, Arial Narrow, Trebuchet, Times, Courier, ...
52 : Symbol = 0x00000008, ///< Font with symbols
53 : Fixed = 0x00000010,
54 : SansSerif = 0x00000020,
55 : Serif = 0x00000040,
56 : Decorative = 0x00000080, ///< Readable and normally used for drawings
57 : Special = 0x00000100, ///< Very special design
58 : Italic = 0x00000200,
59 : Titling = 0x00000400, ///< Only uppercase characters
60 : Capitals = 0x00000800, ///< Only uppercase characters, but lowercase characters smaller as the uppercase characters
61 : CJK = 0x00001000,
62 : CJK_JP = 0x00002000,
63 : CJK_SC = 0x00004000,
64 : CJK_TC = 0x00008000,
65 : CJK_KR = 0x00010000,
66 : CTL = 0x00020000,
67 : NoneLatin = 0x00040000,
68 : Full = 0x00080000, ///< Font with normally all characters
69 : Outline = 0x00100000,
70 : Shadow = 0x00200000,
71 : Rounded = 0x00400000,
72 : Typewriter = 0x00800000, ///< Like a typewriter: Courier, ...
73 : Script = 0x01000000, ///< Handwriting or Script
74 : Handwriting = 0x02000000, ///< More Handwriting with normal letters
75 : Chancery = 0x04000000, ///< Like Zapf Chancery
76 : Comic = 0x08000000, ///< Like Comic Sans MS
77 : BrushScript = 0x10000000, ///< More Script
78 : Gothic = 0x20000000,
79 : Schoolbook = 0x40000000,
80 : OtherStyle = 0x80000000, ///< OldStyle, ... so negativ points
81 : CJK_AllLang = CJK_JP | CJK_SC | CJK_TC | CJK_KR,
82 : AllScript = Script | Handwriting | Chancery | Comic | BrushScript,
83 : AllSubscript = Handwriting | Chancery | Comic | BrushScript,
84 : AllSerifStyle = AllScript | SansSerif | Serif | Fixed | Italic | Gothic | Schoolbook | Shadow | Outline,
85 : };
86 : namespace o3tl
87 : {
88 : template<> struct typed_flags<ImplFontAttrs> : is_typed_flags<ImplFontAttrs, 0xffffffff> {};
89 : }
90 :
91 :
92 : namespace utl
93 : {
94 :
95 : class UNOTOOLS_DLLPUBLIC DefaultFontConfiguration
96 : {
97 : com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
98 : m_xConfigProvider;
99 : com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
100 : m_xConfigAccess;
101 :
102 37290 : struct LocaleAccess
103 : {
104 : // the real string used in the configuration
105 : // used to get rid of upper/lower case problems
106 : OUString aConfigLocaleString;
107 : // xAccess is mutable to be able to be filled on demand
108 : mutable com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xAccess;
109 : };
110 :
111 : std::unordered_map< OUString, LocaleAccess, OUStringHash > m_aConfig;
112 :
113 : OUString tryLocale( const OUString& rBcp47, const OUString& rType ) const;
114 :
115 : public:
116 : DefaultFontConfiguration();
117 : ~DefaultFontConfiguration();
118 :
119 : static DefaultFontConfiguration& get();
120 :
121 : OUString getDefaultFont( const LanguageTag& rLanguageTag, DefaultFontType nType ) const;
122 : OUString getUserInterfaceFont( const LanguageTag& rLanguageTag ) const;
123 : };
124 :
125 505600 : struct UNOTOOLS_DLLPUBLIC FontNameAttr
126 : {
127 : OUString Name;
128 : ::std::vector< OUString > Substitutions;
129 : ::std::vector< OUString > MSSubstitutions;
130 : ::std::vector< OUString > PSSubstitutions;
131 : ::std::vector< OUString > HTMLSubstitutions;
132 : FontWeight Weight;
133 : FontWidth Width;
134 : ImplFontAttrs Type;
135 : };
136 :
137 : class UNOTOOLS_DLLPUBLIC FontSubstConfiguration
138 : {
139 : private:
140 : com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
141 : m_xConfigProvider;
142 : com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
143 : m_xConfigAccess;
144 252 : struct LocaleSubst
145 : {
146 : OUString aConfigLocaleString;
147 : mutable bool bConfigRead;
148 : // note: aSubstAttributes must be sorted alphabetically by Name
149 : // searches on the substitutes are done with Name as key, where
150 : // a minimal match is sufficient (that is e.g. "Thorndale" will match
151 : // "Thorndale BlaBlub"). Also names must be lower case.
152 : mutable std::vector< FontNameAttr > aSubstAttributes;
153 :
154 168 : LocaleSubst() : bConfigRead( false ) {}
155 : };
156 : std::unordered_map< OUString, LocaleSubst, OUStringHash > m_aSubst;
157 : typedef std::unordered_set< OUString, OUStringHash > UniqueSubstHash;
158 : mutable UniqueSubstHash maSubstHash;
159 :
160 : void fillSubstVector( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& rFont,
161 : const OUString& rType,
162 : std::vector< OUString >& rSubstVector ) const;
163 : FontWeight getSubstWeight( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& rFont,
164 : const OUString& rType ) const;
165 : FontWidth getSubstWidth( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& rFont,
166 : const OUString& rType ) const;
167 : ImplFontAttrs getSubstType( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& rFont,
168 : const OUString& rType ) const;
169 : void readLocaleSubst( const OUString& rBcp47 ) const;
170 : public:
171 : FontSubstConfiguration();
172 : ~FontSubstConfiguration();
173 :
174 : static FontSubstConfiguration& get();
175 :
176 : const FontNameAttr* getSubstInfo(
177 : const OUString& rFontName,
178 : const LanguageTag& rLanguageTag = LanguageTag( OUString( "en"))
179 : ) const;
180 : static void getMapName( const OUString& rOrgName, OUString& rShortName, OUString& rFamilyName, FontWeight& rWeight, FontWidth& rWidth, ImplFontAttrs& rType );
181 : };
182 :
183 : } // namespace utl
184 :
185 : #endif // INCLUDED_UNOTOOLS_FONTCFG_HXX
186 :
187 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|