LibreOffice Module chart2 (master) 1
CharacterProperties.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
21
22#include <com/sun/star/beans/XMultiPropertySet.hpp>
23#include <com/sun/star/beans/PropertyAttribute.hpp>
24#include <com/sun/star/awt/FontSlant.hpp>
25#include <com/sun/star/lang/Locale.hpp>
26
27#include <com/sun/star/awt/FontUnderline.hpp>
28#include <com/sun/star/awt/FontWeight.hpp>
29#include <com/sun/star/text/FontRelief.hpp>
30#include <com/sun/star/text/FontEmphasis.hpp>
31#include <com/sun/star/awt/FontStrikeout.hpp>
32#include <com/sun/star/text/WritingMode2.hpp>
33#include <com/sun/star/i18n/ScriptType.hpp>
34#include <osl/diagnose.h>
35#include <unotools/lingucfg.hxx>
38#include <tools/color.hxx>
39#include <vcl/outdev.hxx>
40
41using namespace ::com::sun::star;
42
43using ::com::sun::star::beans::Property;
44
45namespace chart
46{
47
49 std::vector< Property > & rOutProperties )
50{
51 // CharacterProperties
52 rOutProperties.emplace_back( "CharFontName",
53 PROP_CHAR_FONT_NAME,
55 beans::PropertyAttribute::BOUND
56 | beans::PropertyAttribute::MAYBEDEFAULT );
57 rOutProperties.emplace_back( "CharFontStyleName",
60 beans::PropertyAttribute::BOUND
61 | beans::PropertyAttribute::MAYBEDEFAULT
62 | beans::PropertyAttribute::MAYBEVOID );
63 // CharFontFamily (see awt.FontFamily)
64 rOutProperties.emplace_back( "CharFontFamily",
67 beans::PropertyAttribute::BOUND
68 | beans::PropertyAttribute::MAYBEDEFAULT );
69 // CharFontCharSet (see awt.CharSet)
70 rOutProperties.emplace_back( "CharFontCharSet",
71 PROP_CHAR_FONT_CHAR_SET,
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT );
75 // CharFontPitch (see awt.FontPitch)
76 rOutProperties.emplace_back( "CharFontPitch",
79 beans::PropertyAttribute::BOUND
80 | beans::PropertyAttribute::MAYBEDEFAULT );
81 // CharColor
82 rOutProperties.emplace_back( "CharColor",
83 PROP_CHAR_COLOR,
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::MAYBEDEFAULT );
87 // CharEscapement
88 rOutProperties.emplace_back( "CharEscapement",
89 PROP_CHAR_ESCAPEMENT,
91 beans::PropertyAttribute::BOUND
92 | beans::PropertyAttribute::MAYBEVOID );
93 // CharHeight
94 rOutProperties.emplace_back( "CharHeight",
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEDEFAULT );
99 // CharUnderline (see awt.FontUnderline)
100 rOutProperties.emplace_back( "CharUnderline",
101 PROP_CHAR_UNDERLINE,
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEDEFAULT );
105 // CharUnderlineColor
106 rOutProperties.emplace_back( "CharUnderlineColor",
107 PROP_CHAR_UNDERLINE_COLOR,
109 beans::PropertyAttribute::BOUND
110 | beans::PropertyAttribute::MAYBEDEFAULT
111 | beans::PropertyAttribute::MAYBEVOID );
112 // CharUnderlineHasColor
113 rOutProperties.emplace_back( "CharUnderlineHasColor",
114 PROP_CHAR_UNDERLINE_HAS_COLOR,
116 beans::PropertyAttribute::BOUND
117 | beans::PropertyAttribute::MAYBEDEFAULT );
118 // CharOverline (see awt.FontUnderline)
119 rOutProperties.emplace_back( "CharOverline",
122 beans::PropertyAttribute::BOUND
123 | beans::PropertyAttribute::MAYBEDEFAULT );
124 // CharOverlineColor
125 rOutProperties.emplace_back( "CharOverlineColor",
128 beans::PropertyAttribute::BOUND
129 | beans::PropertyAttribute::MAYBEDEFAULT
130 | beans::PropertyAttribute::MAYBEVOID );
131 // CharOverlineHasColor
132 rOutProperties.emplace_back( "CharOverlineHasColor",
135 beans::PropertyAttribute::BOUND
136 | beans::PropertyAttribute::MAYBEDEFAULT );
137 // CharWeight (see awt.FontWeight)
138 rOutProperties.emplace_back( "CharWeight",
139 PROP_CHAR_WEIGHT,
141 beans::PropertyAttribute::BOUND
142 | beans::PropertyAttribute::MAYBEDEFAULT );
143 // CharPosture
144 rOutProperties.emplace_back( "CharPosture",
145 PROP_CHAR_POSTURE,
147 beans::PropertyAttribute::BOUND
148 | beans::PropertyAttribute::MAYBEDEFAULT );
149 rOutProperties.emplace_back( "CharAutoKerning",
150 PROP_CHAR_AUTO_KERNING,
152 beans::PropertyAttribute::BOUND
153 | beans::PropertyAttribute::MAYBEDEFAULT
154 | beans::PropertyAttribute::MAYBEVOID );
155 rOutProperties.emplace_back( "CharKerning",
158 beans::PropertyAttribute::BOUND
159 | beans::PropertyAttribute::MAYBEDEFAULT
160 | beans::PropertyAttribute::MAYBEVOID );
161 // CharEscapementHeight
162 rOutProperties.emplace_back( "CharEscapementHeight",
163 PROP_CHAR_ESCAPEMENT_HEIGHT,
165 beans::PropertyAttribute::BOUND
166 | beans::PropertyAttribute::MAYBEVOID );
167 // CharStrikeout (see awt.FontStrikeout)
168 rOutProperties.emplace_back( "CharStrikeout",
171 beans::PropertyAttribute::BOUND
172 | beans::PropertyAttribute::MAYBEDEFAULT );
173 // CharWordMode
174 rOutProperties.emplace_back( "CharWordMode",
175 PROP_CHAR_WORD_MODE,
177 beans::PropertyAttribute::BOUND
178 | beans::PropertyAttribute::MAYBEDEFAULT );
179 // CharLocale
180 rOutProperties.emplace_back( "CharLocale",
181 PROP_CHAR_LOCALE,
183 //#i111967# no PropertyChangeEvent is fired on change so far
184 beans::PropertyAttribute::MAYBEDEFAULT );
185 // CharShadowed
186 rOutProperties.emplace_back( "CharShadowed",
187 PROP_CHAR_SHADOWED,
189 beans::PropertyAttribute::BOUND
190 | beans::PropertyAttribute::MAYBEDEFAULT );
191 // CharContoured
192 rOutProperties.emplace_back( "CharContoured",
193 PROP_CHAR_CONTOURED,
195 beans::PropertyAttribute::BOUND
196 | beans::PropertyAttribute::MAYBEDEFAULT );
197 // CharRelief (see text.FontRelief)
198 rOutProperties.emplace_back( "CharRelief",
199 PROP_CHAR_RELIEF,
201 beans::PropertyAttribute::BOUND
202 | beans::PropertyAttribute::MAYBEDEFAULT );
203
204 // CharEmphasize (see text.FontEmphasis)
205 rOutProperties.emplace_back( "CharEmphasis",
206 PROP_CHAR_EMPHASIS,
208 beans::PropertyAttribute::BOUND
209 | beans::PropertyAttribute::MAYBEDEFAULT );
210 // CharacterPropertiesAsian
211
212 // CharFontNameAsian
213 rOutProperties.emplace_back( "CharFontNameAsian",
216 beans::PropertyAttribute::BOUND
217 | beans::PropertyAttribute::MAYBEDEFAULT );
218 // CharFontStyleNameAsian
219 rOutProperties.emplace_back( "CharFontStyleNameAsian",
222 beans::PropertyAttribute::BOUND
223 | beans::PropertyAttribute::MAYBEDEFAULT
224 | beans::PropertyAttribute::MAYBEVOID );
225 // CharFontFamilyAsian (see awt.FontFamily)
226 rOutProperties.emplace_back( "CharFontFamilyAsian",
229 beans::PropertyAttribute::BOUND
230 | beans::PropertyAttribute::MAYBEDEFAULT );
231 // CharFontCharSetAsian (see awt.CharSet)
232 rOutProperties.emplace_back( "CharFontCharSetAsian",
235 beans::PropertyAttribute::BOUND
236 | beans::PropertyAttribute::MAYBEDEFAULT );
237 // CharFontPitchAsian (see awt.FontPitch)
238 rOutProperties.emplace_back( "CharFontPitchAsian",
241 beans::PropertyAttribute::BOUND
242 | beans::PropertyAttribute::MAYBEDEFAULT );
243 // CharHeightAsian
244 rOutProperties.emplace_back( "CharHeightAsian",
247 beans::PropertyAttribute::BOUND
248 | beans::PropertyAttribute::MAYBEDEFAULT );
249 // CharWeightAsian
250 rOutProperties.emplace_back( "CharWeightAsian",
253 beans::PropertyAttribute::BOUND
254 | beans::PropertyAttribute::MAYBEDEFAULT );
255 // CharPostureAsian
256 rOutProperties.emplace_back( "CharPostureAsian",
259 beans::PropertyAttribute::BOUND
260 | beans::PropertyAttribute::MAYBEDEFAULT );
261 // CharLocaleAsian
262 rOutProperties.emplace_back( "CharLocaleAsian",
265 //#i111967# no PropertyChangeEvent is fired on change so far
266 beans::PropertyAttribute::MAYBEDEFAULT );
267
268 // CharacterPropertiesComplex
269
270 // CharFontNameComplex
271 rOutProperties.emplace_back( "CharFontNameComplex",
274 beans::PropertyAttribute::BOUND
275 | beans::PropertyAttribute::MAYBEDEFAULT );
276 // CharFontStyleNameComplex
277 rOutProperties.emplace_back( "CharFontStyleNameComplex",
280 beans::PropertyAttribute::BOUND
281 | beans::PropertyAttribute::MAYBEDEFAULT
282 | beans::PropertyAttribute::MAYBEVOID );
283 // CharFontFamilyComplex (see awt.FontFamily)
284 rOutProperties.emplace_back( "CharFontFamilyComplex",
287 beans::PropertyAttribute::BOUND
288 | beans::PropertyAttribute::MAYBEDEFAULT );
289 // CharFontCharSetComplex (see awt.CharSet)
290 rOutProperties.emplace_back( "CharFontCharSetComplex",
293 beans::PropertyAttribute::BOUND
294 | beans::PropertyAttribute::MAYBEDEFAULT );
295 // CharFontPitchComplex (see awt.FontPitch)
296 rOutProperties.emplace_back( "CharFontPitchComplex",
299 beans::PropertyAttribute::BOUND
300 | beans::PropertyAttribute::MAYBEDEFAULT );
301 // CharHeightComplex
302 rOutProperties.emplace_back( "CharHeightComplex",
305 beans::PropertyAttribute::BOUND
306 | beans::PropertyAttribute::MAYBEDEFAULT );
307 // CharWeightComplex
308 rOutProperties.emplace_back( "CharWeightComplex",
311 beans::PropertyAttribute::BOUND
312 | beans::PropertyAttribute::MAYBEDEFAULT );
313 // CharPostureComplex
314 rOutProperties.emplace_back( "CharPostureComplex",
317 beans::PropertyAttribute::BOUND
318 | beans::PropertyAttribute::MAYBEDEFAULT );
319 // CharLocaleComplex
320 rOutProperties.emplace_back( "CharLocaleComplex",
323 //#i111967# no PropertyChangeEvent is fired on change so far
324 beans::PropertyAttribute::MAYBEDEFAULT );
325
326 // Writing Mode left to right vs right to left
327 rOutProperties.emplace_back( "WritingMode",
328 PROP_WRITING_MODE,
329 cppu::UnoType<sal_Int16>::get(), /*css::text::WritingMode2*/
330 beans::PropertyAttribute::BOUND
331 | beans::PropertyAttribute::MAYBEDEFAULT );
332
333 rOutProperties.emplace_back( "ParaIsCharacterDistance",
336 beans::PropertyAttribute::BOUND
337 | beans::PropertyAttribute::MAYBEDEFAULT );
338}
339
342{
343 const float fDefaultFontHeight = 13.0;
344
345 SvtLinguConfig aLinguConfig;
346 lang::Locale aDefaultLocale;
347 aLinguConfig.GetProperty(u"DefaultLocale") >>= aDefaultLocale;
348 lang::Locale aDefaultLocale_CJK;
349 aLinguConfig.GetProperty(u"DefaultLocale_CJK") >>= aDefaultLocale_CJK;
350 lang::Locale aDefaultLocale_CTL;
351 aLinguConfig.GetProperty(u"DefaultLocale_CTL") >>= aDefaultLocale_CTL;
352
353 using namespace ::com::sun::star::i18n::ScriptType;
354 LanguageType nLang;
356 vcl::Font aFont = OutputDevice::GetDefaultFont( DefaultFontType::LATIN_SPREADSHEET, nLang, GetDefaultFontFlags::OnlyOne );
358 vcl::Font aFontCJK = OutputDevice::GetDefaultFont( DefaultFontType::CJK_SPREADSHEET, nLang, GetDefaultFontFlags::OnlyOne );
360 vcl::Font aFontCTL = OutputDevice::GetDefaultFont( DefaultFontType::CTL_SPREADSHEET, nLang, GetDefaultFontFlags::OnlyOne );
361
364 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CHAR_FONT_FAMILY, sal_Int16(aFont.GetFamilyType()) );//awt::FontFamily::SWISS
365 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CHAR_FONT_CHAR_SET, sal_Int16(aFont.GetCharSet()) );//use awt::CharSet::DONTKNOW instead of SYSTEM to avoid assertion issue 50249
366 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CHAR_FONT_PITCH, sal_Int16(aFont.GetPitch()) );//awt::FontPitch::VARIABLE
369 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CHAR_UNDERLINE, awt::FontUnderline::NONE );
372 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CHAR_OVERLINE, awt::FontUnderline::NONE );
375 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CHAR_WEIGHT, awt::FontWeight::NORMAL );
384 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CHAR_RELIEF, text::FontRelief::NONE );
385 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CHAR_EMPHASIS, text::FontEmphasis::NONE );
386
387 // Asian (com.sun.star.style.CharacterPropertiesAsian)
397
398 // Complex Text Layout (com.sun.star.style.CharacterPropertiesComplex)
408
409 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_WRITING_MODE, sal_Int16( css::text::WritingMode2::PAGE ) );
411}
412
414{
417}
418
420 const uno::Reference< beans::XMultiPropertySet > & xMultiPropSet )
421{
422 awt::FontDescriptor aResult;
423 // Note: keep this sorted!
424 uno::Sequence< OUString > aPropNameSeq{
425 "CharFontCharSet", // CharSet
426 "CharFontFamily", // Family
427 "CharFontName", // Name
428 "CharFontPitch", // Pitch
429 "CharFontStyleName", // StyleName
430 "CharHeight", // Height
431 "CharPosture", // Slant
432 "CharStrikeout", // Strikeout
433 "CharUnderline", // Underline
434 "CharWeight", // Weight
435 "CharWordMode"}; // WordLineMode
436 uno::Sequence< uno::Any > aValues( xMultiPropSet->getPropertyValues( aPropNameSeq ));
437
438 sal_Int32 i=0;
439 // Note keep this sorted according to the list above (comments are the fieldnames)
440 aValues[ i++ ] >>= aResult.CharSet;
441 aValues[ i++ ] >>= aResult.Family;
442 aValues[ i++ ] >>= aResult.Name;
443 aValues[ i++ ] >>= aResult.Pitch;
444 aValues[ i++ ] >>= aResult.StyleName;
445 float fCharHeight = 0;
446 aValues[ i++ ] >>= fCharHeight;
447 aResult.Height = static_cast< sal_Int16 >( fCharHeight );
448 aValues[ i++ ] >>= aResult.Slant;
449 aValues[ i++ ] >>= aResult.Strikeout;
450 aValues[ i++ ] >>= aResult.Underline;
451 aValues[ i++ ] >>= aResult.Weight;
452 aValues[ i++ ] >>= aResult.WordLineMode;
453 OSL_ASSERT( i == aValues.getLength());
454
455 return aResult;
456}
457
458} // namespace chart
459
460/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define COMPLEX
#define ASIAN
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
static LanguageType resolveSystemLanguageByScriptType(LanguageType nLang, sal_Int16 nType)
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
css::uno::Any GetProperty(std::u16string_view rPropertyName) const
FontFamily GetFamilyType()
const OUString & GetStyleName() const
const OUString & GetFamilyName() const
FontPitch GetPitch()
rtl_TextEncoding GetCharSet() const
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
float u
OOO_DLLPUBLIC_CHARTTOOLS css::awt::FontDescriptor createFontDescriptorFromPropertySet(const css::uno::Reference< css::beans::XMultiPropertySet > &xMultiPropSet)
OOO_DLLPUBLIC_CHARTTOOLS void AddDefaultsToMap(::chart::tPropertyValueMap &rOutMap)
OOO_DLLPUBLIC_CHARTTOOLS bool IsCharacterPropertyHandle(sal_Int32 nHandle)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
@ FAST_PROPERTY_ID_START_CHAR_PROP
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
int i
PROP_CHAR_SHADOWED
PROP_CHAR_UNDERLINE_COLOR
PROP_CHAR_EMPHASIS
PROP_CHAR_COLOR
PROP_CHAR_RELIEF
PROP_CHAR_WORD_MODE
PROP_CHAR_FONT_NAME
PROP_CHAR_CONTOURED
PROP_CHAR_UNDERLINE
PROP_CHAR_LOCALE
PROP_CHAR_POSTURE
PROP_CHAR_AUTO_KERNING
PROP_CHAR_FONT_CHAR_SET
PROP_CHAR_WEIGHT
PROP_WRITING_MODE
PROP_CHAR_UNDERLINE_HAS_COLOR
sal_Int32 nHandle