1 /* 2 Copyright (C) 2007 Eric Seidel <eric@webkit.org> 3 Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 4 Copyright (C) 2008 Rob Buis <buis@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 "SVGStyledElement.h" 27 28 #include <limits> 29 #include "Path.h" 30 31 namespace WebCore { 32 33 class AtomicString; 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 SVGGlyphIdentifierSVGGlyphIdentifier53 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" inheritedValueSVGGlyphIdentifier67 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 pathData.debugString() == other.pathData.debugString() && 84 languages == other.languages; 85 } 86 87 bool isValid : 1; 88 89 unsigned orientation : 2; // Orientation 90 unsigned arabicForm : 3; // ArabicForm 91 int priority; 92 size_t nameLength; 93 String glyphName; 94 95 float horizontalAdvanceX; 96 float verticalOriginX; 97 float verticalOriginY; 98 float verticalAdvanceY; 99 100 Path pathData; 101 Vector<String> languages; 102 }; 103 104 class SVGGlyphElement : public SVGStyledElement { 105 public: 106 SVGGlyphElement(const QualifiedName&, Document*); 107 virtual ~SVGGlyphElement(); 108 109 virtual void parseMappedAttribute(MappedAttribute*); 110 111 virtual void insertedIntoDocument(); 112 virtual void removedFromDocument(); 113 rendererIsNeeded(RenderStyle *)114 virtual bool rendererIsNeeded(RenderStyle*) { return false; } 115 116 SVGGlyphIdentifier buildGlyphIdentifier() const; 117 118 // Helper function used by SVGFont 119 static void inheritUnspecifiedAttributes(SVGGlyphIdentifier&, const SVGFontData*); 120 static String querySVGFontLanguage(const SVGElement*); 121 122 // Helper function shared between SVGGlyphElement & SVGMissingGlyphElement 123 static SVGGlyphIdentifier buildGenericGlyphIdentifier(const SVGElement*); 124 private: 125 void invalidateGlyphCache(); 126 }; 127 128 } // namespace WebCore 129 130 #endif // ENABLE(SVG_FONTS) 131 #endif 132