2011-05-24 Nikolas Zimmermann <nzimmermann@rim.com>
Reviewed by Antti Koivisto.
Remove platform layering violation: TextRun stores RenderObjects for SVG Fonts support
https://bugs.webkit.org/show_bug.cgi?id=60254
First part:
Remove a long-standing layering violation in TextRun: it stores RenderObject/RenderSVGResource pointers for SVG Fonts support.
Replace the two Render* pointers with a single RefPtr<AbstractRenderingContext>. AbstractRenderingContext is a helper class,
that can be derived from in order to associate additional data with a TextRun. This effectively reduces the memory consumption of TextRun.
Introduce rendering/TextRunRenderingContext.h, which inherits from TextRun::AbstractRenderingContext and holds additional data.
If the primary font in use is a SVG Font then allocate a TextRunRenderingContext object and store it in the RefPtr<AbstractRenderingContext>
in TextRun. If the primary font is not a SVG Font, don't even allocate the TextRunRenderingContext structure, as we won't need the context data.
SVG Fonts glyph matching only works within a context, so we need access to the RenderObject that's drawing the text.
This is the main preparation patch for the SVG Fonts rewrite, that will allow us to share the simple text code path for SVG Fonts as well,
making all CSS text properties work for HTML text using SVG Fonts, and allows proper integration within the GlyphPage concept. Soon
we can intermix WOFF/SVG & native fonts, within segment font declarations.
Second part:
Remove a long-standing layering violation in SimpleFontData: it stores SVGFontData objects, that are living in svg/.
Use the same concept as above, introduce SimpleFontData::AbstractFontData, and let SVGFontData inherit from AbstractFontData and extent it.
If SVG Fonts are used, CSSFontFaceSource will create a SVGFontData object and pass it as PassOwnPtr<AbstractFontData> to SimpleFontData.
All layering violations are gone now, SVG Fonts are cleanly integrated now.
Doesn't affect any tests yet, refactoring only.
* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::getFontData):
* platform/graphics/Font.cpp:
(WebCore::Font::drawText):
(WebCore::Font::width):
(WebCore::Font::selectionRectForText):
(WebCore::Font::offsetForPosition):
* platform/graphics/Font.h:
* platform/graphics/SimpleFontData.cpp:
(WebCore::SimpleFontData::SimpleFontData):
(WebCore::SimpleFontData::~SimpleFontData):
* platform/graphics/SimpleFontData.h:
(WebCore::SimpleFontData::FontData::~FontData):
(WebCore::SimpleFontData::fontMetrics):
(WebCore::SimpleFontData::setMaxCharWidth):
(WebCore::SimpleFontData::setAvgCharWidth):
(WebCore::SimpleFontData::setSpaceWidth):
(WebCore::SimpleFontData::setSpaceGlyph):
(WebCore::SimpleFontData::setZeroWidthSpaceGlyph):
(WebCore::SimpleFontData::fontData):
(WebCore::SimpleFontData::isSVGFont):
(WebCore::SimpleFontData::setMissingGlyphData):
* platform/graphics/TextRun.h:
(WebCore::TextRun::TextRun):
(WebCore::TextRun::setAllowTabs):
(WebCore::TextRun::setXPos):
(WebCore::TextRun::RenderingContext::~RenderingContext):
(WebCore::TextRun::renderingContext):
(WebCore::TextRun::setRenderingContext):
* rendering/EllipsisBox.cpp:
(WebCore::EllipsisBox::paint):
(WebCore::EllipsisBox::selectionRect):
(WebCore::EllipsisBox::paintSelection):
* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::selectionRect):
(WebCore::InlineTextBox::paint):
(WebCore::InlineTextBox::paintSelection):
(WebCore::InlineTextBox::paintCompositionBackground):
(WebCore::InlineTextBox::paintSpellingOrGrammarMarker):
(WebCore::InlineTextBox::paintTextMatchMarker):
(WebCore::InlineTextBox::computeRectForReplacementMarker):
(WebCore::InlineTextBox::offsetForPosition):
(WebCore::InlineTextBox::positionForOffset):
(WebCore::InlineTextBox::constructTextRun):
* rendering/InlineTextBox.h:
* rendering/RenderBlock.cpp:
(WebCore::stripTrailingSpace):
(WebCore::RenderBlock::constructTextRun):
* rendering/RenderBlock.h:
* rendering/RenderBlockLineLayout.cpp:
(WebCore::setLogicalWidthForTextRun):
(WebCore::textWidth):
(WebCore::tryHyphenating):
(WebCore::RenderBlock::LineBreaker::nextLineBreak):
(WebCore::RenderBlock::checkLinesForTextOverflow):
* rendering/RenderCombineText.cpp:
(WebCore::RenderCombineText::combineText):
* rendering/RenderFileUploadControl.cpp:
(WebCore::RenderFileUploadControl::paintObject):
(WebCore::RenderFileUploadControl::computePreferredLogicalWidths):
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::applyLineClamp):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::setImageSizeForAltText):
(WebCore::RenderImage::paintReplaced):
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::updateFromElement):
* rendering/RenderListMarker.cpp:
(WebCore::RenderListMarker::paint):
(WebCore::RenderListMarker::computePreferredLogicalWidths):
(WebCore::RenderListMarker::getRelativeMarkerRect):
* rendering/RenderText.cpp:
(WebCore::RenderText::widthFromCache):
(WebCore::RenderText::trimmedPrefWidths):
(WebCore::RenderText::computePreferredLogicalWidths):
(WebCore::RenderText::width):
* rendering/RenderTextControl.cpp:
(WebCore::RenderTextControl::getAvgCharWidth):
* rendering/svg/RenderSVGAllInOne.cpp:
* rendering/svg/SVGInlineTextBox.cpp:
(WebCore::SVGInlineTextBox::offsetForPositionInFragment):
(WebCore::SVGInlineTextBox::prepareGraphicsContextForTextPainting):
(WebCore::SVGInlineTextBox::restoreGraphicsContextAfterTextPainting):
(WebCore::SVGInlineTextBox::constructTextRun):
(WebCore::SVGInlineTextBox::paintText):
* rendering/svg/SVGTextLayoutEngineSpacing.cpp:
(WebCore::SVGTextLayoutEngineSpacing::calculateSVGKerning):
* rendering/svg/SVGTextMetrics.cpp:
(WebCore::constructTextRun):
(WebCore::SVGTextMetrics::measureCharacterRange):
* rendering/svg/SVGTextRunRenderingContext.cpp: Copied from svg/SVGFont.cpp.
(WebCore::svgFontAndFontFaceElementForFontData):
(WebCore::firstParentRendererForNonTextNode):
(WebCore::referencingRenderObjectFromRun):
(WebCore::activePaintingResourceFromRun):
(WebCore::SVGTextRunWalker::walk):
(WebCore::floatWidthMissingGlyphCallback):
(WebCore::floatWidthOfSubStringUsingSVGFont):
(WebCore::SVGTextRunRenderingContext::floatWidthUsingSVGFont):
(WebCore::SVGTextRunRenderingContext::drawTextUsingSVGFont):
(WebCore::SVGTextRunRenderingContext::selectionRectForTextUsingSVGFont):
(WebCore::SVGTextRunRenderingContext::offsetForPositionForTextUsingSVGFont):
* rendering/svg/SVGTextRunRenderingContext.h: Added.
(WebCore::SVGTextRunRenderingContext::create):
(WebCore::SVGTextRunRenderingContext::context):
(WebCore::SVGTextRunRenderingContext::activePaintingResource):
(WebCore::SVGTextRunRenderingContext::setActivePaintingResource):
(WebCore::SVGTextRunRenderingContext::SVGTextRunRenderingContext):
(WebCore::textRunNeedsRenderingContext):
* svg/SVGAllInOne.cpp:
* svg/SVGFont.cpp: Removed.
* svg/SVGFontData.cpp:
(WebCore::SVGFontData::initializeFontData):
* svg/SVGFontData.h:
(WebCore::SVGFontData::create):
(WebCore::SVGFontData::isSVGFontData):
* svg/SVGGlyphElement.cpp:
(WebCore::SVGGlyphElement::SVGGlyphElement):
(WebCore::SVGGlyphElement::buildGenericGlyphIdentifier):
(WebCore::SVGGlyphElement::buildGlyphIdentifier):
* svg/SVGHKernElement.cpp:
(WebCore::SVGHKernElement::SVGHKernElement):
(WebCore::SVGHKernElement::buildHorizontalKerningPair):
* svg/SVGVKernElement.cpp:
(WebCore::SVGVKernElement::SVGVKernElement):
(WebCore::SVGVKernElement::buildVerticalKerningPair):
* svg/SVGVKernElement.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@87152 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/svg/SVGGlyphElement.cpp b/Source/WebCore/svg/SVGGlyphElement.cpp
index 7a06fe1..b45de5e 100644
--- a/Source/WebCore/svg/SVGGlyphElement.cpp
+++ b/Source/WebCore/svg/SVGGlyphElement.cpp
@@ -30,17 +30,13 @@
#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));
+ ASSERT(hasTagName(SVGNames::glyphTag));
}
PassRefPtr<SVGGlyphElement> SVGGlyphElement::create(const QualifiedName& tagName, Document* document)
@@ -150,28 +146,28 @@
SVGGlyph SVGGlyphElement::buildGenericGlyphIdentifier(const SVGElement* element)
{
SVGGlyph identifier;
- identifier.pathData = parsePathData(element->getAttribute(dAttr));
+ identifier.pathData = parsePathData(element->getAttribute(SVGNames::dAttr));
// Spec: The horizontal advance after rendering the glyph in horizontal orientation.
// If the attribute is not specified, the effect is as if the attribute were set to the
// value of the font's horiz-adv-x attribute. Glyph widths are required to be non-negative,
// even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts.
- identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, horiz_adv_xAttr);
+ identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, SVGNames::horiz_adv_xAttr);
// Spec: The X-coordinate in the font coordinate system of the origin of the 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 value of the font's vert-origin-x attribute.
- identifier.verticalOriginX = parseSVGGlyphAttribute(element, vert_origin_xAttr);
+ identifier.verticalOriginX = parseSVGGlyphAttribute(element, SVGNames::vert_origin_xAttr);
// Spec: The 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 value of the font's vert-origin-y attribute.
- identifier.verticalOriginY = parseSVGGlyphAttribute(element, vert_origin_yAttr);
+ identifier.verticalOriginY = parseSVGGlyphAttribute(element, SVGNames::vert_origin_yAttr);
// Spec: The vertical advance after rendering a glyph in vertical orientation.
// If the attribute is not specified, the effect is as if the attribute were set to the
// value of the font's vert-adv-y attribute.
- identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, vert_adv_yAttr);
+ identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, SVGNames::vert_adv_yAttr);
return identifier;
}
@@ -179,9 +175,9 @@
SVGGlyph SVGGlyphElement::buildGlyphIdentifier() const
{
SVGGlyph identifier(buildGenericGlyphIdentifier(this));
- identifier.glyphName = getAttribute(glyph_nameAttr);
- identifier.orientation = parseOrientation(getAttribute(orientationAttr));
- identifier.arabicForm = parseArabicForm(getAttribute(arabic_formAttr));
+ identifier.glyphName = getAttribute(SVGNames::glyph_nameAttr);
+ identifier.orientation = parseOrientation(getAttribute(SVGNames::orientationAttr));
+ identifier.arabicForm = parseArabicForm(getAttribute(SVGNames::arabic_formAttr));
String language = getAttribute(SVGNames::langAttr);
if (!language.isEmpty())