Reviewed by Eric. Older parts reviewed by Dan.
[WebKit-https.git] / WebCore / svg / SVGGlyphElement.h
index 296a6d9..54069bd 100644 (file)
 #if ENABLE(SVG_FONTS)
 #include "SVGStyledElement.h"
 
+#include <limits>
 #include "Path.h"
 
 namespace WebCore {
-    
-    class SVGGlyphElement : public SVGStyledElement {
-    public:
-        SVGGlyphElement(const QualifiedName&, Document*);
 
-        virtual bool rendererIsNeeded(RenderStyle*) { return false; }
-    };
+    class AtomicString;
+    struct SVGFontData;
 
     // Describe a SVG <glyph> element
     struct SVGGlyphIdentifier {
-        enum Orientation { Vertical, Horizontal, Both };
-        enum ArabicForm { Initial, Medial, Terminal, Isolated };
+        enum Orientation {
+            Vertical,
+            Horizontal,
+            Both
+        };
+
+        // SVG Font depends on exactly this order.
+        enum ArabicForm {
+            None = 0,
+            Isolated,
+            Terminal,
+            Initial,
+            Medial
+        };
 
         SVGGlyphIdentifier()
-            : orientation(Both)
-            , arabicForm(Initial)
+            : isValid(false)
+            , orientation(Both)
+            , arabicForm(None)
             , horizontalAdvanceX(0.0f)
             , verticalOriginX(0.0f)
             , verticalOriginY(0.0f)
@@ -50,34 +60,63 @@ namespace WebCore {
         {
         }
 
-        // 'orientation' property;
-        Orientation orientation;
+        // Used to mark our float properties as "to be inherited from SVGFontData"
+        static float inheritedValue()
+        {
+            static float s_inheritedValue = std::numeric_limits<float>::infinity();
+            return s_inheritedValue;
+        }
+
+        bool operator==(const SVGGlyphIdentifier& other) const
+        {
+            return isValid == other.isValid &&
+                   orientation == other.orientation &&
+                   arabicForm == other.arabicForm &&
+                   glyphName == other.glyphName &&
+                   horizontalAdvanceX == other.horizontalAdvanceX &&
+                   verticalOriginX == other.verticalOriginX &&
+                   verticalOriginY == other.verticalOriginY &&
+                   verticalAdvanceY == other.verticalAdvanceY &&
+                   pathData.debugString() == other.pathData.debugString() &&
+                   languages == other.languages;
+        }
 
-        // 'arabic-form' property
-        ArabicForm arabicForm;
+        bool isValid : 1;
 
-        // 'horiz-adv-x' property
-        float horizontalAdvanceX;
+        Orientation orientation : 2;
+        ArabicForm arabicForm : 3;
+        String glyphName;
 
-        // 'vert-origin-x' property
+        float horizontalAdvanceX;
         float verticalOriginX;
-
-        // 'vert-origin-y' property
         float verticalOriginY;
-
-        // 'vert-adv-y' property
         float verticalAdvanceY;
 
-        // 'd' property
         Path pathData;
-
-        // 'lang' property
         Vector<String> languages;
     };
 
+    class SVGGlyphElement : public SVGStyledElement {
+    public:
+        SVGGlyphElement(const QualifiedName&, Document*);
+        virtual ~SVGGlyphElement();
+
+        virtual void insertedIntoDocument();
+        virtual void removedFromDocument();
+
+        virtual bool rendererIsNeeded(RenderStyle*) { return false; }
+
+        SVGGlyphIdentifier buildGlyphIdentifier() const;
+
+        // Helper function used by SVGFont
+        static void inheritUnspecifiedAttributes(SVGGlyphIdentifier&, const SVGFontData*);
+        static String querySVGFontLanguage(const SVGElement*);
+
+        // Helper function shared between SVGGlyphElement & SVGMissingGlyphElement
+        static SVGGlyphIdentifier buildGenericGlyphIdentifier(const SVGElement*);
+    };
+
 } // namespace WebCore
 
 #endif // ENABLE(SVG_FONTS)
 #endif
-
-// vim:ts=4:noet