Title: [177637] trunk/Source/WebCore
Revision
177637
Author
[email protected]
Date
2014-12-22 11:14:58 -0800 (Mon, 22 Dec 2014)

Log Message

Generic font code should not know about SVG font missing glyph
https://bugs.webkit.org/show_bug.cgi?id=139864

Reviewed by Andreas Kling and Myles Maxfield.

The defined missing glyph is an SVG font concept and should be handled in SVG code.

* platform/graphics/FontGlyphs.cpp:
(WebCore::FontGlyphs::glyphDataForSystemFallback):
(WebCore::FontGlyphs::glyphDataForVariant):

    Return null glyph instead of the missing glyph (the missing glyph was already a null glyph in all non-svg-font cases).
    Use early return style.

* platform/graphics/FontGlyphs.h:
* platform/graphics/SegmentedFontData.cpp:
* platform/graphics/SimpleFontData.cpp:
(WebCore::SimpleFontData::platformGlyphInit):
* platform/graphics/SimpleFontData.h:

    Remove the missingGlyph member.

* platform/graphics/WidthIterator.cpp:
(WebCore::WidthIterator::advanceInternal):

    Explicitly skip over null glyphs. Before they had non-null fontData and would get skipped implicitly.

* platform/graphics/mac/SimpleFontDataMac.mm:
* rendering/svg/SVGTextRunRenderingContext.cpp:
(WebCore::missingGlyphForFont):

    Get the missing glyph from the SVG font element.

(WebCore::SVGTextRunRenderingContext::glyphDataForCharacter):

    Return the missing glyph if the normal lookup didn't produce results.

* svg/SVGFontData.cpp:
(WebCore::SVGFontData::initializeFontData):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (177636 => 177637)


--- trunk/Source/WebCore/ChangeLog	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/ChangeLog	2014-12-22 19:14:58 UTC (rev 177637)
@@ -1,3 +1,45 @@
+2014-12-22  Antti Koivisto  <[email protected]>
+
+        Generic font code should not know about SVG font missing glyph
+        https://bugs.webkit.org/show_bug.cgi?id=139864
+
+        Reviewed by Andreas Kling and Myles Maxfield.
+
+        The defined missing glyph is an SVG font concept and should be handled in SVG code.
+
+        * platform/graphics/FontGlyphs.cpp:
+        (WebCore::FontGlyphs::glyphDataForSystemFallback):
+        (WebCore::FontGlyphs::glyphDataForVariant):
+
+            Return null glyph instead of the missing glyph (the missing glyph was already a null glyph in all non-svg-font cases).
+            Use early return style.
+
+        * platform/graphics/FontGlyphs.h:
+        * platform/graphics/SegmentedFontData.cpp:
+        * platform/graphics/SimpleFontData.cpp:
+        (WebCore::SimpleFontData::platformGlyphInit):
+        * platform/graphics/SimpleFontData.h:
+
+            Remove the missingGlyph member.
+
+        * platform/graphics/WidthIterator.cpp:
+        (WebCore::WidthIterator::advanceInternal):
+
+            Explicitly skip over null glyphs. Before they had non-null fontData and would get skipped implicitly.
+
+        * platform/graphics/mac/SimpleFontDataMac.mm:
+        * rendering/svg/SVGTextRunRenderingContext.cpp:
+        (WebCore::missingGlyphForFont):
+
+            Get the missing glyph from the SVG font element.
+
+        (WebCore::SVGTextRunRenderingContext::glyphDataForCharacter):
+
+            Return the missing glyph if the normal lookup didn't produce results.
+
+        * svg/SVGFontData.cpp:
+        (WebCore::SVGFontData::initializeFontData):
+
 2014-12-22  Chris Dumez  <[email protected]>
 
         Move "Auto" CSS properties to the new StyleBuilder

Modified: trunk/Source/WebCore/platform/graphics/FontGlyphs.cpp (177636 => 177637)


--- trunk/Source/WebCore/platform/graphics/FontGlyphs.cpp	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/platform/graphics/FontGlyphs.cpp	2014-12-22 19:14:58 UTC (rev 177637)
@@ -31,6 +31,7 @@
 
 #include "Font.h"
 #include "FontCache.h"
+#include "GlyphPageTreeNode.h"
 #include "SegmentedFontData.h"
 
 namespace WebCore {
@@ -277,32 +278,26 @@
     }
     const SimpleFontData* originalFontData = primaryFontData(description)->fontDataForCharacter(c);
     RefPtr<SimpleFontData> characterFontData = fontCache().systemFallbackForCharacters(description, originalFontData, m_isForPlatformFont, codeUnits, codeUnitsLength);
-    if (characterFontData) {
-        if (characterFontData->platformData().orientation() == Vertical && !characterFontData->hasVerticalGlyphs() && Font::isCJKIdeographOrSymbol(c))
-            variant = BrokenIdeographVariant;
-        if (variant != NormalVariant)
-            characterFontData = characterFontData->variantFontData(description, variant);
+    if (!characterFontData)
+        return GlyphData();
+
+    if (characterFontData->platformData().orientation() == Vertical && !characterFontData->hasVerticalGlyphs() && Font::isCJKIdeographOrSymbol(c))
+        variant = BrokenIdeographVariant;
+    if (variant != NormalVariant) {
+        characterFontData = characterFontData->variantFontData(description, variant);
+        ASSERT(characterFontData);
     }
-    if (characterFontData) {
-        // Got the fallback glyph and font.
-        GlyphPage* fallbackPage = GlyphPageTreeNode::getRootChild(characterFontData.get(), pageNumber)->page();
-        GlyphData data = "" && fallbackPage->fontDataForCharacter(c) ? fallbackPage->glyphDataForCharacter(c) : characterFontData->missingGlyphData();
-        // Cache it so we don't have to do system fallback again next time.
-        if (variant == NormalVariant) {
-            node.page()->setGlyphDataForCharacter(c, data.glyph, data.fontData);
-            data.fontData->setMaxGlyphPageTreeLevel(std::max(data.fontData->maxGlyphPageTreeLevel(), node.level()));
-            if (!Font::isCJKIdeographOrSymbol(c) && data.fontData->platformData().orientation() != Horizontal && !data.fontData->isTextOrientationFallback())
-                return glyphDataForNonCJKCharacterWithGlyphOrientation(c, description.nonCJKGlyphOrientation(), data, pageNumber);
-        }
-        return data;
-    }
 
-    // Even system fallback can fail; use the missing glyph in that case.
-    // FIXME: It would be nicer to use the missing glyph from the last resort font instead.
-    GlyphData data = ""
-    if (variant == NormalVariant) {
+    GlyphData data;
+    if (GlyphPage* fallbackPage = GlyphPageTreeNode::getRootChild(characterFontData.get(), pageNumber)->page())
+        data = ""
+
+    // Cache it so we don't have to do system fallback again next time.
+    if (variant == NormalVariant && data.glyph) {
         node.page()->setGlyphDataForCharacter(c, data.glyph, data.fontData);
         data.fontData->setMaxGlyphPageTreeLevel(std::max(data.fontData->maxGlyphPageTreeLevel(), node.level()));
+        if (!Font::isCJKIdeographOrSymbol(c) && data.fontData->platformData().orientation() != Horizontal && !data.fontData->isTextOrientationFallback())
+            return glyphDataForNonCJKCharacterWithGlyphOrientation(c, description.nonCJKGlyphOrientation(), data, pageNumber);
     }
     return data;
 }
@@ -321,15 +316,12 @@
 
                 GlyphPageTreeNode* variantNode = GlyphPageTreeNode::getRootChild(variantFontData.get(), pageNumber);
                 GlyphPage* variantPage = variantNode->page();
-                if (variantPage) {
-                    GlyphData data = ""
-                    if (data.fontData)
-                        return data;
-                }
+                if (variantPage)
+                    return variantPage->glyphDataForCharacter(c);
 
                 // Do not attempt system fallback off the variantFontData. This is the very unlikely case that
                 // a font has the lowercase character but the small caps font does not have its uppercase version.
-                return variantFontData->missingGlyphData();
+                return GlyphData();
             }
 
             if (node->isSystemFallback())

Modified: trunk/Source/WebCore/platform/graphics/FontGlyphs.h (177636 => 177637)


--- trunk/Source/WebCore/platform/graphics/FontGlyphs.h	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/platform/graphics/FontGlyphs.h	2014-12-22 19:14:58 UTC (rev 177637)
@@ -22,6 +22,7 @@
 #define FontGlyphs_h
 
 #include "FontSelector.h"
+#include "GlyphPage.h"
 #include "SimpleFontData.h"
 #include "WidthCache.h"
 #include <wtf/Forward.h>

Modified: trunk/Source/WebCore/platform/graphics/SegmentedFontData.cpp (177636 => 177637)


--- trunk/Source/WebCore/platform/graphics/SegmentedFontData.cpp	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/platform/graphics/SegmentedFontData.cpp	2014-12-22 19:14:58 UTC (rev 177637)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "SegmentedFontData.h"
 
+#include "GlyphPageTreeNode.h"
 #include "SimpleFontData.h"
 #include <wtf/Assertions.h>
 #include <wtf/text/WTFString.h>

Modified: trunk/Source/WebCore/platform/graphics/SimpleFontData.cpp (177636 => 177637)


--- trunk/Source/WebCore/platform/graphics/SimpleFontData.cpp	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/platform/graphics/SimpleFontData.cpp	2014-12-22 19:14:58 UTC (rev 177637)
@@ -35,6 +35,7 @@
 #endif
 #include "Font.h"
 #include "FontCache.h"
+#include "GlyphPageTreeNode.h"
 #include "OpenTypeMathData.h"
 #include <wtf/MathExtras.h>
 
@@ -124,8 +125,6 @@
         m_adjustedSpaceWidth = 0;
         determinePitch();
         m_zeroWidthSpaceGlyph = 0;
-        m_missingGlyphData.fontData = this;
-        m_missingGlyphData.glyph = 0;
         return;
     }
 
@@ -149,9 +148,6 @@
     // See <http://bugs.webkit.org/show_bug.cgi?id=13178> and SimpleFontData::isZeroWidthSpaceGlyph()
     if (m_zeroWidthSpaceGlyph == m_spaceGlyph)
         m_zeroWidthSpaceGlyph = 0;
-
-    m_missingGlyphData.fontData = this;
-    m_missingGlyphData.glyph = 0;
 }
 
 SimpleFontData::~SimpleFontData()

Modified: trunk/Source/WebCore/platform/graphics/SimpleFontData.h (177636 => 177637)


--- trunk/Source/WebCore/platform/graphics/SimpleFontData.h	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/platform/graphics/SimpleFontData.h	2014-12-22 19:14:58 UTC (rev 177637)
@@ -31,7 +31,6 @@
 #include "FloatRect.h"
 #include "GlyphBuffer.h"
 #include "GlyphMetricsMap.h"
-#include "GlyphPageTreeNode.h"
 #include "OpenTypeMathData.h"
 #if ENABLE(OPENTYPE_VERTICAL)
 #include "OpenTypeVerticalData.h"
@@ -60,8 +59,10 @@
 
 namespace WebCore {
 
+class GlyphPage;
 class FontDescription;
 class SharedBuffer;
+struct GlyphData;
 struct WidthIterator;
 
 enum FontDataVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMarkVariant, BrokenIdeographVariant };
@@ -180,9 +181,6 @@
     virtual bool isLoading() const override { return m_isLoading; }
     virtual bool isSegmented() const override;
 
-    const GlyphData& missingGlyphData() const { return m_missingGlyphData; }
-    void setMissingGlyphData(const GlyphData& glyphData) { m_missingGlyphData = glyphData; }
-
 #ifndef NDEBUG
     virtual String description() const override;
 #endif
@@ -272,8 +270,6 @@
 
     Glyph m_zeroWidthSpaceGlyph;
 
-    GlyphData m_missingGlyphData;
-
     struct DerivedFontData {
         explicit DerivedFontData(bool custom)
             : forCustomFont(custom)

Modified: trunk/Source/WebCore/platform/graphics/WidthIterator.cpp (177636 => 177637)


--- trunk/Source/WebCore/platform/graphics/WidthIterator.cpp	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/platform/graphics/WidthIterator.cpp	2014-12-22 19:14:58 UTC (rev 177637)
@@ -179,8 +179,11 @@
         int currentCharacter = textIterator.currentCharacter();
         const GlyphData& glyphData = glyphDataForCharacter(character, rtl, currentCharacter, advanceLength, normalizedSpacesStringCache);
         Glyph glyph = glyphData.glyph;
+        if (!glyph) {
+            textIterator.advance(advanceLength);
+            continue;
+        }
         const SimpleFontData* fontData = glyphData.fontData;
-
         ASSERT(fontData);
 
         // Now that we have a glyph and font data, get its width.

Modified: trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm (177636 => 177637)


--- trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm	2014-12-22 19:14:58 UTC (rev 177637)
@@ -35,6 +35,7 @@
 #import "Font.h"
 #import "FontCache.h"
 #import "FontDescription.h"
+#import "GlyphPageTreeNode.h"
 #import "SharedBuffer.h"
 #import "WebCoreSystemInterface.h"
 #if USE(APPKIT)

Modified: trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp (177636 => 177637)


--- trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp	2014-12-22 19:14:58 UTC (rev 177637)
@@ -290,36 +290,40 @@
     }
 }
 
+static GlyphData missingGlyphForFont(const Font& font)
+{
+    const SimpleFontData* primaryFontData = font.primaryFont();
+    if (!primaryFontData->isSVGFont())
+        return GlyphData();
+    SVGFontElement* fontElement;
+    SVGFontFaceElement* fontFaceElement;
+    svgFontAndFontFaceElementForFontData(primaryFontData, fontFaceElement, fontElement);
+    return GlyphData(fontElement->missingGlyph(), primaryFontData);
+}
+
 GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const Font& font, WidthIterator& iterator, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength, String& normalizedSpacesStringCache)
 {
-    const SimpleFontData* primaryFont = font.primaryFont();
-    ASSERT(primaryFont);
-
     GlyphData glyphData = font.glyphDataForCharacter(character, mirror, AutoVariant);
+    if (!glyphData.glyph)
+        return missingGlyphForFont(font);
 
-    // Check if we have the missing glyph data, in which case we can just return.
-    GlyphData missingGlyphData = primaryFont->missingGlyphData();
-    if (glyphData.glyph == missingGlyphData.glyph && glyphData.fontData == missingGlyphData.fontData) {
-        ASSERT(glyphData.fontData);
-        return glyphData;
-    }
+    ASSERT(glyphData.fontData);
 
     // Characters enclosed by an <altGlyph> element, may not be registered in the GlyphPage.
-    if (glyphData.fontData && !glyphData.fontData->isSVGFont()) {
+    if (!glyphData.fontData->isSVGFont()) {
         auto& elementRenderer = is<RenderElement>(renderer()) ? downcast<RenderElement>(renderer()) : *renderer().parent();
         if (Element* parentRendererElement = elementRenderer.element()) {
             if (is<SVGAltGlyphElement>(*parentRendererElement))
-                glyphData.fontData = primaryFont;
+                glyphData.fontData = font.primaryFont();
         }
     }
 
-    const SimpleFontData* fontData = glyphData.fontData;
-    if (!fontData || !fontData->isSVGFont())
+    if (!glyphData.fontData->isSVGFont())
         return glyphData;
 
     SVGFontElement* fontElement = nullptr;
     SVGFontFaceElement* fontFaceElement = nullptr;
-    const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(fontData, fontFaceElement, fontElement);
+    const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(glyphData.fontData, fontFaceElement, fontElement);
     if (!svgFontData)
         return glyphData;
 
@@ -329,6 +333,8 @@
     // arabic-form/orientation/... may not match, we have to apply SVG Glyph selection to discover that.
     if (svgFontData->applySVGGlyphSelection(iterator, glyphData, mirror, currentCharacter, advanceLength, normalizedSpacesStringCache))
         return glyphData;
+
+    GlyphData missingGlyphData = missingGlyphForFont(font);
     if (missingGlyphData.glyph)
         return missingGlyphData;
 

Modified: trunk/Source/WebCore/svg/SVGFontData.cpp (177636 => 177637)


--- trunk/Source/WebCore/svg/SVGFontData.cpp	2014-12-22 19:04:45 UTC (rev 177636)
+++ trunk/Source/WebCore/svg/SVGFontData.cpp	2014-12-22 19:14:58 UTC (rev 177637)
@@ -22,6 +22,7 @@
 #if ENABLE(SVG_FONTS)
 #include "SVGFontData.h"
 
+#include "GlyphPageTreeNode.h"
 #include "RenderElement.h"
 #include "SVGAltGlyphElement.h"
 #include "SVGFontElement.h"
@@ -63,13 +64,6 @@
     SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement();
     ASSERT(svgFontFaceElement);
 
-    SVGFontElement* svgFontElement = svgFontFaceElement->associatedFontElement();
-    ASSERT(svgFontElement);
-    GlyphData missingGlyphData;
-    missingGlyphData.fontData = fontData;
-    missingGlyphData.glyph = svgFontElement->missingGlyph();
-    fontData->setMissingGlyphData(missingGlyphData);
-
     fontData->setZeroWidthSpaceGlyph(0);
     fontData->determinePitch();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to