From 29bc632bd38bf33bd475ef5b925fcea029cf6249 Mon Sep 17 00:00:00 2001 From: moz-wptsync-bot Date: Mon, 7 Aug 2023 14:56:14 +0000 Subject: [PATCH] patch 5 - Add testcases for emHeights and fontBoundingBox where the font's typographic ascent+descent does not equal the em size. Depends on D184608 Differential Revision: https://phabricator.services.mozilla.com/D184609 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1841692 gecko-commit: 90b19e0d07e5d2cd137f135b860f0357df90e338 gecko-reviewers: gfx-reviewers, lsalzman --- fonts/CanvasTest-ascent256.ttf | Bin 0 -> 2444 bytes fonts/CanvasTest-descent0.ttf | Bin 0 -> 2444 bytes .../2d.text.measure.emHeights-low-ascent.html | 45 ++++++++++ ...d.text.measure.emHeights-zero-descent.html | 45 ++++++++++ ...easure.fontBoundingBox-reduced-ascent.html | 43 +++++++++ ....measure.fontBoundingBox-zero-descent.html | 43 +++++++++ .../text/2d.text.measure.fontBoundingBox.html | 11 ++- .../2d.text.measure.emHeights-low-ascent.html | 34 +++++++ ...ext.measure.emHeights-low-ascent.worker.js | 30 +++++++ ...d.text.measure.emHeights-zero-descent.html | 34 +++++++ ...t.measure.emHeights-zero-descent.worker.js | 30 +++++++ ...easure.fontBoundingBox-reduced-ascent.html | 32 +++++++ ...e.fontBoundingBox-reduced-ascent.worker.js | 28 ++++++ ....measure.fontBoundingBox-zero-descent.html | 32 +++++++ ...ure.fontBoundingBox-zero-descent.worker.js | 28 ++++++ .../text/2d.text.measure.fontBoundingBox.html | 11 ++- .../2d.text.measure.fontBoundingBox.worker.js | 11 ++- html/canvas/tools/yaml-new/text.yaml | 83 ++++++++++++++++-- 18 files changed, 516 insertions(+), 24 deletions(-) create mode 100644 fonts/CanvasTest-ascent256.ttf create mode 100644 fonts/CanvasTest-descent0.ttf create mode 100644 html/canvas/element/text/2d.text.measure.emHeights-low-ascent.html create mode 100644 html/canvas/element/text/2d.text.measure.emHeights-zero-descent.html create mode 100644 html/canvas/element/text/2d.text.measure.fontBoundingBox-reduced-ascent.html create mode 100644 html/canvas/element/text/2d.text.measure.fontBoundingBox-zero-descent.html create mode 100644 html/canvas/offscreen/text/2d.text.measure.emHeights-low-ascent.html create mode 100644 html/canvas/offscreen/text/2d.text.measure.emHeights-low-ascent.worker.js create mode 100644 html/canvas/offscreen/text/2d.text.measure.emHeights-zero-descent.html create mode 100644 html/canvas/offscreen/text/2d.text.measure.emHeights-zero-descent.worker.js create mode 100644 html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-reduced-ascent.html create mode 100644 html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-reduced-ascent.worker.js create mode 100644 html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-zero-descent.html create mode 100644 html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-zero-descent.worker.js diff --git a/fonts/CanvasTest-ascent256.ttf b/fonts/CanvasTest-ascent256.ttf new file mode 100644 index 0000000000000000000000000000000000000000..d5924fc2194a3ae0d9a4eca3c293b14909b2a44e GIT binary patch literal 2444 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 + +Canvas test: 2d.text.measure.emHeights-low-ascent + + + + + + + +

2d.text.measure.emHeights-low-ascent

+

Testing emHeights with reduced ascent metric

+ + +A +

Actual output:

+

FAIL (fallback content)

+ +
    + + diff --git a/html/canvas/element/text/2d.text.measure.emHeights-zero-descent.html b/html/canvas/element/text/2d.text.measure.emHeights-zero-descent.html new file mode 100644 index 00000000000000..c3ce994fa14a70 --- /dev/null +++ b/html/canvas/element/text/2d.text.measure.emHeights-zero-descent.html @@ -0,0 +1,45 @@ + + +Canvas test: 2d.text.measure.emHeights-zero-descent + + + + + + + +

    2d.text.measure.emHeights-zero-descent

    +

    Testing emHeights with zero descent metric

    + + +A +

    Actual output:

    +

    FAIL (fallback content)

    + +
      + + diff --git a/html/canvas/element/text/2d.text.measure.fontBoundingBox-reduced-ascent.html b/html/canvas/element/text/2d.text.measure.fontBoundingBox-reduced-ascent.html new file mode 100644 index 00000000000000..653d26d820e34e --- /dev/null +++ b/html/canvas/element/text/2d.text.measure.fontBoundingBox-reduced-ascent.html @@ -0,0 +1,43 @@ + + +Canvas test: 2d.text.measure.fontBoundingBox-reduced-ascent + + + + + + + +

      2d.text.measure.fontBoundingBox-reduced-ascent

      +

      Testing fontBoundingBox for OffscreenCanvas with reduced ascent metric

      + + +A +

      Actual output:

      +

      FAIL (fallback content)

      + +
        + + diff --git a/html/canvas/element/text/2d.text.measure.fontBoundingBox-zero-descent.html b/html/canvas/element/text/2d.text.measure.fontBoundingBox-zero-descent.html new file mode 100644 index 00000000000000..785c0bc1866f0d --- /dev/null +++ b/html/canvas/element/text/2d.text.measure.fontBoundingBox-zero-descent.html @@ -0,0 +1,43 @@ + + +Canvas test: 2d.text.measure.fontBoundingBox-zero-descent + + + + + + + +

        2d.text.measure.fontBoundingBox-zero-descent

        +

        Testing fontBoundingBox for OffscreenCanvas with zero descent metric

        + + +A +

        Actual output:

        +

        FAIL (fallback content)

        + +
          + + diff --git a/html/canvas/element/text/2d.text.measure.fontBoundingBox.html b/html/canvas/element/text/2d.text.measure.fontBoundingBox.html index 90781bd75d1c60..9e7e190754d1bc 100644 --- a/html/canvas/element/text/2d.text.measure.fontBoundingBox.html +++ b/html/canvas/element/text/2d.text.measure.fontBoundingBox.html @@ -29,15 +29,14 @@

          2d.text.measure.fontBoundingBox

          var ctx = canvas.getContext('2d'); await document.fonts.ready; - ctx.font = '50px CanvasTest'; + ctx.font = '40px CanvasTest'; ctx.direction = 'ltr'; ctx.align = 'left' - // approx_equals because font metrics may be rounded slightly differently by different platforms/browsers. - assert_approx_equals(ctx.measureText('A').fontBoundingBoxAscent, 50 * 768 / 1024, 1, "unexpected fontBoundingBoxAscent"); - assert_approx_equals(ctx.measureText('A').fontBoundingBoxDescent, 50 * 256 / 1024, 1, "unexpected fontBoundingBoxDescent"); + _assertSame(ctx.measureText('A').fontBoundingBoxAscent, 30, "ctx.measureText('A').fontBoundingBoxAscent", "30"); + _assertSame(ctx.measureText('A').fontBoundingBoxDescent, 10, "ctx.measureText('A').fontBoundingBoxDescent", "10"); - assert_approx_equals(ctx.measureText('ABCD').fontBoundingBoxAscent, 50 * 768 / 1024, 1, "unexpected fontBoundingBoxAscent"); - assert_approx_equals(ctx.measureText('ABCD').fontBoundingBoxDescent, 50 * 256 / 1024, 1, "unexpected fontBoundingBoxDescent"); + _assertSame(ctx.measureText('ABCD').fontBoundingBoxAscent, 30, "ctx.measureText('ABCD').fontBoundingBoxAscent", "30"); + _assertSame(ctx.measureText('ABCD').fontBoundingBoxDescent, 10, "ctx.measureText('ABCD').fontBoundingBoxDescent", "10"); }, "Testing fontBoundingBox measurements"); diff --git a/html/canvas/offscreen/text/2d.text.measure.emHeights-low-ascent.html b/html/canvas/offscreen/text/2d.text.measure.emHeights-low-ascent.html new file mode 100644 index 00000000000000..2e2e5dde6723d4 --- /dev/null +++ b/html/canvas/offscreen/text/2d.text.measure.emHeights-low-ascent.html @@ -0,0 +1,34 @@ + + +OffscreenCanvas test: 2d.text.measure.emHeights-low-ascent + + + + +

          2d.text.measure.emHeights-low-ascent

          +

          Testing emHeights with reduced ascent metric

          + + + diff --git a/html/canvas/offscreen/text/2d.text.measure.emHeights-low-ascent.worker.js b/html/canvas/offscreen/text/2d.text.measure.emHeights-low-ascent.worker.js new file mode 100644 index 00000000000000..09ee7873092aa0 --- /dev/null +++ b/html/canvas/offscreen/text/2d.text.measure.emHeights-low-ascent.worker.js @@ -0,0 +1,30 @@ +// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. +// OffscreenCanvas test in a worker:2d.text.measure.emHeights-low-ascent +// Description:Testing emHeights with reduced ascent metric +// Note: + +importScripts("/resources/testharness.js"); +importScripts("/html/canvas/resources/canvas-tests.js"); + +promise_test(async t => { + + var canvas = new OffscreenCanvas(100, 50); + var ctx = canvas.getContext('2d'); + + var f = new FontFace("CanvasTest-ascent256", "url('/fonts/CanvasTest-ascent256.ttf')"); + f.load(); + self.fonts.add(f); + await self.fonts.ready; + ctx.font = '40px CanvasTest-ascent256'; + ctx.direction = 'ltr'; + ctx.align = 'left' + _assertSame(ctx.measureText('A').emHeightAscent, 20, "ctx.measureText('A').emHeightAscent", "20"); + _assertSame(ctx.measureText('A').emHeightDescent, 20, "ctx.measureText('A').emHeightDescent", "20"); + _assertSame(ctx.measureText('A').emHeightDescent + ctx.measureText('A').emHeightAscent, 40, "ctx.measureText('A').emHeightDescent + ctx.measureText('A').emHeightAscent", "40"); + + _assertSame(ctx.measureText('ABCD').emHeightAscent, 20, "ctx.measureText('ABCD').emHeightAscent", "20"); + _assertSame(ctx.measureText('ABCD').emHeightDescent, 20, "ctx.measureText('ABCD').emHeightDescent", "20"); + _assertSame(ctx.measureText('ABCD').emHeightDescent + ctx.measureText('ABCD').emHeightAscent, 40, "ctx.measureText('ABCD').emHeightDescent + ctx.measureText('ABCD').emHeightAscent", "40"); + t.done(); +}, "Testing emHeights with reduced ascent metric"); +done(); diff --git a/html/canvas/offscreen/text/2d.text.measure.emHeights-zero-descent.html b/html/canvas/offscreen/text/2d.text.measure.emHeights-zero-descent.html new file mode 100644 index 00000000000000..e39c08ce821d68 --- /dev/null +++ b/html/canvas/offscreen/text/2d.text.measure.emHeights-zero-descent.html @@ -0,0 +1,34 @@ + + +OffscreenCanvas test: 2d.text.measure.emHeights-zero-descent + + + + +

          2d.text.measure.emHeights-zero-descent

          +

          Testing emHeights with zero descent metric

          + + + diff --git a/html/canvas/offscreen/text/2d.text.measure.emHeights-zero-descent.worker.js b/html/canvas/offscreen/text/2d.text.measure.emHeights-zero-descent.worker.js new file mode 100644 index 00000000000000..a2f09782c98fca --- /dev/null +++ b/html/canvas/offscreen/text/2d.text.measure.emHeights-zero-descent.worker.js @@ -0,0 +1,30 @@ +// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. +// OffscreenCanvas test in a worker:2d.text.measure.emHeights-zero-descent +// Description:Testing emHeights with zero descent metric +// Note: + +importScripts("/resources/testharness.js"); +importScripts("/html/canvas/resources/canvas-tests.js"); + +promise_test(async t => { + + var canvas = new OffscreenCanvas(100, 50); + var ctx = canvas.getContext('2d'); + + var f = new FontFace("CanvasTest-descent0", "url('/fonts/CanvasTest-descent0.ttf')"); + f.load(); + self.fonts.add(f); + await self.fonts.ready; + ctx.font = '40px CanvasTest-descent0'; + ctx.direction = 'ltr'; + ctx.align = 'left' + _assertSame(ctx.measureText('A').emHeightAscent, 40, "ctx.measureText('A').emHeightAscent", "40"); + _assertSame(ctx.measureText('A').emHeightDescent, 0, "ctx.measureText('A').emHeightDescent", "0"); + _assertSame(ctx.measureText('A').emHeightDescent + ctx.measureText('A').emHeightAscent, 40, "ctx.measureText('A').emHeightDescent + ctx.measureText('A').emHeightAscent", "40"); + + _assertSame(ctx.measureText('ABCD').emHeightAscent, 40, "ctx.measureText('ABCD').emHeightAscent", "40"); + _assertSame(ctx.measureText('ABCD').emHeightDescent, 0, "ctx.measureText('ABCD').emHeightDescent", "0"); + _assertSame(ctx.measureText('ABCD').emHeightDescent + ctx.measureText('ABCD').emHeightAscent, 40, "ctx.measureText('ABCD').emHeightDescent + ctx.measureText('ABCD').emHeightAscent", "40"); + t.done(); +}, "Testing emHeights with zero descent metric"); +done(); diff --git a/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-reduced-ascent.html b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-reduced-ascent.html new file mode 100644 index 00000000000000..51eb2c822c493f --- /dev/null +++ b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-reduced-ascent.html @@ -0,0 +1,32 @@ + + +OffscreenCanvas test: 2d.text.measure.fontBoundingBox-reduced-ascent + + + + +

          2d.text.measure.fontBoundingBox-reduced-ascent

          +

          Testing fontBoundingBox for OffscreenCanvas with reduced ascent metric

          + + + diff --git a/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-reduced-ascent.worker.js b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-reduced-ascent.worker.js new file mode 100644 index 00000000000000..dea67ff8f6722e --- /dev/null +++ b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-reduced-ascent.worker.js @@ -0,0 +1,28 @@ +// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. +// OffscreenCanvas test in a worker:2d.text.measure.fontBoundingBox-reduced-ascent +// Description:Testing fontBoundingBox for OffscreenCanvas with reduced ascent metric +// Note: + +importScripts("/resources/testharness.js"); +importScripts("/html/canvas/resources/canvas-tests.js"); + +promise_test(async t => { + + var canvas = new OffscreenCanvas(100, 50); + var ctx = canvas.getContext('2d'); + + var f = new FontFace("CanvasTest-ascent256", "url('/fonts/CanvasTest-ascent256.ttf')"); + f.load(); + self.fonts.add(f); + await self.fonts.ready; + ctx.font = '40px CanvasTest-ascent256'; + ctx.direction = 'ltr'; + ctx.align = 'left' + _assertSame(ctx.measureText('A').fontBoundingBoxAscent, 10, "ctx.measureText('A').fontBoundingBoxAscent", "10"); + _assertSame(ctx.measureText('A').fontBoundingBoxDescent, 10, "ctx.measureText('A').fontBoundingBoxDescent", "10"); + + _assertSame(ctx.measureText('ABCD').fontBoundingBoxAscent, 10, "ctx.measureText('ABCD').fontBoundingBoxAscent", "10"); + _assertSame(ctx.measureText('ABCD').fontBoundingBoxDescent, 10, "ctx.measureText('ABCD').fontBoundingBoxDescent", "10"); + t.done(); +}, "Testing fontBoundingBox for OffscreenCanvas with reduced ascent metric"); +done(); diff --git a/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-zero-descent.html b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-zero-descent.html new file mode 100644 index 00000000000000..ea65e58b5c59af --- /dev/null +++ b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-zero-descent.html @@ -0,0 +1,32 @@ + + +OffscreenCanvas test: 2d.text.measure.fontBoundingBox-zero-descent + + + + +

          2d.text.measure.fontBoundingBox-zero-descent

          +

          Testing fontBoundingBox for OffscreenCanvas with zero descent metric

          + + + diff --git a/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-zero-descent.worker.js b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-zero-descent.worker.js new file mode 100644 index 00000000000000..99a886d015cf23 --- /dev/null +++ b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox-zero-descent.worker.js @@ -0,0 +1,28 @@ +// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. +// OffscreenCanvas test in a worker:2d.text.measure.fontBoundingBox-zero-descent +// Description:Testing fontBoundingBox for OffscreenCanvas with zero descent metric +// Note: + +importScripts("/resources/testharness.js"); +importScripts("/html/canvas/resources/canvas-tests.js"); + +promise_test(async t => { + + var canvas = new OffscreenCanvas(100, 50); + var ctx = canvas.getContext('2d'); + + var f = new FontFace("CanvasTest-descent0", "url('/fonts/CanvasTest-descent0.ttf')"); + f.load(); + self.fonts.add(f); + await self.fonts.ready; + ctx.font = '40px CanvasTest-descent0'; + ctx.direction = 'ltr'; + ctx.align = 'left' + _assertSame(ctx.measureText('A').fontBoundingBoxAscent, 30, "ctx.measureText('A').fontBoundingBoxAscent", "30"); + _assertSame(ctx.measureText('A').fontBoundingBoxDescent, 0, "ctx.measureText('A').fontBoundingBoxDescent", "0"); + + _assertSame(ctx.measureText('ABCD').fontBoundingBoxAscent, 30, "ctx.measureText('ABCD').fontBoundingBoxAscent", "30"); + _assertSame(ctx.measureText('ABCD').fontBoundingBoxDescent, 0, "ctx.measureText('ABCD').fontBoundingBoxDescent", "0"); + t.done(); +}, "Testing fontBoundingBox for OffscreenCanvas with zero descent metric"); +done(); diff --git a/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.html b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.html index 439c96c98b126a..36b11f31d7fd53 100644 --- a/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.html +++ b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.html @@ -19,15 +19,14 @@

          2d.text.measure.fontBoundingBox

          f.load(); document.fonts.add(f); await document.fonts.ready; - ctx.font = '50px CanvasTest'; + ctx.font = '40px CanvasTest'; ctx.direction = 'ltr'; ctx.align = 'left' - // approx_equals because font metrics may be rounded slightly differently by different platforms/browsers. - assert_approx_equals(ctx.measureText('A').fontBoundingBoxAscent, 50 * 768 / 1024, 1, "unexpected fontBoundingBoxAscent"); - assert_approx_equals(ctx.measureText('A').fontBoundingBoxDescent, 50 * 256 / 1024, 1, "unexpected fontBoundingBoxDescent"); + _assertSame(ctx.measureText('A').fontBoundingBoxAscent, 30, "ctx.measureText('A').fontBoundingBoxAscent", "30"); + _assertSame(ctx.measureText('A').fontBoundingBoxDescent, 10, "ctx.measureText('A').fontBoundingBoxDescent", "10"); - assert_approx_equals(ctx.measureText('ABCD').fontBoundingBoxAscent, 50 * 768 / 1024, 1, "unexpected fontBoundingBoxAscent"); - assert_approx_equals(ctx.measureText('ABCD').fontBoundingBoxDescent, 50 * 256 / 1024, 1, "unexpected fontBoundingBoxDescent"); + _assertSame(ctx.measureText('ABCD').fontBoundingBoxAscent, 30, "ctx.measureText('ABCD').fontBoundingBoxAscent", "30"); + _assertSame(ctx.measureText('ABCD').fontBoundingBoxDescent, 10, "ctx.measureText('ABCD').fontBoundingBoxDescent", "10"); }, "Testing fontBoundingBox measurements"); diff --git a/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.worker.js b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.worker.js index 463bc21f65e768..b2cde04c0dadfd 100644 --- a/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.worker.js +++ b/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.worker.js @@ -15,15 +15,14 @@ promise_test(async t => { f.load(); self.fonts.add(f); await self.fonts.ready; - ctx.font = '50px CanvasTest'; + ctx.font = '40px CanvasTest'; ctx.direction = 'ltr'; ctx.align = 'left' - // approx_equals because font metrics may be rounded slightly differently by different platforms/browsers. - assert_approx_equals(ctx.measureText('A').fontBoundingBoxAscent, 50 * 768 / 1024, 1, "unexpected fontBoundingBoxAscent"); - assert_approx_equals(ctx.measureText('A').fontBoundingBoxDescent, 50 * 256 / 1024, 1, "unexpected fontBoundingBoxDescent"); + _assertSame(ctx.measureText('A').fontBoundingBoxAscent, 30, "ctx.measureText('A').fontBoundingBoxAscent", "30"); + _assertSame(ctx.measureText('A').fontBoundingBoxDescent, 10, "ctx.measureText('A').fontBoundingBoxDescent", "10"); - assert_approx_equals(ctx.measureText('ABCD').fontBoundingBoxAscent, 50 * 768 / 1024, 1, "unexpected fontBoundingBoxAscent"); - assert_approx_equals(ctx.measureText('ABCD').fontBoundingBoxDescent, 50 * 256 / 1024, 1, "unexpected fontBoundingBoxDescent"); + _assertSame(ctx.measureText('ABCD').fontBoundingBoxAscent, 30, "ctx.measureText('ABCD').fontBoundingBoxAscent", "30"); + _assertSame(ctx.measureText('ABCD').fontBoundingBoxDescent, 10, "ctx.measureText('ABCD').fontBoundingBoxDescent", "10"); t.done(); }, "Testing fontBoundingBox measurements"); done(); diff --git a/html/canvas/tools/yaml-new/text.yaml b/html/canvas/tools/yaml-new/text.yaml index ffdc24087ebed8..93c86b8b5e59e4 100644 --- a/html/canvas/tools/yaml-new/text.yaml +++ b/html/canvas/tools/yaml-new/text.yaml @@ -1060,15 +1060,14 @@ - CanvasTest code: | {{ load_font }} - ctx.font = '50px CanvasTest'; + ctx.font = '40px CanvasTest'; ctx.direction = 'ltr'; ctx.align = 'left' - // approx_equals because font metrics may be rounded slightly differently by different platforms/browsers. - assert_approx_equals(ctx.measureText('A').fontBoundingBoxAscent, 50 * 768 / 1024, 1, "unexpected fontBoundingBoxAscent"); - assert_approx_equals(ctx.measureText('A').fontBoundingBoxDescent, 50 * 256 / 1024, 1, "unexpected fontBoundingBoxDescent"); + @assert ctx.measureText('A').fontBoundingBoxAscent === 30; + @assert ctx.measureText('A').fontBoundingBoxDescent === 10; - assert_approx_equals(ctx.measureText('ABCD').fontBoundingBoxAscent, 50 * 768 / 1024, 1, "unexpected fontBoundingBoxAscent"); - assert_approx_equals(ctx.measureText('ABCD').fontBoundingBoxDescent, 50 * 256 / 1024, 1, "unexpected fontBoundingBoxDescent"); + @assert ctx.measureText('ABCD').fontBoundingBoxAscent === 30; + @assert ctx.measureText('ABCD').fontBoundingBoxDescent === 10; variants: *load-font-variant-definition - name: 2d.text.measure.fontBoundingBox.ahem @@ -1087,6 +1086,40 @@ @assert ctx.measureText('ABCD').fontBoundingBoxDescent === 10; variants: *load-font-variant-definition +- name: 2d.text.measure.fontBoundingBox-reduced-ascent + desc: Testing fontBoundingBox for OffscreenCanvas with reduced ascent metric + test_type: promise + fonts: + - CanvasTest-ascent256 + code: | + {{ load_font }} + ctx.font = '40px CanvasTest-ascent256'; + ctx.direction = 'ltr'; + ctx.align = 'left' + @assert ctx.measureText('A').fontBoundingBoxAscent === 10; + @assert ctx.measureText('A').fontBoundingBoxDescent === 10; + + @assert ctx.measureText('ABCD').fontBoundingBoxAscent === 10; + @assert ctx.measureText('ABCD').fontBoundingBoxDescent === 10; + variants: *load-font-variant-definition + +- name: 2d.text.measure.fontBoundingBox-zero-descent + desc: Testing fontBoundingBox for OffscreenCanvas with zero descent metric + test_type: promise + fonts: + - CanvasTest-descent0 + code: | + {{ load_font }} + ctx.font = '40px CanvasTest-descent0'; + ctx.direction = 'ltr'; + ctx.align = 'left' + @assert ctx.measureText('A').fontBoundingBoxAscent === 30; + @assert ctx.measureText('A').fontBoundingBoxDescent === 0; + + @assert ctx.measureText('ABCD').fontBoundingBoxAscent === 30; + @assert ctx.measureText('ABCD').fontBoundingBoxDescent === 0; + variants: *load-font-variant-definition + - name: 2d.text.measure.emHeights desc: Testing emHeights test_type: promise @@ -1106,6 +1139,44 @@ @assert ctx.measureText('ABCD').emHeightDescent + ctx.measureText('ABCD').emHeightAscent === 40; variants: *load-font-variant-definition +- name: 2d.text.measure.emHeights-low-ascent + desc: Testing emHeights with reduced ascent metric + test_type: promise + fonts: + - CanvasTest-ascent256 + code: | + {{ load_font }} + ctx.font = '40px CanvasTest-ascent256'; + ctx.direction = 'ltr'; + ctx.align = 'left' + @assert ctx.measureText('A').emHeightAscent === 20; + @assert ctx.measureText('A').emHeightDescent === 20; + @assert ctx.measureText('A').emHeightDescent + ctx.measureText('A').emHeightAscent === 40; + + @assert ctx.measureText('ABCD').emHeightAscent === 20; + @assert ctx.measureText('ABCD').emHeightDescent === 20; + @assert ctx.measureText('ABCD').emHeightDescent + ctx.measureText('ABCD').emHeightAscent === 40; + variants: *load-font-variant-definition + +- name: 2d.text.measure.emHeights-zero-descent + desc: Testing emHeights with zero descent metric + test_type: promise + fonts: + - CanvasTest-descent0 + code: | + {{ load_font }} + ctx.font = '40px CanvasTest-descent0'; + ctx.direction = 'ltr'; + ctx.align = 'left' + @assert ctx.measureText('A').emHeightAscent === 40; + @assert ctx.measureText('A').emHeightDescent === 0; + @assert ctx.measureText('A').emHeightDescent + ctx.measureText('A').emHeightAscent === 40; + + @assert ctx.measureText('ABCD').emHeightAscent === 40; + @assert ctx.measureText('ABCD').emHeightDescent === 0; + @assert ctx.measureText('ABCD').emHeightDescent + ctx.measureText('ABCD').emHeightAscent === 40; + variants: *load-font-variant-definition + - name: 2d.text.measure.baselines desc: Testing baselines test_type: promise