This source file includes following definitions.
- create
- invalidateGlyphCache
- parseAttribute
- insertedInto
- removedFrom
- parseArabicForm
- parseOrientation
- inheritUnspecifiedAttributes
- parseSVGGlyphAttribute
- buildGenericGlyphIdentifier
- buildGlyphIdentifier
#include "config.h"
#if ENABLE(SVG_FONTS)
#include "core/svg/SVGGlyphElement.h"
#include "core/svg/SVGFontData.h"
#include "core/svg/SVGFontElement.h"
#include "core/svg/SVGPathUtilities.h"
namespace WebCore {
inline SVGGlyphElement::SVGGlyphElement(Document& document)
: SVGElement(SVGNames::glyphTag, document)
{
ScriptWrappable::init(this);
}
PassRefPtr<SVGGlyphElement> SVGGlyphElement::create(Document& document)
{
return adoptRef(new SVGGlyphElement(document));
}
void SVGGlyphElement::invalidateGlyphCache()
{
ContainerNode* fontNode = parentNode();
if (isSVGFontElement(fontNode))
toSVGFontElement(*fontNode).invalidateGlyphCache();
}
void SVGGlyphElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == SVGNames::dAttr)
invalidateGlyphCache();
else
SVGElement::parseAttribute(name, value);
}
Node::InsertionNotificationRequest SVGGlyphElement::insertedInto(ContainerNode* rootParent)
{
invalidateGlyphCache();
return SVGElement::insertedInto(rootParent);
}
void SVGGlyphElement::removedFrom(ContainerNode* rootParent)
{
if (rootParent->inDocument())
invalidateGlyphCache();
SVGElement::removedFrom(rootParent);
}
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;
}
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->fastGetAttribute(name));
if (value.isEmpty())
return SVGGlyph::inheritedValue();
return value.toFloat();
}
SVGGlyph SVGGlyphElement::buildGenericGlyphIdentifier(const SVGElement* element)
{
SVGGlyph identifier;
buildPathFromString(element->fastGetAttribute(SVGNames::dAttr), identifier.pathData);
identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, SVGNames::horiz_adv_xAttr);
identifier.verticalOriginX = parseSVGGlyphAttribute(element, SVGNames::vert_origin_xAttr);
identifier.verticalOriginY = parseSVGGlyphAttribute(element, SVGNames::vert_origin_yAttr);
identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, SVGNames::vert_adv_yAttr);
return identifier;
}
SVGGlyph SVGGlyphElement::buildGlyphIdentifier() const
{
SVGGlyph identifier(buildGenericGlyphIdentifier(this));
identifier.glyphName = fastGetAttribute(SVGNames::glyph_nameAttr);
identifier.orientation = parseOrientation(fastGetAttribute(SVGNames::orientationAttr));
identifier.arabicForm = parseArabicForm(fastGetAttribute(SVGNames::arabic_formAttr));
String language = fastGetAttribute(SVGNames::langAttr);
if (!language.isEmpty())
identifier.languages = parseDelimitedString(language, ',');
return identifier;
}
}
#endif