SVGGlyphElement.cpp [plain text]
#include "config.h"
#if ENABLE(SVG_FONTS)
#include "SVGGlyphElement.h"
#include "Attribute.h"
#include "SVGFontData.h"
#include "SVGFontElement.h"
#include "SVGFontFaceElement.h"
#include "SVGNames.h"
#include "SVGPathParserFactory.h"
#include "SimpleFontData.h"
#include "XMLNames.h"
namespace WebCore {
using namespace SVGNames;
inline SVGGlyphElement::SVGGlyphElement(const QualifiedName& tagName, Document* document)
: SVGStyledElement(tagName, document)
{
ASSERT(hasTagName(glyphTag));
}
PassRefPtr<SVGGlyphElement> SVGGlyphElement::create(const QualifiedName& tagName, Document* document)
{
return adoptRef(new SVGGlyphElement(tagName, document));
}
void SVGGlyphElement::invalidateGlyphCache()
{
ContainerNode* fontNode = parentNode();
if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) {
if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode))
element->invalidateGlyphCache();
}
}
void SVGGlyphElement::parseMappedAttribute(Attribute* attr)
{
if (attr->name() == SVGNames::dAttr)
invalidateGlyphCache();
else
SVGStyledElement::parseMappedAttribute(attr);
}
void SVGGlyphElement::insertedIntoDocument()
{
invalidateGlyphCache();
SVGStyledElement::insertedIntoDocument();
}
void SVGGlyphElement::removedFromDocument()
{
invalidateGlyphCache();
SVGStyledElement::removedFromDocument();
}
static inline SVGGlyph::ArabicForm parseArabicForm(const AtomicString& value)
{
if (value == "medial")
return SVGGlyph::Medial;
if (value == "terminal")
return SVGGlyph::Terminal;
if (value == "isolated")
return SVGGlyph::Isolated;
if (value == "initial")
return SVGGlyph::Initial;
return SVGGlyph::None;
}
static inline SVGGlyph::Orientation parseOrientation(const AtomicString& value)
{
if (value == "h")
return SVGGlyph::Horizontal;
if (value == "v")
return SVGGlyph::Vertical;
return SVGGlyph::Both;
}
static inline Path parsePathData(const AtomicString& value)
{
Path result;
SVGPathParserFactory* factory = SVGPathParserFactory::self();
factory->buildPathFromString(value, result);
return result;
}
void SVGGlyphElement::inheritUnspecifiedAttributes(SVGGlyph& identifier, const SVGFontData* svgFontData)
{
if (identifier.horizontalAdvanceX == SVGGlyph::inheritedValue())
identifier.horizontalAdvanceX = svgFontData->horizontalAdvanceX();
if (identifier.verticalOriginX == SVGGlyph::inheritedValue())
identifier.verticalOriginX = svgFontData->verticalOriginX();
if (identifier.verticalOriginY == SVGGlyph::inheritedValue())
identifier.verticalOriginY = svgFontData->verticalOriginY();
if (identifier.verticalAdvanceY == SVGGlyph::inheritedValue())
identifier.verticalAdvanceY = svgFontData->verticalAdvanceY();
}
static inline float parseSVGGlyphAttribute(const SVGElement* element, const WebCore::QualifiedName& name)
{
AtomicString value(element->getAttribute(name));
if (value.isEmpty())
return SVGGlyph::inheritedValue();
return value.toFloat();
}
AttributeToPropertyTypeMap& SVGGlyphElement::attributeToPropertyTypeMap()
{
DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
return s_attributeToPropertyTypeMap;
}
void SVGGlyphElement::fillAttributeToPropertyTypeMap()
{
AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
SVGStyledElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
attributeToPropertyTypeMap.set(SVGNames::dAttr, AnimatedPath);
}
SVGGlyph SVGGlyphElement::buildGenericGlyphIdentifier(const SVGElement* element)
{
SVGGlyph identifier;
identifier.pathData = parsePathData(element->getAttribute(dAttr));
identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, horiz_adv_xAttr);
identifier.verticalOriginX = parseSVGGlyphAttribute(element, vert_origin_xAttr);
identifier.verticalOriginY = parseSVGGlyphAttribute(element, vert_origin_yAttr);
identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, vert_adv_yAttr);
return identifier;
}
SVGGlyph SVGGlyphElement::buildGlyphIdentifier() const
{
SVGGlyph identifier(buildGenericGlyphIdentifier(this));
identifier.glyphName = getAttribute(glyph_nameAttr);
identifier.orientation = parseOrientation(getAttribute(orientationAttr));
identifier.arabicForm = parseArabicForm(getAttribute(arabic_formAttr));
String language = getAttribute(SVGNames::langAttr);
if (!language.isEmpty())
identifier.languages = parseDelimitedString(language, ',');
return identifier;
}
}
#endif // ENABLE(SVG_FONTS)