#i10000# Bring module to HEAD.
[LibreOffice.git] / oox / source / drawingml / linepropertiescontext.cxx
blob5f21b0aa7109b2c8747f39c88b472b4038e64d19
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: linepropertiescontext.cxx,v $
7 * $Revision: 1.2 $
9 * last change: $Author: rt $ $Date: 2008-01-17 08:05:51 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 #include "oox/drawingml/linepropertiescontext.hxx"
38 #include <com/sun/star/drawing/LineJoint.hpp>
39 #include <com/sun/star/drawing/LineStyle.hpp>
40 #include "oox/helper/propertymap.hxx"
41 #include "oox/core/namespaces.hxx"
42 #include "oox/drawingml/colorchoicecontext.hxx"
43 #include "oox/drawingml/drawingmltypes.hxx"
45 #include "tokens.hxx"
47 using ::rtl::OUString;
48 using ::com::sun::star::beans::NamedValue;
49 using namespace ::oox::core;
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::drawing;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::xml::sax;
55 // CT_LineProperties
57 namespace oox { namespace drawingml {
58 // ---------------------------------------------------------------------
60 LinePropertiesContext::LinePropertiesContext( const FragmentHandlerRef& xHandler, const Reference< XFastAttributeList >& xAttribs,
61 oox::drawingml::LineProperties& rLineProperties ) throw()
62 : Context( xHandler )
63 , mrLineProperties( rLineProperties )
65 // ST_LineWidth
66 if( xAttribs->hasAttribute( XML_w ) )
67 mrLineProperties.getLineWidth() = boost::optional< sal_Int32 >( GetCoordinate( xAttribs->getOptionalValue( XML_w ) ) );
69 // "ST_LineCap"
70 if( xAttribs->hasAttribute( XML_cap ) )
71 mrLineProperties.getLineCap() = boost::optional< sal_Int32 >( xAttribs->getOptionalValueToken( XML_cap, 0 ) );
73 // if ( xAttribs->hasAttribute( XML_cmpd ) ) ST_CompoundLine
74 // if ( xAttribs->hasAttribute( XML_algn ) ) ST_PenAlignment
77 LinePropertiesContext::~LinePropertiesContext()
81 Reference< XFastContextHandler > LinePropertiesContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
83 Reference< XFastContextHandler > xRet;
84 const rtl::OUString sLineStyle( RTL_CONSTASCII_USTRINGPARAM( "LineStyle" ) );
85 switch( aElementToken )
87 // LineFillPropertiesGroup, line fillings currently unsuported
88 case NMSP_DRAWINGML|XML_noFill:
89 mrLineProperties.getLinePropertyMap()[ sLineStyle ] <<= LineStyle_NONE;
90 break;
91 case NMSP_DRAWINGML|XML_solidFill:
93 mrLineProperties.getLinePropertyMap()[ sLineStyle ] <<= LineStyle_SOLID;
94 xRet = new colorChoiceContext( getHandler(), *mrLineProperties.getLineColor().get() );
96 break;
97 case NMSP_DRAWINGML|XML_gradFill:
98 case NMSP_DRAWINGML|XML_pattFill:
99 mrLineProperties.getLinePropertyMap()[ sLineStyle ] <<= LineStyle_SOLID;
100 break;
102 // LineDashPropertiesGroup
103 case NMSP_DRAWINGML|XML_prstDash: // CT_PresetLineDashProperties
104 mrLineProperties.getPresetDash() = boost::optional< sal_Int32 >( xAttribs->getOptionalValueToken( XML_val, XML_solid ) );
105 break;
106 case NMSP_DRAWINGML|XML_custDash: // CT_DashStopList
107 break;
109 // LineJoinPropertiesGroup
110 case NMSP_DRAWINGML|XML_round:
111 case NMSP_DRAWINGML|XML_bevel:
112 case NMSP_DRAWINGML|XML_miter:
114 LineJoint eJoint = (aElementToken == (NMSP_DRAWINGML|XML_round)) ? LineJoint_ROUND :
115 (aElementToken == (NMSP_DRAWINGML|XML_bevel)) ? LineJoint_BEVEL :
116 LineJoint_MITER;
117 static const OUString sLineJoint( RTL_CONSTASCII_USTRINGPARAM( "LineJoint" ) );
118 mrLineProperties.getLinePropertyMap()[ sLineJoint ] <<= eJoint;
120 break;
122 case NMSP_DRAWINGML|XML_headEnd: // CT_LineEndProperties
123 case NMSP_DRAWINGML|XML_tailEnd: // CT_LineEndProperties
124 { // ST_LineEndType
125 if( xAttribs->hasAttribute( XML_type ) )
127 sal_Int32 nType = xAttribs->getOptionalValueToken( XML_type, 0 );
128 if ( aElementToken == ( NMSP_DRAWINGML|XML_tailEnd ) )
129 mrLineProperties.getStartArrow() = boost::optional< sal_Int32 >( nType );
130 else
131 mrLineProperties.getEndArrow() = boost::optional< sal_Int32 >( nType );
133 if ( xAttribs->hasAttribute( XML_w ) )
135 sal_Int32 nW = xAttribs->getOptionalValueToken( XML_w, 0 );
136 if ( aElementToken == ( NMSP_DRAWINGML|XML_tailEnd ) )
137 mrLineProperties.getStartArrowWidth() = boost::optional< sal_Int32 >( nW );
138 else
139 mrLineProperties.getEndArrowWidth() = boost::optional< sal_Int32 >( nW );
141 if ( xAttribs->hasAttribute( XML_len ) )
143 sal_Int32 nLen = xAttribs->getOptionalValueToken( XML_len, 0 );
144 if ( aElementToken == ( NMSP_DRAWINGML|XML_tailEnd ) )
145 mrLineProperties.getStartArrowLength() = boost::optional< sal_Int32 >( nLen );
146 else
147 mrLineProperties.getEndArrowLength() = boost::optional< sal_Int32 >( nLen );
150 break;
152 if ( !xRet.is() )
153 xRet.set( this );
154 return xRet;