LibreOffice Module sw (master) 1
fontcfg.cxx
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
20#include <fontcfg.hxx>
22#include <osl/diagnose.h>
24#include <vcl/outdev.hxx>
26#include <unotools/lingucfg.hxx>
27#include <com/sun/star/uno/Sequence.hxx>
28#include <com/sun/star/i18n/ScriptType.hpp>
29
30using namespace utl;
31using namespace com::sun::star::uno;
32
33static LanguageType lcl_LanguageOfType(sal_Int16 nType, LanguageType eWestern, LanguageType eCJK, LanguageType eCTL)
34{
36 ? eWestern
37 : nType >= FONT_STANDARD_CTL ? eCTL : eCJK;
38}
39
41{
42 static Sequence<OUString> aNames {
43 "DefaultFont/Standard", // 0
44 "DefaultFont/Heading", // 1
45 "DefaultFont/List", // 2
46 "DefaultFont/Caption", // 3
47 "DefaultFont/Index", // 4
48 "DefaultFontCJK/Standard", // 5
49 "DefaultFontCJK/Heading", // 6
50 "DefaultFontCJK/List", // 7
51 "DefaultFontCJK/Caption", // 8
52 "DefaultFontCJK/Index", // 9
53 "DefaultFontCTL/Standard", // 10
54 "DefaultFontCTL/Heading", // 11
55 "DefaultFontCTL/List", // 12
56 "DefaultFontCTL/Caption", // 13
57 "DefaultFontCTL/Index", // 14
58 "DefaultFont/StandardHeight", // 15
59 "DefaultFont/HeadingHeight", // 16
60 "DefaultFont/ListHeight", // 17
61 "DefaultFont/CaptionHeight", // 18
62 "DefaultFont/IndexHeight", // 19
63 "DefaultFontCJK/StandardHeight", // 20
64 "DefaultFontCJK/HeadingHeight", // 21
65 "DefaultFontCJK/ListHeight", // 22
66 "DefaultFontCJK/CaptionHeight", // 23
67 "DefaultFontCJK/IndexHeight", // 24
68 "DefaultFontCTL/StandardHeight", // 25
69 "DefaultFontCTL/HeadingHeight", // 26
70 "DefaultFontCTL/ListHeight", // 27
71 "DefaultFontCTL/CaptionHeight", // 28
72 "DefaultFontCTL/IndexHeight" // 29
73 };
74 return aNames;
75}
76
78 utl::ConfigItem("Office.Writer")
79{
80 SvtLinguOptions aLinguOpt;
81
83 SvtLinguConfig().GetOptions( aLinguOpt );
84
85 LanguageType eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, css::i18n::ScriptType::LATIN),
86 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, css::i18n::ScriptType::ASIAN),
87 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, css::i18n::ScriptType::COMPLEX);
88
89 for(sal_Int16 i = 0; i < DEF_FONT_COUNT; i++)
90 {
92 lcl_LanguageOfType(i, eWestern, eCJK, eCTL));
94 }
95
97 Sequence<Any> aValues = GetProperties(aNames);
98 const Any* pValues = aValues.getConstArray();
99 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
100 if(aValues.getLength() != aNames.getLength())
101 return;
102
103 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
104 {
105 if(pValues[nProp].hasValue())
106 {
107 if( nProp < DEF_FONT_COUNT)
108 {
109 OUString sVal;
110 pValues[nProp] >>= sVal;
111 m_sDefaultFonts[nProp] = sVal;
112 }
113 else
114 {
115 pValues[nProp] >>= m_nDefaultFontHeight[nProp - DEF_FONT_COUNT];
117 }
118 }
119 }
120}
121
123{
125 Sequence<Any> aValues(aNames.getLength());
126 Any* pValues = aValues.getArray();
127 SvtLinguOptions aLinguOpt;
128
129 SvtLinguConfig().GetOptions( aLinguOpt );
130
131 LanguageType eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, css::i18n::ScriptType::LATIN),
132 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, css::i18n::ScriptType::ASIAN),
133 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, css::i18n::ScriptType::COMPLEX);
134
135 for(sal_uInt16 nProp = 0;
136 nProp < sal::static_int_cast< sal_uInt16, sal_Int32 >( aNames.getLength() );
137 nProp++)
138 {
139 if( nProp < DEF_FONT_COUNT )
140 {
141 if(GetDefaultFor(nProp, lcl_LanguageOfType(nProp, eWestern, eCJK, eCTL)) != m_sDefaultFonts[nProp])
142 pValues[nProp] <<= m_sDefaultFonts[nProp];
143 }
144 else
145 {
146 if(m_nDefaultFontHeight[nProp - DEF_FONT_COUNT] > 0)
147 pValues[nProp] <<= static_cast<sal_Int32>(convertTwipToMm100(m_nDefaultFontHeight[nProp - DEF_FONT_COUNT]));
148 }
149 }
150 PutProperties(aNames, aValues);
151}
152
154{
155}
156
157bool SwStdFontConfig::IsFontDefault(sal_uInt16 nFontType) const
158{
159 bool bSame = false;
160 SvtLinguOptions aLinguOpt;
161
163 SvtLinguConfig().GetOptions(aLinguOpt);
164
165 LanguageType eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, css::i18n::ScriptType::LATIN),
166 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, css::i18n::ScriptType::ASIAN),
167 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, css::i18n::ScriptType::COMPLEX);
168
169 OUString sDefFont(GetDefaultFor(FONT_STANDARD, eWestern));
170 OUString sDefFontCJK(GetDefaultFor(FONT_STANDARD_CJK, eCJK));
171 OUString sDefFontCTL(GetDefaultFor(FONT_STANDARD_CTL, eCTL));
172 LanguageType eLang = lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL);
173 switch( nFontType )
174 {
175 case FONT_STANDARD:
176 bSame = m_sDefaultFonts[nFontType] == sDefFont;
177 break;
179 bSame = m_sDefaultFonts[nFontType] == sDefFontCJK;
180 break;
182 bSame = m_sDefaultFonts[nFontType] == sDefFontCTL;
183 break;
184 case FONT_OUTLINE :
185 case FONT_OUTLINE_CJK :
186 case FONT_OUTLINE_CTL :
187 bSame = m_sDefaultFonts[nFontType] ==
188 GetDefaultFor(nFontType, eLang);
189 break;
190 case FONT_LIST :
191 case FONT_CAPTION :
192 case FONT_INDEX :
193 bSame = m_sDefaultFonts[nFontType] == sDefFont &&
194 m_sDefaultFonts[FONT_STANDARD] == sDefFont;
195 break;
196 case FONT_LIST_CJK :
197 case FONT_CAPTION_CJK :
198 case FONT_INDEX_CJK :
199 {
200 bool b1 = m_sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCJK;
201 bSame = b1 && m_sDefaultFonts[nFontType] == sDefFontCJK;
202 }
203 break;
204 case FONT_LIST_CTL :
205 case FONT_CAPTION_CTL :
206 case FONT_INDEX_CTL :
207 {
208 bool b1 = m_sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCTL;
209 bSame = b1 && m_sDefaultFonts[nFontType] == sDefFontCTL;
210 }
211 break;
212 }
213 return bSame;
214}
215
216OUString SwStdFontConfig::GetDefaultFor(sal_uInt16 nFontType, LanguageType eLang)
217{
218 DefaultFontType nFontId;
219 switch( nFontType )
220 {
221 case FONT_OUTLINE :
222 nFontId = DefaultFontType::LATIN_HEADING;
223 break;
224 case FONT_OUTLINE_CJK :
225 nFontId = DefaultFontType::CJK_HEADING;
226 break;
227 case FONT_OUTLINE_CTL :
228 nFontId = DefaultFontType::CTL_HEADING;
229 break;
231 case FONT_LIST_CJK :
232 case FONT_CAPTION_CJK :
233 case FONT_INDEX_CJK :
234 nFontId = DefaultFontType::CJK_TEXT;
235 break;
237 case FONT_LIST_CTL :
238 case FONT_CAPTION_CTL :
239 case FONT_INDEX_CTL :
240 nFontId = DefaultFontType::CTL_TEXT;
241 break;
242 default:
243 nFontId = DefaultFontType::LATIN_TEXT;
244 }
245 vcl::Font aFont = OutputDevice::GetDefaultFont(nFontId, eLang, GetDefaultFontFlags::OnlyOne);
246 return aFont.GetFamilyName();
247}
248
249sal_Int32 SwStdFontConfig::GetDefaultHeightFor(sal_uInt16 nFontType, LanguageType eLang)
250{
251 sal_Int32 nRet = FONTSIZE_DEFAULT;
252 switch( nFontType )
253 {
254 case FONT_OUTLINE:
255 case FONT_OUTLINE_CJK:
256 case FONT_OUTLINE_CTL:
257 nRet = FONTSIZE_OUTLINE;
258 break;
261 break;
262 }
263 if( eLang == LANGUAGE_THAI && nFontType >= FONT_STANDARD_CTL )
264 {
265 nRet = nRet * 4 / 3;
266 }
267 if( eLang == LANGUAGE_KOREAN )
268 {
270 }
271 return nRet;
272}
273
274void SwStdFontConfig::ChangeInt( sal_uInt16 nFontType, sal_Int32 nHeight )
275{
276 OSL_ENSURE( nFontType < DEF_FONT_COUNT, "invalid index in SwStdFontConfig::ChangeInt()");
277 if( nFontType >= DEF_FONT_COUNT || m_nDefaultFontHeight[nFontType] == nHeight)
278 return;
279
280 SvtLinguOptions aLinguOpt;
282 SvtLinguConfig().GetOptions( aLinguOpt );
283
284 LanguageType eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, css::i18n::ScriptType::LATIN),
285 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, css::i18n::ScriptType::ASIAN),
286 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, css::i18n::ScriptType::COMPLEX);
287
288 // #i92090# default height value sets back to -1
289 const sal_Int32 nDefaultHeight = GetDefaultHeightFor(nFontType, lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL));
290 const bool bIsDefaultHeight = nHeight == nDefaultHeight;
291 if( bIsDefaultHeight && m_nDefaultFontHeight[nFontType] > 0 )
292 {
293 SetModified();
294 m_nDefaultFontHeight[nFontType] = -1;
295 }
296 else if( !bIsDefaultHeight && nHeight != m_nDefaultFontHeight[nFontType] )
297 {
298 SetModified();
299 m_nDefaultFontHeight[nFontType] = nHeight;
300 }
301}
302
304{
305 OSL_ENSURE(nFont + FONT_PER_GROUP * nScriptType < DEF_FONT_COUNT, "wrong index in SwStdFontConfig::GetFontHeight()");
306 sal_Int32 nRet = m_nDefaultFontHeight[nFont + FONT_PER_GROUP * nScriptType];
307 if(nRet <= 0)
308 return GetDefaultHeightFor(nFont + FONT_PER_GROUP * nScriptType, eLang);
309 return nRet;
310}
311
312void SwStdFontConfig::Notify( const css::uno::Sequence< OUString >& ) {}
313
314/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
constexpr auto convertTwipToMm100(N n)
static LanguageType resolveSystemLanguageByScriptType(LanguageType nLang, sal_Int16 nType)
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
void GetOptions(SvtLinguOptions &rOptions) const
OUString m_sDefaultFonts[DEF_FONT_COUNT]
Definition: fontcfg.hxx:58
sal_Int32 GetFontHeight(sal_uInt8 nFont, sal_uInt8 nScriptType, LanguageType eLang)
Definition: fontcfg.cxx:303
virtual void ImplCommit() override
Definition: fontcfg.cxx:122
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: fontcfg.cxx:312
sal_Int32 m_nDefaultFontHeight[DEF_FONT_COUNT]
Definition: fontcfg.hxx:59
static OUString GetDefaultFor(sal_uInt16 nFontType, LanguageType eLang)
Definition: fontcfg.cxx:216
static sal_Int32 GetDefaultHeightFor(sal_uInt16 nFontType, LanguageType eLang)
Definition: fontcfg.cxx:249
static SAL_DLLPRIVATE css::uno::Sequence< OUString > const & GetPropertyNames()
Definition: fontcfg.cxx:40
virtual ~SwStdFontConfig() override
Definition: fontcfg.cxx:153
void ChangeInt(sal_uInt16 nFontType, sal_Int32 nHeight)
Definition: fontcfg.cxx:274
bool IsFontDefault(sal_uInt16 nFontType) const
Definition: fontcfg.cxx:157
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
static bool IsFuzzing()
const OUString & GetFamilyName() const
static LanguageType lcl_LanguageOfType(sal_Int16 nType, LanguageType eWestern, LanguageType eCJK, LanguageType eCTL)
Definition: fontcfg.cxx:33
#define FONT_STANDARD_CTL
Definition: fontcfg.hxx:37
#define FONT_OUTLINE
Definition: fontcfg.hxx:28
#define FONTSIZE_OUTLINE
Definition: fontcfg.hxx:54
#define FONT_STANDARD_CJK
Definition: fontcfg.hxx:32
#define FONT_LIST
Definition: fontcfg.hxx:29
#define FONT_INDEX_CJK
Definition: fontcfg.hxx:36
#define FONT_OUTLINE_CTL
Definition: fontcfg.hxx:38
#define FONTSIZE_CJK_DEFAULT
Definition: fontcfg.hxx:53
#define FONT_CAPTION_CJK
Definition: fontcfg.hxx:35
#define FONT_LIST_CJK
Definition: fontcfg.hxx:34
#define FONTSIZE_KOREAN_DEFAULT
Definition: fontcfg.hxx:52
#define FONT_CAPTION
Definition: fontcfg.hxx:30
#define FONT_INDEX
Definition: fontcfg.hxx:31
#define DEF_FONT_COUNT
Definition: fontcfg.hxx:42
#define FONT_STANDARD
Definition: fontcfg.hxx:27
#define FONT_CAPTION_CTL
Definition: fontcfg.hxx:40
#define FONT_INDEX_CTL
Definition: fontcfg.hxx:41
#define FONT_OUTLINE_CJK
Definition: fontcfg.hxx:33
#define FONT_PER_GROUP
Definition: fontcfg.hxx:44
#define FONTSIZE_DEFAULT
Definition: fontcfg.hxx:51
#define FONT_LIST_CTL
Definition: fontcfg.hxx:39
DefaultFontType
#define LANGUAGE_THAI
#define LANGUAGE_KOREAN
int i
constexpr auto toTwips(N number, Length from)
QPRO_FUNC_TYPE nType
LanguageType nDefaultLanguage
LanguageType nDefaultLanguage_CTL
LanguageType nDefaultLanguage_CJK
unsigned char sal_uInt8