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 <drawingml/textcharacterproperties.hxx>
21 #include <com/sun/star/lang/Locale.hpp>
22 #include <com/sun/star/awt/FontSlant.hpp>
23 #include <com/sun/star/awt/FontWeight.hpp>
24 #include <com/sun/star/i18n/ScriptType.hpp>
25 #include <comphelper/sequence.hxx>
26 #include <i18nlangtag/languagetag.hxx>
27 #include <i18nlangtag/mslangid.hxx>
28 #include <editeng/escapementitem.hxx>
29 #include <oox/helper/helper.hxx>
30 #include <oox/helper/propertyset.hxx>
31 #include <oox/core/xmlfilterbase.hxx>
32 #include <oox/drawingml/drawingmltypes.hxx>
33 #include <oox/token/properties.hxx>
34 #include <oox/token/tokens.hxx>
35
36 using ::oox::core::XmlFilterBase;
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40
41 namespace oox {
42 namespace drawingml {
43
assignUsed(const TextCharacterProperties & rSourceProps)44 void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSourceProps )
45 {
46 // overwrite all properties existing in rSourceProps
47 maHyperlinkPropertyMap.assignUsed( rSourceProps.maHyperlinkPropertyMap );
48 maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
49 maLatinThemeFont.assignIfUsed( rSourceProps.maLatinThemeFont );
50 maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
51 maAsianThemeFont.assignIfUsed( rSourceProps.maAsianThemeFont );
52 maComplexFont.assignIfUsed( rSourceProps.maComplexFont );
53 maComplexThemeFont.assignIfUsed( rSourceProps.maComplexThemeFont );
54 maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
55 maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
56 maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
57 moLang.assignIfUsed( rSourceProps.moLang );
58 moHeight.assignIfUsed( rSourceProps.moHeight );
59 moFontScale.assignIfUsed(rSourceProps.moFontScale);
60 moSpacing.assignIfUsed( rSourceProps.moSpacing );
61 moUnderline.assignIfUsed( rSourceProps.moUnderline );
62 moBaseline.assignIfUsed( rSourceProps.moBaseline );
63 moStrikeout.assignIfUsed( rSourceProps.moStrikeout );
64 moCaseMap.assignIfUsed( rSourceProps.moCaseMap );
65 moBold.assignIfUsed( rSourceProps.moBold );
66 moItalic.assignIfUsed( rSourceProps.moItalic );
67 moUnderlineLineFollowText.assignIfUsed( rSourceProps.moUnderlineLineFollowText );
68 moUnderlineFillFollowText.assignIfUsed( rSourceProps.moUnderlineFillFollowText );
69
70 maTextEffectsProperties = rSourceProps.maTextEffectsProperties;
71 maFillProperties.assignUsed( rSourceProps.maFillProperties );
72 }
73
pushToPropMap(PropertyMap & rPropMap,const XmlFilterBase & rFilter) const74 void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter ) const
75 {
76 OUString aFontName;
77 sal_Int16 nFontPitch = 0;
78 sal_Int16 nFontFamily = 0;
79
80 bool bRet = maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
81 if (!bRet)
82 // In case there is no direct font, try to look it up as a theme reference.
83 bRet = maLatinThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
84 if (bRet)
85 {
86 rPropMap.setProperty( PROP_CharFontName, aFontName);
87 rPropMap.setProperty( PROP_CharFontPitch, nFontPitch);
88 rPropMap.setProperty( PROP_CharFontFamily, nFontFamily);
89 }
90
91 bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
92 if (!bRet)
93 bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
94 if (bRet)
95 {
96 rPropMap.setProperty( PROP_CharFontNameAsian, aFontName);
97 rPropMap.setProperty( PROP_CharFontPitchAsian, nFontFamily);
98 rPropMap.setProperty( PROP_CharFontFamilyAsian, nFontPitch);
99 }
100
101 bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
102 if (!bRet)
103 bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
104 if (bRet)
105 {
106 rPropMap.setProperty( PROP_CharFontNameComplex, aFontName);
107 rPropMap.setProperty( PROP_CharFontPitchComplex, nFontPitch);
108 rPropMap.setProperty( PROP_CharFontFamilyComplex, nFontFamily);
109 }
110
111 if ( maFillProperties.moFillType.has() )
112 rPropMap.setProperty( PROP_CharColor, maFillProperties.getBestSolidColor().getColor( rFilter.getGraphicHelper() ));
113
114 if( moLang.has() && !moLang.get().isEmpty() )
115 {
116 LanguageTag aTag(moLang.get());
117 lang::Locale aLocale(aTag.getLocale());
118 switch(MsLangId::getScriptType(aTag.getLanguageType()))
119 {
120 case css::i18n::ScriptType::LATIN:
121 rPropMap.setProperty( PROP_CharLocale, aLocale);break;
122 case css::i18n::ScriptType::ASIAN:
123 rPropMap.setProperty( PROP_CharLocaleAsian, aLocale);break;
124 case css::i18n::ScriptType::COMPLEX:
125 rPropMap.setProperty( PROP_CharLocaleComplex, aLocale);break;
126 }
127 }
128
129 if( moHeight.has() )
130 {
131 float fHeight = GetFontHeight( moHeight.get() );
132 if (moFontScale.has())
133 fHeight *= (moFontScale.get() / 100000);
134 rPropMap.setProperty( PROP_CharHeight, fHeight);
135 rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
136 rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
137 }
138
139 rPropMap.setProperty( PROP_CharKerning, static_cast<sal_Int16>(GetTextSpacingPoint( moSpacing.get( 0 ) )));
140
141 rPropMap.setProperty( PROP_CharUnderline, GetFontUnderline( moUnderline.get( XML_none ) ));
142 rPropMap.setProperty( PROP_CharStrikeout, GetFontStrikeout( moStrikeout.get( XML_noStrike ) ));
143 rPropMap.setProperty( PROP_CharCaseMap, GetCaseMap( moCaseMap.get( XML_none ) ));
144
145 if( moBaseline.has() ) {
146 rPropMap.setProperty( PROP_CharEscapement, sal_Int16(moBaseline.get( 0 ) / 1000));
147 rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(DFLT_ESC_PROP));
148 } else {
149 rPropMap.setProperty( PROP_CharEscapement, sal_Int16(0));
150 rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(100)); // 100%
151 }
152
153 float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
154 rPropMap.setProperty( PROP_CharWeight, fWeight);
155 rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
156 rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
157
158 awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
159 rPropMap.setProperty( PROP_CharPosture, eSlant);
160 rPropMap.setProperty( PROP_CharPostureAsian, eSlant);
161 rPropMap.setProperty( PROP_CharPostureComplex, eSlant);
162
163 bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
164 if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
165 {
166 rPropMap.setProperty( PROP_CharUnderlineHasColor, true);
167 rPropMap.setProperty( PROP_CharUnderlineColor, maUnderlineColor.getColor( rFilter.getGraphicHelper() ));
168 }
169 // TODO If bUnderlineFillFollowText uFillTx (CT_TextUnderlineFillFollowText) is set, fill color of the underline should be the same color as the text
170
171 if( maHighlightColor.isUsed() )
172 rPropMap.setProperty( PROP_CharBackColor, maHighlightColor.getColor( rFilter.getGraphicHelper() ));
173 }
174
pushToGrabBag(PropertySet & rPropSet,const std::vector<PropertyValue> & aVectorOfProperyValues)175 static void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfProperyValues )
176 {
177 if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfProperyValues.empty())
178 return;
179 Sequence<PropertyValue> aGrabBag;
180 Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);
181 aAnyGrabBag >>= aGrabBag;
182
183 rPropSet.setAnyProperty(PROP_CharInteropGrabBag, makeAny(comphelper::concatSequences(aGrabBag, aVectorOfProperyValues)));
184 }
185
pushToPropSet(PropertySet & rPropSet,const XmlFilterBase & rFilter) const186 void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter ) const
187 {
188 PropertyMap aPropMap;
189 pushToPropMap( aPropMap, rFilter );
190 rPropSet.setProperties( aPropMap );
191 pushToGrabBag(rPropSet, maTextEffectsProperties);
192 }
193
getCharHeightPoints(float fDefault) const194 float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
195 {
196 return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
197 }
198
199 } // namespace drawingml
200 } // namespace oox
201
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
203