Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2007 Eric Seidel <eric (at) webkit.org>
      3  * Copyright (C) 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      4  * Copyright (C) 2008 Rob Buis <buis (at) kde.org>
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  */
     21 
     22 #ifndef SVGGlyphElement_h
     23 #define SVGGlyphElement_h
     24 
     25 #if ENABLE(SVG_FONTS)
     26 #include "Path.h"
     27 #include "SVGStyledElement.h"
     28 
     29 #include <limits>
     30 #include <wtf/Forward.h>
     31 
     32 namespace WebCore {
     33 
     34 class SVGFontData;
     35 
     36 // Describe a SVG <glyph> element
     37 struct SVGGlyphIdentifier {
     38     enum Orientation {
     39         Vertical,
     40         Horizontal,
     41         Both
     42     };
     43 
     44     // SVG Font depends on exactly this order.
     45     enum ArabicForm {
     46         None = 0,
     47         Isolated,
     48         Terminal,
     49         Initial,
     50         Medial
     51     };
     52 
     53     SVGGlyphIdentifier()
     54         : isValid(false)
     55         , orientation(Both)
     56         , arabicForm(None)
     57         , priority(0)
     58         , nameLength(0)
     59         , horizontalAdvanceX(0.0f)
     60         , verticalOriginX(0.0f)
     61         , verticalOriginY(0.0f)
     62         , verticalAdvanceY(0.0f)
     63     {
     64     }
     65 
     66     // Used to mark our float properties as "to be inherited from SVGFontData"
     67     static float inheritedValue()
     68     {
     69         static float s_inheritedValue = std::numeric_limits<float>::infinity();
     70         return s_inheritedValue;
     71     }
     72 
     73     bool operator==(const SVGGlyphIdentifier& other) const
     74     {
     75         return isValid == other.isValid
     76             && orientation == other.orientation
     77             && arabicForm == other.arabicForm
     78             && glyphName == other.glyphName
     79             && horizontalAdvanceX == other.horizontalAdvanceX
     80             && verticalOriginX == other.verticalOriginX
     81             && verticalOriginY == other.verticalOriginY
     82             && verticalAdvanceY == other.verticalAdvanceY
     83             && languages == other.languages;
     84     }
     85 
     86     bool isValid : 1;
     87 
     88     unsigned orientation : 2; // Orientation
     89     unsigned arabicForm : 3; // ArabicForm
     90     int priority;
     91     size_t nameLength;
     92     String glyphName;
     93 
     94     float horizontalAdvanceX;
     95     float verticalOriginX;
     96     float verticalOriginY;
     97     float verticalAdvanceY;
     98 
     99     Path pathData;
    100     Vector<String> languages;
    101 };
    102 
    103 class SVGGlyphElement : public SVGStyledElement {
    104 public:
    105     static PassRefPtr<SVGGlyphElement> create(const QualifiedName&, Document*);
    106 
    107     SVGGlyphIdentifier buildGlyphIdentifier() const;
    108 
    109     // Helper function used by SVGFont
    110     static void inheritUnspecifiedAttributes(SVGGlyphIdentifier&, const SVGFontData*);
    111     static String querySVGFontLanguage(const SVGElement*);
    112 
    113     // Helper function shared between SVGGlyphElement & SVGMissingGlyphElement
    114     static SVGGlyphIdentifier buildGenericGlyphIdentifier(const SVGElement*);
    115 
    116 private:
    117     SVGGlyphElement(const QualifiedName&, Document*);
    118 
    119     virtual void parseMappedAttribute(Attribute*);
    120     virtual void fillAttributeToPropertyTypeMap();
    121     virtual AttributeToPropertyTypeMap& attributeToPropertyTypeMap();
    122 
    123     virtual void insertedIntoDocument();
    124     virtual void removedFromDocument();
    125 
    126     virtual bool rendererIsNeeded(RenderStyle*) { return false; }
    127 
    128     void invalidateGlyphCache();
    129 };
    130 
    131 } // namespace WebCore
    132 
    133 #endif // ENABLE(SVG_FONTS)
    134 #endif
    135