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