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 .
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 <i18nlangtag/languagetag.hxx>
25 #include <editeng/escapementitem.hxx>
26 #include "oox/helper/helper.hxx"
27 #include "oox/helper/propertyset.hxx"
28 #include "oox/core/xmlfilterbase.hxx"
29 #include "oox/drawingml/drawingmltypes.hxx"
30 #include "oox/token/tokens.hxx"
32 using ::oox::core::XmlFilterBase
;
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::beans
;
40 void TextCharacterProperties::assignUsed( const TextCharacterProperties
& rSourceProps
)
42 // overwrite all properties exisiting in rSourceProps
43 maHyperlinkPropertyMap
.assignUsed( rSourceProps
.maHyperlinkPropertyMap
);
44 maLatinFont
.assignIfUsed( rSourceProps
.maLatinFont
);
45 maLatinThemeFont
.assignIfUsed( rSourceProps
.maLatinThemeFont
);
46 maAsianFont
.assignIfUsed( rSourceProps
.maAsianFont
);
47 maAsianThemeFont
.assignIfUsed( rSourceProps
.maAsianThemeFont
);
48 maComplexFont
.assignIfUsed( rSourceProps
.maComplexFont
);
49 maComplexThemeFont
.assignIfUsed( rSourceProps
.maComplexThemeFont
);
50 maSymbolFont
.assignIfUsed( rSourceProps
.maSymbolFont
);
51 maCharColor
.assignIfUsed( rSourceProps
.maCharColor
);
52 maHighlightColor
.assignIfUsed( rSourceProps
.maHighlightColor
);
53 maUnderlineColor
.assignIfUsed( rSourceProps
.maUnderlineColor
);
54 moHeight
.assignIfUsed( rSourceProps
.moHeight
);
55 moSpacing
.assignIfUsed( rSourceProps
.moSpacing
);
56 moUnderline
.assignIfUsed( rSourceProps
.moUnderline
);
57 moBaseline
.assignIfUsed( rSourceProps
.moBaseline
);
58 moStrikeout
.assignIfUsed( rSourceProps
.moStrikeout
);
59 moCaseMap
.assignIfUsed( rSourceProps
.moCaseMap
);
60 moBold
.assignIfUsed( rSourceProps
.moBold
);
61 moItalic
.assignIfUsed( rSourceProps
.moItalic
);
62 moUnderlineLineFollowText
.assignIfUsed( rSourceProps
.moUnderlineLineFollowText
);
63 moUnderlineFillFollowText
.assignIfUsed( rSourceProps
.moUnderlineFillFollowText
);
65 maTextEffectsProperties
= rSourceProps
.maTextEffectsProperties
;
66 maGradientProps
.assignUsed( rSourceProps
.maGradientProps
);
69 void TextCharacterProperties::pushToPropMap( PropertyMap
& rPropMap
, const XmlFilterBase
& rFilter
, bool bUseOptional
) const
72 sal_Int16 nFontPitch
= 0;
73 sal_Int16 nFontFamily
= 0;
75 bool bRet
= maLatinFont
.getFontData( aFontName
, nFontPitch
, nFontFamily
, rFilter
);
77 // In case there is no direct font, try to look it up as a theme reference.
78 bRet
= maLatinThemeFont
.getFontData( aFontName
, nFontPitch
, nFontFamily
, rFilter
);
81 rPropMap
.setProperty( PROP_CharFontName
, aFontName
);
82 rPropMap
.setProperty( PROP_CharFontPitch
, nFontPitch
);
83 rPropMap
.setProperty( PROP_CharFontFamily
, nFontFamily
);
86 bRet
= maAsianFont
.getFontData( aFontName
, nFontPitch
, nFontFamily
, rFilter
);
88 bRet
= maAsianThemeFont
.getFontData( aFontName
, nFontPitch
, nFontFamily
, rFilter
);
91 rPropMap
.setProperty( PROP_CharFontNameAsian
, aFontName
);
92 rPropMap
.setProperty( PROP_CharFontPitchAsian
, nFontFamily
);
93 rPropMap
.setProperty( PROP_CharFontFamilyAsian
, nFontPitch
);
96 bRet
= maComplexFont
.getFontData( aFontName
, nFontPitch
, nFontFamily
, rFilter
);
98 bRet
= maComplexThemeFont
.getFontData( aFontName
, nFontPitch
, nFontFamily
, rFilter
);
101 rPropMap
.setProperty( PROP_CharFontNameComplex
, aFontName
);
102 rPropMap
.setProperty( PROP_CharFontPitchComplex
, nFontPitch
);
103 rPropMap
.setProperty( PROP_CharFontFamilyComplex
, nFontFamily
);
106 // symbolfont, will now be ... textrun.cxx ... ausgewertet !!!i#113673
108 if( maCharColor
.isUsed() )
109 rPropMap
.setProperty( PROP_CharColor
, maCharColor
.getColor( rFilter
.getGraphicHelper() ));
110 if( maGradientProps
.maGradientStops
.size() > 0 )
111 rPropMap
.setProperty( PROP_CharColor
, maGradientProps
.maGradientStops
.begin()->second
.getColor( rFilter
.getGraphicHelper() ));
113 if( moLang
.has() && !moLang
.get().isEmpty() )
115 lang::Locale
aLocale( LanguageTag( moLang
.get()).getLocale());
116 rPropMap
.setProperty( PROP_CharLocale
, aLocale
);
117 rPropMap
.setProperty( PROP_CharLocaleAsian
, aLocale
);
118 rPropMap
.setProperty( PROP_CharLocaleComplex
, aLocale
);
123 float fHeight
= GetFontHeight( moHeight
.get() );
124 rPropMap
.setProperty( PROP_CharHeight
, fHeight
);
125 rPropMap
.setProperty( PROP_CharHeightAsian
, fHeight
);
126 rPropMap
.setProperty( PROP_CharHeightComplex
, fHeight
);
129 rPropMap
.setProperty( PROP_CharKerning
, (sal_Int16
) GetTextSpacingPoint( moSpacing
.get( 0 ) ));
131 rPropMap
.setProperty( PROP_CharUnderline
, GetFontUnderline( moUnderline
.get( XML_none
) ));
132 rPropMap
.setProperty( PROP_CharStrikeout
, GetFontStrikeout( moStrikeout
.get( XML_noStrike
) ));
133 rPropMap
.setProperty( PROP_CharCaseMap
, GetCaseMap( moCaseMap
.get( XML_none
) ));
135 if( moBaseline
.has() ) {
136 rPropMap
.setProperty( PROP_CharEscapement
, sal_Int16(moBaseline
.get( 0 ) / 1000));
137 rPropMap
.setProperty( PROP_CharEscapementHeight
, sal_Int8(DFLT_ESC_PROP
));
139 rPropMap
.setProperty( PROP_CharEscapement
, sal_Int16(0));
140 rPropMap
.setProperty( PROP_CharEscapementHeight
, sal_Int8(100)); // 100%
143 if( !bUseOptional
|| moBold
.has() ) {
144 float fWeight
= moBold
.get( false ) ? awt::FontWeight::BOLD
: awt::FontWeight::NORMAL
;
145 rPropMap
.setProperty( PROP_CharWeight
, fWeight
);
146 rPropMap
.setProperty( PROP_CharWeightAsian
, fWeight
);
147 rPropMap
.setProperty( PROP_CharWeightComplex
, fWeight
);
150 if( !bUseOptional
|| moItalic
.has() ) {
151 awt::FontSlant eSlant
= moItalic
.get( false ) ? awt::FontSlant_ITALIC
: awt::FontSlant_NONE
;
152 rPropMap
.setProperty( PROP_CharPosture
, eSlant
);
153 rPropMap
.setProperty( PROP_CharPostureAsian
, eSlant
);
154 rPropMap
.setProperty( PROP_CharPostureComplex
, eSlant
);
157 bool bUnderlineFillFollowText
= moUnderlineFillFollowText
.get( false );
158 if( moUnderline
.has() && maUnderlineColor
.isUsed() && !bUnderlineFillFollowText
)
160 rPropMap
.setProperty( PROP_CharUnderlineHasColor
, true);
161 rPropMap
.setProperty( PROP_CharUnderlineColor
, maUnderlineColor
.getColor( rFilter
.getGraphicHelper() ));
165 void pushToGrabBag( PropertySet
& rPropSet
, const std::vector
<PropertyValue
>& aVectorOfProperyValues
)
167 if (!rPropSet
.hasProperty(PROP_CharInteropGrabBag
) || aVectorOfProperyValues
.empty())
169 Sequence
<PropertyValue
> aGrabBag
;
170 Any aAnyGrabBag
= rPropSet
.getAnyProperty(PROP_CharInteropGrabBag
);
171 aAnyGrabBag
>>= aGrabBag
;
173 sal_Int32 nLength
= aGrabBag
.getLength();
174 aGrabBag
.realloc(nLength
+ aVectorOfProperyValues
.size());
176 for (size_t i
= 0; i
< aVectorOfProperyValues
.size(); i
++)
178 PropertyValue aPropertyValue
= aVectorOfProperyValues
[i
];
179 aGrabBag
[nLength
+ i
] = aPropertyValue
;
182 rPropSet
.setAnyProperty(PROP_CharInteropGrabBag
, makeAny(aGrabBag
));
185 void TextCharacterProperties::pushToPropSet( PropertySet
& rPropSet
, const XmlFilterBase
& rFilter
, bool bUseOptional
) const
187 PropertyMap aPropMap
;
188 pushToPropMap( aPropMap
, rFilter
, bUseOptional
);
189 rPropSet
.setProperties( aPropMap
);
190 pushToGrabBag(rPropSet
, maTextEffectsProperties
);
193 float TextCharacterProperties::getCharHeightPoints( float fDefault
) const
195 return moHeight
.has() ? GetFontHeight( moHeight
.get() ) : fDefault
;
198 } // namespace drawingml
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */