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