Changeset 135888 in webkit


Ignore:
Timestamp:
Nov 27, 2012, 11:25:54 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Canvas does not draw any text if the font is not fully loaded yet
https://bugs.webkit.org/show_bug.cgi?id=103392

Patch by Christophe Dumez <Christophe Dumez> on 2012-11-27
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Update CanvasRenderingContext2D::drawTextInternal() so that the
text is being drawn, even if custom fonts are still being loaded.
Without this, WebKit was not drawing any text on the canvas if
the needed font is custom and is not fully loaded yet. This seems
broken.

The new behavior is according to specification:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html

The specification says: "If a font is used before it is fully
loaded, or if the font style source object does not have that
font in scope at the time the font is to be used, then it must be
treated as if it was an unknown font, falling back to another as
described by the relevant CSS specifications."

Test: http/tests/canvas/canvas-slow-font-loading.html

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::drawTextInternal):

  • platform/graphics/Font.cpp:

(WebCore::Font::drawText): Add argument to specify the behavior
when custom fonts are not ready. By default, it will not draw
anything (same behavior as before). However, the Canvas code
can now request that a fallback font is used if the custom
font is not fully loaded yet.

  • platform/graphics/Font.h: #undef Complex if defined to avoid

conflicting with Complex value in CodePath enum. X11/X.h is
defining Complex to 0.

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContext::drawBidiText):

  • platform/graphics/GraphicsContext.h:

(WebCore):
(GraphicsContext):

LayoutTests:

Add canvas test to check that text is drawn using a fallback font
if the primary font is not fully loaded yet.

  • http/tests/canvas/canvas-slow-font-loading-expected.html: Added.
  • http/tests/canvas/canvas-slow-font-loading.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r135887 r135888  
     12012-11-27  Christophe Dumez  <christophe.dumez@intel.com>
     2
     3        Canvas does not draw any text if the font is not fully loaded yet
     4        https://bugs.webkit.org/show_bug.cgi?id=103392
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Add canvas test to check that text is drawn using a fallback font
     9        if the primary font is not fully loaded yet.
     10
     11        * http/tests/canvas/canvas-slow-font-loading-expected.html: Added.
     12        * http/tests/canvas/canvas-slow-font-loading.html: Added.
     13
    1142012-11-27  Yael Aharon  <yael.aharon@intel.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r135886 r135888  
     12012-11-27  Christophe Dumez  <christophe.dumez@intel.com>
     2
     3        Canvas does not draw any text if the font is not fully loaded yet
     4        https://bugs.webkit.org/show_bug.cgi?id=103392
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Update CanvasRenderingContext2D::drawTextInternal() so that the
     9        text is being drawn, even if custom fonts are still being loaded.
     10        Without this, WebKit was not drawing any text on the canvas if
     11        the needed font is custom and is not fully loaded yet. This seems
     12        broken.
     13
     14        The new behavior is according to specification:
     15        http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html
     16
     17        The specification says: "If a font is used before it is fully
     18        loaded, or if the font style source object does not have that
     19        font in scope at the time the font is to be used, then it must be
     20        treated as if it was an unknown font, falling back to another as
     21        described by the relevant CSS specifications."
     22
     23        Test: http/tests/canvas/canvas-slow-font-loading.html
     24
     25        * html/canvas/CanvasRenderingContext2D.cpp:
     26        (WebCore::CanvasRenderingContext2D::drawTextInternal):
     27        * platform/graphics/Font.cpp:
     28        (WebCore::Font::drawText): Add argument to specify the behavior
     29        when custom fonts are not ready. By default, it will not draw
     30        anything (same behavior as before). However, the Canvas code
     31        can now request that a fallback font is used if the custom
     32        font is not fully loaded yet.
     33        * platform/graphics/Font.h: #undef Complex if defined to avoid
     34        conflicting with Complex value in CodePath enum. X11/X.h is
     35        defining Complex to 0.
     36        * platform/graphics/GraphicsContext.cpp:
     37        (WebCore::GraphicsContext::drawBidiText):
     38        * platform/graphics/GraphicsContext.h:
     39        (WebCore):
     40        (GraphicsContext):
     41
    1422012-11-27  Dean Jackson  <dino@apple.com>
    243
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r135848 r135888  
    23072307            // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) still work.
    23082308            maskImageContext->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1));
    2309             maskImageContext->drawBidiText(font, textRun, FloatPoint(0, 0));
     2309            maskImageContext->drawBidiText(font, textRun, FloatPoint(0, 0), Font::UseFallbackIfFontNotReady);
    23102310        } else {
    23112311            maskImageContext->translate(-maskRect.x(), -maskRect.y());
    2312             maskImageContext->drawBidiText(font, textRun, location);
     2312            maskImageContext->drawBidiText(font, textRun, location, Font::UseFallbackIfFontNotReady);
    23132313        }
    23142314
     
    23342334        // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) still work.
    23352335        c->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1));
    2336         c->drawBidiText(font, textRun, FloatPoint(0, 0));
     2336        c->drawBidiText(font, textRun, FloatPoint(0, 0), Font::UseFallbackIfFontNotReady);
    23372337    } else
    2338         c->drawBidiText(font, textRun, location);
     2338        c->drawBidiText(font, textRun, location, Font::UseFallbackIfFontNotReady);
    23392339
    23402340    didDraw(textRect);
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r133921 r135888  
    157157}
    158158
    159 void Font::drawText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to) const
    160 {
    161     // Don't draw anything while we are using custom fonts that are in the process of loading.
    162     if (loadingCustomFonts())
     159void Font::drawText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to, CustomFontNotReadyAction customFontNotReadyAction) const
     160{
     161    // Don't draw anything while we are using custom fonts that are in the process of loading,
     162    // except if the 'force' argument is set to true (in which case it will use a fallback
     163    // font).
     164    if (loadingCustomFonts() && customFontNotReadyAction == DoNotPaintIfFontNotReady)
    163165        return;
    164166   
  • trunk/Source/WebCore/platform/graphics/Font.h

    r133534 r135888  
    4343#endif
    4444
     45// "X11/X.h" defines Complex to 0 and conflicts
     46// with Complex value in CodePath enum.
     47#ifdef Complex
     48#undef Complex
     49#endif
     50
    4551namespace WebCore {
    4652
     
    98104    void update(PassRefPtr<FontSelector>) const;
    99105
    100     void drawText(GraphicsContext*, const TextRun&, const FloatPoint&, int from = 0, int to = -1) const;
     106    enum CustomFontNotReadyAction { DoNotPaintIfFontNotReady, UseFallbackIfFontNotReady };
     107    void drawText(GraphicsContext*, const TextRun&, const FloatPoint&, int from = 0, int to = -1, CustomFontNotReadyAction = DoNotPaintIfFontNotReady) const;
    101108    void drawEmphasisMarks(GraphicsContext*, const TextRun&, const AtomicString& mark, const FloatPoint&, int from = 0, int to = -1) const;
    102109
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r134348 r135888  
    2929#include "BidiResolver.h"
    3030#include "BitmapImage.h"
    31 #include "Font.h"
    3231#include "Generator.h"
    3332#include "ImageBuffer.h"
     
    405404}
    406405
    407 void GraphicsContext::drawBidiText(const Font& font, const TextRun& run, const FloatPoint& point)
     406void GraphicsContext::drawBidiText(const Font& font, const TextRun& run, const FloatPoint& point, Font::CustomFontNotReadyAction customFontNotReadyAction)
    408407{
    409408    if (paintingDisabled())
     
    429428        subrun.setDirectionalOverride(bidiRun->dirOverride(false));
    430429
    431         font.drawText(this, subrun, currPoint);
     430        font.drawText(this, subrun, currPoint, 0, -1, customFontNotReadyAction);
    432431
    433432        bidiRun = bidiRun->next();
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r134348 r135888  
    3131#include "DashArray.h"
    3232#include "FloatRect.h"
     33#include "Font.h"
    3334#include "Gradient.h"
    3435#include "Image.h"
     
    115116    class AffineTransform;
    116117    class DrawingBuffer;
    117     class Font;
    118118    class Generator;
    119119#if !USE(SKIA)
     
    356356        void drawText(const Font&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
    357357        void drawEmphasisMarks(const Font&, const TextRun& , const AtomicString& mark, const FloatPoint&, int from = 0, int to = -1);
    358         void drawBidiText(const Font&, const TextRun&, const FloatPoint&);
     358        void drawBidiText(const Font&, const TextRun&, const FloatPoint&, Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady);
    359359        void drawHighlightForText(const Font&, const TextRun&, const FloatPoint&, int h, const Color& backgroundColor, ColorSpace, int from = 0, int to = -1);
    360360
Note: See TracChangeset for help on using the changeset viewer.