fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / drawingml / linepropertiescontext.cxx
blobbc5395dab4d7709b3085b1f8c7f1a184d0824ab3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/linepropertiescontext.hxx"
21 #include "oox/drawingml/drawingmltypes.hxx"
22 #include "drawingml/fillpropertiesgroupcontext.hxx"
23 #include "oox/drawingml/lineproperties.hxx"
24 #include "oox/helper/attributelist.hxx"
26 using namespace ::oox::core;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::xml::sax;
30 // CT_LineProperties
32 namespace oox { namespace drawingml {
34 LinePropertiesContext::LinePropertiesContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs,
35 LineProperties& rLineProperties ) throw()
36 : ContextHandler2( rParent )
37 , mrLineProperties( rLineProperties )
39 mrLineProperties.moLineWidth = rAttribs.getInteger( XML_w );
40 mrLineProperties.moLineCompound = rAttribs.getToken( XML_cmpd );
41 mrLineProperties.moLineCap = rAttribs.getToken( XML_cap );
44 LinePropertiesContext::~LinePropertiesContext()
48 ContextHandlerRef LinePropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
50 switch( nElement )
52 // LineFillPropertiesGroup
53 case A_TOKEN( noFill ):
54 case A_TOKEN( solidFill ):
55 case A_TOKEN( gradFill ):
56 case A_TOKEN( pattFill ):
57 return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, mrLineProperties.maLineFill );
58 break;
60 // LineDashPropertiesGroup
61 case A_TOKEN( prstDash ): // CT_PresetLineDashProperties
62 mrLineProperties.moPresetDash = rAttribs.getToken( XML_val );
63 break;
64 case A_TOKEN( custDash ): // CT_DashStopList
65 return this;
66 break;
67 case A_TOKEN( ds ):
69 // 'a:ds' has 2 attributes : 'd' and 'sp'
70 // both are of type 'a:ST_PositivePercentage'
71 // according to the specs Office will read percentages formatted with a trailing percent sign
72 // or formatted as 1000th of a percent without a trailing percent sign, but only write percentages
73 // as 1000th's of a percent without a trailing percent sign.
74 // The code below takes care of both scenarios by converting to '1000th of a percent' always
75 OUString aStr;
76 sal_Int32 nDash = 0;
77 aStr = rAttribs.getString( XML_d, "" );
78 if ( aStr.endsWith("%") )
80 // Ends with a '%'
81 aStr = aStr.copy(0, aStr.getLength() - 1);
82 aStr = aStr.trim();
83 nDash = aStr.toInt32();
85 // Convert to 1000th of a percent
86 nDash *= 1000;
88 else
90 nDash = rAttribs.getInteger( XML_d, 0 );
93 sal_Int32 nSp = 0;
94 aStr = rAttribs.getString( XML_sp, "" );
95 if ( aStr.endsWith("%") )
97 // Ends with a '%'
98 aStr = aStr.copy(0, aStr.getLength() - 1);
99 aStr = aStr.trim();
100 nSp = aStr.toInt32();
102 // Convert to 1000th of a percent
103 nSp *= 1000;
105 else
107 nSp = rAttribs.getInteger( XML_sp, 0 );
110 mrLineProperties.maCustomDash.push_back( LineProperties::DashStop( nDash, nSp ) );
112 break;
114 // LineJoinPropertiesGroup
115 case A_TOKEN( round ):
116 case A_TOKEN( bevel ):
117 case A_TOKEN( miter ):
118 mrLineProperties.moLineJoint = getBaseToken( nElement );
119 break;
121 case A_TOKEN( headEnd ): // CT_LineEndProperties
122 case A_TOKEN( tailEnd ): // CT_LineEndProperties
123 { // ST_LineEndType
124 bool bTailEnd = nElement == A_TOKEN( tailEnd );
125 LineArrowProperties& rArrowProps = bTailEnd ? mrLineProperties.maEndArrow : mrLineProperties.maStartArrow;
126 rArrowProps.moArrowType = rAttribs.getToken( XML_type );
127 rArrowProps.moArrowWidth = rAttribs.getToken( XML_w );
128 rArrowProps.moArrowLength = rAttribs.getToken( XML_len );
130 break;
132 return 0;
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */