1 | /* |
2 | * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 | * Copyright (C) 2004, 2005, 2006, 2007 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 | #pragma once |
22 | |
23 | #include "ExceptionOr.h" |
24 | #include "SVGPropertyTraits.h" |
25 | |
26 | namespace WebCore { |
27 | |
28 | class AffineTransform; |
29 | class FloatRect; |
30 | |
31 | class SVGPreserveAspectRatioValue { |
32 | WTF_MAKE_FAST_ALLOCATED; |
33 | public: |
34 | enum SVGPreserveAspectRatioType { |
35 | SVG_PRESERVEASPECTRATIO_UNKNOWN = 0, |
36 | SVG_PRESERVEASPECTRATIO_NONE = 1, |
37 | SVG_PRESERVEASPECTRATIO_XMINYMIN = 2, |
38 | SVG_PRESERVEASPECTRATIO_XMIDYMIN = 3, |
39 | SVG_PRESERVEASPECTRATIO_XMAXYMIN = 4, |
40 | SVG_PRESERVEASPECTRATIO_XMINYMID = 5, |
41 | SVG_PRESERVEASPECTRATIO_XMIDYMID = 6, |
42 | SVG_PRESERVEASPECTRATIO_XMAXYMID = 7, |
43 | SVG_PRESERVEASPECTRATIO_XMINYMAX = 8, |
44 | SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9, |
45 | SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10 |
46 | }; |
47 | |
48 | enum SVGMeetOrSliceType { |
49 | SVG_MEETORSLICE_UNKNOWN = 0, |
50 | SVG_MEETORSLICE_MEET = 1, |
51 | SVG_MEETORSLICE_SLICE = 2 |
52 | }; |
53 | |
54 | SVGPreserveAspectRatioValue(); |
55 | SVGPreserveAspectRatioValue(const String&); |
56 | |
57 | ExceptionOr<void> setAlign(unsigned short); |
58 | unsigned short align() const { return m_align; } |
59 | |
60 | ExceptionOr<void> setMeetOrSlice(unsigned short); |
61 | unsigned short meetOrSlice() const { return m_meetOrSlice; } |
62 | |
63 | void transformRect(FloatRect& destRect, FloatRect& srcRect) const; |
64 | |
65 | AffineTransform getCTM(float logicalX, float logicalY, float logicalWidth, float logicalHeight, float physicalWidth, float physicalHeight) const; |
66 | |
67 | void parse(const String&); |
68 | bool parse(const UChar*& currParam, const UChar* end, bool validate); |
69 | |
70 | String valueAsString() const; |
71 | |
72 | private: |
73 | SVGPreserveAspectRatioType m_align; |
74 | SVGMeetOrSliceType m_meetOrSlice; |
75 | |
76 | bool parseInternal(const UChar*& currParam, const UChar* end, bool validate); |
77 | }; |
78 | |
79 | template<> struct SVGPropertyTraits<SVGPreserveAspectRatioValue> { |
80 | static SVGPreserveAspectRatioValue initialValue() { return SVGPreserveAspectRatioValue(); } |
81 | static SVGPreserveAspectRatioValue fromString(const String& string) { return SVGPreserveAspectRatioValue(string); } |
82 | static Optional<SVGPreserveAspectRatioValue> parse(const QualifiedName&, const String&) { ASSERT_NOT_REACHED(); return initialValue(); } |
83 | static String toString(const SVGPreserveAspectRatioValue& type) { return type.valueAsString(); } |
84 | }; |
85 | |
86 | } // namespace WebCore |
87 | |