2010-12-28 Abhishek Arya <inferno@chromium.org>
authorinferno@chromium.org <inferno@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Dec 2010 19:18:36 +0000 (19:18 +0000)
committerinferno@chromium.org <inferno@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Dec 2010 19:18:36 +0000 (19:18 +0000)
        Reviewed by Kenneth Russell.

        Fix crash with invalid font in m_fontList by not drawing text when a custom font is in the
        process of loading.
        https://bugs.webkit.org/show_bug.cgi?id=51681

        Test: canvas/philip/tests/2d.text-custom-font-load-crash.html

        * html/canvas/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::drawTextInternal): bail out if a custom font is loading.
        * platform/graphics/Font.cpp:
        (WebCore::Font::operator==): Replace condition with new function loadingCustomFonts()
        (WebCore::Font::drawText): Replace condition with new function loadingCustomFonts()
        (WebCore::Font::drawEmphasisMarks): Replace condition with new function loadingCustomFonts()
        * platform/graphics/Font.h:
        (WebCore::Font::loadingCustomFonts): new function that returns if a custom font is loading.
2010-12-28  Abhishek Arya  <inferno@chromium.org>

        Reviewed by Kenneth Russell.

        Tests that we do not crash when drawing text during custom font load.
        https://bugs.webkit.org/show_bug.cgi?id=51681

        * canvas/philip/tests/2d.text-custom-font-load-crash-expected.txt: Added.
        * canvas/philip/tests/2d.text-custom-font-load-crash.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74716 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/canvas/philip/tests/2d.text-custom-font-load-crash-expected.txt [new file with mode: 0644]
LayoutTests/canvas/philip/tests/2d.text-custom-font-load-crash.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/canvas/CanvasRenderingContext2D.cpp
WebCore/platform/graphics/Font.cpp
WebCore/platform/graphics/Font.h

index 4a394c0..97076d7 100644 (file)
@@ -1,3 +1,13 @@
+2010-12-28  Abhishek Arya  <inferno@chromium.org>
+
+        Reviewed by Kenneth Russell.
+
+        Tests that we do not crash when drawing text during custom font load.
+        https://bugs.webkit.org/show_bug.cgi?id=51681
+
+        * canvas/philip/tests/2d.text-custom-font-load-crash-expected.txt: Added.
+        * canvas/philip/tests/2d.text-custom-font-load-crash.html: Added.
+
 2010-12-28  Andrey Kosyakov  <caseq@chromium.org>
 
         Reviewed by Pavel Feldman.
diff --git a/LayoutTests/canvas/philip/tests/2d.text-custom-font-load-crash-expected.txt b/LayoutTests/canvas/philip/tests/2d.text-custom-font-load-crash-expected.txt
new file mode 100644 (file)
index 0000000..1042c76
--- /dev/null
@@ -0,0 +1,2 @@
+Test passes if it does not crash.
+
diff --git a/LayoutTests/canvas/philip/tests/2d.text-custom-font-load-crash.html b/LayoutTests/canvas/philip/tests/2d.text-custom-font-load-crash.html
new file mode 100644 (file)
index 0000000..c24b0cb
--- /dev/null
@@ -0,0 +1,33 @@
+<!DOCTYPE html>\r
+<div>Test passes if it does not crash.</div>\r
+<script src="../tests.js"></script>\r
+<style>\r
+@font-face {\r
+font-family: CanvasTest; \r
+  src: url("does_not_exist.ttf");\r
+}\r
+</style>\r
+<applet>\r
+<canvas id="c">\r
+</applet>\r
+<ul id="d"></ul>\r
+<script>\r
+if (window.layoutTestController)\r
+    layoutTestController.dumpAsText();\r
+\r
+_addTest(function(canvas, ctx) {\r
+\r
+ctx.fillRect(0, 0, 100, 50);\r
+ctx.font = '1px CanvasTest';\r
+ctx.fillText('AA', 0, 50);\r
+deferTest();\r
+\r
+setTimeout(wrapFunction(function () {\r
+    ctx.fillText('AA', 0, 50);\r
+\r
+    if (window.layoutTestController)\r
+        layoutTestController.notifyDone();\r
+}), 500);\r
+\r
+});\r
+</script>\r
index f152806..716a242 100644 (file)
@@ -1,3 +1,22 @@
+2010-12-28  Abhishek Arya  <inferno@chromium.org>
+
+        Reviewed by Kenneth Russell.
+
+        Fix crash with invalid font in m_fontList by not drawing text when a custom font is in the
+        process of loading.
+        https://bugs.webkit.org/show_bug.cgi?id=51681
+
+        Test: canvas/philip/tests/2d.text-custom-font-load-crash.html
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::drawTextInternal): bail out if a custom font is loading.
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::operator==): Replace condition with new function loadingCustomFonts()
+        (WebCore::Font::drawText): Replace condition with new function loadingCustomFonts()
+        (WebCore::Font::drawEmphasisMarks): Replace condition with new function loadingCustomFonts()
+        * platform/graphics/Font.h:
+        (WebCore::Font::loadingCustomFonts): new function that returns if a custom font is loading.
+
 2010-12-28  Dimitri Glazkov  <dglazkov@chromium.org>
 
         Reviewed by Eric Seidel.
index d498538..f2b6147 100644 (file)
@@ -1760,6 +1760,10 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
         return;
 
     const Font& font = accessFont();
+    
+    // Don't draw anything while we are using custom fonts that are in the process of loading.
+    if (font.loadingCustomFonts())
+        return;
 
     // FIXME: Handle maxWidth.
     // FIXME: Need to turn off font smoothing.
index 8828a31..887e21d 100644 (file)
@@ -109,8 +109,7 @@ bool Font::operator==(const Font& other) const
 {
     // Our FontData don't have to be checked, since checking the font description will be fine.
     // FIXME: This does not work if the font was made with the FontPlatformData constructor.
-    if ((m_fontList && m_fontList->loadingCustomFonts()) ||
-        (other.m_fontList && other.m_fontList->loadingCustomFonts()))
+    if (loadingCustomFonts() || other.loadingCustomFonts())
         return false;
     
     FontSelector* first = m_fontList ? m_fontList->fontSelector() : 0;
@@ -138,7 +137,7 @@ void Font::update(PassRefPtr<FontSelector> fontSelector) const
 void Font::drawText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to) const
 {
     // Don't draw anything while we are using custom fonts that are in the process of loading.
-    if (m_fontList && m_fontList->loadingCustomFonts())
+    if (loadingCustomFonts())
         return;
     
     to = (to == -1 ? run.length() : to);
@@ -158,7 +157,7 @@ void Font::drawText(GraphicsContext* context, const TextRun& run, const FloatPoi
 
 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
 {
-    if (m_fontList && m_fontList->loadingCustomFonts())
+    if (loadingCustomFonts())
         return;
 
     if (to < 0)
index 4097f1e..ec3d220 100644 (file)
@@ -210,6 +210,11 @@ public:
     }
 
     FontSelector* fontSelector() const;
+    bool loadingCustomFonts() const
+    {
+        return m_fontList && m_fontList->loadingCustomFonts();
+    }
+
     static bool treatAsSpace(UChar c) { return c == ' ' || c == '\t' || c == '\n' || c == noBreakSpace; }
     static bool treatAsZeroWidthSpace(UChar c) { return c < 0x20 || (c >= 0x7F && c < 0xA0) || c == softHyphen || (c >= 0x200c && c <= 0x200f) || (c >= 0x202a && c <= 0x202e) || c == objectReplacementCharacter; }
     static bool canReceiveTextEmphasis(UChar32 c);