1 /* 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) 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 SVGPreserveAspectRatio_h 22 #define SVGPreserveAspectRatio_h 23 24 #if ENABLE(SVG) 25 #include "ExceptionCode.h" 26 #include "SVGPropertyTraits.h" 27 28 namespace WebCore { 29 30 class AffineTransform; 31 class FloatRect; 32 33 class SVGPreserveAspectRatio { 34 public: 35 enum SVGPreserveAspectRatioType { 36 SVG_PRESERVEASPECTRATIO_UNKNOWN = 0, 37 SVG_PRESERVEASPECTRATIO_NONE = 1, 38 SVG_PRESERVEASPECTRATIO_XMINYMIN = 2, 39 SVG_PRESERVEASPECTRATIO_XMIDYMIN = 3, 40 SVG_PRESERVEASPECTRATIO_XMAXYMIN = 4, 41 SVG_PRESERVEASPECTRATIO_XMINYMID = 5, 42 SVG_PRESERVEASPECTRATIO_XMIDYMID = 6, 43 SVG_PRESERVEASPECTRATIO_XMAXYMID = 7, 44 SVG_PRESERVEASPECTRATIO_XMINYMAX = 8, 45 SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9, 46 SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10 47 }; 48 49 enum SVGMeetOrSliceType { 50 SVG_MEETORSLICE_UNKNOWN = 0, 51 SVG_MEETORSLICE_MEET = 1, 52 SVG_MEETORSLICE_SLICE = 2 53 }; 54 55 SVGPreserveAspectRatio(); 56 57 void setAlign(unsigned short align, ExceptionCode&); 58 unsigned short align() const { return m_align; } 59 60 void setMeetOrSlice(unsigned short, ExceptionCode&); 61 unsigned short meetOrSlice() const { return m_meetOrSlice; } 62 63 void transformRect(FloatRect& destRect, FloatRect& srcRect); 64 65 AffineTransform getCTM(float logicX, float logicY, 66 float logicWidth, float logicHeight, 67 float physWidth, float physHeight) const; 68 69 template<class Consumer> 70 static bool parsePreserveAspectRatio(Consumer* consumer, const String& value, bool validate = true) 71 { 72 bool result = false; 73 const UChar* begin = value.characters(); 74 const UChar* end = begin + value.length(); 75 consumer->setPreserveAspectRatioBaseValue(parsePreserveAspectRatio(begin, end, validate, result)); 76 return result; 77 } 78 79 // It's recommended to use the method above, only SVGViewSpec needs this parsing method 80 static SVGPreserveAspectRatio parsePreserveAspectRatio(const UChar*& currParam, const UChar* end, bool validate, bool& result); 81 82 String valueAsString() const; 83 84 private: 85 SVGPreserveAspectRatioType m_align; 86 SVGMeetOrSliceType m_meetOrSlice; 87 }; 88 89 template<> 90 struct SVGPropertyTraits<SVGPreserveAspectRatio> { 91 static SVGPreserveAspectRatio initialValue() { return SVGPreserveAspectRatio(); } 92 static String toString(const SVGPreserveAspectRatio& type) { return type.valueAsString(); } 93 }; 94 95 } // namespace WebCore 96 97 #endif // ENABLE(SVG) 98 #endif // SVGPreserveAspectRatio_h 99