karbon

vdashpattern.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002, The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqdom.h>
21
22#include "vdashpattern.h"
23
24VDashPattern::VDashPattern( double offset )
25 : m_offset( offset )
26{
27}
28
29void
30VDashPattern::save( TQDomElement& element ) const
31{
32 if( m_array.size() != 0 )
33 {
34 TQDomElement me = element.ownerDocument().createElement( "DASHPATTERN" );
35 element.appendChild( me );
36
37 if( m_offset != 0.0 )
38 me.setAttribute( "offset", m_offset );
39
40 TQDomElement dash;
41
42 TQValueListConstIterator<float> itr;
43 for( itr = m_array.begin(); itr != m_array.end(); ++itr )
44 {
45 dash = element.ownerDocument().createElement( "DASH" );
46 me.appendChild( dash );
47 dash.setAttribute( "l", *( itr ) );
48 }
49 }
50}
51
52void
53VDashPattern::load( const TQDomElement& element )
54{
55 m_offset = element.attribute( "offset", "0.0" ).toDouble();
56
57 float value;
58
59 TQDomNodeList list = element.childNodes();
60 for( uint i = 0; i < list.count(); ++i )
61 {
62 if( list.item( i ).isElement() )
63 {
64 TQDomElement e = list.item( i ).toElement();
65 if( e.tagName() == "DASH" )
66 {
67 value = e.attribute( "l", "0.0" ).toFloat();
68 if( value < 0.0 )
69 value = 0.0;
70
71 m_array.append( value );
72 }
73 }
74 }
75}
76