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 library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef SVGLength_h 22 #define SVGLength_h 23 24 #if ENABLE(SVG) 25 #include "PlatformString.h" 26 27 namespace WebCore { 28 29 enum SVGLengthType { 30 LengthTypeUnknown = 0, 31 LengthTypeNumber = 1, 32 LengthTypePercentage = 2, 33 LengthTypeEMS = 3, 34 LengthTypeEXS = 4, 35 LengthTypePX = 5, 36 LengthTypeCM = 6, 37 LengthTypeMM = 7, 38 LengthTypeIN = 8, 39 LengthTypePT = 9, 40 LengthTypePC = 10 41 }; 42 43 enum SVGLengthMode { 44 LengthModeWidth = 0, 45 LengthModeHeight, 46 LengthModeOther 47 }; 48 49 class SVGElement; 50 51 class SVGLength { 52 public: 53 // Forward declare these enums in the w3c naming scheme, for IDL generation 54 enum { 55 SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown, 56 SVG_LENGTHTYPE_NUMBER = LengthTypeNumber, 57 SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage, 58 SVG_LENGTHTYPE_EMS = LengthTypeEMS, 59 SVG_LENGTHTYPE_EXS = LengthTypeEXS, 60 SVG_LENGTHTYPE_PX = LengthTypePX, 61 SVG_LENGTHTYPE_CM = LengthTypeCM, 62 SVG_LENGTHTYPE_MM = LengthTypeMM, 63 SVG_LENGTHTYPE_IN = LengthTypeIN, 64 SVG_LENGTHTYPE_PT = LengthTypePT, 65 SVG_LENGTHTYPE_PC = LengthTypePC 66 }; 67 68 SVGLength(SVGLengthMode mode = LengthModeOther, const String& valueAsString = String()); 69 70 SVGLengthType unitType() const; 71 72 float value(const SVGElement* context) const; 73 void setValue(float); 74 75 float valueInSpecifiedUnits() const; 76 void setValueInSpecifiedUnits(float); 77 78 float valueAsPercentage() const; 79 80 String valueAsString() const; 81 bool setValueAsString(const String&); 82 83 void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits); 84 void convertToSpecifiedUnits(unsigned short, const SVGElement* context); 85 86 // Helper functions 87 static float PercentageOfViewport(float value, const SVGElement* context, SVGLengthMode); 88 isRelative()89 inline bool isRelative() const 90 { 91 SVGLengthType type = unitType(); 92 return (type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS); 93 } 94 95 private: 96 float m_valueInSpecifiedUnits; 97 unsigned int m_unit; 98 }; 99 100 } // namespace WebCore 101 102 #endif // ENABLE(SVG) 103 #endif // SVGLength_h 104