• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGAngle.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  2004, 2005, 2006 Rob Buis <buis@kde.org>
4 
5  This file is part of the KDE project
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "config.h"
24 #include "wtf/Platform.h"
25 
26 #if ENABLE(SVG)
27 #include "SVGAngle.h"
28 
29 #include <math.h>
30 #include <wtf/MathExtras.h>
31 
32 namespace WebCore {
33 
34 SVGAngle::SVGAngle()
35  : RefCounted<SVGAngle>(0)
36  , m_unitType(SVG_ANGLETYPE_UNKNOWN)
37  , m_value(0)
38  , m_valueInSpecifiedUnits(0)
39 {
40 }
41 
42 SVGAngle::~SVGAngle()
43 {
44 }
45 
46 SVGAngle::SVGAngleType SVGAngle::unitType() const
47 {
48  return m_unitType;
49 }
50 
51 void SVGAngle::setValue(float value)
52 {
53  m_value = value;
54 }
55 
56 float SVGAngle::value() const
57 {
58  return m_value;
59 }
60 
61 // calc m_value
62 void SVGAngle::calculate()
63 {
64  if (m_unitType == SVG_ANGLETYPE_GRAD)
65  m_value = grad2deg(m_valueInSpecifiedUnits);
66  else if (m_unitType == SVG_ANGLETYPE_RAD)
67  m_value = rad2deg(m_valueInSpecifiedUnits);
68  else if (m_unitType == SVG_ANGLETYPE_UNSPECIFIED || m_unitType == SVG_ANGLETYPE_DEG)
69  m_value = m_valueInSpecifiedUnits;
70 }
71 
72 void SVGAngle::setValueInSpecifiedUnits(float valueInSpecifiedUnits)
73 {
74  m_valueInSpecifiedUnits = valueInSpecifiedUnits;
75  calculate();
76 }
77 
78 float SVGAngle::valueInSpecifiedUnits() const
79 {
80  return m_valueInSpecifiedUnits;
81 }
82 
83 void SVGAngle::setValueAsString(const String& s)
84 {
85  m_valueAsString = s;
86 
87  bool bOK;
88  m_valueInSpecifiedUnits = m_valueAsString.toFloat(&bOK);
89  m_unitType = SVG_ANGLETYPE_UNSPECIFIED;
90 
91  if (!bOK) {
92  if (m_valueAsString.endsWith("deg"))
93  m_unitType = SVG_ANGLETYPE_DEG;
94  else if (m_valueAsString.endsWith("grad"))
95  m_unitType = SVG_ANGLETYPE_GRAD;
96  else if (m_valueAsString.endsWith("rad"))
97  m_unitType = SVG_ANGLETYPE_RAD;
98  }
99 
100  calculate();
101 }
102 
103 String SVGAngle::valueAsString() const
104 {
105  m_valueAsString = String::number(m_valueInSpecifiedUnits);
106 
107  switch (m_unitType) {
108  case SVG_ANGLETYPE_UNSPECIFIED:
109  case SVG_ANGLETYPE_DEG:
110  m_valueAsString += "deg";
111  break;
112  case SVG_ANGLETYPE_RAD:
113  m_valueAsString += "rad";
114  break;
115  case SVG_ANGLETYPE_GRAD:
116  m_valueAsString += "grad";
117  break;
118  case SVG_ANGLETYPE_UNKNOWN:
119  break;
120  }
121 
122  return m_valueAsString;
123 }
124 
125 void SVGAngle::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits)
126 {
127  m_unitType = (SVGAngleType)unitType;
128  m_valueInSpecifiedUnits = valueInSpecifiedUnits;
129  calculate();
130 }
131 
132 void SVGAngle::convertToSpecifiedUnits(unsigned short unitType)
133 {
134  if (m_unitType == unitType)
135  return;
136 
137  if (m_unitType == SVG_ANGLETYPE_DEG && unitType == SVG_ANGLETYPE_RAD)
138  m_valueInSpecifiedUnits = deg2rad(m_valueInSpecifiedUnits);
139  else if (m_unitType == SVG_ANGLETYPE_GRAD && unitType == SVG_ANGLETYPE_RAD)
140  m_valueInSpecifiedUnits = grad2rad(m_valueInSpecifiedUnits);
141  else if (m_unitType == SVG_ANGLETYPE_DEG && unitType == SVG_ANGLETYPE_GRAD)
142  m_valueInSpecifiedUnits = deg2grad(m_valueInSpecifiedUnits);
143  else if (m_unitType == SVG_ANGLETYPE_RAD && unitType == SVG_ANGLETYPE_GRAD)
144  m_valueInSpecifiedUnits = rad2grad(m_valueInSpecifiedUnits);
145  else if (m_unitType == SVG_ANGLETYPE_RAD && unitType == SVG_ANGLETYPE_DEG)
146  m_valueInSpecifiedUnits = rad2deg(m_valueInSpecifiedUnits);
147  else if (m_unitType == SVG_ANGLETYPE_GRAD && unitType == SVG_ANGLETYPE_DEG)
148  m_valueInSpecifiedUnits = grad2deg(m_valueInSpecifiedUnits);
149 
150  m_unitType = (SVGAngleType)unitType;
151 }
152 
153 // Helpers
154 double SVGAngle::todeg(double rad)
155 {
156  return rad2deg(rad);
157 }
158 
159 double SVGAngle::torad(double deg)
160 {
161  return deg2rad(deg);
162 }
163 
164 double SVGAngle::shortestArcBisector(double angle1, double angle2)
165 {
166  double bisector = (angle1 + angle2) / 2;
167 
168  if (fabs(angle1 - angle2) > 180)
169  bisector += 180;
170 
171  return bisector;
172 }
173 
174 }
175 
176 #endif // ENABLE(SVG)
SVGAngle.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal