namespace WebCore {
SVGFontData::SVGFontData(SVGFontFaceElement* fontFaceElement)
- : CustomFontData(false)
- , m_svgFontFaceElement(fontFaceElement)
+ : CustomFontData()
+ , m_svgFontFaceElement(fontFaceElement->createWeakRef())
, m_horizontalOriginX(fontFaceElement->horizontalOriginX())
, m_horizontalOriginY(fontFaceElement->horizontalOriginY())
, m_horizontalAdvanceX(fontFaceElement->horizontalAdvanceX())
ASSERT_ARG(fontFaceElement, fontFaceElement);
}
+SVGFontData::~SVGFontData()
+{
+}
+
void SVGFontData::initializeFontData(SimpleFontData* fontData, float fontSize)
{
ASSERT(fontData);
SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement();
- ASSERT(svgFontFaceElement);
SVGFontElement* svgFontElement = svgFontFaceElement->associatedFontElement();
ASSERT(svgFontElement);
float SVGFontData::widthForSVGGlyph(Glyph glyph, float fontSize) const
{
+ // FIXME: (http://crbug.com/359380) Width calculation may be triggered after removeNode from the current editing impl.
+ // The retrieved width is not being used, so here we return a dummy value.
+ if (shouldSkipDrawing())
+ return 0.0;
+
SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement();
- ASSERT(svgFontFaceElement);
+
+ // RenderView::clearSelection is invoked while removing some element, e.g.
+ // Document::nodeWillBeRemoved => FrameSelection::nodeWillBeRemoved => RenderView::clearSelection.
+ // Since recalc style has not been executed yet, RenderStyle might have some reference to
+ // SVGFontFaceElement which was also removed.
+ // In this case, use default horizontalAdvanceX instead of associatedFontElement's one.
+ if (!svgFontFaceElement->inDocument())
+ return m_horizontalAdvanceX * scaleEmToUnits(fontSize, svgFontFaceElement->unitsPerEm());
SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontElement();
ASSERT(associatedFontElement);
arabicForms = charactersWithArabicForm(remainingTextInRun, mirror);
SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement();
- ASSERT(svgFontFaceElement);
-
SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontElement();
ASSERT(associatedFontElement);
if (Element* parentRenderObjectElement = toElement(parentRenderObject->node())) {
language = parentRenderObjectElement->getAttribute(XMLNames::langAttr);
- if (parentRenderObjectElement->hasTagName(SVGNames::altGlyphTag)) {
- if (!toSVGAltGlyphElement(parentRenderObjectElement)->hasValidGlyphElements(altGlyphNames))
+ if (isSVGAltGlyphElement(*parentRenderObjectElement)) {
+ if (!toSVGAltGlyphElement(*parentRenderObjectElement).hasValidGlyphElements(altGlyphNames))
altGlyphNames.clear();
}
}
size_t altGlyphNamesSize = altGlyphNames.size();
if (altGlyphNamesSize) {
for (size_t index = 0; index < altGlyphNamesSize; ++index)
- associatedFontElement->collectGlyphsForGlyphName(altGlyphNames[index], glyphs);
+ associatedFontElement->collectGlyphsForAltGlyphReference(altGlyphNames[index], glyphs);
// Assign the unicodeStringLength now that its known.
size_t glyphsSize = glyphs.size();
// Later code will fail if we do not do this and the glyph is incompatible.
if (glyphsSize) {
SVGGlyph& svgGlyph = glyphs[0];
- iterator.setLastGlyphName(svgGlyph.glyphName);
glyphData.glyph = svgGlyph.tableEntry;
advanceLength = svgGlyph.unicodeStringLength;
return true;
continue;
if (!isCompatibleGlyph(svgGlyph, isVerticalText, language, arabicForms, currentCharacter, currentCharacter + svgGlyph.unicodeStringLength))
continue;
- iterator.setLastGlyphName(svgGlyph.glyphName);
glyphData.glyph = svgGlyph.tableEntry;
advanceLength = svgGlyph.unicodeStringLength;
return true;
}
- iterator.setLastGlyphName(String());
return false;
}
ASSERT(fontData->isSVGFont());
SVGFontFaceElement* fontFaceElement = this->svgFontFaceElement();
- ASSERT(fontFaceElement);
-
SVGFontElement* fontElement = fontFaceElement->associatedFontElement();
ASSERT(fontElement);
for (unsigned i = 0; i < length; ++i) {
String lookupString(buffer + i, 1);
fontElement->collectGlyphsForString(lookupString, glyphs);
- if (glyphs.isEmpty()) {
- pageToFill->setGlyphDataForIndex(offset + i, 0, 0);
+ if (glyphs.isEmpty())
continue;
- }
// Associate entry in glyph page with first valid SVGGlyph.
// If there are multiple valid ones, just take the first one. WidthIterator will take
// Each character here consists of a surrogate pair
String lookupString(buffer + i * 2, 2);
fontElement->collectGlyphsForString(lookupString, glyphs);
- if (glyphs.isEmpty()) {
- pageToFill->setGlyphDataForIndex(offset + i, 0, 0);
+ if (glyphs.isEmpty())
continue;
- }
// Associate entry in glyph page with first valid SVGGlyph.
// If there are multiple valid ones, just take the first one. WidthIterator will take
return mirroredCharacters.toString();
}
+SVGFontFaceElement* SVGFontData::svgFontFaceElement() const
+{
+ // FIXME: SVGFontData should be only used from the document with the SVGFontFaceElement.
+ RELEASE_ASSERT(m_svgFontFaceElement && m_svgFontFaceElement->inDocument());
+ return m_svgFontFaceElement.get();
+}
+
+bool SVGFontData::shouldSkipDrawing() const
+{
+ // FIXME: (http://crbug.com/359380) Glyph may be referenced after removeNode from the current editing impl.
+ return !m_svgFontFaceElement || !m_svgFontFaceElement->inDocument();
+}
+
} // namespace WebCore
#endif