diff options
Diffstat (limited to 'Source/WebCore/svg/SVGFontFaceElement.cpp')
-rw-r--r-- | Source/WebCore/svg/SVGFontFaceElement.cpp | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/Source/WebCore/svg/SVGFontFaceElement.cpp b/Source/WebCore/svg/SVGFontFaceElement.cpp index beac300e7..4a93c7e28 100644 --- a/Source/WebCore/svg/SVGFontFaceElement.cpp +++ b/Source/WebCore/svg/SVGFontFaceElement.cpp @@ -24,7 +24,6 @@ #if ENABLE(SVG_FONTS) #include "SVGFontFaceElement.h" -#include "Attribute.h" #include "CSSFontFaceSrcValue.h" #include "CSSParser.h" #include "CSSPropertyNames.h" @@ -33,7 +32,7 @@ #include "CSSValueList.h" #include "Document.h" #include "ElementIterator.h" -#include "Font.h" +#include "FontCascade.h" #include "SVGDocumentExtensions.h" #include "SVGFontElement.h" #include "SVGFontFaceSrcElement.h" @@ -42,6 +41,7 @@ #include "StyleProperties.h" #include "StyleResolver.h" #include "StyleRule.h" +#include "StyleScope.h" #include <math.h> namespace WebCore { @@ -50,15 +50,15 @@ using namespace SVGNames; inline SVGFontFaceElement::SVGFontFaceElement(const QualifiedName& tagName, Document& document) : SVGElement(tagName, document) - , m_fontFaceRule(StyleRuleFontFace::create(MutableStyleProperties::create(CSSStrictMode))) - , m_fontElement(0) + , m_fontFaceRule(StyleRuleFontFace::create(MutableStyleProperties::create(HTMLStandardMode))) + , m_fontElement(nullptr) { ASSERT(hasTagName(font_faceTag)); } -PassRefPtr<SVGFontFaceElement> SVGFontFaceElement::create(const QualifiedName& tagName, Document& document) +Ref<SVGFontFaceElement> SVGFontFaceElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new SVGFontFaceElement(tagName, document)); + return adoptRef(*new SVGFontFaceElement(tagName, document)); } void SVGFontFaceElement::parseAttribute(const QualifiedName& name, const AtomicString& value) @@ -75,16 +75,21 @@ void SVGFontFaceElement::parseAttribute(const QualifiedName& name, const AtomicS unsigned SVGFontFaceElement::unitsPerEm() const { - const AtomicString& value = fastGetAttribute(units_per_emAttr); + const AtomicString& value = attributeWithoutSynchronization(units_per_emAttr); if (value.isEmpty()) - return gDefaultUnitsPerEm; + return FontMetrics::defaultUnitsPerEm; return static_cast<unsigned>(ceilf(value.toFloat())); } int SVGFontFaceElement::xHeight() const { - return static_cast<int>(ceilf(fastGetAttribute(x_heightAttr).toFloat())); + return static_cast<int>(ceilf(attributeWithoutSynchronization(x_heightAttr).toFloat())); +} + +int SVGFontFaceElement::capHeight() const +{ + return static_cast<int>(ceilf(attributeWithoutSynchronization(cap_heightAttr).toFloat())); } float SVGFontFaceElement::horizontalOriginX() const @@ -95,7 +100,7 @@ float SVGFontFaceElement::horizontalOriginX() const // Spec: The X-coordinate in the font coordinate system of the origin of a glyph to be used when // drawing horizontally oriented text. (Note that the origin applies to all glyphs in the font.) // If the attribute is not specified, the effect is as if a value of "0" were specified. - return m_fontElement->fastGetAttribute(horiz_origin_xAttr).toFloat(); + return m_fontElement->attributeWithoutSynchronization(horiz_origin_xAttr).toFloat(); } float SVGFontFaceElement::horizontalOriginY() const @@ -106,7 +111,7 @@ float SVGFontFaceElement::horizontalOriginY() const // Spec: The Y-coordinate in the font coordinate system of the origin of a glyph to be used when // drawing horizontally oriented text. (Note that the origin applies to all glyphs in the font.) // If the attribute is not specified, the effect is as if a value of "0" were specified. - return m_fontElement->fastGetAttribute(horiz_origin_yAttr).toFloat(); + return m_fontElement->attributeWithoutSynchronization(horiz_origin_yAttr).toFloat(); } float SVGFontFaceElement::horizontalAdvanceX() const @@ -117,7 +122,7 @@ float SVGFontFaceElement::horizontalAdvanceX() const // Spec: The default horizontal advance after rendering a glyph in horizontal orientation. Glyph // widths are required to be non-negative, even if the glyph is typically rendered right-to-left, // as in Hebrew and Arabic scripts. - return m_fontElement->fastGetAttribute(horiz_adv_xAttr).toFloat(); + return m_fontElement->attributeWithoutSynchronization(horiz_adv_xAttr).toFloat(); } float SVGFontFaceElement::verticalOriginX() const @@ -128,7 +133,7 @@ float SVGFontFaceElement::verticalOriginX() const // Spec: The default X-coordinate in the font coordinate system of the origin of a glyph to be used when // drawing vertically oriented text. If the attribute is not specified, the effect is as if the attribute // were set to half of the effective value of attribute horiz-adv-x. - const AtomicString& value = m_fontElement->fastGetAttribute(vert_origin_xAttr); + const AtomicString& value = m_fontElement->attributeWithoutSynchronization(vert_origin_xAttr); if (value.isEmpty()) return horizontalAdvanceX() / 2.0f; @@ -143,7 +148,7 @@ float SVGFontFaceElement::verticalOriginY() const // Spec: The default Y-coordinate in the font coordinate system of the origin of a glyph to be used when // drawing vertically oriented text. If the attribute is not specified, the effect is as if the attribute // were set to the position specified by the font's ascent attribute. - const AtomicString& value = m_fontElement->fastGetAttribute(vert_origin_yAttr); + const AtomicString& value = m_fontElement->attributeWithoutSynchronization(vert_origin_yAttr); if (value.isEmpty()) return ascent(); @@ -157,7 +162,7 @@ float SVGFontFaceElement::verticalAdvanceY() const // Spec: The default vertical advance after rendering a glyph in vertical orientation. If the attribute is // not specified, the effect is as if a value equivalent of one em were specified (see units-per-em). - const AtomicString& value = m_fontElement->fastGetAttribute(vert_adv_yAttr); + const AtomicString& value = m_fontElement->attributeWithoutSynchronization(vert_adv_yAttr); if (value.isEmpty()) return 1.0f; @@ -170,12 +175,12 @@ int SVGFontFaceElement::ascent() const // unaccented height of the font within the font coordinate system. If the attribute is not specified, // the effect is as if the attribute were set to the difference between the units-per-em value and the // vert-origin-y value for the corresponding font. - const AtomicString& ascentValue = fastGetAttribute(ascentAttr); + const AtomicString& ascentValue = attributeWithoutSynchronization(ascentAttr); if (!ascentValue.isEmpty()) return static_cast<int>(ceilf(ascentValue.toFloat())); if (m_fontElement) { - const AtomicString& vertOriginY = m_fontElement->fastGetAttribute(vert_origin_yAttr); + const AtomicString& vertOriginY = m_fontElement->attributeWithoutSynchronization(vert_origin_yAttr); if (!vertOriginY.isEmpty()) return static_cast<int>(unitsPerEm()) - static_cast<int>(ceilf(vertOriginY.toFloat())); } @@ -189,7 +194,7 @@ int SVGFontFaceElement::descent() const // Spec: Same syntax and semantics as the 'descent' descriptor within an @font-face rule. The maximum // unaccented depth of the font within the font coordinate system. If the attribute is not specified, // the effect is as if the attribute were set to the vert-origin-y value for the corresponding font. - const AtomicString& descentValue = fastGetAttribute(descentAttr); + const AtomicString& descentValue = attributeWithoutSynchronization(descentAttr); if (!descentValue.isEmpty()) { // 14 different W3C SVG 1.1 testcases use a negative descent value, // where a positive was meant to be used Including: @@ -199,7 +204,7 @@ int SVGFontFaceElement::descent() const } if (m_fontElement) { - const AtomicString& vertOriginY = m_fontElement->fastGetAttribute(vert_origin_yAttr); + const AtomicString& vertOriginY = m_fontElement->attributeWithoutSynchronization(vert_origin_yAttr); if (!vertOriginY.isEmpty()) return static_cast<int>(ceilf(vertOriginY.toFloat())); } @@ -216,13 +221,13 @@ String SVGFontFaceElement::fontFamily() const SVGFontElement* SVGFontFaceElement::associatedFontElement() const { ASSERT(parentNode() == m_fontElement); - ASSERT(!parentNode() || isSVGFontElement(parentNode())); + ASSERT(!parentNode() || is<SVGFontElement>(*parentNode())); return m_fontElement; } void SVGFontFaceElement::rebuildFontFace() { - if (!inDocument()) { + if (!isConnected()) { ASSERT(!m_fontElement); return; } @@ -230,16 +235,16 @@ void SVGFontFaceElement::rebuildFontFace() // we currently ignore all but the first src element, alternatively we could concat them auto srcElement = childrenOfType<SVGFontFaceSrcElement>(*this).first(); - bool describesParentFont = isSVGFontElement(parentNode()); + bool describesParentFont = is<SVGFontElement>(*parentNode()); RefPtr<CSSValueList> list; if (describesParentFont) { - m_fontElement = toSVGFontElement(parentNode()); + m_fontElement = downcast<SVGFontElement>(parentNode()); list = CSSValueList::createCommaSeparated(); list->append(CSSFontFaceSrcValue::createLocal(fontFamily())); } else { - m_fontElement = 0; + m_fontElement = nullptr; if (srcElement) list = srcElement->srcValue(); } @@ -253,26 +258,26 @@ void SVGFontFaceElement::rebuildFontFace() if (describesParentFont) { // Traverse parsed CSS values and associate CSSFontFaceSrcValue elements with ourselves. RefPtr<CSSValue> src = m_fontFaceRule->properties().getPropertyCSSValue(CSSPropertySrc); - CSSValueList* srcList = toCSSValueList(src.get()); + CSSValueList* srcList = downcast<CSSValueList>(src.get()); unsigned srcLength = srcList ? srcList->length() : 0; - for (unsigned i = 0; i < srcLength; i++) { - if (CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBoundsCheck(i))) + for (unsigned i = 0; i < srcLength; ++i) { + if (CSSFontFaceSrcValue* item = downcast<CSSFontFaceSrcValue>(srcList->itemWithoutBoundsCheck(i))) item->setSVGFontFaceElement(this); } } - document().styleResolverChanged(DeferRecalcStyle); + document().styleScope().didChangeStyleSheetEnvironment(); } Node::InsertionNotificationRequest SVGFontFaceElement::insertedInto(ContainerNode& rootParent) { SVGElement::insertedInto(rootParent); - if (!rootParent.inDocument()) { + if (!rootParent.isConnected()) { ASSERT(!m_fontElement); return InsertionDone; } - document().accessSVGExtensions()->registerSVGFontFaceElement(this); + document().accessSVGExtensions().registerSVGFontFaceElement(this); rebuildFontFace(); return InsertionDone; @@ -282,12 +287,12 @@ void SVGFontFaceElement::removedFrom(ContainerNode& rootParent) { SVGElement::removedFrom(rootParent); - if (rootParent.inDocument()) { - m_fontElement = 0; - document().accessSVGExtensions()->unregisterSVGFontFaceElement(this); + if (rootParent.isConnected()) { + m_fontElement = nullptr; + document().accessSVGExtensions().unregisterSVGFontFaceElement(this); m_fontFaceRule->mutableProperties().clear(); - document().styleResolverChanged(DeferRecalcStyle); + document().styleScope().didChangeStyleSheetEnvironment(); } else ASSERT(!m_fontElement); } |