Chromium Code Reviews| Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| index 8456aba1db2b4de549857a809bf166dec4e1618a..0f172667fb46aa460c714621f9ab459c02280fd5 100644 |
| --- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| +++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| @@ -2065,6 +2065,17 @@ PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text |
| return metrics.release(); |
| } |
| +static inline bool isSpaceCharacters(UChar c) |
| +{ |
| + // According to specification all space characters should be replaced with 0x0020 space character. |
| + // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-preparation-algorithm |
| + // The space characters according to specification are : U+0020, U+0009, U+000A, U+000C, and U+000D. |
| + // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#space-character |
| + // This function returns true for 0x000B also, so that this is backward compatible. |
| + // Otherwise, the test LayoutTests/canvas/philip/tests/2d.text.draw.space.collapse.space.html will fail |
| + return c == 0x0009 || c == 0x000A || c == 0x000B || c == 0x000C || c == 0x000D; |
| +} |
| + |
| static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPtr matchFunction, const String& replacement) |
| { |
| const size_t replacementLength = replacement.length(); |
| @@ -2111,7 +2122,7 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo |
| const FontMetrics& fontMetrics = font.fontMetrics(); |
| // According to spec, all the space characters must be replaced with U+0020 SPACE characters. |
| String normalizedText = text; |
| - replaceCharacterInString(normalizedText, isSpaceOrNewline, " "); |
| + replaceCharacterInString(normalizedText, isSpaceCharacters, " "); |
|
Justin Novosad
2014/05/20 18:29:50
What exactly is wrong with isSpaceOrNewline? Why a
|
| // FIXME: Need to turn off font smoothing. |