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/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
;
34 namespace oox
{ namespace drawingml
{
36 LinePropertiesContext::LinePropertiesContext( ContextHandler2Helper
& 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
)
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
);
62 // LineDashPropertiesGroup
63 case A_TOKEN( prstDash
): // CT_PresetLineDashProperties
64 mrLineProperties
.moPresetDash
= rAttribs
.getToken( XML_val
);
66 case A_TOKEN( custDash
): // CT_DashStopList
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
79 aStr
= rAttribs
.getString( XML_d
, "" );
80 if ( aStr
.endsWith("%") )
83 aStr
= aStr
.copy(0, aStr
.getLength() - 1);
85 nDash
= aStr
.toInt32();
87 // Convert to 1000th of a percent
92 nDash
= rAttribs
.getInteger( XML_d
, 0 );
96 aStr
= rAttribs
.getString( XML_sp
, "" );
97 if ( aStr
.endsWith("%") )
100 aStr
= aStr
.copy(0, aStr
.getLength() - 1);
102 nSp
= aStr
.toInt32();
104 // Convert to 1000th of a percent
109 nSp
= rAttribs
.getInteger( XML_sp
, 0 );
112 mrLineProperties
.maCustomDash
.push_back( LineProperties::DashStop( nDash
, nSp
) );
116 // LineJoinPropertiesGroup
117 case A_TOKEN( round
):
118 case A_TOKEN( bevel
):
119 case A_TOKEN( miter
):
120 mrLineProperties
.moLineJoint
= getBaseToken( nElement
);
123 case A_TOKEN( headEnd
): // CT_LineEndProperties
124 case A_TOKEN( tailEnd
): // CT_LineEndProperties
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
);
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */