1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_UNOTOOLS_FONTCFG_HXX
20 #define INCLUDED_UNOTOOLS_FONTCFG_HXX
22 #include <config_options.h>
23 #include <unotools/unotoolsdllapi.h>
24 #include <tools/solar.h>
25 #include <tools/fontenum.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <o3tl/typed_flags_set.hxx>
29 #include <unordered_map>
30 #include <unordered_set>
33 namespace com::sun::star::container
{ class XNameAccess
; }
34 namespace com::sun::star::lang
{ class XMultiServiceFactory
; }
38 enum class DefaultFontType
;
40 // If you think the below concept of classifying a font (typeface) as possibly being one or several
41 // of "Default", "Standard", and "Normal", etc, is madness, you are probably right. On the other
42 // hand we have in officecfg/registry/data/org/openoffice/VCL.xcu carefully (or not) assigned to
43 // each font mentioned in that file what its attributes are, so it is quite possible that touching
44 // this would cause a regression that nobody would notice until after many years.
46 // Note that the bit flags must match the entries in the pAttribNames array in
47 // unotools/source/config/fontcfg.cxx.
49 enum class ImplFontAttrs
: sal_uLong
52 Default
= 0x00000001, ///< Default-Font like Andale Sans UI, Palace Script, Albany, Thorndale, Cumberland, ...
53 Standard
= 0x00000002, ///< Standard-Font like Arial, Times, Courier, ...
54 Normal
= 0x00000004, ///< Normal Font for writing text like Arial, Verdana, Arial Narrow, Trebuchet, Times, Courier, ...
55 Symbol
= 0x00000008, ///< Font with symbols
57 SansSerif
= 0x00000020,
59 Decorative
= 0x00000080, ///< Readable and normally used for drawings
60 Special
= 0x00000100, ///< Very special design
62 Titling
= 0x00000400, ///< Only uppercase characters
63 Capitals
= 0x00000800, ///< Only uppercase characters, but lowercase characters smaller as the uppercase characters
70 NoneLatin
= 0x00040000,
71 Full
= 0x00080000, ///< Font with normally all characters
75 Typewriter
= 0x00800000, ///< Like a typewriter: Courier, ...
76 Script
= 0x01000000, ///< Handwriting or Script
77 Handwriting
= 0x02000000, ///< More Handwriting with normal letters
78 Chancery
= 0x04000000, ///< Like Zapf Chancery
79 Comic
= 0x08000000, ///< Like Comic Sans MS
80 BrushScript
= 0x10000000, ///< More Script
82 Schoolbook
= 0x40000000,
83 OtherStyle
= 0x80000000, ///< OldStyle, ... so negative points
84 CJK_AllLang
= CJK_JP
| CJK_SC
| CJK_TC
| CJK_KR
,
85 AllScript
= Script
| Handwriting
| Chancery
| Comic
| BrushScript
,
86 AllSubscript
= Handwriting
| Chancery
| Comic
| BrushScript
,
87 AllSerifStyle
= AllScript
| SansSerif
| Serif
| Fixed
| Italic
| Gothic
| Schoolbook
| Shadow
| Outline
,
91 template<> struct typed_flags
<ImplFontAttrs
> : is_typed_flags
<ImplFontAttrs
, 0xffffffff> {};
98 class UNOTOOLS_DLLPUBLIC DefaultFontConfiguration
100 css::uno::Reference
< css::lang::XMultiServiceFactory
>
102 css::uno::Reference
< css::container::XNameAccess
>
107 // the real string used in the configuration
108 // used to get rid of upper/lower case problems
109 OUString aConfigLocaleString
;
110 // xAccess is mutable to be able to be filled on demand
111 mutable css::uno::Reference
< css::container::XNameAccess
> xAccess
;
114 std::unordered_map
< OUString
, LocaleAccess
> m_aConfig
;
116 OUString
tryLocale( const OUString
& rBcp47
, const OUString
& rType
) const;
119 DefaultFontConfiguration();
120 ~DefaultFontConfiguration();
122 static DefaultFontConfiguration
& get();
124 OUString
getDefaultFont( const LanguageTag
& rLanguageTag
, DefaultFontType nType
) const;
125 OUString
getUserInterfaceFont( const LanguageTag
& rLanguageTag
) const;
128 struct UNOTOOLS_DLLPUBLIC FontNameAttr
131 ::std::vector
< OUString
> Substitutions
;
132 ::std::vector
< OUString
> MSSubstitutions
;
138 class UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC
) FontSubstConfiguration
141 css::uno::Reference
< css::lang::XMultiServiceFactory
>
143 css::uno::Reference
< css::container::XNameAccess
>
147 OUString aConfigLocaleString
;
148 mutable bool bConfigRead
;
149 // note: aSubstAttributes must be sorted alphabetically by Name
150 // searches on the substitutes are done with Name as key, where
151 // a minimal match is sufficient (that is e.g. "Thorndale" will match
152 // "Thorndale BlaBlub"). Also names must be lower case.
153 mutable std::vector
< FontNameAttr
> aSubstAttributes
;
155 LocaleSubst() : bConfigRead( false ) {}
157 std::unordered_map
< OUString
, LocaleSubst
> m_aSubst
;
158 typedef std::unordered_set
< OUString
> UniqueSubstHash
;
159 mutable UniqueSubstHash maSubstHash
;
161 void fillSubstVector( const css::uno::Reference
< css::container::XNameAccess
>& rFont
,
162 const OUString
& rType
,
163 std::vector
< OUString
>& rSubstVector
) const;
164 FontWeight
getSubstWeight( const css::uno::Reference
< css::container::XNameAccess
>& rFont
,
165 const OUString
& rType
) const;
166 FontWidth
getSubstWidth( const css::uno::Reference
< css::container::XNameAccess
>& rFont
,
167 const OUString
& rType
) const;
168 ImplFontAttrs
getSubstType( const css::uno::Reference
< css::container::XNameAccess
>& rFont
,
169 const OUString
& rType
) const;
170 void readLocaleSubst( const OUString
& rBcp47
) const;
172 FontSubstConfiguration();
173 ~FontSubstConfiguration();
175 static FontSubstConfiguration
& get();
177 const FontNameAttr
* getSubstInfo( const OUString
& rFontName
) const;
178 static void getMapName( const OUString
& rOrgName
, OUString
& rShortName
, OUString
& rFamilyName
, FontWeight
& rWeight
, FontWidth
& rWidth
, ImplFontAttrs
& rType
);
183 #endif // INCLUDED_UNOTOOLS_FONTCFG_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */