1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <drawingml/textcharacterproperties.hxx>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/awt/FontWeight.hpp>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <comphelper/sequence.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <i18nlangtag/mslangid.hxx>
#include <editeng/escapementitem.hxx>
#include <oox/helper/helper.hxx>
#include <oox/helper/propertyset.hxx>
#include <oox/core/xmlfilterbase.hxx>
#include <oox/drawingml/drawingmltypes.hxx>
#include <oox/token/properties.hxx>
#include <oox/token/tokens.hxx>
using ::oox::core::XmlFilterBase;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
namespace oox::drawingml {
void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSourceProps )
{
// overwrite all properties existing in rSourceProps
maHyperlinkPropertyMap.assignUsed( rSourceProps.maHyperlinkPropertyMap );
maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
maLatinThemeFont.assignIfUsed( rSourceProps.maLatinThemeFont );
maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
maAsianThemeFont.assignIfUsed( rSourceProps.maAsianThemeFont );
maComplexFont.assignIfUsed( rSourceProps.maComplexFont );
maComplexThemeFont.assignIfUsed( rSourceProps.maComplexThemeFont );
maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
moLang.assignIfUsed( rSourceProps.moLang );
moHeight.assignIfUsed( rSourceProps.moHeight );
moFontScale.assignIfUsed(rSourceProps.moFontScale);
moSpacing.assignIfUsed( rSourceProps.moSpacing );
moUnderline.assignIfUsed( rSourceProps.moUnderline );
moBaseline.assignIfUsed( rSourceProps.moBaseline );
moStrikeout.assignIfUsed( rSourceProps.moStrikeout );
moCaseMap.assignIfUsed( rSourceProps.moCaseMap );
moBold.assignIfUsed( rSourceProps.moBold );
moItalic.assignIfUsed( rSourceProps.moItalic );
moUnderlineLineFollowText.assignIfUsed( rSourceProps.moUnderlineLineFollowText );
moUnderlineFillFollowText.assignIfUsed( rSourceProps.moUnderlineFillFollowText );
maTextEffectsProperties = rSourceProps.maTextEffectsProperties;
maFillProperties.assignUsed( rSourceProps.maFillProperties );
}
void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
{
OUString aFontName;
sal_Int16 nFontPitch = 0;
sal_Int16 nFontFamily = 0;
bool bRet = maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
if (!bRet)
// In case there is no direct font, try to look it up as a theme reference.
bRet = maLatinThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
if (bRet)
{
rPropMap.setProperty( PROP_CharFontName, aFontName);
rPropMap.setProperty( PROP_CharFontPitch, nFontPitch);
rPropMap.setProperty( PROP_CharFontFamily, nFontFamily);
}
bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
if (!bRet)
bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
if (bRet)
{
rPropMap.setProperty( PROP_CharFontNameAsian, aFontName);
rPropMap.setProperty( PROP_CharFontPitchAsian, nFontFamily);
rPropMap.setProperty( PROP_CharFontFamilyAsian, nFontPitch);
}
bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
if (!bRet)
bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
if (bRet)
{
rPropMap.setProperty( PROP_CharFontNameComplex, aFontName);
rPropMap.setProperty( PROP_CharFontPitchComplex, nFontPitch);
rPropMap.setProperty( PROP_CharFontFamilyComplex, nFontFamily);
}
if ( maFillProperties.moFillType.has() )
{
Color aColor = maFillProperties.getBestSolidColor();
rPropMap.setProperty(PROP_CharColor, aColor.getColor(rFilter.getGraphicHelper()));
if (aColor.hasTransparency())
{
rPropMap.setProperty(PROP_CharTransparence, aColor.getTransparency());
}
}
if( moLang.has() && !moLang.get().isEmpty() )
{
LanguageTag aTag(moLang.get());
lang::Locale aLocale(aTag.getLocale());
switch(MsLangId::getScriptType(aTag.getLanguageType()))
{
case css::i18n::ScriptType::LATIN:
rPropMap.setProperty( PROP_CharLocale, aLocale);break;
case css::i18n::ScriptType::ASIAN:
rPropMap.setProperty( PROP_CharLocaleAsian, aLocale);break;
case css::i18n::ScriptType::COMPLEX:
rPropMap.setProperty( PROP_CharLocaleComplex, aLocale);break;
}
}
if( moHeight.has() )
{
float fHeight = GetFontHeight( moHeight.get() );
if (moFontScale.has())
fHeight *= (moFontScale.get() / 100000);
rPropMap.setProperty( PROP_CharHeight, fHeight);
rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
}
rPropMap.setProperty( PROP_CharKerning, static_cast<sal_Int16>(GetTextSpacingPoint( moSpacing.get( 0 ) )));
rPropMap.setProperty( PROP_CharUnderline, GetFontUnderline( moUnderline.get( XML_none ) ));
rPropMap.setProperty( PROP_CharStrikeout, GetFontStrikeout( moStrikeout.get( XML_noStrike ) ));
rPropMap.setProperty( PROP_CharCaseMap, GetCaseMap( moCaseMap.get( XML_none ) ));
if( moBaseline.has() ) {
rPropMap.setProperty( PROP_CharEscapement, sal_Int16(moBaseline.get( 0 ) / 1000));
rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(DFLT_ESC_PROP));
} else {
rPropMap.setProperty( PROP_CharEscapement, sal_Int16(0));
rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(100)); // 100%
}
float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
rPropMap.setProperty( PROP_CharWeight, fWeight);
rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
rPropMap.setProperty( PROP_CharPosture, eSlant);
rPropMap.setProperty( PROP_CharPostureAsian, eSlant);
rPropMap.setProperty( PROP_CharPostureComplex, eSlant);
bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
{
rPropMap.setProperty( PROP_CharUnderlineHasColor, true);
rPropMap.setProperty( PROP_CharUnderlineColor, maUnderlineColor.getColor( rFilter.getGraphicHelper() ));
}
// TODO If bUnderlineFillFollowText uFillTx (CT_TextUnderlineFillFollowText) is set, fill color of the underline should be the same color as the text
if( maHighlightColor.isUsed() )
rPropMap.setProperty( PROP_CharBackColor, maHighlightColor.getColor( rFilter.getGraphicHelper() ));
}
static void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfPropertyValues )
{
if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfPropertyValues.empty())
return;
Sequence<PropertyValue> aGrabBag;
Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);<--- Variable 'aAnyGrabBag' is assigned a value that is never used.
aAnyGrabBag >>= aGrabBag;<--- Variable 'aAnyGrabBag' is assigned a value that is never used.
rPropSet.setAnyProperty(PROP_CharInteropGrabBag, makeAny(comphelper::concatSequences(aGrabBag, aVectorOfPropertyValues)));
}
void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
{
PropertyMap aPropMap;
pushToPropMap( aPropMap, rFilter );
rPropSet.setProperties( aPropMap );
pushToGrabBag(rPropSet, maTextEffectsProperties);
}
float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
{
return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
}
} // namespace oox::drawingml
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|