WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-108881-20130809183522.patch (text/plain), 9.42 KB, created by
Rashmi Shyamasundar
on 2013-08-09 05:59:53 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Rashmi Shyamasundar
Created:
2013-08-09 05:59:53 PDT
Size:
9.42 KB
patch
obsolete
>Subversion Revision: 153420 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 899ca78359fab66c2fa980e30243b3a76a6f2e91..3e55a1fc6fe6e3ddec1d4b2b6965886581314cc0 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,27 @@ >+2013-08-09 Rashmi Shyamasundar <rashmi.s2@samsung.com> >+ >+ Canvas fillText and measureText handle ideographic spaces differently >+ https://bugs.webkit.org/show_bug.cgi?id=108881 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ According to spec for text preparation algorithm >+ http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-preparation-algorithm >+ all the space characters mentioned in the spec >+ http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#space-character >+ should be replaced by U+0020 space character. >+ The canvas functions fillText and measureText should run the text preparation algorithm. >+ This patch modifies the canvas functions drawTextInternal and measureText to conform to the above spec. >+ >+ Tests: fast/canvas/canvas-fillText-ideographicSpace.html >+ fast/canvas/canvas-measureText-ideographicSpace.html >+ >+ * html/canvas/CanvasRenderingContext2D.cpp: >+ (WebCore::shouldSpaceBeReplaced): >+ (WebCore::replaceCharacterInString): >+ (WebCore::CanvasRenderingContext2D::measureText): >+ (WebCore::CanvasRenderingContext2D::drawTextInternal): >+ > 2013-07-29 Kwang Yul Seo <skyul@company100.net> > > [EFL] Improve string use in ErrorsEfl >diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp >old mode 100644 >new mode 100755 >index caae0ba2568e50e3f6b06ddb1cd5f9d62e29dfd3..4544293b3f84101b6ca8ddbe087618a9bbe800ad >--- a/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp >+++ b/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp >@@ -91,6 +91,12 @@ static bool isOriginClean(CachedImage* cachedImage, SecurityOrigin* securityOrig > return !securityOrigin->taintsCanvas(cachedImage->response().url()); > } > >+// Spec : http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#space-character >+static inline bool isHTMLSpace(UChar c) >+{ >+ return (c == 0x0009 || c == 0x000A || c == 0x000B || c == 0x000C || c == 0x000D); >+} >+ > class CanvasStrokeStyleApplier : public StrokeStyleApplier { > public: > CanvasStrokeStyleApplier(CanvasRenderingContext2D* canvasContext) >@@ -2101,19 +2107,33 @@ void CanvasRenderingContext2D::strokeText(const String& text, float x, float y, > drawTextInternal(text, x, y, false, maxWidth, true); > } > >+static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPtr matchFunction, const String& replacement) >+{ >+ const unsigned replacementLength = replacement.length(); >+ size_t index = 0; >+ while ((index = text.find(matchFunction, index)) != notFound) { >+ text.replace(index, 1, replacement); >+ index += replacementLength; >+ } >+} >+ > PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text) > { > FontCachePurgePreventer fontCachePurgePreventer; > > RefPtr<TextMetrics> metrics = TextMetrics::create(); > >+ // According to spec all space characters should be replaced with +U0020 space character >+ String normalizedText = text; >+ replaceCharacterInString(normalizedText, isHTMLSpace, " "); >+ > #if PLATFORM(QT) > // We always use complex text shaping since it can't be turned off for QPainterPath::addText(). > Font::CodePath oldCodePath = Font::codePath(); > Font::setCodePath(Font::Complex); > #endif > >- metrics->setWidth(accessFont().width(TextRun(text))); >+ metrics->setWidth(accessFont().width(TextRun(normalizedText))); > > #if PLATFORM(QT) > Font::setCodePath(oldCodePath); >@@ -2122,16 +2142,6 @@ PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text > return metrics.release(); > } > >-static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPtr matchFunction, const String& replacement) >-{ >- const size_t replacementLength = replacement.length(); >- size_t index = 0; >- while ((index = text.find(matchFunction, index)) != notFound) { >- text.replace(index, 1, replacement); >- index += replacementLength; >- } >-} >- > void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth, bool useMaxWidth) > { > GraphicsContext* c = drawingContext(); >@@ -2159,7 +2169,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, isHTMLSpace, " "); > > // FIXME: Need to turn off font smoothing. > >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index bd570651db119aceb3e32000f9292c14bab54d10..c3ad1a5fb27b96bf8056e6d9ad913e9c2749447a 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,23 @@ >+2013-08-09 Rashmi Shyamasundar <rashmi.s2@samsung.com> >+ >+ Canvas fillText and measureText handle ideographic spaces differently >+ https://bugs.webkit.org/show_bug.cgi?id=108881 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ According to the text preparation algorithm defined in the spec >+ http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-preparation-algorithm >+ all the spaces listed in the spec >+ http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#space-character >+ should be replaced by +U0020 space character. >+ The below listed layout tests verify the conformance to above spec. >+ These tests are passing on Ubuntu-Firefox 23.0. >+ >+ * fast/canvas/canvas-fillText-ideographicSpace-expected.html: Added. >+ * fast/canvas/canvas-fillText-ideographicSpace.html: Added. >+ * fast/canvas/canvas-measureText-ideographicSpace-expected.txt: Added. >+ * fast/canvas/canvas-measureText-ideographicSpace.html: Added. >+ > 2013-07-28 Antoine Quint <graouts@apple.com> > > fast/forms/input-in-table-cell-no-value.html fails on platform without ENABLE(INPUT_TYPE_DATE) >diff --git a/LayoutTests/fast/canvas/canvas-fillText-ideographicSpace-expected.html b/LayoutTests/fast/canvas/canvas-fillText-ideographicSpace-expected.html >new file mode 100755 >index 0000000000000000000000000000000000000000..828a1ec8abef73256801904df77ecf8bbf8080a9 >--- /dev/null >+++ b/LayoutTests/fast/canvas/canvas-fillText-ideographicSpace-expected.html >@@ -0,0 +1,9 @@ >+<!DOCTYPE html> >+<html> >+<head> >+ <meta charcode="utf-16"> >+</head> >+<body> >+<pre style="padding: 0px; font-size: 12px; font-family: Osaka; display: inline">a b c</pre> >+</body> >+</html> >diff --git a/LayoutTests/fast/canvas/canvas-fillText-ideographicSpace.html b/LayoutTests/fast/canvas/canvas-fillText-ideographicSpace.html >new file mode 100755 >index 0000000000000000000000000000000000000000..a42e88920cc220e3e2af450eb09c55509c2ee204 >--- /dev/null >+++ b/LayoutTests/fast/canvas/canvas-fillText-ideographicSpace.html >@@ -0,0 +1,20 @@ >+<!DOCTYPE html> >+<html> >+<head> >+ <meta charcode="utf-16"> >+ <script> >+ document.addEventListener('DOMContentLoaded', function () { >+ var canvas = document.getElementsByTagName('canvas')[0]; >+ var context = canvas.getContext('2d'); >+ var iSp = '\u3000'; >+ var str = 'a' + iSp + 'b' + iSp + 'c'; >+ context.font = '12px Osaka'; >+ context.textBaseline = 'top'; >+ context.fillText(str, 0, 3); >+ }, false); >+ </script> >+</head> >+<body> >+<canvas width="320" height="160"></canvas> >+</body> >+</html> >diff --git a/LayoutTests/fast/canvas/canvas-measureText-ideographicSpace-expected.txt b/LayoutTests/fast/canvas/canvas-measureText-ideographicSpace-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..ef3ab475b17d06bc39a41943a4be87787936bde9 >--- /dev/null >+++ b/LayoutTests/fast/canvas/canvas-measureText-ideographicSpace-expected.txt >@@ -0,0 +1,5 @@ >+PASS spanWidth is canvasWidth >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/fast/canvas/canvas-measureText-ideographicSpace.html b/LayoutTests/fast/canvas/canvas-measureText-ideographicSpace.html >new file mode 100755 >index 0000000000000000000000000000000000000000..3c1a778625a1780ba90a75e6d723434eaae7b3d3 >--- /dev/null >+++ b/LayoutTests/fast/canvas/canvas-measureText-ideographicSpace.html >@@ -0,0 +1,24 @@ >+<!DOCTYPE html> >+<html> >+<head> >+ <meta charcode="utf-16"> >+ <script src="../js/resources/js-test-pre.js"></script> >+</head> >+<body> >+<canvas></canvas> >+<span style="padding: 0px; font-size: 12px; font-family: Osaka; display: inline; visibility: hidden">a b c</span> >+<script> >+ var canvas = document.getElementsByTagName('canvas')[0]; >+ var context = canvas.getContext('2d'); >+ var iSp = '\u3000'; >+ var str = 'a' + iSp + 'b' + iSp + 'c'; >+ context.font = '12px Osaka'; >+ canvasWidth = context.measureText(str).width; >+ >+ var span = document.getElementsByTagName('span')[0]; >+ spanWidth = span.offsetWidth; >+ shouldBe("spanWidth", "canvasWidth"); >+</script> >+<script src="../js/resources/js-test-post.js"></script> >+</body> >+</html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 108881
:
186505
|
208243
|
208414
|
208421
|
208423
|
208427
|
208432
|
208514
|
208518
|
208523
|
208908
|
209259
|
209261
|
209284
|
209748
|
209760
|
209765
|
209768
|
209848
|
209852
|
211185