Changeset 29839 in webkit


Ignore:
Timestamp:
Jan 28, 2008 3:37:04 PM (16 years ago)
Author:
Nikolas Zimmermann
Message:

Reviewed by Eric, Dan & Oliver.

Fixes: http://bugs.webkit.org/show_bug.cgi?id=16980

Support external SVG Fonts, by reusing the custom font handling logic.
This enables us - as first engine - to render HTML pages using SVG Fonts.

Fixes fonts-elem-03-b.svg / fonts-elem-04-b.svg / fonts-elem-07-b.svg
Add new testcase svg-fonts-in-html.html.

Location:
trunk
Files:
5 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r29838 r29839  
     12008-01-28  Nikolas Zimmermann  <zimmermann@kde.org>
     2
     3        Reviewed by Eric, Dan & Oliver.
     4
     5        Update layout tests after adding external SVG Fonts support.
     6
     7        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-03-b-expected.checksum:
     8        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-03-b-expected.png:
     9        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-03-b-expected.txt:
     10        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-04-b-expected.checksum:
     11        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-04-b-expected.png:
     12        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-04-b-expected.txt:
     13        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-07-b-expected.checksum:
     14        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-07-b-expected.png:
     15        * platform/mac/svg/W3C-SVG-1.1/fonts-elem-07-b-expected.txt:
     16        * platform/mac/svg/custom/svg-fonts-in-html-expected.checksum: Added.
     17        * platform/mac/svg/custom/svg-fonts-in-html-expected.png: Added.
     18        * platform/mac/svg/custom/svg-fonts-in-html-expected.txt: Added.
     19        * svg/custom/resources/graffiti.svg: Added.
     20        * svg/custom/svg-fonts-in-html.html: Added.
     21
    1222008-01-28  Dan Bernstein  <mitz@apple.com>
    223
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/fonts-elem-03-b-expected.checksum

    r27850 r29839  
    1 69da9bd20420dbff4d3cb6dbd1600c5b
     1eba2190f5fda7b0f31bd8c21914c56c8
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/fonts-elem-03-b-expected.txt

    r26599 r29839  
    2929        RenderSVGInlineText {#text} at (0,-17) size 74x22
    3030          chunk 1 text run 1 at (67.00,210.00) startOffset 0 endOffset 8 width 74.00: "SVG Font"
    31       RenderSVGContainer {g} at (165,166) size 210x69 [transform={m=((1.00,0.00)(0.00,1.00)) t=(165.00,220.00)}]
     31      RenderSVGContainer {g} at (165,172) size 210x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(165.00,220.00)}]
    3232        RenderPath {line} at (165,219.50) size 210x1 [stroke={[type=SOLID] [color=#888888]}] [fill={[type=SOLID] [color=#000000]}] [data="M0.00,0.00L210.00,0.00"]
    33         RenderSVGText {text} at (0,0) size 198x69 contains 1 chunk(s)
    34           RenderSVGInlineText {#text} at (0,-54) size 198x69
    35             chunk 1 text run 1 at (0.00,0.00) startOffset 0 endOffset 5 width 198.00: "Ay\x{D6}@\x{E7}"
     33        RenderSVGText {text} at (0,0) size 210x60 contains 1 chunk(s)
     34          RenderSVGInlineText {#text} at (0,-48) size 210x60
     35            chunk 1 text run 1 at (0.00,0.00) startOffset 0 endOffset 5 width 209.71: "Ay\x{D6}@\x{E7}"
    3636    RenderSVGText {text} at (10,340) size 264x46 contains 1 chunk(s)
    3737      RenderSVGInlineText {#text} at (0,-36) size 264x46
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/fonts-elem-04-b-expected.checksum

    r27850 r29839  
    1 fd770c729d92e1ff25890592d2aa786c
     1ae5055bccd277a00b383c5118ff19215
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/fonts-elem-04-b-expected.txt

    r26599 r29839  
    2929        RenderSVGInlineText {#text} at (0,-17) size 74x22
    3030          chunk 1 text run 1 at (67.00,210.00) startOffset 0 endOffset 8 width 74.00: "SVG Font"
    31       RenderSVGContainer {g} at (165,166) size 210x69 [transform={m=((1.00,0.00)(0.00,1.00)) t=(165.00,220.00)}]
     31      RenderSVGContainer {g} at (165,172) size 210x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(165.00,220.00)}]
    3232        RenderPath {line} at (165,219.50) size 210x1 [stroke={[type=SOLID] [color=#888888]}] [fill={[type=SOLID] [color=#000000]}] [data="M0.00,0.00L210.00,0.00"]
    33         RenderSVGText {text} at (0,0) size 198x69 contains 1 chunk(s)
    34           RenderSVGInlineText {#text} at (0,-54) size 198x69
    35             chunk 1 text run 1 at (0.00,0.00) startOffset 0 endOffset 5 width 198.00: "Ay\x{D6}@\x{E7}"
     33        RenderSVGText {text} at (0,0) size 210x60 contains 1 chunk(s)
     34          RenderSVGInlineText {#text} at (0,-48) size 210x60
     35            chunk 1 text run 1 at (0.00,0.00) startOffset 0 endOffset 5 width 209.71: "Ay\x{D6}@\x{E7}"
    3636    RenderSVGText {text} at (10,340) size 264x46 contains 1 chunk(s)
    3737      RenderSVGInlineText {#text} at (0,-36) size 264x46
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/fonts-elem-07-b-expected.checksum

    r27850 r29839  
    1 824f78aa5e369a55cb492952e2150734
     1979e7c3eb5f8f6fecf13f084192db268
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/fonts-elem-07-b-expected.txt

    r26599 r29839  
    3030        RenderSVGInlineText {#text} at (0,-17) size 74x22
    3131          chunk 1 text run 1 at (65.00,210.00) startOffset 0 endOffset 8 width 74.00: "SVG Font"
    32       RenderSVGContainer {g} at (165,166) size 210x69 [transform={m=((1.00,0.00)(0.00,1.00)) t=(165.00,220.00)}]
     32      RenderSVGContainer {g} at (165,172) size 210x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(165.00,220.00)}]
    3333        RenderPath {line} at (165,219.50) size 210x1 [stroke={[type=SOLID] [color=#888888]}] [fill={[type=SOLID] [color=#000000]}] [data="M0.00,0.00L210.00,0.00"]
    34         RenderSVGText {text} at (0,0) size 198x69 contains 1 chunk(s)
    35           RenderSVGInlineText {#text} at (0,-54) size 198x69
    36             chunk 1 text run 1 at (0.00,0.00) startOffset 0 endOffset 5 width 198.00: "Ay\x{D6}@\x{E7}"
     34        RenderSVGText {text} at (0,0) size 210x60 contains 1 chunk(s)
     35          RenderSVGInlineText {#text} at (0,-48) size 210x60
     36            chunk 1 text run 1 at (0.00,0.00) startOffset 0 endOffset 5 width 209.71: "Ay\x{D6}@\x{E7}"
    3737    RenderSVGText {text} at (10,340) size 264x46 contains 1 chunk(s)
    3838      RenderSVGInlineText {#text} at (0,-36) size 264x46
  • trunk/WebCore/ChangeLog

    r29838 r29839  
     12008-01-28  Nikolas Zimmermann  <zimmermann@kde.org>
     2
     3        Reviewed by Eric, Dan & Oliver.
     4
     5        Fixes: http://bugs.webkit.org/show_bug.cgi?id=16980
     6
     7        Support external SVG Fonts, by reusing the custom font handling logic.
     8        This enables us - as first engine - to render HTML pages using SVG Fonts.
     9
     10        Fixes fonts-elem-03-b.svg / fonts-elem-04-b.svg / fonts-elem-07-b.svg
     11        Add new testcase svg-fonts-in-html.html.
     12
     13        * css/CSSFontFaceSource.cpp:
     14        (WebCore::CSSFontFaceSource::getFontData):
     15        * css/CSSFontFaceSource.h:
     16        * css/CSSFontFaceSrcValue.cpp:
     17        (WebCore::CSSFontFaceSrcValue::isSVGFontFaceSrc):
     18        (WebCore::CSSFontFaceSrcValue::isSupportedFormat):
     19        * css/CSSFontFaceSrcValue.h:
     20        * css/CSSFontSelector.cpp:
     21        (WebCore::CSSFontSelector::addFontFaceRule):
     22        * loader/CachedFont.cpp:
     23        (WebCore::CachedFont::~CachedFont):
     24        (WebCore::CachedFont::ensureSVGFontData):
     25        (WebCore::CachedFont::extractFontFromSVGData):
     26        (WebCore::CachedFont::platformDataFromSVGData):
     27        * loader/CachedFont.h:
     28        * platform/graphics/Font.cpp:
     29        (WebCore::Font::offsetForPosition):
     30        * platform/graphics/Font.h:
     31        * svg/SVGFont.cpp:
     32        (WebCore::floatWidthOfSubStringUsingSVGFont):
     33        (WebCore::Font::drawTextUsingSVGFont):
     34        (WebCore::Font::offsetForPositionForTextUsingSVGFont):
     35        * svg/SVGFontFaceElement.cpp:
     36        (WebCore::SVGFontFaceElement::rebuildFontFace):
     37        * svg/SVGFontFaceElement.h:
     38        * svg/SVGFontFaceUriElement.cpp:
     39        (WebCore::SVGFontFaceUriElement::srcValue):
     40
    1412008-01-28  Dan Bernstein  <mitz@apple.com>
    242
  • trunk/WebCore/css/CSSFontFaceSource.cpp

    r29700 r29839  
    3737
    3838#if ENABLE(SVG_FONTS)
     39#include "FontCustomPlatformData.h"
     40#include "HTMLNames.h"
    3941#include "SVGFontData.h"
    40 #include "FontCustomPlatformData.h"
     42#include "SVGFontElement.h"
     43#include "SVGURIReference.h"
    4144#endif
    4245
     
    114117    // If we are still loading, then we let the system pick a font.
    115118    if (isLoaded()) {
     119        if (m_font) {
    116120#if ENABLE(SVG_FONTS)
    117         if (m_svgFontFaceElement)
    118             fontData.set(new SimpleFontData(FontPlatformData(fontDescription.computedPixelSize(), syntheticBold, syntheticItalic),
    119                                             true, false, new SVGFontData(m_svgFontFaceElement.get())));
    120 #endif
    121 
    122         if (!fontData) {
    123             ASSERT(m_font);
    124 
    125             // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef.
    126             if (!m_font->ensureCustomFontData())
     121            // For SVG fonts parse the external SVG document, and extract the <font> element.
     122            if (!m_font->ensureSVGFontData())
    127123                return 0;
    128124
    129             fontData.set(new SimpleFontData(m_font->platformDataFromCustomData(fontDescription.computedPixelSize(), syntheticBold, syntheticItalic), true, false));
     125            if (!m_externalSVGFontElement)
     126                m_externalSVGFontElement = m_font->getSVGFontById(SVGURIReference::getTarget(m_string));
     127
     128            if (m_externalSVGFontElement) {
     129                SVGFontFaceElement* fontFaceElement = 0;
     130
     131                // Select first <font-face> child
     132                for (Node* fontChild = m_externalSVGFontElement->firstChild(); fontChild; fontChild = fontChild->nextSibling()) {
     133                    if (fontChild->hasTagName(SVGNames::font_faceTag)) {
     134                        fontFaceElement = static_cast<SVGFontFaceElement*>(fontChild);
     135                        break;
     136                    }
     137                }
     138
     139                if (fontFaceElement) {
     140                    if (!m_svgFontFaceElement) {
     141                        // We're created using a CSS @font-face rule, that means we're not associated with a SVGFontFaceElement.
     142                        // Use the imported <font-face> tag as referencing font-face element for these cases.
     143                        m_svgFontFaceElement = fontFaceElement;
     144                    }
     145
     146                    SVGFontData* svgFontData = new SVGFontData(fontFaceElement);
     147                    fontData.set(new SimpleFontData(m_font->platformDataFromCustomData(fontDescription.computedPixelSize(), syntheticBold, syntheticItalic), true, false, svgFontData));
     148                }
     149            } else
     150#endif
     151            {
     152                // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef.
     153                if (!m_font->ensureCustomFontData())
     154                    return 0;
     155
     156                fontData.set(new SimpleFontData(m_font->platformDataFromCustomData(fontDescription.computedPixelSize(), syntheticBold, syntheticItalic), true, false));
     157            }
     158        } else {
     159#if ENABLE(SVG_FONTS)
     160            // In-Document SVG Fonts
     161            if (m_svgFontFaceElement) {
     162                SVGFontData* svgFontData = new SVGFontData(m_svgFontFaceElement.get());
     163                fontData.set(new SimpleFontData(FontPlatformData(fontDescription.computedPixelSize(), syntheticBold, syntheticItalic), true, false, svgFontData));
     164            }
     165#endif
    130166        }
    131167    } else {
    132168        // Kick off the load now.
    133169        m_font->beginLoadIfNeeded(fontSelector->docLoader());
    134 
    135170        FontPlatformData* tempData = FontCache::getCachedFontPlatformData(fontDescription, m_string);
    136171        if (!tempData)
  • trunk/WebCore/css/CSSFontFaceSource.h

    r29703 r29839  
    7474#if ENABLE(SVG_FONTS)
    7575    RefPtr<SVGFontFaceElement> m_svgFontFaceElement;
     76    RefPtr<SVGFontElement> m_externalSVGFontElement;
    7677#endif
    7778};
  • trunk/WebCore/css/CSSFontFaceSrcValue.cpp

    r29663 r29839  
    2929namespace WebCore {
    3030
     31#if ENABLE(SVG_FONTS)
     32bool CSSFontFaceSrcValue::isSVGFontFaceSrc() const
     33{
     34    return equalIgnoringCase(m_format, "svg");
     35}
     36#endif
     37
    3138bool CSSFontFaceSrcValue::isSupportedFormat() const
    3239{
     
    3946        return true;
    4047    }
    41    
    42     return equalIgnoringCase(m_format, "truetype") || equalIgnoringCase(m_format, "opentype");
     48
     49    return equalIgnoringCase(m_format, "truetype") || equalIgnoringCase(m_format, "opentype")
     50#if ENABLE(SVG_FONTS)
     51           || isSVGFontFaceSrc()
     52#endif
     53           ;
    4354}
    4455
  • trunk/WebCore/css/CSSFontFaceSrcValue.h

    r29703 r29839  
    5252
    5353#if ENABLE(SVG_FONTS)
     54    bool isSVGFontFaceSrc() const;
     55
    5456    SVGFontFaceElement* svgFontFaceElement() const { return m_svgFontFaceElement.get(); }
    5557    void setSVGFontFaceElement(SVGFontFaceElement* element) { m_svgFontFaceElement = element; }
  • trunk/WebCore/css/CSSFontSelector.cpp

    r29704 r29839  
    11/*
    22 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
    3  *           (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
     3 *           (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    141141
    142142#if ENABLE(SVG_FONTS)
    143     bool foundInDocumentSVGFont = false;
     143    bool foundSVGFont = false;
    144144#endif
    145145
     
    148148        CSSFontFaceSrcValue* item = static_cast<CSSFontFaceSrcValue*>(srcList->item(i));
    149149        CSSFontFaceSource* source = 0;
     150
     151#if ENABLE(SVG_FONTS)
     152        foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement();
     153#endif
    150154
    151155        if (!item->isLocal()) {
     
    158162            String family = item->resource();
    159163
    160 #if ENABLE(SVG_FONTS)
    161             foundInDocumentSVGFont = item->svgFontFaceElement() != 0;
    162 #endif
    163 
    164164            // Test the validity of the local font now.  We don't want to include this font if it does not exist
    165165            // on the system.  If it *does* exist on the system, then we don't need to look any further.
    166166            if (FontCache::fontExists(fontDescription, family)
    167 #if ENABLE(SVG_FONTS)   
    168                 || foundInDocumentSVGFont
     167#if ENABLE(SVG_FONTS)
     168                || foundSVGFont
    169169#endif
    170170               ) {
    171171                source = new CSSFontFaceSource(family);
    172 #if ENABLE(SVG_FONTS)
    173                 source->setSVGFontFaceElement(item->svgFontFaceElement());
    174 #endif
    175172                foundLocal = true;
    176173            }
     
    180177            fontFace = new CSSFontFace();
    181178
    182         if (source)
     179        if (source) {
     180#if ENABLE(SVG_FONTS)
     181            source->setSVGFontFaceElement(item->svgFontFaceElement());
     182#endif
    183183            fontFace->addSource(source);
     184        }
    184185
    185186        // We can just break if we see a local font that is valid.
     
    233234        // SVG allows several <font> elements with the same font-family, differing only
    234235        // in ie. font-variant. Be sure to pick up the right one - in getFontData below.
    235         if (foundInDocumentSVGFont && fontDescription.smallCaps())
     236        if (foundSVGFont && fontDescription.smallCaps())
    236237            familyName += "-webkit-svg-small-caps";
    237238#endif
     239
    238240        String hash = hashForFont(familyName.lower(), fontDescription.bold(), fontDescription.italic());
    239241        CSSSegmentedFontFace* segmentedFontFace = m_fonts.get(hash).get();
  • trunk/WebCore/loader/CachedFont.cpp

    r29781 r29839  
    3030#include "CachedResourceClient.h"
    3131#include "CachedResourceClientWalker.h"
     32#include "DOMImplementation.h"
    3233#include "FontPlatformData.h"
    3334#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK)
     
    3738#include "loader.h"
    3839#include <wtf/Vector.h>
     40
     41#if ENABLE(SVG_FONTS)
     42#include "HTMLNames.h"
     43#include "NodeList.h"
     44#include "SVGElement.h"
     45#include "SVGFontElement.h"
     46#include "SVGGElement.h"
     47#endif
    3948
    4049namespace WebCore {
     
    94103}
    95104
    96 FontPlatformData CachedFont::platformDataFromCustomData(int size, bool bold, bool italic)
     105FontPlatformData CachedFont::platformDataFromCustomData(float size, bool bold, bool italic)
    97106{
     107#if ENABLE(SVG_FONTS)
     108    if (m_externalSVGDocument)
     109        return FontPlatformData(size, bold, italic);
     110#endif
    98111#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK)
    99112    ASSERT(m_fontData);
    100     return m_fontData->fontPlatformData(size, bold, italic);
     113    return m_fontData->fontPlatformData(static_cast<int>(size), bold, italic);
    101114#else
    102115    return FontPlatformData();
    103116#endif
    104117}
     118
     119#if ENABLE(SVG_FONTS)
     120bool CachedFont::ensureSVGFontData()
     121{
     122    if (!m_externalSVGDocument && !m_errorOccurred && !m_loading && m_data) {
     123        m_externalSVGDocument = new SVGDocument(DOMImplementation::instance(), 0);
     124        m_externalSVGDocument->open();
     125
     126        TextResourceDecoder decoder("application/xml");
     127        m_externalSVGDocument->write(decoder.decode(m_data->data(), m_data->size()));
     128
     129        m_externalSVGDocument->finishParsing();
     130        m_externalSVGDocument->close();
     131    }
     132
     133    return m_externalSVGDocument;
     134}
     135
     136SVGFontElement* CachedFont::getSVGFontById(const String& fontName) const
     137{
     138    RefPtr<NodeList> list = m_externalSVGDocument->getElementsByTagName(SVGNames::fontTag.localName());
     139    if (!list)
     140        return 0;
     141
     142    unsigned fonts = list->length();
     143    for (unsigned i = 0; i < fonts; ++i) {
     144        Node* node = list->item(i);
     145        ASSERT(node);
     146
     147        if (static_cast<Element*>(node)->getAttribute(HTMLNames::idAttr) != fontName)
     148            continue;
     149
     150        ASSERT(node->hasTagName(SVGNames::fontTag));
     151        return static_cast<SVGFontElement*>(node);
     152    }
     153
     154    return 0;
     155}
     156#endif
    105157
    106158void CachedFont::allReferencesRemoved()
  • trunk/WebCore/loader/CachedFont.h

    r29663 r29839  
    3030#include <wtf/Vector.h>
    3131
     32#if ENABLE(SVG_FONTS)
     33#include "SVGElement.h"
     34#include "SVGDocument.h"
     35#endif
     36
    3237namespace WebCore {
    3338
     
    3641class FontCustomPlatformData;
    3742class FontPlatformData;
     43class SVGFontElement;
    3844
    3945class CachedFont : public CachedResource {
     
    5359
    5460    void beginLoadIfNeeded(DocLoader* dl);
     61
    5562    bool ensureCustomFontData();
     63    FontPlatformData platformDataFromCustomData(float size, bool bold, bool italic);
    5664
    57     FontPlatformData platformDataFromCustomData(int size, bool bold, bool italic);
     65#if ENABLE(SVG_FONTS)
     66    bool ensureSVGFontData();
     67    SVGFontElement* getSVGFontById(const String&) const;
     68#endif
    5869
    5970private:
    6071    FontCustomPlatformData* m_fontData;
    6172    bool m_loadInitiated;
     73
     74#if ENABLE(SVG_FONTS)
     75    RefPtr<SVGDocument> m_externalSVGDocument;
     76#endif
    6277
    6378    friend class Cache;
  • trunk/WebCore/platform/graphics/Font.cpp

    r29700 r29839  
    742742int Font::offsetForPosition(const TextRun& run, int x, bool includePartialGlyphs) const
    743743{
     744#if ENABLE(SVG_FONTS)
     745    if (primaryFont()->isSVGFont())
     746        return offsetForPositionForTextUsingSVGFont(run, x, includePartialGlyphs);
     747#endif
     748
    744749    if (canUseGlyphCache(run))
    745750        return offsetForPositionForSimpleText(run, x, includePartialGlyphs);
  • trunk/WebCore/platform/graphics/Font.h

    r29712 r29839  
    231231    float floatWidthUsingSVGFont(const TextRun&) const;
    232232    FloatRect selectionRectForTextUsingSVGFont(const TextRun&, const IntPoint&, int h, int from, int to) const;
     233    int offsetForPositionForTextUsingSVGFont(const TextRun&, int position, bool includePartialGlyphs) const;
    233234#endif
    234235    void drawGlyphs(GraphicsContext*, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
  • trunk/WebCore/svg/SVGFont.cpp

    r29838 r29839  
    3434#include "SVGMissingGlyphElement.h"
    3535#include "SVGPaintServer.h"
     36#include "SVGPaintServerSolid.h"
    3637#include "XMLNames.h"
    3738
     
    367368        data.length = 0.0f;
    368369
     370        String language;
     371        bool isVerticalText = false; // Holds true for HTML text
     372
     373        // TODO: language matching & svg glyphs should be possible for HTML text, too.
    369374        if (RenderObject* renderObject = run.referencingRenderObject()) {
    370             bool isVerticalText = isVerticalWritingMode(renderObject->style()->svgStyle());
    371 
    372             String language;
     375            isVerticalText = isVerticalWritingMode(renderObject->style()->svgStyle());
     376
    373377            if (SVGElement* element = static_cast<SVGElement*>(renderObject->element()))
    374378                language = element->getAttribute(XMLNames::langAttr);
    375 
    376             SVGTextRunWalker<SVGTextRunWalkerMeasuredLengthData> runWalker(fontData, fontElement, data, floatWidthUsingSVGFontCallback, floatWidthMissingGlyphCallback);
    377             runWalker.walk(run, isVerticalText, language, 0, run.length());
    378         }
    379 
     379        }
     380
     381        SVGTextRunWalker<SVGTextRunWalkerMeasuredLengthData> runWalker(fontData, fontElement, data, floatWidthUsingSVGFontCallback, floatWidthMissingGlyphCallback);
     382        runWalker.walk(run, isVerticalText, language, 0, run.length());
    380383        return data.length;
    381384    }
     
    471474
    472475        SVGTextRunWalkerDrawTextData data;
    473 
     476        data.currentPoint = point;
     477        data.scale = convertEmUnitToPixel(size(), fontFaceElement->unitsPerEm(), 1.0f);
     478
     479        // Required to be valid for SVG text only.
    474480        data.renderObject = run.referencingRenderObject();
    475         ASSERT(data.renderObject);
    476 
    477481        data.activePaintServer = run.activePaintServer();
     482
     483        // If renderObject is not set, we're dealing for HTML text rendered using SVG Fonts.
     484        if (!data.renderObject) {
     485            ASSERT(!data.activePaintServer);
     486
     487            // TODO: We're only supporting simple filled HTML text so far.
     488            SVGPaintServerSolid* solidPaintServer = SVGPaintServer::sharedSolidPaintServer();
     489            solidPaintServer->setColor(context->fillColor());
     490
     491            data.activePaintServer = solidPaintServer;
     492        }
     493
    478494        ASSERT(data.activePaintServer);
    479495
    480         data.scale = convertEmUnitToPixel(size(), fontFaceElement->unitsPerEm(), 1.0f);
    481         data.isVerticalText = isVerticalWritingMode(data.renderObject->style()->svgStyle());   
     496        data.isVerticalText = false;
    482497        data.xStartOffset = floatWidthOfSubStringUsingSVGFont(this, run, run.rtl() ? to : 0, run.rtl() ? run.length() : from);
    483         data.currentPoint = point;
    484498        data.glyphOrigin = FloatPoint();
    485499        data.context = context;
    486500
    487501        String language;
    488         if (SVGElement* element = static_cast<SVGElement*>(data.renderObject->element()))
    489             language = element->getAttribute(XMLNames::langAttr);
    490 
     502
     503        // TODO: language matching & svg glyphs should be possible for HTML text, too.
     504        if (data.renderObject) {   
     505            data.isVerticalText = isVerticalWritingMode(data.renderObject->style()->svgStyle());   
     506
     507            if (SVGElement* element = static_cast<SVGElement*>(data.renderObject->element()))
     508                language = element->getAttribute(XMLNames::langAttr);
     509        }
     510       
    491511        if (!data.isVerticalText) {
    492512            data.glyphOrigin.setX(fontData->horizontalOriginX() * data.scale);
     
    505525}
    506526
     527int Font::offsetForPositionForTextUsingSVGFont(const TextRun&, int position, bool includePartialGlyphs) const
     528{
     529    // TODO: Fix text selection when HTML text is drawn using a SVG Font
     530    // We need to integrate the SVG text selection code in the offsetForPosition() framework.
     531    // This will also fix a major issue, that SVG Text code can't select arabic strings properly.
     532    return 0;
     533}
     534
    507535}
    508536
  • trunk/WebCore/svg/SVGFontFaceElement.cpp

    r29805 r29839  
    304304        return;
    305305
    306     // Special handling for local SVG fonts (those which have a <font> parent, and are only used within the document)
    307     if (parentNode() && parentNode()->hasTagName(fontTag)) {
    308         RefPtr<CSSValueList> list = new CSSValueList;
    309 
    310         RefPtr<CSSFontFaceSrcValue> src = new CSSFontFaceSrcValue(fontFamily(), true /* isLocal */);
    311         src->setSVGFontFaceElement(this);
    312         list->append(src);
    313 
    314         CSSProperty srcProperty(CSS_PROP_SRC, list);
    315         const CSSProperty* srcPropertyRef = &srcProperty;
    316         m_styleDeclaration->addParsedProperties(&srcPropertyRef, 1);
    317 
    318         m_fontElement = static_cast<SVGFontElement*>(parentNode());
    319         document()->updateStyleSelector();
    320         return;
    321     }
    322 
    323     // TODO: External SVG fonts support - re use existing "custom font" handling logic.
    324 
    325306    // we currently ignore all but the first src element, alternatively we could concat them
    326307    SVGFontFaceSrcElement* srcElement = 0;
     
    340321#endif
    341322
    342     if (srcElement) {
    343         // This is the only class (other than CSSParser) to create CSSValue objects and set them on the CSSStyleDeclaration manually
    344         // we use the addParsedProperties method, and fake having an array of CSSProperty pointers.
    345         CSSProperty srcProperty(CSS_PROP_SRC, srcElement->srcValue());
    346         const CSSProperty* srcPropertyRef = &srcProperty;
    347         m_styleDeclaration->addParsedProperties(&srcPropertyRef, 1);
     323    bool describesParentFont = parentNode()->hasTagName(fontTag);
     324    RefPtr<CSSValueList> list;
     325
     326    if (describesParentFont) {
     327        m_fontElement = static_cast<SVGFontElement*>(parentNode());
     328
     329        list = new CSSValueList;
     330        list->append(new CSSFontFaceSrcValue(fontFamily(), true));
     331    } else if (srcElement)
     332        list = srcElement->srcValue();
     333
     334    if (!list)
     335        return;
     336
     337    // Parse in-memory CSS rules
     338    CSSProperty srcProperty(CSS_PROP_SRC, list);
     339    const CSSProperty* srcPropertyRef = &srcProperty;
     340    m_styleDeclaration->addParsedProperties(&srcPropertyRef, 1);
     341
     342    if (describesParentFont) {   
     343        // Traverse parsed CSS values and associate CSSFontFaceSrcValue elements with ourselves.
     344        RefPtr<CSSValue> src = m_styleDeclaration->getPropertyCSSValue(CSS_PROP_SRC);
     345        CSSValueList* srcList = static_cast<CSSValueList*>(src.get());
     346
     347        unsigned srcLength = srcList ? srcList->length() : 0;
     348        for (unsigned i = 0; i < srcLength; i++) {
     349            if (CSSFontFaceSrcValue* item = static_cast<CSSFontFaceSrcValue*>(srcList->item(i)))
     350                item->setSVGFontFaceElement(this);
     351        }
    348352    }
    349353
  • trunk/WebCore/svg/SVGFontFaceUriElement.cpp

    r29663 r29839  
    4040{
    4141    RefPtr<CSSFontFaceSrcValue> src = new CSSFontFaceSrcValue(getAttribute(XLinkNames::hrefAttr), false);
    42     src->setFormat(getAttribute(formatAttr));
     42    AtomicString value(getAttribute(formatAttr));
     43    src->setFormat(value.isEmpty() ? "svg" : value); // Default format
    4344    return src.release();
    4445}
Note: See TracChangeset for help on using the changeset viewer.