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/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
;
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
)
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
);
60 // LineDashPropertiesGroup
61 case A_TOKEN( prstDash
): // CT_PresetLineDashProperties
62 mrLineProperties
.moPresetDash
= rAttribs
.getToken( XML_val
);
64 case A_TOKEN( custDash
): // CT_DashStopList
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
77 aStr
= rAttribs
.getString( XML_d
, "" );
78 if ( aStr
.endsWith("%") )
81 aStr
= aStr
.copy(0, aStr
.getLength() - 1);
83 nDash
= aStr
.toInt32();
85 // Convert to 1000th of a percent
90 nDash
= rAttribs
.getInteger( XML_d
, 0 );
94 aStr
= rAttribs
.getString( XML_sp
, "" );
95 if ( aStr
.endsWith("%") )
98 aStr
= aStr
.copy(0, aStr
.getLength() - 1);
100 nSp
= aStr
.toInt32();
102 // Convert to 1000th of a percent
107 nSp
= rAttribs
.getInteger( XML_sp
, 0 );
110 mrLineProperties
.maCustomDash
.push_back( LineProperties::DashStop( nDash
, nSp
) );
114 // LineJoinPropertiesGroup
115 case A_TOKEN( round
):
116 case A_TOKEN( bevel
):
117 case A_TOKEN( miter
):
118 mrLineProperties
.moLineJoint
= getBaseToken( nElement
);
121 case A_TOKEN( headEnd
): // CT_LineEndProperties
122 case A_TOKEN( tailEnd
): // CT_LineEndProperties
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
);
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */