• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005, 2006, 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 #ifndef SVGLength_h
24 #define SVGLength_h
25 
26 #if ENABLE(SVG)
27 #include "PlatformString.h"
28 
29 namespace WebCore {
30 
31     enum SVGLengthType {
32         LengthTypeUnknown = 0,
33         LengthTypeNumber = 1,
34         LengthTypePercentage = 2,
35         LengthTypeEMS = 3,
36         LengthTypeEXS = 4,
37         LengthTypePX = 5,
38         LengthTypeCM = 6,
39         LengthTypeMM = 7,
40         LengthTypeIN = 8,
41         LengthTypePT = 9,
42         LengthTypePC = 10
43     };
44 
45     enum SVGLengthMode {
46         LengthModeWidth = 0,
47         LengthModeHeight,
48         LengthModeOther
49     };
50 
51     class SVGElement;
52 
53     class SVGLength {
54     public:
55         // Forward declare these enums in the w3c naming scheme, for IDL generation
56         enum {
57             SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown,
58             SVG_LENGTHTYPE_NUMBER = LengthTypeNumber,
59             SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage,
60             SVG_LENGTHTYPE_EMS = LengthTypeEMS,
61             SVG_LENGTHTYPE_EXS = LengthTypeEXS,
62             SVG_LENGTHTYPE_PX = LengthTypePX,
63             SVG_LENGTHTYPE_CM = LengthTypeCM,
64             SVG_LENGTHTYPE_MM = LengthTypeMM,
65             SVG_LENGTHTYPE_IN = LengthTypeIN,
66             SVG_LENGTHTYPE_PT = LengthTypePT,
67             SVG_LENGTHTYPE_PC = LengthTypePC
68         };
69 
70         SVGLength(SVGLengthMode mode = LengthModeOther, const String& valueAsString = String());
71 
72         SVGLengthType unitType() const;
73 
74         float value(const SVGElement* context) const;
75         void setValue(float);
76 
77         float valueInSpecifiedUnits() const;
78         void setValueInSpecifiedUnits(float);
79 
80         float valueAsPercentage() const;
81 
82         String valueAsString() const;
83         bool setValueAsString(const String&);
84 
85         void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits);
86         void convertToSpecifiedUnits(unsigned short, const SVGElement* context);
87 
88         // Helper functions
89         static float PercentageOfViewport(float value, const SVGElement* context, SVGLengthMode);
90 
isRelative()91         inline bool isRelative() const
92         {
93             SVGLengthType type = unitType();
94             return (type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS);
95         }
96 
97     private:
98         float m_valueInSpecifiedUnits;
99         unsigned int m_unit;
100     };
101 
102 } // namespace WebCore
103 
104 #endif // ENABLE(SVG)
105 #endif // SVGLength_h
106