LibreOffice Module oox (master)  1
linepropertiescontext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
24 #include <oox/token/namespaces.hxx>
25 #include <oox/token/tokens.hxx>
26 
27 using namespace ::oox::core;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::xml::sax;
30 
31 // CT_LineProperties
32 
33 namespace oox::drawingml {
34 
36  LineProperties& rLineProperties ) noexcept
37 : ContextHandler2( rParent )
38 , mrLineProperties( rLineProperties )
39 {
40  mrLineProperties.moLineWidth = rAttribs.getInteger( XML_w );
41  mrLineProperties.moLineCompound = rAttribs.getToken( XML_cmpd );
42  mrLineProperties.moLineCap = rAttribs.getToken( XML_cap );
43 }
44 
46 {
47 }
48 
50 {
51  switch( nElement )
52  {
53  // LineFillPropertiesGroup
54  case A_TOKEN( noFill ):
55  case A_TOKEN( solidFill ):
56  case A_TOKEN( gradFill ):
57  case A_TOKEN( pattFill ):
58  return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, mrLineProperties.maLineFill );
59  break;
60 
61  // LineDashPropertiesGroup
62  case A_TOKEN( prstDash ): // CT_PresetLineDashProperties
63  mrLineProperties.moPresetDash = rAttribs.getToken( XML_val );
64  break;
65  case A_TOKEN( custDash ): // CT_DashStopList
66  return this;
67  case A_TOKEN( ds ):
68  {
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("%") )
79  {
80  // Ends with a '%'
81  aStr = aStr.copy(0, aStr.getLength() - 1);
82  aStr = aStr.trim();
83  nDash = aStr.toInt32();
84 
85  // Convert to 1000th of a percent
86  nDash *= 1000;
87  }
88  else
89  {
90  nDash = rAttribs.getInteger( XML_d, 0 );
91  }
92 
93  sal_Int32 nSp = 0;
94  aStr = rAttribs.getString( XML_sp, "" );
95  if ( aStr.endsWith("%") )
96  {
97  // Ends with a '%'
98  aStr = aStr.copy(0, aStr.getLength() - 1);
99  aStr = aStr.trim();
100  nSp = aStr.toInt32();
101 
102  // Convert to 1000th of a percent
103  nSp *= 1000;
104  }
105  else
106  {
107  nSp = rAttribs.getInteger( XML_sp, 0 );
108  }
109 
110  mrLineProperties.maCustomDash.emplace_back( nDash, nSp );
111  }
112  break;
113 
114  // LineJoinPropertiesGroup
115  case A_TOKEN( round ):
116  case A_TOKEN( bevel ):
117  case A_TOKEN( miter ):
118  mrLineProperties.moLineJoint = getBaseToken( nElement );
119  break;
120 
121  case A_TOKEN( headEnd ): // CT_LineEndProperties
122  case A_TOKEN( tailEnd ): // CT_LineEndProperties
123  { // ST_LineEndType
124  bool bTailEnd = nElement == A_TOKEN( tailEnd );
126  rArrowProps.moArrowType = rAttribs.getToken( XML_type );
127  rArrowProps.moArrowWidth = rAttribs.getToken( XML_w );
128  rArrowProps.moArrowLength = rAttribs.getToken( XML_len );
129  }
130  break;
131  }
132  return nullptr;
133 }
134 
135 }
136 
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
LinePropertiesContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttributes, LineProperties &rLineProperties) noexcept
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
OptValue< sal_Int32 > moPresetDash
Line width (EMUs).
LineArrowProperties maStartArrow
LineArrowProperties maEndArrow
Start line arrow style.
OptValue< sal_Int32 > moLineJoint
Line cap (OOXML token).
Provides access to attribute values of an element.
FillProperties maLineFill
End line arrow style.
::oox::core::ContextHandlerRef createFillContext(::oox::core::ContextHandler2Helper const &rParent, sal_Int32 nElement, const ::oox::AttributeList &rAttribs, FillProperties &rFillProps)
Helper class that provides a context stack.
DashStopVector maCustomDash
Line fill (solid, gradient, ...).
aStr
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.