Home | History | Annotate | Download | only in svg
      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 #include "core/svg/properties/SVGPropertyTraits.h"
     25 
     26 namespace WebCore {
     27 
     28 class AffineTransform;
     29 class ExceptionState;
     30 class FloatRect;
     31 
     32 class SVGPreserveAspectRatio {
     33     WTF_MAKE_FAST_ALLOCATED;
     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, ExceptionState&);
     58     unsigned short align() const { return m_align; }
     59 
     60     void setMeetOrSlice(unsigned short, ExceptionState&);
     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     void parse(const String&);
     70     bool parse(const LChar*& ptr, const LChar* end, bool validate);
     71     bool parse(const UChar*& ptr, const UChar* end, bool validate);
     72 
     73     String valueAsString() const;
     74 
     75 private:
     76     template<typename CharType>
     77     bool parseInternal(const CharType*& ptr, const CharType* end, bool validate);
     78 
     79     SVGPreserveAspectRatioType m_align;
     80     SVGMeetOrSliceType m_meetOrSlice;
     81 };
     82 
     83 template<>
     84 struct SVGPropertyTraits<SVGPreserveAspectRatio> {
     85     static SVGPreserveAspectRatio initialValue() { return SVGPreserveAspectRatio(); }
     86     static String toString(const SVGPreserveAspectRatio& type) { return type.valueAsString(); }
     87 };
     88 
     89 } // namespace WebCore
     90 
     91 #endif // SVGPreserveAspectRatio_h
     92