File indexing completed on 2024-04-28 15:24:34

0001 /*
0002     Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
0003                   2004, 2005, 2006 Rob Buis <buis@kde.org>
0004 
0005     This file is part of the KDE project
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #ifndef SVGLength_h
0024 #define SVGLength_h
0025 
0026 #if ENABLE(SVG)
0027 
0028 //#include "PlatformString.h"
0029 #include "Document.h"
0030 
0031 namespace WebCore
0032 {
0033 
0034 class SVGStyledElement;
0035 
0036 enum SVGLengthType {
0037     LengthTypeUnknown = 0,
0038     LengthTypeNumber = 1,
0039     LengthTypePercentage = 2,
0040     LengthTypeEMS = 3,
0041     LengthTypeEXS = 4,
0042     LengthTypePX = 5,
0043     LengthTypeCM = 6,
0044     LengthTypeMM = 7,
0045     LengthTypeIN = 8,
0046     LengthTypePT = 9,
0047     LengthTypePC = 10
0048 };
0049 
0050 enum SVGLengthMode {
0051     LengthModeWidth = 0,
0052     LengthModeHeight,
0053     LengthModeOther
0054 };
0055 
0056 class SVGLength
0057 {
0058 public:
0059     // Forward declare these enums in the w3c naming scheme, for IDL generation
0060     enum {
0061         SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown,
0062         SVG_LENGTHTYPE_NUMBER = LengthTypeNumber,
0063         SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage,
0064         SVG_LENGTHTYPE_EMS = LengthTypeEMS,
0065         SVG_LENGTHTYPE_EXS = LengthTypeEXS,
0066         SVG_LENGTHTYPE_PX = LengthTypePX,
0067         SVG_LENGTHTYPE_CM = LengthTypeCM,
0068         SVG_LENGTHTYPE_MM = LengthTypeMM,
0069         SVG_LENGTHTYPE_IN = LengthTypeIN,
0070         SVG_LENGTHTYPE_PT = LengthTypePT,
0071         SVG_LENGTHTYPE_PC = LengthTypePC
0072     };
0073 
0074     SVGLength(const SVGStyledElement *context = nullptr, SVGLengthMode mode = LengthModeOther, const String &valueAsString = String());
0075 
0076     // 'SVGLength' functions
0077     SVGLengthType unitType() const;
0078 
0079     float value() const;
0080     void setValue(float);
0081 
0082     float valueInSpecifiedUnits() const;
0083     void setValueInSpecifiedUnits(float);
0084 
0085     float valueAsPercentage() const;
0086 
0087     String valueAsString() const;
0088     bool setValueAsString(const String &);
0089 
0090     void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits);
0091     void convertToSpecifiedUnits(unsigned short);
0092 
0093     // Helper functions
0094     static float PercentageOfViewport(float value, const SVGStyledElement *, SVGLengthMode);
0095 
0096     inline bool isRelative() const
0097     {
0098         SVGLengthType type = unitType();
0099         return (type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS);
0100     }
0101 
0102 private:
0103     float m_valueInSpecifiedUnits;
0104     unsigned int m_unit;
0105 
0106     const SVGStyledElement *m_context;
0107 };
0108 
0109 } // namespace WebCore
0110 
0111 #endif // ENABLE(SVG)
0112 #endif // SVGLength_h
0113