Changeset 87152 in webkit


Ignore:
Timestamp:
May 24, 2011 8:27:36 AM (13 years ago)
Author:
Nikolas Zimmermann
Message:

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:
Location:
trunk/Source/WebCore
Files:
1 added
38 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r87150 r87152  
    16181618        rendering/svg/SVGTextLayoutEngineBaseline.cpp
    16191619        rendering/svg/SVGTextLayoutEngineSpacing.cpp
     1620        rendering/svg/SVGTextRunRenderingContext.cpp
    16201621        rendering/svg/SVGTextMetrics.cpp
    16211622        rendering/svg/SVGTextQuery.cpp
     
    16721673        svg/SVGFilterPrimitiveStandardAttributes.cpp
    16731674        svg/SVGFitToViewBox.cpp
    1674         svg/SVGFont.cpp
    16751675        svg/SVGFontData.cpp
    16761676        svg/SVGFontElement.cpp
  • trunk/Source/WebCore/ChangeLog

    r87151 r87152  
     12011-05-24  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        Remove platform layering violation: TextRun stores RenderObjects for SVG Fonts support
     6        https://bugs.webkit.org/show_bug.cgi?id=60254
     7
     8        First part:
     9        Remove a long-standing layering violation in TextRun: it stores RenderObject/RenderSVGResource pointers for SVG Fonts support.
     10        Replace the two Render* pointers with a single RefPtr<AbstractRenderingContext>. AbstractRenderingContext is a helper class,
     11        that can be derived from in order to associate additional data with a TextRun. This effectively reduces the memory consumption of TextRun.
     12
     13        Introduce rendering/TextRunRenderingContext.h, which inherits from TextRun::AbstractRenderingContext and holds additional data.
     14        If the primary font in use is a SVG Font then allocate a TextRunRenderingContext object and store it in the RefPtr<AbstractRenderingContext>
     15        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.
     16        SVG Fonts glyph matching only works within a context, so we need access to the RenderObject that's drawing the text.
     17
     18        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,
     19        making all CSS text properties work for HTML text using SVG Fonts, and allows proper integration within the GlyphPage concept. Soon
     20        we can intermix WOFF/SVG & native fonts, within segment font declarations.
     21
     22        Second part:
     23        Remove a long-standing layering violation in SimpleFontData: it stores SVGFontData objects, that are living in svg/.
     24        Use the same concept as above, introduce SimpleFontData::AbstractFontData, and let SVGFontData inherit from AbstractFontData and extent it.
     25        If SVG Fonts are used, CSSFontFaceSource will create a SVGFontData object and pass it as PassOwnPtr<AbstractFontData> to SimpleFontData.
     26
     27        All layering violations are gone now, SVG Fonts are cleanly integrated now.
     28        Doesn't affect any tests yet, refactoring only.
     29
     30        * CMakeLists.txt:
     31        * GNUmakefile.list.am:
     32        * WebCore.gypi:
     33        * WebCore.pro:
     34        * WebCore.vcproj/WebCore.vcproj:
     35        * WebCore.xcodeproj/project.pbxproj:
     36        * css/CSSFontFaceSource.cpp:
     37        (WebCore::CSSFontFaceSource::getFontData):
     38        * platform/graphics/Font.cpp:
     39        (WebCore::Font::drawText):
     40        (WebCore::Font::width):
     41        (WebCore::Font::selectionRectForText):
     42        (WebCore::Font::offsetForPosition):
     43        * platform/graphics/Font.h:
     44        * platform/graphics/SimpleFontData.cpp:
     45        (WebCore::SimpleFontData::SimpleFontData):
     46        (WebCore::SimpleFontData::~SimpleFontData):
     47        * platform/graphics/SimpleFontData.h:
     48        (WebCore::SimpleFontData::FontData::~FontData):
     49        (WebCore::SimpleFontData::fontMetrics):
     50        (WebCore::SimpleFontData::setMaxCharWidth):
     51        (WebCore::SimpleFontData::setAvgCharWidth):
     52        (WebCore::SimpleFontData::setSpaceWidth):
     53        (WebCore::SimpleFontData::setSpaceGlyph):
     54        (WebCore::SimpleFontData::setZeroWidthSpaceGlyph):
     55        (WebCore::SimpleFontData::fontData):
     56        (WebCore::SimpleFontData::isSVGFont):
     57        (WebCore::SimpleFontData::setMissingGlyphData):
     58        * platform/graphics/TextRun.h:
     59        (WebCore::TextRun::TextRun):
     60        (WebCore::TextRun::setAllowTabs):
     61        (WebCore::TextRun::setXPos):
     62        (WebCore::TextRun::RenderingContext::~RenderingContext):
     63        (WebCore::TextRun::renderingContext):
     64        (WebCore::TextRun::setRenderingContext):
     65        * rendering/EllipsisBox.cpp:
     66        (WebCore::EllipsisBox::paint):
     67        (WebCore::EllipsisBox::selectionRect):
     68        (WebCore::EllipsisBox::paintSelection):
     69        * rendering/InlineTextBox.cpp:
     70        (WebCore::InlineTextBox::selectionRect):
     71        (WebCore::InlineTextBox::paint):
     72        (WebCore::InlineTextBox::paintSelection):
     73        (WebCore::InlineTextBox::paintCompositionBackground):
     74        (WebCore::InlineTextBox::paintSpellingOrGrammarMarker):
     75        (WebCore::InlineTextBox::paintTextMatchMarker):
     76        (WebCore::InlineTextBox::computeRectForReplacementMarker):
     77        (WebCore::InlineTextBox::offsetForPosition):
     78        (WebCore::InlineTextBox::positionForOffset):
     79        (WebCore::InlineTextBox::constructTextRun):
     80        * rendering/InlineTextBox.h:
     81        * rendering/RenderBlock.cpp:
     82        (WebCore::stripTrailingSpace):
     83        (WebCore::RenderBlock::constructTextRun):
     84        * rendering/RenderBlock.h:
     85        * rendering/RenderBlockLineLayout.cpp:
     86        (WebCore::setLogicalWidthForTextRun):
     87        (WebCore::textWidth):
     88        (WebCore::tryHyphenating):
     89        (WebCore::RenderBlock::LineBreaker::nextLineBreak):
     90        (WebCore::RenderBlock::checkLinesForTextOverflow):
     91        * rendering/RenderCombineText.cpp:
     92        (WebCore::RenderCombineText::combineText):
     93        * rendering/RenderFileUploadControl.cpp:
     94        (WebCore::RenderFileUploadControl::paintObject):
     95        (WebCore::RenderFileUploadControl::computePreferredLogicalWidths):
     96        * rendering/RenderFlexibleBox.cpp:
     97        (WebCore::RenderFlexibleBox::applyLineClamp):
     98        * rendering/RenderImage.cpp:
     99        (WebCore::RenderImage::setImageSizeForAltText):
     100        (WebCore::RenderImage::paintReplaced):
     101        * rendering/RenderListBox.cpp:
     102        (WebCore::RenderListBox::updateFromElement):
     103        * rendering/RenderListMarker.cpp:
     104        (WebCore::RenderListMarker::paint):
     105        (WebCore::RenderListMarker::computePreferredLogicalWidths):
     106        (WebCore::RenderListMarker::getRelativeMarkerRect):
     107        * rendering/RenderText.cpp:
     108        (WebCore::RenderText::widthFromCache):
     109        (WebCore::RenderText::trimmedPrefWidths):
     110        (WebCore::RenderText::computePreferredLogicalWidths):
     111        (WebCore::RenderText::width):
     112        * rendering/RenderTextControl.cpp:
     113        (WebCore::RenderTextControl::getAvgCharWidth):
     114        * rendering/svg/RenderSVGAllInOne.cpp:
     115        * rendering/svg/SVGInlineTextBox.cpp:
     116        (WebCore::SVGInlineTextBox::offsetForPositionInFragment):
     117        (WebCore::SVGInlineTextBox::prepareGraphicsContextForTextPainting):
     118        (WebCore::SVGInlineTextBox::restoreGraphicsContextAfterTextPainting):
     119        (WebCore::SVGInlineTextBox::constructTextRun):
     120        (WebCore::SVGInlineTextBox::paintText):
     121        * rendering/svg/SVGTextLayoutEngineSpacing.cpp:
     122        (WebCore::SVGTextLayoutEngineSpacing::calculateSVGKerning):
     123        * rendering/svg/SVGTextMetrics.cpp:
     124        (WebCore::constructTextRun):
     125        (WebCore::SVGTextMetrics::measureCharacterRange):
     126        * rendering/svg/SVGTextRunRenderingContext.cpp: Copied from svg/SVGFont.cpp.
     127        (WebCore::svgFontAndFontFaceElementForFontData):
     128        (WebCore::firstParentRendererForNonTextNode):
     129        (WebCore::referencingRenderObjectFromRun):
     130        (WebCore::activePaintingResourceFromRun):
     131        (WebCore::SVGTextRunWalker::walk):
     132        (WebCore::floatWidthMissingGlyphCallback):
     133        (WebCore::floatWidthOfSubStringUsingSVGFont):
     134        (WebCore::SVGTextRunRenderingContext::floatWidthUsingSVGFont):
     135        (WebCore::SVGTextRunRenderingContext::drawTextUsingSVGFont):
     136        (WebCore::SVGTextRunRenderingContext::selectionRectForTextUsingSVGFont):
     137        (WebCore::SVGTextRunRenderingContext::offsetForPositionForTextUsingSVGFont):
     138        * rendering/svg/SVGTextRunRenderingContext.h: Added.
     139        (WebCore::SVGTextRunRenderingContext::create):
     140        (WebCore::SVGTextRunRenderingContext::context):
     141        (WebCore::SVGTextRunRenderingContext::activePaintingResource):
     142        (WebCore::SVGTextRunRenderingContext::setActivePaintingResource):
     143        (WebCore::SVGTextRunRenderingContext::SVGTextRunRenderingContext):
     144        (WebCore::textRunNeedsRenderingContext):
     145        * svg/SVGAllInOne.cpp:
     146        * svg/SVGFont.cpp: Removed.
     147        * svg/SVGFontData.cpp:
     148        (WebCore::SVGFontData::initializeFontData):
     149        * svg/SVGFontData.h:
     150        (WebCore::SVGFontData::create):
     151        (WebCore::SVGFontData::isSVGFontData):
     152        * svg/SVGGlyphElement.cpp:
     153        (WebCore::SVGGlyphElement::SVGGlyphElement):
     154        (WebCore::SVGGlyphElement::buildGenericGlyphIdentifier):
     155        (WebCore::SVGGlyphElement::buildGlyphIdentifier):
     156        * svg/SVGHKernElement.cpp:
     157        (WebCore::SVGHKernElement::SVGHKernElement):
     158        (WebCore::SVGHKernElement::buildHorizontalKerningPair):
     159        * svg/SVGVKernElement.cpp:
     160        (WebCore::SVGVKernElement::SVGVKernElement):
     161        (WebCore::SVGVKernElement::buildVerticalKerningPair):
     162        * svg/SVGVKernElement.h:
     163
    11642011-05-24  Ryuan Choi  <ryuan.choi@samsung.com>
    2165
  • trunk/Source/WebCore/GNUmakefile.list.am

    r87150 r87152  
    30923092        Source/WebCore/rendering/svg/SVGTextQuery.cpp \
    30933093        Source/WebCore/rendering/svg/SVGTextQuery.h \
     3094        Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp \
     3095        Source/WebCore/rendering/svg/SVGTextRunRenderingContext.h \
    30943096        Source/WebCore/rendering/TableLayout.h \
    30953097        Source/WebCore/rendering/TrailingFloatsRootInlineBox.h \
     
    33893391        Source/WebCore/svg/SVGFitToViewBox.cpp \
    33903392        Source/WebCore/svg/SVGFitToViewBox.h \
    3391         Source/WebCore/svg/SVGFont.cpp \
    33923393        Source/WebCore/svg/SVGFontData.cpp \
    33933394        Source/WebCore/svg/SVGFontData.h \
  • trunk/Source/WebCore/WebCore.gypi

    r87150 r87152  
    54835483            'rendering/svg/SVGTextQuery.cpp',
    54845484            'rendering/svg/SVGTextQuery.h',
     5485            'rendering/svg/SVGTextRunRenderingContext.cpp',
     5486            'rendering/svg/SVGTextRunRenderingContext.h',
    54855487            'storage/AbstractDatabase.cpp',
    54865488            'storage/ChangeVersionWrapper.cpp',
     
    57345736            'svg/SVGFitToViewBox.cpp',
    57355737            'svg/SVGFitToViewBox.h',
    5736             'svg/SVGFont.cpp',
    57375738            'svg/SVGFontData.cpp',
    57385739            'svg/SVGFontData.h',
  • trunk/Source/WebCore/WebCore.pro

    r87150 r87152  
    22532253    rendering/svg/SVGTextMetrics.h \
    22542254    rendering/svg/SVGTextQuery.h \
     2255    rendering/svg/SVGTextRunRenderingContext.h \
    22552256    rendering/TransformState.h \
    22562257    svg/animation/SMILTimeContainer.h \
     
    32093210              rendering/svg/SVGTextMetrics.cpp \
    32103211              rendering/svg/SVGTextQuery.cpp \
     3212              rendering/svg/SVGTextRunRenderingContext.cpp \
    32113213              svg/SVGDocumentExtensions.cpp \
    32123214              svg/SVGImageLoader.cpp \
     
    32623264              svg/SVGFilterPrimitiveStandardAttributes.cpp \
    32633265              svg/SVGFitToViewBox.cpp \
    3264               svg/SVGFont.cpp \
    32653266              svg/SVGFontData.cpp \
    32663267              svg/SVGFontElement.cpp \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r87150 r87152  
    4152741527                                        >
    4152841528                                </File>
     41529                                <File
     41530                                        RelativePath="..\rendering\svg\SVGTextRunRenderingContext.cpp"
     41531                                        >
     41532                                        <FileConfiguration
     41533                                                Name="Debug|Win32"
     41534                                                ExcludedFromBuild="true"
     41535                                                >
     41536                                                <Tool
     41537                                                        Name="VCCLCompilerTool"
     41538                                                />
     41539                                        </FileConfiguration>
     41540                                        <FileConfiguration
     41541                                                Name="Release|Win32"
     41542                                                ExcludedFromBuild="true"
     41543                                                >
     41544                                                <Tool
     41545                                                        Name="VCCLCompilerTool"
     41546                                                />
     41547                                        </FileConfiguration>
     41548                                        <FileConfiguration
     41549                                                Name="Debug_Cairo_CFLite|Win32"
     41550                                                ExcludedFromBuild="true"
     41551                                                >
     41552                                                <Tool
     41553                                                        Name="VCCLCompilerTool"
     41554                                                />
     41555                                        </FileConfiguration>
     41556                                        <FileConfiguration
     41557                                                Name="Release_Cairo_CFLite|Win32"
     41558                                                ExcludedFromBuild="true"
     41559                                                >
     41560                                                <Tool
     41561                                                        Name="VCCLCompilerTool"
     41562                                                />
     41563                                        </FileConfiguration>
     41564                                        <FileConfiguration
     41565                                                Name="Debug_All|Win32"
     41566                                                ExcludedFromBuild="true"
     41567                                                >
     41568                                                <Tool
     41569                                                        Name="VCCLCompilerTool"
     41570                                                />
     41571                                        </FileConfiguration>
     41572                                        <FileConfiguration
     41573                                                Name="Production|Win32"
     41574                                                ExcludedFromBuild="true"
     41575                                                >
     41576                                                <Tool
     41577                                                        Name="VCCLCompilerTool"
     41578                                                />
     41579                                        </FileConfiguration>
     41580                                </File>
     41581                                <File
     41582                                        RelativePath="..\rendering\svg\SVGTextRunRenderingContext.h"
     41583                                        >
     41584                                </File>
    4152941585                        </Filter>
    4153041586                </Filter>
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r87150 r87152  
    9999                085B92BA0EFDE73D00E6123C /* FormDataBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 085B92B80EFDE73D00E6123C /* FormDataBuilder.cpp */; };
    100100                085B92BB0EFDE73D00E6123C /* FormDataBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 085B92B90EFDE73D00E6123C /* FormDataBuilder.h */; settings = {ATTRIBUTES = (); }; };
     101                085CD275138BB8E000907F2D /* SVGTextRunRenderingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 085CD274138BB8E000907F2D /* SVGTextRunRenderingContext.h */; };
    101102                08641D4712142F7D008DE9F6 /* RenderImageResourceStyleImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08641D4512142F7D008DE9F6 /* RenderImageResourceStyleImage.cpp */; };
    102103                08641D4812142F7D008DE9F6 /* RenderImageResourceStyleImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 08641D4612142F7D008DE9F6 /* RenderImageResourceStyleImage.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    43774378                B25599A40D00D8BA00BB825C /* SVGImage.h in Headers */ = {isa = PBXBuildFile; fileRef = B255990C0D00D8B900BB825C /* SVGImage.h */; };
    43784379                B25599A50D00D8BA00BB825C /* EmptyClients.h in Headers */ = {isa = PBXBuildFile; fileRef = B255990D0D00D8B900BB825C /* EmptyClients.h */; };
    4379                 B262B8040D1F32D000158F09 /* SVGFont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B262B8030D1F32D000158F09 /* SVGFont.cpp */; };
    43804380                B266CD4D0C3AEC6500EB08D2 /* JSSVGException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B266CD4B0C3AEC6500EB08D2 /* JSSVGException.cpp */; };
    43814381                B266CD4E0C3AEC6500EB08D2 /* JSSVGException.h in Headers */ = {isa = PBXBuildFile; fileRef = B266CD4C0C3AEC6500EB08D2 /* JSSVGException.h */; };
     
    64956495                085B92B80EFDE73D00E6123C /* FormDataBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormDataBuilder.cpp; sourceTree = "<group>"; };
    64966496                085B92B90EFDE73D00E6123C /* FormDataBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormDataBuilder.h; sourceTree = "<group>"; };
     6497                085CD274138BB8E000907F2D /* SVGTextRunRenderingContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextRunRenderingContext.h; sourceTree = "<group>"; };
    64976498                08641D4512142F7D008DE9F6 /* RenderImageResourceStyleImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderImageResourceStyleImage.cpp; sourceTree = "<group>"; };
    64986499                08641D4612142F7D008DE9F6 /* RenderImageResourceStyleImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderImageResourceStyleImage.h; sourceTree = "<group>"; };
     
    65366537                08C925180FCC7C4A00480DEC /* FilterEffect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FilterEffect.h; path = filters/FilterEffect.h; sourceTree = "<group>"; };
    65376538                08CA3D4312894A3800FFF260 /* SVGStaticPropertyWithParentTearOff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGStaticPropertyWithParentTearOff.h; sourceTree = "<group>"; };
     6539                08D29440138669E40097C89B /* SVGTextRunRenderingContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextRunRenderingContext.cpp; sourceTree = "<group>"; };
    65386540                08D46CE2127AD5FC0089694B /* SVGAnimatedEnumeration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAnimatedEnumeration.h; sourceTree = "<group>"; };
    65396541                08E4FE450E2BD41400F4CAE0 /* JSSVGLengthCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGLengthCustom.cpp; sourceTree = "<group>"; };
     
    1080710809                B255990C0D00D8B900BB825C /* SVGImage.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGImage.h; sourceTree = "<group>"; };
    1080810810                B255990D0D00D8B900BB825C /* EmptyClients.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EmptyClients.h; sourceTree = "<group>"; };
    10809                 B262B8030D1F32D000158F09 /* SVGFont.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGFont.cpp; sourceTree = "<group>"; };
    1081010811                B266CD4B0C3AEC6500EB08D2 /* JSSVGException.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGException.cpp; sourceTree = "<group>"; };
    1081110812                B266CD4C0C3AEC6500EB08D2 /* JSSVGException.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSSVGException.h; sourceTree = "<group>"; };
     
    1277912780                                0854B0121255E4E600B9CDD0 /* SVGTextQuery.cpp */,
    1278012781                                0854B0131255E4E600B9CDD0 /* SVGTextQuery.h */,
     12782                                08D29440138669E40097C89B /* SVGTextRunRenderingContext.cpp */,
     12783                                085CD274138BB8E000907F2D /* SVGTextRunRenderingContext.h */,
    1278112784                        );
    1278212785                        path = svg;
     
    1730817311                                B222787C0D00BF200071B782 /* SVGFitToViewBox.h */,
    1730917312                                B222787D0D00BF200071B782 /* SVGFitToViewBox.idl */,
    17310                                 B262B8030D1F32D000158F09 /* SVGFont.cpp */,
    1731117313                                B237C8A50D344D110013F707 /* SVGFontData.cpp */,
    1731217314                                B237C8A60D344D110013F707 /* SVGFontData.h */,
     
    2018320185                                85B498F30ADB336A00925CBB /* DOMCSSValueInternal.h in Headers */,
    2018420186                                858C383C0AA8ED8200B187A4 /* DOMCSSValueList.h in Headers */,
    20185                                 C0F2A44113869AAB0066C534 /* preprocessor.pm in Headers */,
    2018620187                                85909D2B0ACC7D5500DF01F1 /* DOMCSSValueListInternal.h in Headers */,
    2018720188                                E10B9CCC0B747A44003ED890 /* DOMCustomXPathNSResolver.h in Headers */,
     
    2206422065                                37919C240B7D188600A56998 /* PositionIterator.h in Headers */,
    2206522066                                FE80D7D10E9C1F25000D6F75 /* PositionOptions.h in Headers */,
     22067                                C0F2A44113869AAB0066C534 /* preprocessor.pm in Headers */,
    2206622068                                B71FE6DF11091CB300DAEF77 /* PrintContext.h in Headers */,
    2206722069                                A8EA7EBC0A1945D000A8EF5F /* ProcessingInstruction.h in Headers */,
     
    2263122633                                B2227AD10D00BF220071B782 /* SVGTextPositioningElement.h in Headers */,
    2263222634                                0854B0251255E4E600B9CDD0 /* SVGTextQuery.h in Headers */,
     22635                                085CD275138BB8E000907F2D /* SVGTextRunRenderingContext.h in Headers */,
    2263322636                                B2227AD40D00BF220071B782 /* SVGTitleElement.h in Headers */,
    2263422637                                B2227AD70D00BF220071B782 /* SVGTransform.h in Headers */,
     
    2528225285                                B2227A0E0D00BF220071B782 /* SVGFilterPrimitiveStandardAttributes.cpp in Sources */,
    2528325286                                B2227A110D00BF220071B782 /* SVGFitToViewBox.cpp in Sources */,
    25284                                 B262B8040D1F32D000158F09 /* SVGFont.cpp in Sources */,
    2528525287                                B237C8A70D344D110013F707 /* SVGFontData.cpp in Sources */,
    2528625288                                B2A1F2AA0CEF0ABF00442F6A /* SVGFontElement.cpp in Sources */,
  • trunk/Source/WebCore/css/CSSFontFaceSource.cpp

    r84836 r87152  
    155155                    }
    156156
    157                     fontData = adoptPtr(new SimpleFontData(adoptPtr(new SVGFontData(fontFaceElement)), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic));
     157                    fontData = adoptPtr(new SimpleFontData(SVGFontData::create(fontFaceElement), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic));
    158158                }
    159159            } else
     
    171171            // In-Document SVG Fonts
    172172            if (m_svgFontFaceElement)
    173                 fontData = adoptPtr(new SimpleFontData(adoptPtr(new SVGFontData(m_svgFontFaceElement.get())), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic));
     173                fontData = adoptPtr(new SimpleFontData(SVGFontData::create(m_svgFontFaceElement.get()), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic));
    174174#endif
    175175        }
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r86667 r87152  
    137137
    138138#if ENABLE(SVG_FONTS)
    139     if (primaryFont()->isSVGFont()) {
    140         drawTextUsingSVGFont(context, run, point, from, to);
     139    if (TextRun::RenderingContext* renderingContext = run.renderingContext()) {
     140        renderingContext->drawTextUsingSVGFont(*this, context, run, point, from, to);
    141141        return;
    142142    }
     
    179179{
    180180#if ENABLE(SVG_FONTS)
    181     if (primaryFont()->isSVGFont())
    182         return floatWidthUsingSVGFont(run);
     181    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
     182        return renderingContext->floatWidthUsingSVGFont(*this, run);
    183183#endif
    184184
     
    196196float Font::width(const TextRun& run, int extraCharsAvailable, int& charsConsumed, String& glyphName) const
    197197{
    198 #if !ENABLE(SVG_FONTS)
     198#if ENABLE(SVG_FONTS)
     199    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
     200        return renderingContext->floatWidthUsingSVGFont(*this, run, extraCharsAvailable, charsConsumed, glyphName);
     201#else
    199202    UNUSED_PARAM(extraCharsAvailable);
    200 #else
    201     if (primaryFont()->isSVGFont())
    202         return floatWidthUsingSVGFont(run, extraCharsAvailable, charsConsumed, glyphName);
    203203#endif
    204204
     
    215215{
    216216#if ENABLE(SVG_FONTS)
    217     if (primaryFont()->isSVGFont())
    218         return selectionRectForTextUsingSVGFont(run, point, h, from, to);
    219 #endif
    220 
     217    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
     218        return renderingContext->selectionRectForTextUsingSVGFont(*this, run, point, h, from, to);
     219#endif
     220 
    221221    to = (to == -1 ? run.length() : to);
    222222
     
    230230{
    231231#if ENABLE(SVG_FONTS)
    232     if (primaryFont()->isSVGFont())
    233         return offsetForPositionForTextUsingSVGFont(run, x, includePartialGlyphs);
     232    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
     233        return renderingContext->offsetForPositionForTextUsingSVGFont(*this, run, x, includePartialGlyphs);
    234234#endif
    235235
     
    239239    return offsetForPositionForComplexText(run, x, includePartialGlyphs);
    240240}
    241 
    242 #if ENABLE(SVG_FONTS)
    243 bool Font::isSVGFont() const
    244 {
    245     return primaryFont()->isSVGFont();
    246 }
    247 #endif
    248241
    249242String Font::normalizeSpaces(const UChar* characters, unsigned length)
  • trunk/Source/WebCore/platform/graphics/Font.h

    r84609 r87152  
    5151class GlyphPageTreeNode;
    5252class GraphicsContext;
    53 class SVGFontElement;
    5453class TextRun;
    5554
     
    158157
    159158private:
    160 #if ENABLE(SVG_FONTS)
    161     void drawTextUsingSVGFont(GraphicsContext*, const TextRun&, const FloatPoint&, int from, int to) const;
    162     float floatWidthUsingSVGFont(const TextRun&) const;
    163     float floatWidthUsingSVGFont(const TextRun&, int extraCharsAvailable, int& charsConsumed, String& glyphName) const;
    164     FloatRect selectionRectForTextUsingSVGFont(const TextRun&, const FloatPoint&, int h, int from, int to) const;
    165     int offsetForPositionForTextUsingSVGFont(const TextRun&, float position, bool includePartialGlyphs) const;
    166 #endif
    167 
    168159    enum ForTextEmphasisOrNot { NotForTextEmphasis, ForTextEmphasis };
    169160
     
    221212    static String normalizeSpaces(const UChar*, unsigned length);
    222213
    223 #if ENABLE(SVG_FONTS)
    224     bool isSVGFont() const;
    225     SVGFontElement* svgFont() const;
    226 #endif
    227 
    228214    bool needsTranscoding() const { return m_needsTranscoding; }
    229215
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.cpp

    r85853 r87152  
    3434#include "FontCache.h"
    3535
    36 #if ENABLE(SVG_FONTS)
    37 #include "SVGFontData.h"
    38 #include "SVGFontElement.h"
    39 #include "SVGFontFaceElement.h"
    40 #include "SVGGlyphElement.h"
    41 #endif
    42 
    4336#include <wtf/MathExtras.h>
    4437#include <wtf/UnusedParam.h>
     
    6457}
    6558
    66 #if ENABLE(SVG_FONTS)
    67 SimpleFontData::SimpleFontData(PassOwnPtr<SVGFontData> svgFontData, int size, bool syntheticBold, bool syntheticItalic)
     59SimpleFontData::SimpleFontData(PassOwnPtr<SimpleFontData::FontData> fontData, int size, bool syntheticBold, bool syntheticItalic)
    6860    : m_platformData(FontPlatformData(size, syntheticBold, syntheticItalic))
     61    , m_fontData(fontData)
    6962    , m_treatAsFixedPitch(false)
    70     , m_svgFontData(svgFontData)
    7163    , m_isCustomFont(true)
    7264    , m_isLoading(false)
     
    7567    , m_hasVerticalGlyphs(false)
    7668{
    77     SVGFontFaceElement* svgFontFaceElement = m_svgFontData->svgFontFaceElement();
    78     unsigned unitsPerEm = svgFontFaceElement->unitsPerEm();
    79 
    80     float scale = size;
    81     if (unitsPerEm)
    82         scale /= unitsPerEm;
    83 
    84     float xHeight = svgFontFaceElement->xHeight() * scale;
    85     float ascent = svgFontFaceElement->ascent() * scale;
    86     float descent = svgFontFaceElement->descent() * scale;
    87     float lineGap = 0.1f * size;
    88 
    89     SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontElement();
    90     if (!xHeight) {   
    91         // Fallback if x_heightAttr is not specified for the font element.
    92         Vector<SVGGlyph> letterXGlyphs;
    93         associatedFontElement->getGlyphIdentifiersForString(String("x", 1), letterXGlyphs);
    94         xHeight = letterXGlyphs.isEmpty() ? 2 * ascent / 3 : letterXGlyphs.first().horizontalAdvanceX * scale;
    95     }
    96 
    97     m_fontMetrics.setUnitsPerEm(unitsPerEm);
    98     m_fontMetrics.setAscent(ascent);
    99     m_fontMetrics.setDescent(descent);
    100     m_fontMetrics.setLineGap(lineGap);
    101     m_fontMetrics.setLineSpacing(roundf(ascent) + roundf(descent) + roundf(lineGap));
    102     m_fontMetrics.setXHeight(xHeight);
    103 
    104     Vector<SVGGlyph> spaceGlyphs;
    105     associatedFontElement->getGlyphIdentifiersForString(String(" ", 1), spaceGlyphs);
    106     m_spaceWidth = spaceGlyphs.isEmpty() ? xHeight : spaceGlyphs.first().horizontalAdvanceX * scale;
    107 
    108     Vector<SVGGlyph> numeralZeroGlyphs;
    109     associatedFontElement->getGlyphIdentifiersForString(String("0", 1), numeralZeroGlyphs);
    110     m_avgCharWidth = numeralZeroGlyphs.isEmpty() ? m_spaceWidth : numeralZeroGlyphs.first().horizontalAdvanceX * scale;
    111 
    112     Vector<SVGGlyph> letterWGlyphs;
    113     associatedFontElement->getGlyphIdentifiersForString(String("W", 1), letterWGlyphs);
    114     m_maxCharWidth = letterWGlyphs.isEmpty() ? ascent : letterWGlyphs.first().horizontalAdvanceX * scale;
    115 
    116     // FIXME: is there a way we can get the space glyph from the SVGGlyph above?
    117     m_spaceGlyph = 0;
    118     m_zeroWidthSpaceGlyph = 0;
    119     determinePitch();
    120     m_missingGlyphData.fontData = this;
    121     m_missingGlyphData.glyph = 0;
    122 }
    123 #endif
     69    m_fontData->initializeFontData(this, size);
     70}
    12471
    12572#if !(PLATFORM(QT) && !HAVE(QRAWFONT))
     
    187134{
    188135#if ENABLE(SVG_FONTS)
    189     if (!m_svgFontData || !m_svgFontData->svgFontFaceElement())
     136    if (!m_fontData)
    190137#endif
    191138        platformDestroy();
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r86401 r87152  
    6565class FontDescription;
    6666class SharedBuffer;
    67 class SVGFontData;
    6867
    6968enum FontDataVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMarkVariant };
     
    7271class SimpleFontData : public FontData {
    7372public:
     73    class FontData {
     74        WTF_MAKE_FAST_ALLOCATED;
     75    public:
     76        virtual ~FontData() { }
     77   
     78        virtual void initializeFontData(SimpleFontData*, int) = 0;
     79    };
     80
     81    // Used to create platform fonts.
    7482    SimpleFontData(const FontPlatformData&, bool isCustomFont = false, bool isLoading = false, bool isTextOrientationFallback = false);
    75 #if ENABLE(SVG_FONTS)
    76     SimpleFontData(PassOwnPtr<SVGFontData>, int size, bool syntheticBold, bool syntheticItalic);
    77 #endif
     83
     84    // Used to create SVG Fonts.
     85    SimpleFontData(PassOwnPtr<SimpleFontData::FontData>, int size, bool syntheticBold, bool syntheticItalic);
     86
    7887    virtual ~SimpleFontData();
    7988
     
    105114    bool isTextOrientationFallback() const { return m_isTextOrientationFallback; }
    106115
     116    FontMetrics& fontMetrics() { return m_fontMetrics; }
    107117    const FontMetrics& fontMetrics() const { return m_fontMetrics; }
     118   
    108119    float maxCharWidth() const { return m_maxCharWidth; }
     120    void setMaxCharWidth(float maxCharWidth) { m_maxCharWidth = maxCharWidth; }
     121
    109122    float avgCharWidth() const { return m_avgCharWidth; }
     123    void setAvgCharWidth(float avgCharWidth) { m_avgCharWidth = avgCharWidth; }
    110124
    111125    FloatRect boundsForGlyph(Glyph) const;
     
    115129
    116130    float spaceWidth() const { return m_spaceWidth; }
     131    void setSpaceWidth(float spaceWidth) { m_spaceWidth = spaceWidth; }
    117132
    118133#if USE(CG) || USE(CAIRO) || PLATFORM(WX) || USE(SKIA_ON_MAC_CHROME)
     
    121136
    122137    Glyph spaceGlyph() const { return m_spaceGlyph; }
     138    void setSpaceGlyph(Glyph spaceGlyph) { m_spaceGlyph = spaceGlyph; }
     139    void setZeroWidthSpaceGlyph(Glyph spaceGlyph) { m_zeroWidthSpaceGlyph = spaceGlyph; }
    123140    bool isZeroWidthSpaceGlyph(Glyph glyph) const { return glyph == m_zeroWidthSpaceGlyph && glyph; }
    124141
     
    129146    Pitch pitch() const { return m_treatAsFixedPitch ? FixedPitch : VariablePitch; }
    130147
    131 #if ENABLE(SVG_FONTS)
    132     SVGFontData* svgFontData() const { return m_svgFontData.get(); }
    133     bool isSVGFont() const { return m_svgFontData; }
    134 #else
    135     bool isSVGFont() const { return false; }
    136 #endif
     148    SimpleFontData::FontData* fontData() const { return m_fontData.get(); }
     149    bool isSVGFont() const { return m_fontData; }
    137150
    138151    virtual bool isCustomFont() const { return m_isCustomFont; }
     
    141154
    142155    const GlyphData& missingGlyphData() const { return m_missingGlyphData; }
     156    void setMissingGlyphData(const GlyphData& glyphData) { m_missingGlyphData = glyphData; }
    143157
    144158#ifndef NDEBUG
     
    209223   
    210224    FontPlatformData m_platformData;
     225    OwnPtr<SimpleFontData::FontData> m_fontData;
    211226
    212227    mutable OwnPtr<GlyphMetricsMap<FloatRect> > m_glyphToBoundsMap;
     
    214229
    215230    bool m_treatAsFixedPitch;
    216 
    217 #if ENABLE(SVG_FONTS)
    218     OwnPtr<SVGFontData> m_svgFontData;
    219 #endif
    220 
    221231    bool m_isCustomFont;  // Whether or not we are custom font loaded via @font-face
    222232    bool m_isLoading; // Whether or not this custom font is still in the act of loading.
  • trunk/Source/WebCore/platform/graphics/TextRun.h

    r85143 r87152  
    2525#define TextRun_h
    2626
    27 #include "PlatformString.h"
    2827#include "TextDirection.h"
     28#include <wtf/RefCounted.h>
     29#include <wtf/text/WTFString.h>
    2930
    3031namespace WebCore {
    3132
    32 class RenderObject;
    33 class RenderSVGResource;
     33class FloatPoint;
     34class FloatRect;
     35class Font;
     36class GraphicsContext;
    3437
    3538class TextRun {
     
    5760        , m_directionalOverride(directionalOverride)
    5861        , m_disableSpacing(false)
    59 #if ENABLE(SVG_FONTS)
    60         , m_referencingRenderObject(0)
    61         , m_activePaintingResource(0)
    62 #endif
    6362    {
    6463    }
     
    7776        , m_directionalOverride(directionalOverride)
    7877        , m_disableSpacing(false)
    79 #if ENABLE(SVG_FONTS)
    80         , m_referencingRenderObject(0)
    81         , m_activePaintingResource(0)
    82 #endif
    8378    {
    8479    }
     
    9893
    9994    bool allowTabs() const { return m_allowTabs; }
     95    void setAllowTabs(bool allowTabs) { m_allowTabs = allowTabs; }
    10096    float xPos() const { return m_xpos; }
     97    void setXPos(float xPos) { m_xpos = xPos; }
    10198    float expansion() const { return m_expansion; }
    10299    bool allowsLeadingExpansion() const { return m_expansionBehavior & AllowLeadingExpansion; }
     
    112109    void setDirectionalOverride(bool override) { m_directionalOverride = override; }
    113110
     111    class RenderingContext : public RefCounted<RenderingContext> {
     112    public:
     113        virtual ~RenderingContext() { }
     114
    114115#if ENABLE(SVG_FONTS)
    115     RenderObject* referencingRenderObject() const { return m_referencingRenderObject; }
    116     void setReferencingRenderObject(RenderObject* object) { m_referencingRenderObject = object; }
     116        // FIXME: Note that the SVG Font integration APIs will be more abstract and simpler once the SVG Fonts rewrite patch lands (59085).
     117        virtual void drawTextUsingSVGFont(const Font&, GraphicsContext*, const TextRun&, const FloatPoint&, int from, int to) const = 0;
     118        virtual float floatWidthUsingSVGFont(const Font&, const TextRun&) const = 0;
     119        virtual float floatWidthUsingSVGFont(const Font&, const TextRun&, int extraCharsAvailable, int& charsConsumed, String& glyphName) const = 0;
     120        virtual FloatRect selectionRectForTextUsingSVGFont(const Font&, const TextRun&, const FloatPoint&, int h, int from, int to) const = 0;
     121        virtual int offsetForPositionForTextUsingSVGFont(const Font&, const TextRun&, float position, bool includePartialGlyphs) const = 0;
     122#endif
     123    };
    117124
    118     RenderSVGResource* activePaintingResource() const { return m_activePaintingResource; }
    119     void setActivePaintingResource(RenderSVGResource* object) { m_activePaintingResource = object; }
    120 #endif
     125    RenderingContext* renderingContext() const { return m_renderingContext.get(); }
     126    void setRenderingContext(PassRefPtr<RenderingContext> context) { m_renderingContext = context; }
    121127
    122128private:
     
    137143    bool m_directionalOverride; // Was this direction set by an override character.
    138144    bool m_disableSpacing;
    139 
    140 #if ENABLE(SVG_FONTS)
    141     RenderObject* m_referencingRenderObject;
    142     RenderSVGResource* m_activePaintingResource;
    143 #endif
     145    RefPtr<RenderingContext> m_renderingContext;
    144146};
    145147
  • trunk/Source/WebCore/rendering/EllipsisBox.cpp

    r87018 r87152  
    4545    }
    4646
     47    const Font& font = style->font();
    4748    if (selectionState() != RenderObject::SelectionNone) {
    48         paintSelection(context, tx, ty, style, style->font());
     49        paintSelection(context, tx, ty, style, font);
    4950
    5051        // Select the correct color for painting the text.
     
    5556
    5657    // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
    57     context->drawText(style->font(), RenderBlock::constructTextRunAllowTrailingExpansion(m_str, style), IntPoint(m_x + tx, m_y + ty + style->fontMetrics().ascent()));
     58    context->drawText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(m_x + tx, m_y + ty + style->fontMetrics().ascent()));
    5859
    5960    // Restore the regular fill color.
     
    7576{
    7677    RenderStyle* style = m_renderer->style(m_firstLine);
    77     const Font& f = style->font();
     78    const Font& font = style->font();
    7879    // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
    79     return enclosingIntRect(f.selectionRectForText(RenderBlock::constructTextRunAllowTrailingExpansion(m_str, style), IntPoint(m_x + tx, m_y + ty + root()->selectionTop()), root()->selectionHeight()));
     80    return enclosingIntRect(font.selectionRectForText(RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(m_x + tx, m_y + ty + root()->selectionTop()), root()->selectionHeight()));
    8081}
    8182
     
    9798    context->clip(IntRect(m_x + tx, y + ty, m_logicalWidth, h));
    9899    // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
    99     context->drawHighlightForText(font, RenderBlock::constructTextRunAllowTrailingExpansion(m_str, style), IntPoint(m_x + tx, m_y + ty + y), h, c, style->colorSpace());
     100    context->drawHighlightForText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(m_x + tx, m_y + ty + y), h, c, style->colorSpace());
    100101}
    101102
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r87018 r87152  
    4242#include "RenderRubyText.h"
    4343#include "RenderTheme.h"
     44#include "SVGTextRunRenderingContext.h"
    4445#include "Text.h"
    45 #include "TextRun.h"
    4646#include "break_lines.h"
    4747#include <wtf/AlwaysInline.h>
     
    183183    int selHeight = selectionHeight();
    184184    RenderStyle* styleToUse = textObj->style(m_firstLine);
    185     const Font& f = styleToUse->font();
     185    const Font& font = styleToUse->font();
    186186
    187187    BufferForAppendingHyphen charactersWithHyphen;
    188188    bool respectHyphen = ePos == m_len && hasHyphen();
    189     TextRun textRun = constructTextRun(styleToUse, respectHyphen ? &charactersWithHyphen : 0);
     189    TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charactersWithHyphen : 0);
    190190    if (respectHyphen)
    191191        endPos = textRun.length();
    192192
    193     IntRect r = enclosingIntRect(f.selectionRectForText(textRun, FloatPoint(logicalLeft(), selTop), selHeight, sPos, ePos));
     193    IntRect r = enclosingIntRect(font.selectionRectForText(textRun, FloatPoint(logicalLeft(), selTop), selHeight, sPos, ePos));
    194194
    195195    int logicalWidth = r.width();
     
    644644
    645645    BufferForAppendingHyphen charactersWithHyphen;
    646     TextRun textRun = constructTextRun(styleToUse, characters, length, hasHyphen() ? &charactersWithHyphen : 0);
     646    TextRun textRun = constructTextRun(styleToUse, font, characters, length, hasHyphen() ? &charactersWithHyphen : 0);
    647647    if (hasHyphen())
    648648        length = textRun.length();
     
    681681            updateGraphicsContext(context, emphasisMarkColor, textStrokeColor, textStrokeWidth, styleToUse->colorSpace());
    682682
    683             static TextRun objectReplacementCharacterTextRun(&objectReplacementCharacter, 1);
     683            DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
    684684            TextRun& emphasisMarkTextRun = combinedText ? objectReplacementCharacterTextRun : textRun;
    685685            FloatPoint emphasisMarkTextOrigin = combinedText ? FloatPoint(boxOrigin.x() + boxRect.width() / 2, boxOrigin.y() + font.fontMetrics().ascent()) : textOrigin;
     
    707707            updateGraphicsContext(context, selectionEmphasisMarkColor, textStrokeColor, textStrokeWidth, styleToUse->colorSpace());
    708708
    709             static TextRun objectReplacementCharacterTextRun(&objectReplacementCharacter, 1);
     709            DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
    710710            TextRun& emphasisMarkTextRun = combinedText ? objectReplacementCharacterTextRun : textRun;
    711711            FloatPoint emphasisMarkTextOrigin = combinedText ? FloatPoint(boxOrigin.x() + boxRect.width() / 2, boxOrigin.y() + font.fontMetrics().ascent()) : textOrigin;
     
    809809    BufferForAppendingHyphen charactersWithHyphen;
    810810    bool respectHyphen = ePos == length && hasHyphen();
    811     TextRun textRun = constructTextRun(style, characters, length, respectHyphen ? &charactersWithHyphen : 0);
     811    TextRun textRun = constructTextRun(style, font, characters, length, respectHyphen ? &charactersWithHyphen : 0);
    812812    if (respectHyphen)
    813813        ePos = textRun.length();
     
    844844    int selHeight = selectionHeight();
    845845    FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
    846     context->drawHighlightForText(font, constructTextRun(style), localOrigin, selHeight, c, style->colorSpace(), sPos, ePos);
     846    context->drawHighlightForText(font, constructTextRun(style, font), localOrigin, selHeight, c, style->colorSpace(), sPos, ePos);
    847847}
    848848
     
    10021002        int selHeight = selectionHeight();
    10031003        FloatPoint startPoint(boxOrigin.x(), boxOrigin.y() - deltaY);
    1004         TextRun run = constructTextRun(style);
     1004        TextRun run = constructTextRun(style, font);
    10051005
    10061006        // FIXME: Convert the document markers to float rects.
     
    10471047    int sPos = max(marker.startOffset() - m_start, (unsigned)0);
    10481048    int ePos = min(marker.endOffset() - m_start, (unsigned)m_len);
    1049     TextRun run = constructTextRun(style);
     1049    TextRun run = constructTextRun(style, font);
    10501050    // Always compute and store the rect associated with this marker. The computed rect is in absolute coordinates.
    10511051    IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoint(m_x, selectionTop()), selHeight, sPos, ePos));
     
    10741074    int sPos = max(marker.startOffset() - m_start, (unsigned)0);
    10751075    int ePos = min(marker.endOffset() - m_start, (unsigned)m_len);
    1076     TextRun run = constructTextRun(style);
     1076    TextRun run = constructTextRun(style, font);
    10771077    IntPoint startPoint = IntPoint(m_x, y);
    10781078   
     
    12331233    RenderText* text = toRenderText(renderer());
    12341234    RenderStyle* style = text->style(m_firstLine);
    1235     const Font* f = &style->font();
    1236     int offset = f->offsetForPosition(constructTextRun(style), lineOffset - logicalLeft(), includePartialGlyphs);
     1235    const Font& font = style->font();
     1236    int offset = font.offsetForPosition(constructTextRun(style, font), lineOffset - logicalLeft(), includePartialGlyphs);
    12371237    if (blockIsInOppositeDirection && (!offset || offset == m_len))
    12381238        return !offset ? m_len : 0;
     
    12511251    RenderStyle* styleToUse = text->style(m_firstLine);
    12521252    ASSERT(styleToUse);
    1253     const Font& f = styleToUse->font();
     1253    const Font& font = styleToUse->font();
    12541254    int from = !isLeftToRightDirection() ? offset - m_start : 0;
    12551255    int to = !isLeftToRightDirection() ? m_len : offset - m_start;
    12561256    // FIXME: Do we need to add rightBearing here?
    1257     return f.selectionRectForText(constructTextRun(styleToUse), IntPoint(logicalLeft(), 0), 0, from, to).maxX();
     1257    return font.selectionRectForText(constructTextRun(styleToUse, font), IntPoint(logicalLeft(), 0), 0, from, to).maxX();
    12581258}
    12591259
     
    12821282}
    12831283
    1284 TextRun InlineTextBox::constructTextRun(RenderStyle* style, BufferForAppendingHyphen* charactersWithHyphen) const
     1284TextRun InlineTextBox::constructTextRun(RenderStyle* style, const Font& font, BufferForAppendingHyphen* charactersWithHyphen) const
    12851285{
    12861286    ASSERT(style);
     
    12901290    ASSERT(textRenderer->characters());
    12911291
    1292     return constructTextRun(style, textRenderer->characters() + start(), len(), charactersWithHyphen);
    1293 }
    1294 
    1295 TextRun InlineTextBox::constructTextRun(RenderStyle* style, const UChar* characters, int length, BufferForAppendingHyphen* charactersWithHyphen) const
     1292    return constructTextRun(style, font, textRenderer->characters() + start(), len(), charactersWithHyphen);
     1293}
     1294
     1295TextRun InlineTextBox::constructTextRun(RenderStyle* style, const Font& font, const UChar* characters, int length, BufferForAppendingHyphen* charactersWithHyphen) const
    12961296{
    12971297    ASSERT(style);
     
    13031303        adjustCharactersAndLengthForHyphen(*charactersWithHyphen, style, characters, length);
    13041304
    1305     // FIXME: Remove TextRuns all-in-one-constructor and use explicit setters here.
    1306     return TextRun(characters, length, textRenderer->allowTabs(), textPos(), expansion(), expansionBehavior(), direction(), m_dirOverride || style->visuallyOrdered());
     1305    TextRun run(characters, length, textRenderer->allowTabs(), textPos(), expansion(), expansionBehavior(), direction(), m_dirOverride || style->visuallyOrdered());
     1306    if (textRunNeedsRenderingContext(font))
     1307        run.setRenderingContext(SVGTextRunRenderingContext::create(textRenderer));
     1308
     1309    return run;
    13071310}
    13081311
  • trunk/Source/WebCore/rendering/InlineTextBox.h

    r86819 r87152  
    100100    int selectionHeight();
    101101
    102     TextRun constructTextRun(RenderStyle*, BufferForAppendingHyphen* = 0) const;
    103     TextRun constructTextRun(RenderStyle*, const UChar*, int length, BufferForAppendingHyphen* = 0) const;
     102    TextRun constructTextRun(RenderStyle*, const Font&, BufferForAppendingHyphen* = 0) const;
     103    TextRun constructTextRun(RenderStyle*, const Font&, const UChar*, int length, BufferForAppendingHyphen* = 0) const;
    104104
    105105public:
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r87101 r87152  
    5252#include "RenderView.h"
    5353#include "Settings.h"
    54 #include "TextRun.h"
     54#include "SVGTextRunRenderingContext.h"
    5555#include "TransformState.h"
    5656#include <wtf/StdLibExtras.h>
     
    47084708        const UChar space = ' ';
    47094709        const Font& font = t->style()->font(); // FIXME: This ignores first-line.
    4710         float spaceWidth = font.width(TextRun(&space, 1));
     4710        float spaceWidth = font.width(RenderBlock::constructTextRun(t, font, &space, 1, t->style()));
    47114711        inlineMax -= spaceWidth + font.wordSpacing();
    47124712        if (inlineMin > inlineMax)
     
    63176317}
    63186318
    6319 TextRun RenderBlock::constructTextRunAllowTrailingExpansion(const UChar* characters, int length, RenderStyle* style, TextRunFlags flags)
     6319TextRun RenderBlock::constructTextRun(RenderObject* context, const Font& font, const UChar* characters, int length, RenderStyle* style, TextRun::ExpansionBehavior expansion, TextRunFlags flags)
    63206320{
    63216321    ASSERT(style);
     
    63306330    }
    63316331
    6332     // FIXME: Remove TextRuns all-in-one-constructor and use explicit setters here.
    6333     return TextRun(characters, length, false, 0, 0, TextRun::AllowTrailingExpansion, textDirection, directionalOverride);
    6334 }
    6335 
    6336 TextRun RenderBlock::constructTextRunAllowTrailingExpansion(const String& string, RenderStyle* style, TextRunFlags flags)
    6337 {
    6338     return constructTextRunAllowTrailingExpansion(string.characters(), string.length(), style, flags);
     6332    TextRun run(characters, length, false, 0, 0, expansion, textDirection, directionalOverride);
     6333    if (textRunNeedsRenderingContext(font))
     6334        run.setRenderingContext(SVGTextRunRenderingContext::create(context));
     6335
     6336    return run;
     6337}
     6338
     6339TextRun RenderBlock::constructTextRun(RenderObject* context, const Font& font, const String& string, RenderStyle* style, TextRun::ExpansionBehavior expansion, TextRunFlags flags)
     6340{
     6341    return constructTextRun(context, font, string.characters(), string.length(), style, expansion, flags);
    63396342}
    63406343
  • trunk/Source/WebCore/rendering/RenderBlock.h

    r87101 r87152  
    2828#include "RenderLineBoxList.h"
    2929#include "RootInlineBox.h"
     30#include "TextRun.h"
    3031#include <wtf/OwnPtr.h>
    3132#include <wtf/ListHashSet.h>
     
    170171    static void appendRunsForObject(BidiRunList<BidiRun>&, int start, int end, RenderObject*, InlineBidiResolver&);
    171172
    172     static TextRun constructTextRunAllowTrailingExpansion(const String&, RenderStyle*, TextRunFlags = DefaultTextRunFlags);
    173     static TextRun constructTextRunAllowTrailingExpansion(const UChar*, int length, RenderStyle*, TextRunFlags = DefaultTextRunFlags);
     173    static TextRun constructTextRun(RenderObject* context, const Font&, const String&, RenderStyle*,
     174                                    TextRun::ExpansionBehavior = TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion, TextRunFlags = DefaultTextRunFlags);
     175
     176    static TextRun constructTextRun(RenderObject* context, const Font&, const UChar*, int length, RenderStyle*,
     177                                    TextRun::ExpansionBehavior = TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion, TextRunFlags = DefaultTextRunFlags);
    174178
    175179    ColumnInfo* columnInfo() const;
  • trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp

    r87026 r87152  
    3737#include "Settings.h"
    3838#include "TextBreakIterator.h"
    39 #include "TextRun.h"
    4039#include "TrailingFloatsRootInlineBox.h"
    4140#include "VerticalPositionCache.h"
     
    483482    if (static_cast<InlineTextBox*>(run->m_box)->hasHyphen()) {
    484483        const AtomicString& hyphenString = renderer->style()->hyphenString();
    485         hyphenWidth = renderer->style(lineInfo.isFirstLine())->font().width(TextRun(hyphenString.characters(), hyphenString.length()));
     484        const Font& font = renderer->style(lineInfo.isFirstLine())->font();
     485        hyphenWidth = font.width(RenderBlock::constructTextRun(renderer, font, hyphenString.string(), renderer->style()));
    486486    }
    487487    run->m_box->setLogicalWidth(renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow) + hyphenWidth);
     
    15771577    if (isFixedPitch || (!from && len == text->textLength()) || text->style()->hasTextCombine())
    15781578        return text->width(from, len, font, xPos);
    1579     return font.width(TextRun(text->characters() + from, len, !collapseWhiteSpace, xPos));
     1579    TextRun run = RenderBlock::constructTextRun(text, font, text->characters() + from, len, text->style());
     1580    run.setAllowTabs(!collapseWhiteSpace);
     1581    run.setXPos(xPos);
     1582    return font.width(run);
    15801583}
    15811584
     
    15931596
    15941597    const AtomicString& hyphenString = text->style()->hyphenString();
    1595     int hyphenWidth = font.width(TextRun(hyphenString.characters(), hyphenString.length()));
     1598    int hyphenWidth = font.width(RenderBlock::constructTextRun(text, font, hyphenString.string(), text->style()));
    15961599
    15971600    float maxPrefixWidth = availableWidth - xPos - hyphenWidth - lastSpaceWordSpacing;
     
    16011604        return;
    16021605
    1603     unsigned prefixLength = font.offsetForPosition(TextRun(text->characters() + lastSpace, pos - lastSpace, !collapseWhiteSpace, xPos + lastSpaceWordSpacing), maxPrefixWidth, false);
     1606    TextRun run = RenderBlock::constructTextRun(text, font, text->characters() + lastSpace, pos - lastSpace, text->style());
     1607    run.setAllowTabs(!collapseWhiteSpace);
     1608    run.setXPos(xPos + lastSpaceWordSpacing);
     1609
     1610    unsigned prefixLength = font.offsetForPosition(run, maxPrefixWidth, false);
    16041611    if (prefixLength < static_cast<unsigned>(minimumPrefixLength))
    16051612        return;
     
    20442051            // Non-zero only when kerning is enabled, in which case we measure words with their trailing
    20452052            // space, then subtract its width.
    2046             float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(TextRun(&space, 1)) + wordSpacing : 0;
     2053            float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(constructTextRun(t, f, &space, 1, style)) + wordSpacing : 0;
    20472054
    20482055            float wrapW = width.uncommittedWidth() + inlineLogicalWidth(current.m_obj, !appliedStartWidth, true);
     
    20732080                if (c == softHyphen && autoWrap && !hyphenWidth && style->hyphens() != HyphensNone) {
    20742081                    const AtomicString& hyphenString = style->hyphenString();
    2075                     hyphenWidth = f.width(TextRun(hyphenString.characters(), hyphenString.length()));
     2082                    hyphenWidth = f.width(constructTextRun(t, f, hyphenString.string(), current.m_obj->style()));
    20762083                    width.addUncommittedWidth(hyphenWidth);
    20772084                }
     
    24042411    // Determine the width of the ellipsis using the current font.
    24052412    // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable"
    2406     TextRun ellipsisRun(&horizontalEllipsis, 1);
     2413    const Font& font = style()->font();
    24072414    DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
    24082415    const Font& firstLineFont = firstLineStyle()->font();
    2409     const Font& font = style()->font();
    2410     int firstLineEllipsisWidth = firstLineFont.width(ellipsisRun);
    2411     int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(ellipsisRun);
     2416    int firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle()));
     2417    int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
    24122418
    24132419    // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
  • trunk/Source/WebCore/rendering/RenderCombineText.cpp

    r81251 r87152  
    2222#include "RenderCombineText.h"
    2323
    24 #include "TextRun.h"
     24#include "RenderBlock.h"
    2525
    2626namespace WebCore {
     
    9494        return;
    9595
    96     TextRun run = TextRun(String(text()));
     96    TextRun run = RenderBlock::constructTextRun(this, originalFont(), String(text()), style());
    9797    FontDescription description = originalFont().fontDescription();
    9898    float emWidth = description.computedSize() * textCombineMargin;
  • trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp

    r86739 r87152  
    222222    if (paintInfo.phase == PaintPhaseForeground) {
    223223        const String& displayedFilename = fileTextValue();
    224         TextRun textRun = constructTextRunAllowTrailingExpansion(displayedFilename, style(), RespectDirection | RespectDirectionOverride);
     224        const Font& font = style()->font();
     225        TextRun textRun = constructTextRun(this, font, displayedFilename, style(), TextRun::AllowTrailingExpansion, RespectDirection | RespectDirectionOverride);
    225226
    226227        // Determine where the filename should be placed
     
    232233            textX = contentLeft + buttonAndIconWidth;
    233234        else
    234             textX = contentLeft + contentWidth() - buttonAndIconWidth - style()->font().width(textRun);
     235            textX = contentLeft + contentWidth() - buttonAndIconWidth - font.width(textRun);
    235236        // We want to match the button's baseline
    236237        RenderButton* buttonRenderer = toRenderButton(m_button->renderer());
     
    242243       
    243244        // Draw the filename
    244         paintInfo.context->drawBidiText(style()->font(), textRun, IntPoint(textX, textY));
     245        paintInfo.context->drawBidiText(font, textRun, IntPoint(textX, textY));
    245246       
    246247        if (m_fileChooser->icon()) {
     
    272273    ASSERT(style);
    273274
     275    const Font& font = style->font();
    274276    if (style->width().isFixed() && style->width().value() > 0)
    275277        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeContentBoxLogicalWidth(style->width().value());
     
    278280        // (using "0" as the nominal character).
    279281        const UChar ch = '0';
    280         float charWidth = style->font().width(constructTextRunAllowTrailingExpansion(String(&ch, 1), style));
     282        float charWidth = font.width(constructTextRun(this, font, String(&ch, 1), style, TextRun::AllowTrailingExpansion));
    281283        m_maxPreferredLogicalWidth = (int)ceilf(charWidth * defaultWidthNumChars);
    282284    }
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r86389 r87152  
    2828#include "RenderLayer.h"
    2929#include "RenderView.h"
    30 #include "TextRun.h"
    3130#include <wtf/StdLibExtras.h>
    3231#include <wtf/unicode/CharacterNames.h>
     
    903902        InlineBox* anchorBox = lastLine->lastChild();
    904903        if (anchorBox && anchorBox->renderer()->style()->isLink())
    905             totalWidth = anchorBox->logicalWidth() + font.width(TextRun(ellipsisAndSpace, 2));
     904            totalWidth = anchorBox->logicalWidth() + font.width(constructTextRun(this, font, ellipsisAndSpace, 2, style()));
    906905        else {
    907906            anchorBox = 0;
    908             totalWidth = font.width(TextRun(&horizontalEllipsis, 1));
     907            totalWidth = font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
    909908        }
    910909
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r86739 r87152  
    4040#include "RenderLayer.h"
    4141#include "RenderView.h"
    42 #include "TextRun.h"
    4342#include <wtf/UnusedParam.h>
    4443
     
    105104    if (!m_altText.isEmpty()) {
    106105        const Font& font = style()->font();
    107         IntSize textSize(min(font.width(TextRun(m_altText)), maxAltTextWidth), min(font.fontMetrics().height(), maxAltTextHeight));
     106        IntSize textSize(min(font.width(RenderBlock::constructTextRun(this, font, m_altText, style())), maxAltTextWidth), min(font.fontMetrics().height(), maxAltTextHeight));
    108107        imageSize = imageSize.expandedTo(textSize);
    109108    }
     
    287286                // Only draw the alt text if it'll fit within the content box,
    288287                // and only if it fits above the error image.
    289                 TextRun textRun(text);
     288                TextRun textRun = RenderBlock::constructTextRun(this, font, text, style());
    290289                int textWidth = font.width(textRun);
    291290                if (errorPictureDrawn) {
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r87101 r87152  
    5757#include "SelectElement.h"
    5858#include "SpatialNavigation.h"
    59 #include "TextRun.h"
    6059#include <math.h>
    6160
     
    121120            if (!text.isEmpty()) {
    122121                // FIXME: Why is this always LTR? Can't text direction affect the width?
    123                 float textWidth = itemFont.width(constructTextRunAllowTrailingExpansion(text, style()));
     122                float textWidth = itemFont.width(constructTextRun(this, itemFont, text, style(), TextRun::AllowTrailingExpansion));
    124123                width = max(width, textWidth);
    125124            }
  • trunk/Source/WebCore/rendering/RenderListMarker.cpp

    r86197 r87152  
    3232#include "RenderListItem.h"
    3333#include "RenderView.h"
    34 #include "TextRun.h"
    3534#include <wtf/unicode/CharacterNames.h>
    3635
     
    12541253        return;
    12551254
    1256     TextRun textRun(m_text);
     1255    const Font& font = style()->font();
     1256    TextRun textRun = RenderBlock::constructTextRun(this, font, m_text, style());
    12571257
    12581258    GraphicsContextStateSaver stateSaver(*context, false);
     
    12701270
    12711271    if (type == Asterisks || type == Footnotes)
    1272         context->drawText(style()->font(), textRun, textOrigin);
     1272        context->drawText(font, textRun, textOrigin);
    12731273    else {
    12741274        // Text is not arbitrary. We can judge whether it's RTL from the first character,
     
    12811281            for (int i = 0; i < length; ++i)
    12821282                reversedText[length - i - 1] = m_text[i];
    1283             textRun = TextRun(reversedText.data(), length);
    1284         }
    1285 
    1286         const Font& font = style()->font();
     1283            textRun.setText(reversedText.data(), length);
     1284        }
     1285
    12871286        const UChar suffix = listMarkerSuffix(type, m_listItem->value());
    12881287        if (style()->isLeftToRightDirection()) {
    12891288            int width = font.width(textRun);
    1290             context->drawText(style()->font(), textRun, textOrigin);
     1289            context->drawText(font, textRun, textOrigin);
    12911290            UChar suffixSpace[2] = { suffix, ' ' };
    1292             context->drawText(style()->font(), TextRun(suffixSpace, 2), textOrigin + IntSize(width, 0));
     1291            context->drawText(font, RenderBlock::constructTextRun(this, font, suffixSpace, 2, style()), textOrigin + IntSize(width, 0));
    12931292        } else {
    12941293            UChar spaceSuffix[2] = { ' ', suffix };
    1295             TextRun spaceSuffixRun(spaceSuffix, 2);
     1294            TextRun spaceSuffixRun = RenderBlock::constructTextRun(this, font, spaceSuffix, 2, style());
    12961295            int width = font.width(spaceSuffixRun);
    1297             context->drawText(style()->font(), spaceSuffixRun, textOrigin);
    1298             context->drawText(style()->font(), textRun, textOrigin + IntSize(width, 0));
     1296            context->drawText(font, spaceSuffixRun, textOrigin);
     1297            context->drawText(font, textRun, textOrigin + IntSize(width, 0));
    12991298        }
    13001299    }
     
    14561455                int itemWidth = font.width(m_text);
    14571456                UChar suffixSpace[2] = { listMarkerSuffix(type, m_listItem->value()), ' ' };
    1458                 int suffixSpaceWidth = font.width(TextRun(suffixSpace, 2));
     1457                int suffixSpaceWidth = font.width(RenderBlock::constructTextRun(this, font, suffixSpace, 2, style()));
    14591458                logicalWidth = itemWidth + suffixSpaceWidth;
    14601459            }
     
    16791678            int itemWidth = font.width(m_text);
    16801679            UChar suffixSpace[2] = { listMarkerSuffix(type, m_listItem->value()), ' ' };
    1681             int suffixSpaceWidth = font.width(TextRun(suffixSpace, 2));
     1680            int suffixSpaceWidth = font.width(RenderBlock::constructTextRun(this, font, suffixSpace, 2, style()));
    16821681            relativeRect = IntRect(0, 0, itemWidth + suffixSpaceWidth, font.fontMetrics().height());
    16831682    }
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r85677 r87152  
    4141#include "TextBreakIterator.h"
    4242#include "TextResourceDecoder.h"
    43 #include "TextRun.h"
    4443#include "VisiblePosition.h"
    4544#include "break_lines.h"
     
    632631    }
    633632
    634     return f.width(TextRun(text()->characters() + start, len, allowTabs(), xPos), fallbackFonts, glyphOverflow);
     633    TextRun run = RenderBlock::constructTextRun(const_cast<RenderText*>(this), f, text()->characters() + start, len, style());
     634    run.setAllowTabs(allowTabs());
     635    run.setXPos(xPos);
     636    return f.width(run, fallbackFonts, glyphOverflow);
    635637}
    636638
     
    677679    StringImpl& text = *m_text.impl();
    678680    if (text[0] == ' ' || (text[0] == '\n' && !style()->preserveNewline()) || text[0] == '\t') {
    679         const Font& f = style()->font(); // FIXME: This ignores first-line.
     681        const Font& font = style()->font(); // FIXME: This ignores first-line.
    680682        if (stripFrontSpaces) {
    681683            const UChar space = ' ';
    682             float spaceWidth = f.width(TextRun(&space, 1));
     684            float spaceWidth = font.width(RenderBlock::constructTextRun(this, font, &space, 1, style()));
    683685            maxW -= spaceWidth;
    684686        } else
    685             maxW += f.wordSpacing();
     687            maxW += font.wordSpacing();
    686688    }
    687689
     
    916918                currMaxWidth = 0;
    917919            } else {
    918                 currMaxWidth += f.width(TextRun(txt + i, 1, allowTabs(), leadWidth + currMaxWidth));
     920                TextRun run = RenderBlock::constructTextRun(this, f, txt + i, 1, style());
     921                run.setAllowTabs(allowTabs());
     922                run.setXPos(leadWidth + currMaxWidth);
     923
     924                currMaxWidth += f.width(run);
    919925                glyphOverflow.right = 0;
    920926                needsWordSpacing = isSpace && !previousCharacterIsSpace && i == len - 1;
     
    12901296        } else
    12911297            w = widthFromCache(f, from, len, xPos, fallbackFonts, glyphOverflow);
    1292     } else
    1293         w = f.width(TextRun(text()->characters() + from, len, allowTabs(), xPos), fallbackFonts, glyphOverflow);
     1298    } else {
     1299        TextRun run = RenderBlock::constructTextRun(const_cast<RenderText*>(this), f, text()->characters() + from, len, style());
     1300        run.setAllowTabs(allowTabs());
     1301        run.setXPos(xPos);
     1302        w = f.width(run, fallbackFonts, glyphOverflow);
     1303    }
    12941304
    12951305    return w;
  • trunk/Source/WebCore/rendering/RenderTextControl.cpp

    r87067 r87152  
    4141#include "TextControlInnerElements.h"
    4242#include "TextIterator.h"
    43 #include "TextRun.h"
    4443#include <wtf/unicode/CharacterNames.h>
    4544
     
    535534
    536535    const UChar ch = '0';
    537     return style()->font().width(constructTextRunAllowTrailingExpansion(String(&ch, 1), style()));
     536    const Font& font = style()->font();
     537    return font.width(constructTextRun(this, font, String(&ch, 1), style(), TextRun::AllowTrailingExpansion));
    538538}
    539539
  • trunk/Source/WebCore/rendering/svg/RenderSVGAllInOne.cpp

    r81540 r87152  
    7373#include "SVGTextLayoutEngineBaseline.cpp"
    7474#include "SVGTextLayoutEngineSpacing.cpp"
     75#include "SVGTextRunRenderingContext.cpp"
    7576#include "SVGTextMetrics.cpp"
    7677#include "SVGTextQuery.cpp"
  • trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp

    r85143 r87152  
    3333#include "SVGImageBufferTools.h"
    3434#include "SVGRootInlineBox.h"
    35 #include "TextRun.h"
     35#include "SVGTextRunRenderingContext.h"
    3636
    3737using namespace std;
     
    6767    ASSERT(style);
    6868
    69     TextRun textRun(constructTextRun(style, fragment));
     69    TextRun textRun = constructTextRun(style, fragment);
    7070
    7171    // Eventually handle lengthAdjust="spacingAndGlyphs".
     
    380380{
    381381    bool acquiredResource = acquirePaintingResource(context, scalingFactor, parent()->renderer(), style);
     382    if (!acquiredResource)
     383        return false;
    382384
    383385#if ENABLE(SVG_FONTS)
    384386    // SVG Fonts need access to the painting resource used to draw the current text chunk.
    385     if (acquiredResource)
    386         textRun.setActivePaintingResource(m_paintingResource);
     387    TextRun::RenderingContext* renderingContext = textRun.renderingContext();
     388    if (renderingContext)
     389        static_cast<SVGTextRunRenderingContext*>(renderingContext)->setActivePaintingResource(m_paintingResource);
    387390#endif
    388391
    389     return acquiredResource;
     392    return true;
    390393}
    391394
     
    395398
    396399#if ENABLE(SVG_FONTS)
    397     textRun.setActivePaintingResource(0);
     400    TextRun::RenderingContext* renderingContext = textRun.renderingContext();
     401    if (renderingContext)
     402        static_cast<SVGTextRunRenderingContext*>(renderingContext)->setActivePaintingResource(0);
     403#else
     404    UNUSED_PARAM(textRun);
    398405#endif
    399406}
     
    416423                , m_dirOverride || style->visuallyOrdered() /* directionalOverride */);
    417424
    418 #if ENABLE(SVG_FONTS)
    419     run.setReferencingRenderObject(text);
    420 #endif
     425    if (textRunNeedsRenderingContext(style->font()))
     426        run.setRenderingContext(SVGTextRunRenderingContext::create(text));
    421427
    422428    // We handle letter & word spacing ourselves.
     
    660666
    661667    // Fast path if there is no selection, just draw the whole chunk part using the regular style
    662     TextRun textRun(constructTextRun(style, fragment));
     668    TextRun textRun = constructTextRun(style, fragment);
    663669    if (!hasSelection || startPosition >= endPosition) {
    664670        paintTextWithShadows(context, style, textRun, fragment, 0, fragment.length);
     
    674680        SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, selectionStyle);
    675681
    676     TextRun selectionTextRun(constructTextRun(selectionStyle, fragment));
     682    TextRun selectionTextRun = constructTextRun(selectionStyle, fragment);
    677683    paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition);
    678684
  • trunk/Source/WebCore/rendering/svg/SVGTextLayoutEngineSpacing.cpp

    r76442 r87152  
    2727
    2828#if ENABLE(SVG_FONTS)
     29#include "SVGFontData.h"
    2930#include "SVGFontElement.h"
     31#include "SVGFontFaceElement.h"
    3032#endif
    3133
     
    4143{
    4244#if ENABLE(SVG_FONTS)
    43     if (!m_font.isSVGFont()) {
     45    const SimpleFontData* fontData = m_font.primaryFont();
     46    if (!fontData->isSVGFont()) {
    4447        m_lastGlyph.isValid = false;
    4548        return 0;
    4649    }
    4750
    48     SVGFontElement* svgFont = m_font.svgFont();
    49     ASSERT(svgFont);
     51    ASSERT(fontData->isCustomFont());
     52    ASSERT(fontData->isSVGFont());
     53
     54    const SVGFontData* svgFontData = static_cast<const SVGFontData*>(fontData->fontData());
     55    SVGFontFaceElement* svgFontFace = svgFontData->svgFontFaceElement();
     56    ASSERT(svgFontFace);
     57
     58    SVGFontElement* svgFont = svgFontFace->associatedFontElement();
     59    if (!svgFont) {
     60        m_lastGlyph.isValid = false;
     61        return 0;
     62    }
    5063
    5164    float kerning = 0;
  • trunk/Source/WebCore/rendering/svg/SVGTextMetrics.cpp

    r85143 r87152  
    2424
    2525#include "RenderSVGInlineText.h"
    26 #include "TextRun.h"
     26#include "SVGTextRunRenderingContext.h"
    2727
    2828namespace WebCore {
     
    8787                , style->unicodeBidi() == Override /* directionalOverride */);
    8888
    89 #if ENABLE(SVG_FONTS)
    90     run.setReferencingRenderObject(text);
    91 #endif
     89    if (textRunNeedsRenderingContext(style->font()))
     90        run.setRenderingContext(SVGTextRunRenderingContext::create(text));
    9291
    9392    // We handle letter & word spacing ourselves.
     
    9998{
    10099    ASSERT(text);
    101     TextRun run(constructTextRun(text, text->characters(), position, length));
    102     return SVGTextMetrics(text, run, position, text->textLength());
     100    return SVGTextMetrics(text, constructTextRun(text, text->characters(), position, length), position, text->textLength());
    103101}
    104102
  • trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp

    r86823 r87152  
    11/*
    22 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
    3  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
     3 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
    44 *
    55 * This library is free software; you can redistribute it and/or
     
    3737#include "SVGMissingGlyphElement.h"
    3838#include "SVGNames.h"
     39#include "SVGTextRunRenderingContext.h"
    3940#include "SimpleFontData.h"
    40 #include "TextRun.h"
    4141#include "XMLNames.h"
    4242
     
    6060static inline const SVGFontData* svgFontAndFontFaceElementForFontData(const SimpleFontData* fontData, SVGFontFaceElement*& fontFace, SVGFontElement*& font)
    6161{
     62    ASSERT(fontData);
    6263    ASSERT(fontData->isCustomFont());
    6364    ASSERT(fontData->isSVGFont());
    6465
    65     const SVGFontData* svgFontData = static_cast<const SVGFontData*>(fontData->svgFontData());
     66    const SVGFontData* svgFontData = static_cast<const SVGFontData*>(fontData->fontData());
    6667
    6768    fontFace = svgFontData->svgFontFaceElement();
     
    7071    font = fontFace->associatedFontElement();
    7172    return svgFontData;
     73}
     74
     75static inline RenderObject* firstParentRendererForNonTextNode(RenderObject* renderer)
     76{
     77    ASSERT(renderer);
     78    RenderObject* newRenderer = renderer->isText() ? renderer->parent() : renderer;
     79    ASSERT(newRenderer->node());
     80    ASSERT(newRenderer->node()->isElementNode());
     81    return newRenderer;
     82}
     83
     84static inline RenderObject* referencingRenderObjectFromRun(const TextRun& run)
     85{
     86    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
     87        return static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
     88    return 0;
     89}
     90
     91static inline RenderSVGResource* activePaintingResourceFromRun(const TextRun& run)
     92{
     93    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
     94        return static_cast<SVGTextRunRenderingContext*>(renderingContext)->activePaintingResource();
     95    return 0;
    7296}
    7397
     
    101125        int endOfScanRange = to + m_walkerData.extraCharsAvailable;
    102126
     127        RenderObject* renderObject = referencingRenderObjectFromRun(run);
     128        RenderObject* parentRenderObject = firstParentRendererForNonTextNode(renderObject);
     129
    103130        bool haveAltGlyph = false;
    104131        SVGGlyph altGlyphIdentifier;
    105         if (RenderObject* renderObject = run.referencingRenderObject()) {
    106             RenderObject* parentRenderer = renderObject->parent();
    107             ASSERT(parentRenderer);
    108             if (parentRenderer->node() && parentRenderer->node()->hasTagName(SVGNames::altGlyphTag)) {
    109                 SVGGlyphElement* glyphElement = static_cast<SVGAltGlyphElement*>(parentRenderer->node())->glyphElement();
    110                 if (glyphElement) {
    111                     haveAltGlyph = true;
    112                     altGlyphIdentifier = glyphElement->buildGlyphIdentifier();
    113                     altGlyphIdentifier.isValid = true;
    114                     altGlyphIdentifier.unicodeStringLength = to - from;
    115                 }
     132        Node* node = parentRenderObject->node();
     133        if (node->hasTagName(SVGNames::altGlyphTag)) {
     134            if (SVGGlyphElement* glyphElement = static_cast<SVGAltGlyphElement*>(node)->glyphElement()) {
     135                haveAltGlyph = true;
     136                altGlyphIdentifier = glyphElement->buildGlyphIdentifier();
     137                altGlyphIdentifier.isValid = true;
     138                altGlyphIdentifier.unicodeStringLength = to - from;
    116139            }
    117140        }
     
    158181                    // Fallback to system font fallback
    159182                    TextRun subRun(run);
     183                    subRun.setRenderingContext(0);
    160184                    subRun.setText(subRun.data(i), 1);
    161185
     
    211235    font.update(data.font->fontSelector());
    212236
    213     data.length += font.width(run);
    214 }
    215 
    216 
    217 SVGFontElement* Font::svgFont() const
    218 {
    219     if (!isSVGFont())
    220         return 0;
     237    TextRun fallbackRun(run);
     238    fallbackRun.setRenderingContext(0);
     239    data.length += font.width(fallbackRun);
     240}
     241
     242static float floatWidthOfSubStringUsingSVGFont(const Font& font, const TextRun& run, int extraCharsAvailable, int from, int to, int& charsConsumed, String& glyphName)
     243{
     244    int newFrom = to > from ? from : to;
     245    int newTo = to > from ? to : from;
     246
     247    from = newFrom;
     248    to = newTo;
    221249
    222250    SVGFontElement* fontElement = 0;
    223251    SVGFontFaceElement* fontFaceElement = 0;
    224     if (svgFontAndFontFaceElementForFontData(primaryFont(), fontFaceElement, fontElement))
    225         return fontElement;
    226    
    227     return 0;
    228 }
    229 
    230 static float floatWidthOfSubStringUsingSVGFont(const Font* font, const TextRun& run, int extraCharsAvailable, int from, int to, int& charsConsumed, String& glyphName)
    231 {
    232     int newFrom = to > from ? from : to;
    233     int newTo = to > from ? to : from;
    234 
    235     from = newFrom;
    236     to = newTo;
    237 
    238     SVGFontElement* fontElement = 0;
    239     SVGFontFaceElement* fontFaceElement = 0;
    240 
    241     if (const SVGFontData* fontData = svgFontAndFontFaceElementForFontData(font->primaryFont(), fontFaceElement, fontElement)) {
     252
     253    if (const SVGFontData* fontData = svgFontAndFontFaceElementForFontData(font.primaryFont(), fontFaceElement, fontElement)) {
    242254        if (!fontElement)
    243255            return 0.0f;
     
    245257        SVGTextRunWalkerMeasuredLengthData data;
    246258
    247         data.font = font;
     259        data.font = &font;
    248260        data.at = from;
    249261        data.from = from;
     
    251263        data.extraCharsAvailable = extraCharsAvailable;
    252264        data.charsConsumed = 0;
    253         data.scale = convertEmUnitToPixel(font->size(), fontFaceElement->unitsPerEm(), 1.0f);
     265        data.scale = convertEmUnitToPixel(font.size(), fontFaceElement->unitsPerEm(), 1.0f);
    254266        data.length = 0.0f;
    255267
    256         String language;
    257         bool isVerticalText = false; // Holds true for HTML text
    258 
    259         // TODO: language matching & svg glyphs should be possible for HTML text, too.
    260         if (RenderObject* renderObject = run.referencingRenderObject()) {
    261             RenderObject* parentRenderer = renderObject->parent();
    262             ASSERT(parentRenderer);
    263             isVerticalText = isVerticalWritingMode(parentRenderer->style()->svgStyle());
    264 
    265             if (SVGElement* element = static_cast<SVGElement*>(parentRenderer->node()))
    266                 language = element->getAttribute(XMLNames::langAttr);
    267         }
     268        RenderObject* renderObject = referencingRenderObjectFromRun(run);
     269        RenderObject* parentRenderObject = firstParentRendererForNonTextNode(renderObject);
     270
     271        String language = toElement(parentRenderObject->node())->getAttribute(XMLNames::langAttr);
     272        bool isVerticalText = isVerticalWritingMode(parentRenderObject->style()->svgStyle());
    268273
    269274        SVGTextRunWalker<SVGTextRunWalkerMeasuredLengthData> runWalker(fontData, fontElement, data, floatWidthUsingSVGFontCallback, floatWidthMissingGlyphCallback);
     
    277282}
    278283
    279 float Font::floatWidthUsingSVGFont(const TextRun& run) const
     284float SVGTextRunRenderingContext::floatWidthUsingSVGFont(const Font& font, const TextRun& run) const
    280285{
    281286    int charsConsumed;
    282287    String glyphName;
    283     return floatWidthOfSubStringUsingSVGFont(this, run, 0, 0, run.length(), charsConsumed, glyphName);
    284 }
    285 
    286 float Font::floatWidthUsingSVGFont(const TextRun& run, int extraCharsAvailable, int& charsConsumed, String& glyphName) const
    287 {
    288     return floatWidthOfSubStringUsingSVGFont(this, run, extraCharsAvailable, 0, run.length(), charsConsumed, glyphName);
     288    return floatWidthOfSubStringUsingSVGFont(font, run, 0, 0, run.length(), charsConsumed, glyphName);
     289}
     290
     291float SVGTextRunRenderingContext::floatWidthUsingSVGFont(const Font& font, const TextRun& run, int extraCharsAvailable, int& charsConsumed, String& glyphName) const
     292{
     293    return floatWidthOfSubStringUsingSVGFont(font, run, extraCharsAvailable, 0, run.length(), charsConsumed, glyphName);
    289294}
    290295
     
    311316}
    312317
    313 void Font::drawTextUsingSVGFont(GraphicsContext* context, const TextRun& run,
    314                                 const FloatPoint& point, int from, int to) const
     318void SVGTextRunRenderingContext::drawTextUsingSVGFont(const Font& font, GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to) const
    315319{
    316320    SVGFontElement* fontElement = 0;
    317321    SVGFontFaceElement* fontFaceElement = 0;
    318322
    319     if (const SVGFontData* fontData = svgFontAndFontFaceElementForFontData(primaryFont(), fontFaceElement, fontElement)) {
     323    if (const SVGFontData* fontData = svgFontAndFontFaceElementForFontData(font.primaryFont(), fontFaceElement, fontElement)) {
    320324        if (!fontElement)
    321325            return;
     
    323327        SVGTextRunWalkerDrawTextData data;
    324328        FloatPoint currentPoint = point;
    325         float scale = convertEmUnitToPixel(size(), fontFaceElement->unitsPerEm(), 1.0f);
    326 
    327         RenderSVGResource* activePaintingResource = run.activePaintingResource();
    328 
    329         // If renderObject is not set, we're dealing for HTML text rendered using SVG Fonts.
    330         if (!run.referencingRenderObject()) {
    331             ASSERT(!activePaintingResource);
    332 
     329        float scale = convertEmUnitToPixel(font.size(), fontFaceElement->unitsPerEm(), 1.0f);
     330
     331        // We can only paint SVGFonts if a context is available.
     332        RenderObject* renderObject = referencingRenderObjectFromRun(run);
     333        RenderObject* parentRenderObject = firstParentRendererForNonTextNode(renderObject);
     334
     335        // If activePaintingResource is not set, we're dealing for HTML text rendered using SVG Fonts.
     336        RenderSVGResource* activePaintingResource = activePaintingResourceFromRun(run);
     337        if (!activePaintingResource) {
    333338            // TODO: We're only supporting simple filled HTML text so far.
    334339            RenderSVGResourceSolidColor* solidPaintingResource = RenderSVGResource::sharedSolidPaintingResource();
     
    338343        }
    339344
    340         ASSERT(activePaintingResource);
    341 
    342345        int charsConsumed;
    343346        String glyphName;
    344         bool isVerticalText = false;
    345         float xStartOffset = floatWidthOfSubStringUsingSVGFont(this, run, 0, run.rtl() ? to : 0, run.rtl() ? run.length() : from, charsConsumed, glyphName);
     347        float xStartOffset = floatWidthOfSubStringUsingSVGFont(font, run, 0, run.rtl() ? to : 0, run.rtl() ? run.length() : from, charsConsumed, glyphName);
    346348        FloatPoint glyphOrigin;
    347349
    348         String language;
    349 
    350         // TODO: language matching & svg glyphs should be possible for HTML text, too.
    351         RenderObject* referencingRenderObject = run.referencingRenderObject();
    352         RenderObject* referencingRenderObjectParent = referencingRenderObject ? referencingRenderObject->parent() : 0;
    353         RenderStyle* referencingRenderObjectParentStyle = 0;
    354         if (referencingRenderObject) {
    355             ASSERT(referencingRenderObjectParent);
    356             referencingRenderObjectParentStyle = referencingRenderObjectParent->style();
    357 
    358             isVerticalText = isVerticalWritingMode(referencingRenderObjectParentStyle->svgStyle());   
    359             if (SVGElement* element = static_cast<SVGElement*>(referencingRenderObjectParent->node()))
    360                 language = element->getAttribute(XMLNames::langAttr);
    361         }
    362 
     350        Node* node = parentRenderObject->node();
     351        String language = toElement(node)->getAttribute(XMLNames::langAttr);
     352
     353        RenderStyle* parentRenderObjectStyle = parentRenderObject->style();
     354        bool isVerticalText = isVerticalWritingMode(parentRenderObjectStyle->svgStyle());
    363355        if (!isVerticalText) {
    364356            glyphOrigin.setX(fontData->horizontalOriginX() * scale);
     
    395387                    glyphPath.transform(glyphPathTransform);
    396388
    397                     if (activePaintingResource->applyResource(referencingRenderObjectParent, referencingRenderObjectParentStyle, context, resourceMode)) {
    398                         if (referencingRenderObject) {
    399                             RenderSVGInlineText* textRenderer = toRenderSVGInlineText(referencingRenderObject);
     389                    if (activePaintingResource->applyResource(parentRenderObject, parentRenderObjectStyle, context, resourceMode)) {
     390                        if (renderObject && renderObject->isSVGInlineText()) {
     391                            const RenderSVGInlineText* textRenderer = toRenderSVGInlineText(renderObject);
    400392                            context->setStrokeThickness(context->strokeThickness() * textRenderer->scalingFactor());
    401393                        }
    402                         activePaintingResource->postApplyResource(referencingRenderObjectParent, context, resourceMode, &glyphPath);
     394                        activePaintingResource->postApplyResource(parentRenderObject, context, resourceMode, &glyphPath);
    403395                    }
    404396                }
     
    410402            } else {
    411403                // Handle system font fallback
    412                 FontDescription fontDescription(m_fontDescription);
     404                FontDescription fontDescription(font.fontDescription());
    413405                fontDescription.setFamily(FontFamily());
    414406                Font font(fontDescription, 0, 0); // spacing handled by SVG text code.
    415                 font.update(fontSelector());
     407                font.update(font.fontSelector());
    416408
    417409                TextRun fallbackCharacterRun(run);
     410                fallbackCharacterRun.setRenderingContext(0);
    418411                fallbackCharacterRun.setText(&data.fallbackCharacters[run.rtl() ? data.fallbackCharacters.size() - fallbackCharacterIndex - 1 : fallbackCharacterIndex], 1);
    419412                font.drawText(context, fallbackCharacterRun, currentPoint);
     
    430423}
    431424
    432 FloatRect Font::selectionRectForTextUsingSVGFont(const TextRun& run, const FloatPoint& point, int height, int from, int to) const
     425FloatRect SVGTextRunRenderingContext::selectionRectForTextUsingSVGFont(const Font& font, const TextRun& run, const FloatPoint& point, int height, int from, int to) const
    433426{
    434427    int charsConsumed;
    435428    String glyphName;
    436429
    437     return FloatRect(point.x() + floatWidthOfSubStringUsingSVGFont(this, run, 0, run.rtl() ? to : 0, run.rtl() ? run.length() : from, charsConsumed, glyphName),
    438                      point.y(), floatWidthOfSubStringUsingSVGFont(this, run, 0, from, to, charsConsumed, glyphName), height);
    439 }
    440 
    441 int Font::offsetForPositionForTextUsingSVGFont(const TextRun&, float, bool) const
     430    return FloatRect(point.x() + floatWidthOfSubStringUsingSVGFont(font, run, 0, run.rtl() ? to : 0, run.rtl() ? run.length() : from, charsConsumed, glyphName),
     431                     point.y(), floatWidthOfSubStringUsingSVGFont(font, run, 0, from, to, charsConsumed, glyphName), height);
     432}
     433
     434int SVGTextRunRenderingContext::offsetForPositionForTextUsingSVGFont(const Font&, const TextRun&, float, bool) const
    442435{
    443436    // TODO: Fix text selection when HTML text is drawn using a SVG Font
  • trunk/Source/WebCore/svg/SVGAllInOne.cpp

    r84522 r87152  
    7878#include "SVGFilterPrimitiveStandardAttributes.cpp"
    7979#include "SVGFitToViewBox.cpp"
    80 #include "SVGFont.cpp"
    8180#include "SVGFontData.cpp"
    8281#include "SVGFontElement.cpp"
  • trunk/Source/WebCore/svg/SVGFontData.cpp

    r66397 r87152  
    2323#include "SVGFontData.h"
    2424
     25#include "SVGFontElement.h"
     26#include "SVGGlyph.h"
     27
    2528namespace WebCore {
    2629
     
    3740}
    3841
     42void SVGFontData::initializeFontData(SimpleFontData* fontData, int size)
     43{
     44    ASSERT(fontData);
     45
     46    SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement();
     47    unsigned unitsPerEm = svgFontFaceElement->unitsPerEm();
     48
     49    float scale = size;
     50    if (unitsPerEm)
     51        scale /= unitsPerEm;
     52
     53    float xHeight = svgFontFaceElement->xHeight() * scale;
     54    float ascent = svgFontFaceElement->ascent() * scale;
     55    float descent = svgFontFaceElement->descent() * scale;
     56    float lineGap = 0.1f * size;
     57
     58    SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontElement();
     59    if (!xHeight) {
     60        // Fallback if x_heightAttr is not specified for the font element.
     61        Vector<SVGGlyph> letterXGlyphs;
     62        associatedFontElement->getGlyphIdentifiersForString(String("x", 1), letterXGlyphs);
     63        xHeight = letterXGlyphs.isEmpty() ? 2 * ascent / 3 : letterXGlyphs.first().horizontalAdvanceX * scale;
     64    }
     65
     66    FontMetrics& fontMetrics = fontData->fontMetrics();
     67    fontMetrics.setUnitsPerEm(unitsPerEm);
     68    fontMetrics.setAscent(ascent);
     69    fontMetrics.setDescent(descent);
     70    fontMetrics.setLineGap(lineGap);
     71    fontMetrics.setLineSpacing(roundf(ascent) + roundf(descent) + roundf(lineGap));
     72    fontMetrics.setXHeight(xHeight);
     73
     74    Vector<SVGGlyph> spaceGlyphs;
     75    associatedFontElement->getGlyphIdentifiersForString(String(" ", 1), spaceGlyphs);
     76    fontData->setSpaceWidth(spaceGlyphs.isEmpty() ? xHeight : spaceGlyphs.first().horizontalAdvanceX * scale);
     77
     78    Vector<SVGGlyph> numeralZeroGlyphs;
     79    associatedFontElement->getGlyphIdentifiersForString(String("0", 1), numeralZeroGlyphs);
     80    fontData->setAvgCharWidth(numeralZeroGlyphs.isEmpty() ? fontData->spaceWidth() : numeralZeroGlyphs.first().horizontalAdvanceX * scale);
     81
     82    Vector<SVGGlyph> letterWGlyphs;
     83    associatedFontElement->getGlyphIdentifiersForString(String("W", 1), letterWGlyphs);
     84    fontData->setMaxCharWidth(letterWGlyphs.isEmpty() ? ascent : letterWGlyphs.first().horizontalAdvanceX * scale);
     85
     86    // FIXME: is there a way we can get the space glyph from the SVGGlyph above?
     87    fontData->setSpaceGlyph(0);
     88    fontData->setZeroWidthSpaceGlyph(0);
     89    fontData->determinePitch();
     90
     91    GlyphData missingGlyphData;
     92    missingGlyphData.fontData = fontData;
     93    missingGlyphData.glyph = 0;
     94    fontData->setMissingGlyphData(missingGlyphData);
     95}
     96
    3997} // namespace WebCore
    4098
  • trunk/Source/WebCore/svg/SVGFontData.h

    r76248 r87152  
    2222
    2323#if ENABLE(SVG_FONTS)
     24#include "SimpleFontData.h"
    2425#include "SVGFontFaceElement.h"
    2526
    2627namespace WebCore {
    2728
    28 class SVGFontData {
    29     WTF_MAKE_NONCOPYABLE(SVGFontData); WTF_MAKE_FAST_ALLOCATED;
     29class SVGFontData : public SimpleFontData::FontData {
    3030public:
    31     SVGFontData(SVGFontFaceElement*);
     31    static PassOwnPtr<SVGFontData> create(SVGFontFaceElement* element)
     32    {
     33        return adoptPtr(new SVGFontData(element));
     34    }
     35
    3236    virtual ~SVGFontData() { }
     37
     38    virtual bool isSVGFontData() const { return true; }
     39    virtual void initializeFontData(SimpleFontData*, int size);
    3340
    3441    SVGFontFaceElement* svgFontFaceElement() const { return m_svgFontFaceElement; }
     
    4350
    4451private:
     52    SVGFontData(SVGFontFaceElement*);
     53
    4554    // Ths SVGFontFaceElement is kept alive --
    4655    // 1) in the external font case: by the CSSFontFaceSource, which holds a reference to the external SVG document
  • trunk/Source/WebCore/svg/SVGGlyphElement.cpp

    r86050 r87152  
    3131#include "SVGNames.h"
    3232#include "SVGPathParserFactory.h"
    33 #include "SimpleFontData.h"
    34 #include "XMLNames.h"
    3533
    3634namespace WebCore {
    37 
    38 using namespace SVGNames;
    3935
    4036inline SVGGlyphElement::SVGGlyphElement(const QualifiedName& tagName, Document* document)
    4137    : SVGStyledElement(tagName, document)
    4238{
    43     ASSERT(hasTagName(glyphTag));
     39    ASSERT(hasTagName(SVGNames::glyphTag));
    4440}
    4541
     
    151147{
    152148    SVGGlyph identifier;
    153     identifier.pathData = parsePathData(element->getAttribute(dAttr));
     149    identifier.pathData = parsePathData(element->getAttribute(SVGNames::dAttr));
    154150 
    155151    // Spec: The horizontal advance after rendering the glyph in horizontal orientation.
     
    157153    // value of the font's horiz-adv-x attribute. Glyph widths are required to be non-negative,
    158154    // even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts.
    159     identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, horiz_adv_xAttr);
     155    identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, SVGNames::horiz_adv_xAttr);
    160156
    161157    // Spec: The X-coordinate in the font coordinate system of the origin of the glyph to be
    162158    // used when drawing vertically oriented text. If the attribute is not specified, the effect
    163159    // is as if the attribute were set to the value of the font's vert-origin-x attribute.
    164     identifier.verticalOriginX = parseSVGGlyphAttribute(element, vert_origin_xAttr);
     160    identifier.verticalOriginX = parseSVGGlyphAttribute(element, SVGNames::vert_origin_xAttr);
    165161
    166162    // Spec: The Y-coordinate in the font coordinate system of the origin of a glyph to be
    167163    // used when drawing vertically oriented text. If the attribute is not specified, the effect
    168164    // is as if the attribute were set to the value of the font's vert-origin-y attribute.
    169     identifier.verticalOriginY = parseSVGGlyphAttribute(element, vert_origin_yAttr);
     165    identifier.verticalOriginY = parseSVGGlyphAttribute(element, SVGNames::vert_origin_yAttr);
    170166
    171167    // Spec: The vertical advance after rendering a glyph in vertical orientation.
    172168    // If the attribute is not specified, the effect is as if the attribute were set to the
    173169    // value of the font's vert-adv-y attribute.
    174     identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, vert_adv_yAttr);
     170    identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, SVGNames::vert_adv_yAttr);
    175171
    176172    return identifier;
     
    180176{
    181177    SVGGlyph identifier(buildGenericGlyphIdentifier(this));
    182     identifier.glyphName = getAttribute(glyph_nameAttr);
    183     identifier.orientation = parseOrientation(getAttribute(orientationAttr));
    184     identifier.arabicForm = parseArabicForm(getAttribute(arabic_formAttr));
     178    identifier.glyphName = getAttribute(SVGNames::glyph_nameAttr);
     179    identifier.orientation = parseOrientation(getAttribute(SVGNames::orientationAttr));
     180    identifier.arabicForm = parseArabicForm(getAttribute(SVGNames::arabic_formAttr));
    185181
    186182    String language = getAttribute(SVGNames::langAttr);
  • trunk/Source/WebCore/svg/SVGHKernElement.cpp

    r86050 r87152  
    2525#include "SVGHKernElement.h"
    2626
    27 #include "SVGFontData.h"
    2827#include "SVGFontElement.h"
    2928#include "SVGFontFaceElement.h"
    3029#include "SVGNames.h"
    31 #include "SimpleFontData.h"
    32 #include "XMLNames.h"
    3330
    3431namespace WebCore {
    35 
    36 using namespace SVGNames;
    3732
    3833inline SVGHKernElement::SVGHKernElement(const QualifiedName& tagName, Document* document)
    3934    : SVGElement(tagName, document)
    4035{
    41     ASSERT(hasTagName(hkernTag));
     36    ASSERT(hasTagName(SVGNames::hkernTag));
    4237}
    4338
     
    6964void SVGHKernElement::buildHorizontalKerningPair(KerningPairVector& kerningPairs)
    7065{
    71     String u1 = getAttribute(u1Attr);
    72     String g1 = getAttribute(g1Attr);
    73     String u2 = getAttribute(u2Attr);
    74     String g2 = getAttribute(g2Attr);
     66    String u1 = getAttribute(SVGNames::u1Attr);
     67    String g1 = getAttribute(SVGNames::g1Attr);
     68    String u2 = getAttribute(SVGNames::u2Attr);
     69    String g2 = getAttribute(SVGNames::g2Attr);
    7570    if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty()))
    7671        return;
     
    8176        && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1)
    8277        && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) {
    83         kerningPair.kerning = getAttribute(kAttr).string().toFloat();
     78        kerningPair.kerning = getAttribute(SVGNames::kAttr).string().toFloat();
    8479        kerningPairs.append(kerningPair);
    8580    }
  • trunk/Source/WebCore/svg/SVGVKernElement.cpp

    r86050 r87152  
    2323#include "SVGVKernElement.h"
    2424
    25 #include "SVGFontData.h"
    2625#include "SVGFontElement.h"
    2726#include "SVGFontFaceElement.h"
    2827#include "SVGNames.h"
    29 #include "SimpleFontData.h"
    30 #include "XMLNames.h"
    3128
    3229namespace WebCore {
    33 
    34 using namespace SVGNames;
    3530
    3631inline SVGVKernElement::SVGVKernElement(const QualifiedName& tagName, Document* document)
    3732    : SVGElement(tagName, document)
    3833{
    39     ASSERT(hasTagName(vkernTag));
     34    ASSERT(hasTagName(SVGNames::vkernTag));
    4035}
    4136
     
    6762void SVGVKernElement::buildVerticalKerningPair(KerningPairVector& kerningPairs)
    6863{
    69     String u1 = getAttribute(u1Attr);
    70     String g1 = getAttribute(g1Attr);
    71     String u2 = getAttribute(u2Attr);
    72     String g2 = getAttribute(g2Attr);
     64    String u1 = getAttribute(SVGNames::u1Attr);
     65    String g1 = getAttribute(SVGNames::g1Attr);
     66    String u2 = getAttribute(SVGNames::u2Attr);
     67    String g2 = getAttribute(SVGNames::g2Attr);
    7368    if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty()))
    7469        return;
     
    7974        && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1)
    8075        && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) {
    81         kerningPair.kerning = getAttribute(kAttr).string().toFloat();
     76        kerningPair.kerning = getAttribute(SVGNames::kAttr).string().toFloat();
    8277        kerningPairs.append(kerningPair);
    8378    }
  • trunk/Source/WebCore/svg/SVGVKernElement.h

    r87125 r87152  
    3131namespace WebCore {
    3232
    33 class SVGFontData;
    34 
    3533class SVGVKernElement : public SVGElement {
    3634public:
Note: See TracChangeset for help on using the changeset viewer.