Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / linepropertiescontext.cxx
blob3dd7d50b8b1d78deba4a7d9319f8aae867bb9692
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/misccontexts.hxx>
23 #include <drawingml/lineproperties.hxx>
24 #include <oox/helper/attributelist.hxx>
25 #include <oox/token/namespaces.hxx>
26 #include <oox/token/tokens.hxx>
28 using namespace ::oox::core;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::xml::sax;
32 // CT_LineProperties
34 namespace oox { namespace drawingml {
36 LinePropertiesContext::LinePropertiesContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs,
37 LineProperties& rLineProperties ) throw()
38 : ContextHandler2( rParent )
39 , mrLineProperties( rLineProperties )
41 mrLineProperties.moLineWidth = rAttribs.getInteger( XML_w );
42 mrLineProperties.moLineCompound = rAttribs.getToken( XML_cmpd );
43 mrLineProperties.moLineCap = rAttribs.getToken( XML_cap );
46 LinePropertiesContext::~LinePropertiesContext()
50 ContextHandlerRef LinePropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
52 switch( nElement )
54 // LineFillPropertiesGroup
55 case A_TOKEN( noFill ):
56 case A_TOKEN( solidFill ):
57 case A_TOKEN( gradFill ):
58 case A_TOKEN( pattFill ):
59 return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, mrLineProperties.maLineFill );
60 break;
62 // LineDashPropertiesGroup
63 case A_TOKEN( prstDash ): // CT_PresetLineDashProperties
64 mrLineProperties.moPresetDash = rAttribs.getToken( XML_val );
65 break;
66 case A_TOKEN( custDash ): // CT_DashStopList
67 return this;
68 break;
69 case A_TOKEN( ds ):
71 // 'a:ds' has 2 attributes : 'd' and 'sp'
72 // both are of type 'a:ST_PositivePercentage'
73 // according to the specs Office will read percentages formatted with a trailing percent sign
74 // or formatted as 1000th of a percent without a trailing percent sign, but only write percentages
75 // as 1000th's of a percent without a trailing percent sign.
76 // The code below takes care of both scenarios by converting to '1000th of a percent' always
77 OUString aStr;
78 sal_Int32 nDash = 0;
79 aStr = rAttribs.getString( XML_d, "" );
80 if ( aStr.endsWith("%") )
82 // Ends with a '%'
83 aStr = aStr.copy(0, aStr.getLength() - 1);
84 aStr = aStr.trim();
85 nDash = aStr.toInt32();
87 // Convert to 1000th of a percent
88 nDash *= 1000;
90 else
92 nDash = rAttribs.getInteger( XML_d, 0 );
95 sal_Int32 nSp = 0;
96 aStr = rAttribs.getString( XML_sp, "" );
97 if ( aStr.endsWith("%") )
99 // Ends with a '%'
100 aStr = aStr.copy(0, aStr.getLength() - 1);
101 aStr = aStr.trim();
102 nSp = aStr.toInt32();
104 // Convert to 1000th of a percent
105 nSp *= 1000;
107 else
109 nSp = rAttribs.getInteger( XML_sp, 0 );
112 mrLineProperties.maCustomDash.emplace_back( nDash, nSp );
114 break;
116 // LineJoinPropertiesGroup
117 case A_TOKEN( round ):
118 case A_TOKEN( bevel ):
119 case A_TOKEN( miter ):
120 mrLineProperties.moLineJoint = getBaseToken( nElement );
121 break;
123 case A_TOKEN( headEnd ): // CT_LineEndProperties
124 case A_TOKEN( tailEnd ): // CT_LineEndProperties
125 { // ST_LineEndType
126 bool bTailEnd = nElement == A_TOKEN( tailEnd );
127 LineArrowProperties& rArrowProps = bTailEnd ? mrLineProperties.maEndArrow : mrLineProperties.maStartArrow;
128 rArrowProps.moArrowType = rAttribs.getToken( XML_type );
129 rArrowProps.moArrowWidth = rAttribs.getToken( XML_w );
130 rArrowProps.moArrowLength = rAttribs.getToken( XML_len );
132 break;
134 return nullptr;
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */