REGRESSION(r281419): iCloud.com Notes web app fonts render incorrectly
https://bugs.webkit.org/show_bug.cgi?id=235559
<rdar://problem/87268956>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character-expected.txt: Added.
* web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character.html: Added.

Source/WebCore:

Chrome and Firefox render U+0000 NULL as invisible. We should do the same, despite it technically being classified as a control character.

https://github.com/w3c/csswg-drafts/pull/6983

Test: imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character.html

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

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@288564 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog
index e818519..6bffcae 100644
--- a/LayoutTests/imported/w3c/ChangeLog
+++ b/LayoutTests/imported/w3c/ChangeLog
@@ -1,3 +1,14 @@
+2022-01-25  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        REGRESSION(r281419): iCloud.com Notes web app fonts render incorrectly
+        https://bugs.webkit.org/show_bug.cgi?id=235559
+        <rdar://problem/87268956>
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character-expected.txt: Added.
+        * web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character.html: Added.
+
 2022-01-25  Antti Koivisto  <antti@apple.com>
 
         [CSS Container Queries] Parsing support for container-name property
diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character-expected.txt
new file mode 100644
index 0000000..61e43eb
--- /dev/null
+++ b/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character-expected.txt
@@ -0,0 +1,5 @@
+Testing the NULL character
+Actual output:
+
+PASS Testing letter spacing and word spacing
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character.html b/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character.html
new file mode 100644
index 0000000..6cca2692
--- /dev/null
+++ b/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/html/canvas/resources/canvas-tests.js"></script>
+<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
+</head>
+<body class="show_output">
+<p class="desc">Testing the NULL character</p>
+
+
+<p class="output">Actual output:</p>
+<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
+
+<ul id="d"></ul>
+<script>
+var t = async_test("Testing letter spacing and word spacing");
+_addTest(function(canvas, ctx) {
+    ctx.font = "48px 'Helvetica'";
+    let result = ctx.measureText("\u0000");
+    _assertSame(result.width, 0, "result.width", "0");
+});
+</script>
+</body>
+</html>
+
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index d081ecd..58f22de 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,20 @@
+2022-01-25  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        REGRESSION(r281419): iCloud.com Notes web app fonts render incorrectly
+        https://bugs.webkit.org/show_bug.cgi?id=235559
+        <rdar://problem/87268956>
+
+        Reviewed by Darin Adler.
+
+        Chrome and Firefox render U+0000 NULL as invisible. We should do the same, despite it technically being classified as a control character.
+
+        https://github.com/w3c/csswg-drafts/pull/6983
+
+        Test: imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/null-character.html
+
+        * platform/graphics/WidthIterator.cpp:
+        (WebCore::WidthIterator::applyCSSVisibilityRules):
+
 2022-01-25  Antoine Quint  <graouts@webkit.org>
 
         Refactor KeyframeEffect::getKeyframes()
diff --git a/Source/WebCore/platform/graphics/WidthIterator.cpp b/Source/WebCore/platform/graphics/WidthIterator.cpp
index 39f5eb2..f8ce675 100644
--- a/Source/WebCore/platform/graphics/WidthIterator.cpp
+++ b/Source/WebCore/platform/graphics/WidthIterator.cpp
@@ -606,7 +606,9 @@
 
         // https://www.w3.org/TR/css-text-3/#white-space-processing
         // "Control characters (Unicode category Cc)—other than tabs (U+0009), line feeds (U+000A), carriage returns (U+000D) and sequences that form a segment break—must be rendered as a visible glyph"
-        if (u_charType(characterResponsibleForThisGlyph) == U_CONTROL_CHAR) {
+        // Also, we're omitting NULL (U+0000) from this set because Chrome and Firefox do so and it's needed for compat. See https://github.com/w3c/csswg-drafts/pull/6983.
+        if (characterResponsibleForThisGlyph != nullCharacter
+            && u_charType(characterResponsibleForThisGlyph) == U_CONTROL_CHAR) {
             // Let's assume that .notdef is visible.
             GlyphBufferGlyph visibleGlyph = 0;
             clobberGlyph(i, visibleGlyph);