xref: /aoo4110/main/oox/source/vml/vmlformatting.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/vml/vmlformatting.hxx"
25 
26 #include <rtl/strbuf.hxx>
27 #include "oox/drawingml/color.hxx"
28 #include "oox/drawingml/drawingmltypes.hxx"
29 #include "oox/drawingml/fillproperties.hxx"
30 #include "oox/drawingml/lineproperties.hxx"
31 #include "oox/drawingml/shapepropertymap.hxx"
32 #include "oox/helper/attributelist.hxx"
33 #include "oox/helper/graphichelper.hxx"
34 
35 namespace oox {
36 namespace vml {
37 
38 // ============================================================================
39 
40 using namespace ::com::sun::star::geometry;
41 
42 using ::oox::drawingml::Color;
43 using ::oox::drawingml::FillProperties;
44 using ::oox::drawingml::LineArrowProperties;
45 using ::oox::drawingml::LineProperties;
46 using ::oox::drawingml::ShapePropertyMap;
47 using ::rtl::OStringBuffer;
48 using ::rtl::OUString;
49 
50 // ============================================================================
51 
52 namespace {
53 
lclExtractDouble(double & orfValue,sal_Int32 & ornEndPos,const OUString & rValue)54 bool lclExtractDouble( double& orfValue, sal_Int32& ornEndPos, const OUString& rValue )
55 {
56     // extract the double value and find start position of unit characters
57     rtl_math_ConversionStatus eConvStatus = rtl_math_ConversionStatus_Ok;
58     orfValue = ::rtl::math::stringToDouble( rValue, '.', '\0', &eConvStatus, &ornEndPos );
59     return eConvStatus == rtl_math_ConversionStatus_Ok;
60 }
61 
62 } // namespace
63 
64 // ----------------------------------------------------------------------------
65 
separatePair(OUString & orValue1,OUString & orValue2,const OUString & rValue,sal_Unicode cSep)66 /*static*/ bool ConversionHelper::separatePair( OUString& orValue1, OUString& orValue2,
67         const OUString& rValue, sal_Unicode cSep )
68 {
69     sal_Int32 nSepPos = rValue.indexOf( cSep );
70     if( nSepPos >= 0 )
71     {
72         orValue1 = rValue.copy( 0, nSepPos ).trim();
73         orValue2 = rValue.copy( nSepPos + 1 ).trim();
74     }
75     else
76     {
77         orValue1 = rValue.trim();
78     }
79     return (orValue1.getLength() > 0) && (orValue2.getLength() > 0);
80 }
81 
decodeBool(const OUString & rValue)82 /*static*/ bool ConversionHelper::decodeBool( const OUString& rValue )
83 {
84     sal_Int32 nToken = AttributeConversion::decodeToken( rValue );
85     // anything else than 't' or 'true' is considered to be false, as specified
86     return (nToken == XML_t) || (nToken == XML_true);
87 }
88 
decodePercent(const OUString & rValue,double fDefValue)89 /*static*/ double ConversionHelper::decodePercent( const OUString& rValue, double fDefValue )
90 {
91     if( rValue.getLength() == 0 )
92         return fDefValue;
93 
94     double fValue = 0.0;
95     sal_Int32 nEndPos = 0;
96     if( !lclExtractDouble( fValue, nEndPos, rValue ) )
97         return fDefValue;
98 
99     if( nEndPos == rValue.getLength() )
100         return fValue;
101 
102     if( (nEndPos + 1 == rValue.getLength()) && (rValue[ nEndPos ] == '%') )
103         return fValue / 100.0;
104 
105     OSL_ENSURE( false, "ConversionHelper::decodePercent - unknown measure unit" );
106     return fDefValue;
107 }
108 
decodeMeasureToEmu(const GraphicHelper & rGraphicHelper,const OUString & rValue,sal_Int32 nRefValue,bool bPixelX,bool bDefaultAsPixel)109 /*static*/ sal_Int64 ConversionHelper::decodeMeasureToEmu( const GraphicHelper& rGraphicHelper,
110         const OUString& rValue, sal_Int32 nRefValue, bool bPixelX, bool bDefaultAsPixel )
111 {
112     // default for missing values is 0
113     if( rValue.getLength() == 0 )
114         return 0;
115 
116     // TODO: according to spec, value may contain "auto"
117     if( rValue.equalsAscii( "auto" ) )
118     {
119         OSL_ENSURE( false, "ConversionHelper::decodeMeasureToEmu - special value 'auto' must be handled by caller" );
120         return nRefValue;
121     }
122 
123     // extract the double value and find start position of unit characters
124     double fValue = 0.0;
125     sal_Int32 nEndPos = 0;
126     if( !lclExtractDouble( fValue, nEndPos, rValue ) || (fValue == 0.0) )
127         return 0;
128 
129     // process trailing unit, convert to EMU
130     static const OUString saPx = CREATE_OUSTRING( "px" );
131     OUString aUnit;
132     if( (0 < nEndPos) && (nEndPos < rValue.getLength()) )
133         aUnit = rValue.copy( nEndPos );
134     else if( bDefaultAsPixel )
135         aUnit = saPx;
136     // else default is EMU
137 
138     if( aUnit.getLength() == 2 )
139     {
140         sal_Unicode cChar1 = aUnit[ 0 ];
141         sal_Unicode cChar2 = aUnit[ 1 ];
142         if( (cChar1 == 'i') && (cChar2 == 'n') )        // 1 inch = 914,400 EMU
143             fValue *= 914400.0;
144         else if( (cChar1 == 'c') && (cChar2 == 'm') )   // 1 cm = 360,000 EMU
145             fValue *= 360000.0;
146         else if( (cChar1 == 'm') && (cChar2 == 'm') )   // 1 mm = 36,000 EMU
147             fValue *= 36000.0;
148         else if( (cChar1 == 'p') && (cChar2 == 't') )   // 1 point = 1/72 inch = 12,700 MEU
149             fValue *= 12700.0;
150         else if( (cChar1 == 'p') && (cChar2 == 'c') )   // 1 pica = 1/6 inch = 152,400 EMU
151             fValue *= 152400.0;
152         else if( (cChar1 == 'p') && (cChar2 == 'x') )   // 1 pixel, dependent on output device
153             fValue = static_cast< double >( ::oox::drawingml::convertHmmToEmu(
154                 bPixelX ?
155                     rGraphicHelper.convertScreenPixelXToHmm( fValue ) :
156                     rGraphicHelper.convertScreenPixelYToHmm( fValue ) ) );
157     }
158     else if( (aUnit.getLength() == 1) && (aUnit[ 0 ] == '%') )
159     {
160         fValue *= nRefValue / 100.0;
161     }
162     else if( bDefaultAsPixel || (aUnit.getLength() > 0) )   // default as EMU and no unit -> do nothing
163     {
164         OSL_ENSURE( false, "ConversionHelper::decodeMeasureToEmu - unknown measure unit" );
165         fValue = nRefValue;
166     }
167     return static_cast< sal_Int64 >( fValue + 0.5 );
168 }
169 
decodeMeasureToHmm(const GraphicHelper & rGraphicHelper,const OUString & rValue,sal_Int32 nRefValue,bool bPixelX,bool bDefaultAsPixel)170 /*static*/ sal_Int32 ConversionHelper::decodeMeasureToHmm( const GraphicHelper& rGraphicHelper,
171         const OUString& rValue, sal_Int32 nRefValue, bool bPixelX, bool bDefaultAsPixel )
172 {
173     return ::oox::drawingml::convertEmuToHmm( decodeMeasureToEmu( rGraphicHelper, rValue, nRefValue, bPixelX, bDefaultAsPixel ) );
174 }
175 
decodeColor(const GraphicHelper & rGraphicHelper,const OptValue<OUString> & roVmlColor,const OptValue<double> & roVmlOpacity,sal_Int32 nDefaultRgb,sal_Int32 nPrimaryRgb)176 /*static*/ Color ConversionHelper::decodeColor( const GraphicHelper& rGraphicHelper,
177         const OptValue< OUString >& roVmlColor, const OptValue< double >& roVmlOpacity,
178         sal_Int32 nDefaultRgb, sal_Int32 nPrimaryRgb )
179 {
180     Color aDmlColor;
181 
182     // convert opacity
183     const sal_Int32 DML_FULL_OPAQUE = ::oox::drawingml::MAX_PERCENT;
184     double fOpacity = roVmlOpacity.get( 1.0 );
185     sal_Int32 nOpacity = getLimitedValue< sal_Int32, double >( fOpacity * DML_FULL_OPAQUE, 0, DML_FULL_OPAQUE );
186     if( nOpacity < DML_FULL_OPAQUE )
187         aDmlColor.addTransformation( XML_alpha, nOpacity );
188 
189     // color attribute not present - set passed default color
190     if( !roVmlColor.has() )
191     {
192         aDmlColor.setSrgbClr( nDefaultRgb );
193         return aDmlColor;
194     }
195 
196     // separate leading color name or RGB value from following palette index
197     OUString aColorName, aColorIndex;
198     separatePair( aColorName, aColorIndex, roVmlColor.get(), ' ' );
199 
200     // RGB colors in the format '#RRGGBB'
201     if( (aColorName.getLength() == 7) && (aColorName[ 0 ] == '#') )
202     {
203         aDmlColor.setSrgbClr( aColorName.copy( 1 ).toInt32( 16 ) );
204         return aDmlColor;
205     }
206 
207     // RGB colors in the format '#RGB'
208     if( (aColorName.getLength() == 4) && (aColorName[ 0 ] == '#') )
209     {
210         sal_Int32 nR = aColorName.copy( 1, 1 ).toInt32( 16 ) * 0x11;
211         sal_Int32 nG = aColorName.copy( 2, 1 ).toInt32( 16 ) * 0x11;
212         sal_Int32 nB = aColorName.copy( 3, 1 ).toInt32( 16 ) * 0x11;
213         aDmlColor.setSrgbClr( (nR << 16) | (nG << 8) | nB );
214         return aDmlColor;
215     }
216 
217     /*  Predefined color names or system color names (resolve to RGB to detect
218         valid color name). */
219     sal_Int32 nColorToken = AttributeConversion::decodeToken( aColorName );
220     sal_Int32 nRgbValue = Color::getVmlPresetColor( nColorToken, API_RGB_TRANSPARENT );
221     if( nRgbValue == API_RGB_TRANSPARENT )
222         nRgbValue = rGraphicHelper.getSystemColor( nColorToken, API_RGB_TRANSPARENT );
223     if( nRgbValue != API_RGB_TRANSPARENT )
224     {
225         aDmlColor.setSrgbClr( nRgbValue );
226         return aDmlColor;
227     }
228 
229     // try palette colors enclosed in brackets
230     if( (aColorIndex.getLength() >= 3) && (aColorIndex[ 0 ] == '[') && (aColorIndex[ aColorIndex.getLength() - 1 ] == ']') )
231     {
232         aDmlColor.setPaletteClr( aColorIndex.copy( 1, aColorIndex.getLength() - 2 ).toInt32() );
233         return aDmlColor;
234     }
235 
236     // try fill gradient modificator 'fill <modifier>(<amount>)'
237     if( (nPrimaryRgb != API_RGB_TRANSPARENT) && (nColorToken == XML_fill) )
238     {
239         sal_Int32 nOpenParen = aColorIndex.indexOf( '(' );
240         sal_Int32 nCloseParen = aColorIndex.indexOf( ')' );
241         if( (2 <= nOpenParen) && (nOpenParen + 1 < nCloseParen) && (nCloseParen + 1 == aColorIndex.getLength()) )
242         {
243             sal_Int32 nModToken = XML_TOKEN_INVALID;
244             switch( AttributeConversion::decodeToken( aColorIndex.copy( 0, nOpenParen ) ) )
245             {
246                 case XML_darken:    nModToken = XML_shade;
247                 case XML_lighten:   nModToken = XML_tint;
248             }
249             sal_Int32 nValue = aColorIndex.copy( nOpenParen + 1, nCloseParen - nOpenParen - 1 ).toInt32();
250             if( (nModToken != XML_TOKEN_INVALID) && (0 <= nValue) && (nValue < 255) )
251             {
252                 /*  Simulate this modifier color by a color with related transformation.
253                     The modifier amount has to be converted from the range [0;255] to
254                     percentage [0;100000] used by DrawingML. */
255                 aDmlColor.setSrgbClr( nPrimaryRgb );
256                 aDmlColor.addTransformation( nModToken, static_cast< sal_Int32 >( nValue * ::oox::drawingml::MAX_PERCENT / 255 ) );
257                 return aDmlColor;
258             }
259         }
260     }
261 
262     OSL_ENSURE( false, OStringBuffer( "ConversionHelper::decodeColor - invalid VML color name '" ).
263         append( OUStringToOString( roVmlColor.get(), RTL_TEXTENCODING_ASCII_US ) ).append( '\'' ).getStr() );
264     aDmlColor.setSrgbClr( nDefaultRgb );
265     return aDmlColor;
266 }
267 
268 // ============================================================================
269 
270 namespace {
271 
lclGetEmu(const GraphicHelper & rGraphicHelper,const OptValue<OUString> & roValue,sal_Int64 nDefValue)272 sal_Int64 lclGetEmu( const GraphicHelper& rGraphicHelper, const OptValue< OUString >& roValue, sal_Int64 nDefValue )
273 {
274     return roValue.has() ? ConversionHelper::decodeMeasureToEmu( rGraphicHelper, roValue.get(), 0, false, false ) : nDefValue;
275 }
276 
lclGetDmlLineDash(OptValue<sal_Int32> & oroPresetDash,LineProperties::DashStopVector & orCustomDash,const OptValue<OUString> & roDashStyle)277 void lclGetDmlLineDash( OptValue< sal_Int32 >& oroPresetDash, LineProperties::DashStopVector& orCustomDash, const OptValue< OUString >& roDashStyle )
278 {
279     if( roDashStyle.has() )
280     {
281         const OUString& rDashStyle = roDashStyle.get();
282         switch( AttributeConversion::decodeToken( rDashStyle ) )
283         {
284             case XML_solid:             oroPresetDash = XML_solid;          return;
285             case XML_shortdot:          oroPresetDash = XML_sysDot;         return;
286             case XML_shortdash:         oroPresetDash = XML_sysDash;        return;
287             case XML_shortdashdot:      oroPresetDash = XML_sysDashDot;     return;
288             case XML_shortdashdotdot:   oroPresetDash = XML_sysDashDotDot;  return;
289             case XML_dot:               oroPresetDash = XML_dot;            return;
290             case XML_dash:              oroPresetDash = XML_dash;           return;
291             case XML_dashdot:           oroPresetDash = XML_dashDot;        return;
292             case XML_longdash:          oroPresetDash = XML_lgDash;         return;
293             case XML_longdashdot:       oroPresetDash = XML_lgDashDot;      return;
294             case XML_longdashdotdot:    oroPresetDash = XML_lgDashDotDot;   return;
295 
296             // try to convert user-defined dash style
297             default:
298             {
299                 ::std::vector< sal_Int32 > aValues;
300                 sal_Int32 nIndex = 0;
301                 while( nIndex >= 0 )
302                     aValues.push_back( rDashStyle.getToken( 0, ' ', nIndex ).toInt32() );
303                 size_t nPairs = aValues.size() / 2; // ignore last value if size is odd
304                 for( size_t nPairIdx = 0; nPairIdx < nPairs; ++nPairIdx )
305                     orCustomDash.push_back( LineProperties::DashStop( aValues[ 2 * nPairIdx ], aValues[ 2 * nPairIdx + 1 ] ) );
306             }
307         }
308     }
309 }
310 
lclGetDmlArrowType(const OptValue<sal_Int32> & roArrowType)311 sal_Int32 lclGetDmlArrowType( const OptValue< sal_Int32 >& roArrowType )
312 {
313     if( roArrowType.has() ) switch( roArrowType.get() )
314     {
315         case XML_none:      return XML_none;
316         case XML_block:     return XML_triangle;
317         case XML_classic:   return XML_stealth;
318         case XML_diamond:   return XML_diamond;
319         case XML_oval:      return XML_oval;
320         case XML_open:      return XML_arrow;
321     }
322     return XML_none;
323 }
324 
lclGetDmlArrowWidth(const OptValue<sal_Int32> & roArrowWidth)325 sal_Int32 lclGetDmlArrowWidth( const OptValue< sal_Int32 >& roArrowWidth )
326 {
327     if( roArrowWidth.has() ) switch( roArrowWidth.get() )
328     {
329         case XML_narrow:    return XML_sm;
330         case XML_medium:    return XML_med;
331         case XML_wide:      return XML_lg;
332     }
333     return XML_med;
334 }
335 
lclGetDmlArrowLength(const OptValue<sal_Int32> & roArrowLength)336 sal_Int32 lclGetDmlArrowLength( const OptValue< sal_Int32 >& roArrowLength )
337 {
338     if( roArrowLength.has() ) switch( roArrowLength.get() )
339     {
340         case XML_short:     return XML_sm;
341         case XML_medium:    return XML_med;
342         case XML_long:      return XML_lg;
343     }
344     return XML_med;
345 }
346 
lclConvertArrow(LineArrowProperties & orArrowProp,const StrokeArrowModel & rStrokeArrow)347 void lclConvertArrow( LineArrowProperties& orArrowProp, const StrokeArrowModel& rStrokeArrow )
348 {
349     orArrowProp.moArrowType = lclGetDmlArrowType( rStrokeArrow.moArrowType );
350     orArrowProp.moArrowWidth = lclGetDmlArrowWidth( rStrokeArrow.moArrowWidth );
351     orArrowProp.moArrowLength = lclGetDmlArrowLength( rStrokeArrow.moArrowLength );
352 }
353 
lclGetDmlLineCompound(const OptValue<sal_Int32> & roLineStyle)354 sal_Int32 lclGetDmlLineCompound( const OptValue< sal_Int32 >& roLineStyle )
355 {
356     if( roLineStyle.has() ) switch( roLineStyle.get() )
357     {
358         case XML_single:            return XML_sng;
359         case XML_thinThin:          return XML_dbl;
360         case XML_thinThick:         return XML_thinThick;
361         case XML_thickThin:         return XML_thickThin;
362         case XML_thickBetweenThin:  return XML_tri;
363     }
364     return XML_sng;
365 }
366 
lclGetDmlLineCap(const OptValue<sal_Int32> & roEndCap)367 sal_Int32 lclGetDmlLineCap( const OptValue< sal_Int32 >& roEndCap )
368 {
369     if( roEndCap.has() ) switch( roEndCap.get() )
370     {
371         case XML_flat:      return XML_flat;
372         case XML_square:    return XML_sq;
373         case XML_round:     return XML_rnd;
374     }
375     return XML_flat;    // different defaults in VML (flat) and DrawingML (square)
376 }
377 
lclGetDmlLineJoint(const OptValue<sal_Int32> & roJoinStyle)378 sal_Int32 lclGetDmlLineJoint( const OptValue< sal_Int32 >& roJoinStyle )
379 {
380     if( roJoinStyle.has() ) switch( roJoinStyle.get() )
381     {
382         case XML_round: return XML_round;
383         case XML_bevel: return XML_bevel;
384         case XML_miter: return XML_miter;
385     }
386     return XML_round;
387 }
388 
389 } // namespace
390 
391 // ============================================================================
392 
assignUsed(const StrokeArrowModel & rSource)393 void StrokeArrowModel::assignUsed( const StrokeArrowModel& rSource )
394 {
395     moArrowType.assignIfUsed( rSource.moArrowType );
396     moArrowWidth.assignIfUsed( rSource.moArrowWidth );
397     moArrowLength.assignIfUsed( rSource.moArrowLength );
398 }
399 
400 // ============================================================================
401 
assignUsed(const StrokeModel & rSource)402 void StrokeModel::assignUsed( const StrokeModel& rSource )
403 {
404     moStroked.assignIfUsed( rSource.moStroked );
405     maStartArrow.assignUsed( rSource.maStartArrow );
406     maEndArrow.assignUsed( rSource.maEndArrow );
407     moColor.assignIfUsed( rSource.moColor );
408     moOpacity.assignIfUsed( rSource.moOpacity );
409     moWeight.assignIfUsed( rSource.moWeight );
410     moDashStyle.assignIfUsed( rSource.moDashStyle );
411     moLineStyle.assignIfUsed( rSource.moLineStyle );
412     moEndCap.assignIfUsed( rSource.moEndCap );
413     moJoinStyle.assignIfUsed( rSource.moJoinStyle );
414 }
415 
pushToPropMap(ShapePropertyMap & rPropMap,const GraphicHelper & rGraphicHelper) const416 void StrokeModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper ) const
417 {
418     /*  Convert VML line formatting to DrawingML line formatting and let the
419         DrawingML code do the hard work. */
420     LineProperties aLineProps;
421 
422     if( moStroked.get( true ) )
423     {
424         aLineProps.maLineFill.moFillType = XML_solidFill;
425         lclConvertArrow( aLineProps.maStartArrow, maStartArrow );
426         lclConvertArrow( aLineProps.maEndArrow, maEndArrow );
427         aLineProps.maLineFill.maFillColor = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_BLACK );
428         aLineProps.moLineWidth = getLimitedValue< sal_Int32, sal_Int64 >( lclGetEmu( rGraphicHelper, moWeight, 1 ), 0, SAL_MAX_INT32 );
429         lclGetDmlLineDash( aLineProps.moPresetDash, aLineProps.maCustomDash, moDashStyle );
430         aLineProps.moLineCompound = lclGetDmlLineCompound( moLineStyle );
431         aLineProps.moLineCap = lclGetDmlLineCap( moEndCap );
432         aLineProps.moLineJoint = lclGetDmlLineJoint( moJoinStyle );
433     }
434     else
435     {
436         aLineProps.maLineFill.moFillType = XML_noFill;
437     }
438 
439     aLineProps.pushToPropMap( rPropMap, rGraphicHelper );
440 }
441 
442 // ============================================================================
443 
assignUsed(const FillModel & rSource)444 void FillModel::assignUsed( const FillModel& rSource )
445 {
446     moFilled.assignIfUsed( rSource.moFilled );
447     moColor.assignIfUsed( rSource.moColor );
448     moOpacity.assignIfUsed( rSource.moOpacity );
449     moColor2.assignIfUsed( rSource.moColor2 );
450     moOpacity2.assignIfUsed( rSource.moOpacity2 );
451     moType.assignIfUsed( rSource.moType );
452     moAngle.assignIfUsed( rSource.moAngle );
453     moFocus.assignIfUsed( rSource.moFocus );
454     moFocusPos.assignIfUsed( rSource.moFocusPos );
455     moFocusSize.assignIfUsed( rSource.moFocusSize );
456     moBitmapPath.assignIfUsed( rSource.moBitmapPath );
457     moRotate.assignIfUsed( rSource.moRotate );
458 }
459 
pushToPropMap(ShapePropertyMap & rPropMap,const GraphicHelper & rGraphicHelper) const460 void FillModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper ) const
461 {
462     /*  Convert VML fill formatting to DrawingML fill formatting and let the
463         DrawingML code do the hard work. */
464     FillProperties aFillProps;
465 
466     if( moFilled.get( true ) )
467     {
468         sal_Int32 nFillType = moType.get( XML_solid );
469         switch( nFillType )
470         {
471             case XML_gradient:
472             case XML_gradientRadial:
473             {
474                 aFillProps.moFillType = XML_gradFill;
475                 aFillProps.maGradientProps.moRotateWithShape = moRotate.get( false );
476                 double fFocus = moFocus.get( 0.0 );
477 
478                 // prepare colors
479                 Color aColor1 = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_WHITE );
480                 Color aColor2 = ConversionHelper::decodeColor( rGraphicHelper, moColor2, moOpacity2, API_RGB_WHITE, aColor1.getColor( rGraphicHelper ) );
481 
482                 // type XML_gradient is linear or axial gradient
483                 if( nFillType == XML_gradient )
484                 {
485                     // normalize angle to range [0;360) degrees
486                     sal_Int32 nVmlAngle = getIntervalValue< sal_Int32, sal_Int32 >( moAngle.get( 0 ), 0, 360 );
487 
488                     // focus of -50% or 50% is axial gradient
489                     if( ((-0.75 <= fFocus) && (fFocus <= -0.25)) || ((0.25 <= fFocus) && (fFocus <= 0.75)) )
490                     {
491                         /*  According to spec, focus of 50% is outer-to-inner,
492                             and -50% is inner-to-outer (color to color2).
493                             BUT: For angles >= 180 deg., the behaviour is
494                             reversed... that's not spec'ed of course. So,
495                             [0;180) deg. and 50%, or [180;360) deg. and -50% is
496                             outer-to-inner in fact. */
497                         bool bOuterToInner = (fFocus > 0.0) == (nVmlAngle < 180);
498                         // simulate axial gradient by 3-step DrawingML gradient
499                         const Color& rOuterColor = bOuterToInner ? aColor1 : aColor2;
500                         const Color& rInnerColor = bOuterToInner ? aColor2 : aColor1;
501                         aFillProps.maGradientProps.maGradientStops[ 0.0 ] = aFillProps.maGradientProps.maGradientStops[ 1.0 ] = rOuterColor;
502                         aFillProps.maGradientProps.maGradientStops[ 0.5 ] = rInnerColor;
503                     }
504                     else    // focus of -100%, 0%, and 100% is linear gradient
505                     {
506                         /*  According to spec, focus of -100% or 100% swaps the
507                             start and stop colors, effectively reversing the
508                             gradient. BUT: For angles >= 180 deg., the
509                             behaviour is reversed. This means that in this case
510                             a focus of 0% swaps the gradient. */
511                         if( ((fFocus < -0.75) || (fFocus > 0.75)) == (nVmlAngle < 180) )
512                             (nVmlAngle += 180) %= 360;
513                         // set the start and stop colors
514                         aFillProps.maGradientProps.maGradientStops[ 0.0 ] = aColor1;
515                         aFillProps.maGradientProps.maGradientStops[ 1.0 ] = aColor2;
516                     }
517 
518                     // VML counts counterclockwise from bottom, DrawingML clockwise from left
519                     sal_Int32 nDmlAngle = (630 - nVmlAngle) % 360;
520                     aFillProps.maGradientProps.moShadeAngle = nDmlAngle * ::oox::drawingml::PER_DEGREE;
521                 }
522                 else    // XML_gradientRadial is rectangular gradient
523                 {
524                     aFillProps.maGradientProps.moGradientPath = XML_rect;
525                     // convert VML focus position and size to DrawingML fill-to-rect
526                     DoublePair aFocusPos = moFocusPos.get( DoublePair( 0.0, 0.0 ) );
527                     DoublePair aFocusSize = moFocusSize.get( DoublePair( 0.0, 0.0 ) );
528                     double fLeft   = getLimitedValue< double, double >( aFocusPos.first, 0.0, 1.0 );
529                     double fTop    = getLimitedValue< double, double >( aFocusPos.second, 0.0, 1.0 );
530                     double fRight  = getLimitedValue< double, double >( fLeft + aFocusSize.first, fLeft, 1.0 );
531                     double fBottom = getLimitedValue< double, double >( fTop + aFocusSize.second, fTop, 1.0 );
532                     aFillProps.maGradientProps.moFillToRect = IntegerRectangle2D(
533                         static_cast< sal_Int32 >( fLeft * ::oox::drawingml::MAX_PERCENT ),
534                         static_cast< sal_Int32 >( fTop * ::oox::drawingml::MAX_PERCENT ),
535                         static_cast< sal_Int32 >( (1.0 - fRight) * ::oox::drawingml::MAX_PERCENT ),
536                         static_cast< sal_Int32 >( (1.0 - fBottom) * ::oox::drawingml::MAX_PERCENT ) );
537 
538                     // set the start and stop colors (focus of 0% means outer-to-inner)
539                     bool bOuterToInner = (-0.5 <= fFocus) && (fFocus <= 0.5);
540                     aFillProps.maGradientProps.maGradientStops[ 0.0 ] = bOuterToInner ? aColor2 : aColor1;
541                     aFillProps.maGradientProps.maGradientStops[ 1.0 ] = bOuterToInner ? aColor1 : aColor2;
542                 }
543             }
544             break;
545 
546             case XML_pattern:
547             case XML_tile:
548             case XML_frame:
549             {
550                 if( moBitmapPath.has() && moBitmapPath.get().getLength() > 0 )
551                 {
552                     aFillProps.maBlipProps.mxGraphic = rGraphicHelper.importEmbeddedGraphic( moBitmapPath.get() );
553                     if( aFillProps.maBlipProps.mxGraphic.is() )
554                     {
555                         aFillProps.moFillType = XML_blipFill;
556                         aFillProps.maBlipProps.moBitmapMode = (nFillType == XML_frame) ? XML_stretch : XML_tile;
557                         break;  // do not break if bitmap is missing, but run to XML_solid instead
558                     }
559                 }
560             }
561             // run-through to XML_solid in case of missing bitmap path intended!
562 
563             case XML_solid:
564             default:
565             {
566                 aFillProps.moFillType = XML_solidFill;
567                 // fill color (default is white)
568                 aFillProps.maFillColor = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_WHITE );
569             }
570         }
571     }
572     else
573     {
574         aFillProps.moFillType = XML_noFill;
575     }
576 
577     aFillProps.pushToPropMap( rPropMap, rGraphicHelper );
578 }
579 
580 // ============================================================================
581 
582 } // namespace vml
583 } // namespace oox
584