Skip to content

script: Implement CanvasRenderingContext2D.measureText - #32704

Merged
mrobinson merged 1 commit into
servo:mainfrom
chocolate-pie:canvas-measure-text
Jul 17, 2024
Merged

mrobinson merged 1 commit into
servo:mainfrom
chocolate-pie:canvas-measure-text

Conversation

@chocolate-pie

Copy link
Copy Markdown
Contributor

Replace stub implementation of CanvasRenderingContext2D.measureText with real one.


@chocolate-pie
chocolate-pie requested a review from gterzian as a code owner July 5, 2024 11:43
@jdm jdm added the T-linux-wpt Do a try run of the WPT label Jul 5, 2024
@github-actions github-actions Bot removed the T-linux-wpt Do a try run of the WPT label Jul 5, 2024
@github-actions

github-actions Bot commented Jul 5, 2024

Copy link
Copy Markdown

🔨 Triggering try run (#9807939572) for Linux WPT

@github-actions

github-actions Bot commented Jul 5, 2024

Copy link
Copy Markdown

Test results for linux-wpt-layout-2020 from try job (#9807939572):

Flaky unexpected result (9)
  • OK /html/browsers/browsing-the-web/navigating-across-documents/empty-iframe-load-event.html (#29066)
    • FAIL [expected PASS] subtest: Check execution order from nested timeout

      assert_equals: Expected nested setTimeout to run second expected true but got false
      

    • FAIL [expected PASS] subtest: Check execution order on load handler

      assert_equals: Expected onload to run first expected false but got true
      

  • TIMEOUT [expected OK] /html/interaction/focus/the-autofocus-attribute/autofocus-dialog.html (#29087)
    • TIMEOUT [expected FAIL] subtest: <dialog>-contained autofocus element gets focused when the dialog is shown

      Test timed out
      

  • TIMEOUT [expected OK] /html/interaction/focus/the-autofocus-attribute/supported-elements.html (#24145)
    • TIMEOUT [expected PASS] subtest: Non-HTMLElement should not support autofocus

      Test timed out
      

    • NOTRUN [expected FAIL] subtest: Host element with delegatesFocus should support autofocus
    • NOTRUN [expected FAIL] subtest: Host element with delegatesFocus including no focusable descendants should be skipped
    • NOTRUN [expected FAIL] subtest: Area element should support autofocus
  • OK [expected TIMEOUT] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-1.html (#24066)
    • FAIL [expected NOTRUN] subtest: Check that popups from a sandboxed iframe do not escape the sandbox

      assert_equals: It came from a sandboxed iframe expected "null" but got "http://web-platform.test:8000"
      

  • OK [expected CRASH] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-2.html (#22154)
  • OK /html/semantics/forms/form-submission-0/text-plain.window.html (#28687)
    • PASS [expected FAIL] subtest: text/plain: Basic test (formdata event)
  • OK /html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_noopener.html (#23205)
    • PASS [expected FAIL] subtest: Check that rel=noopener with target=_self does a normal load
  • TIMEOUT [expected OK] /resource-timing/nested-context-navigations-iframe.html (#24311)
    • TIMEOUT [expected PASS] subtest: Test that iframe navigations are not observable by the parent, even after history navigations by the parent

      Test timed out
      

    • NOTRUN [expected PASS] subtest: Test that crossorigin iframe navigations are not observable by the parent, even after history navigations by the parent
    • NOTRUN [expected PASS] subtest: Test that cross-site iframe navigations are not observable by the parent, even after history navigations by the parent
    • NOTRUN [expected PASS] subtest: Test that iframe navigations are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that crossorigin iframe navigations are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that cross-site iframe navigations are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that iframe refreshes are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that crossorigin iframe refreshes are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that cross-site iframe refreshes are not observable by the parent
  • TIMEOUT [expected OK] /webmessaging/with-ports/017.html (#24486)
    • TIMEOUT [expected PASS] subtest: origin of the script that invoked the method, about:blank

      Test timed out
      

Stable unexpected results that are known to be intermittent (21)
  • FAIL [expected PASS] /_mozilla/css/dirty_viewport.html (#13731)
  • FAIL [expected PASS] /_mozilla/css/iframe/hide_and_show.html (#15265)
  • OK /css/css-fonts/variations/at-font-face-font-matching.html (#20684)
    • FAIL [expected PASS] subtest: Matching font-weight: '399' should prefer '350 399' over '340 360'

      assert_equals: Unexpected font on test element expected 487 but got 532
      

    • FAIL [expected PASS] subtest: Matching font-style: 'italic' should prefer 'oblique 5deg 10deg' over 'oblique 5deg'

      assert_equals: Unexpected font on test element expected 487 but got 532
      

  • OK [expected ERROR] /css/css-ui/text-overflow-023.html (#19861)
  • TIMEOUT [expected OK] /css/cssom-view/MediaQueryList-addListener-handleEvent.html (#24571)
    • TIMEOUT [expected PASS] subtest: doesn't look up handleEvent method on callable event listeners

      Test timed out
      

    • NOTRUN [expected PASS] subtest: rethrows errors when getting handleEvent
    • NOTRUN [expected FAIL] subtest: throws if handleEvent is falsy and not callable
    • NOTRUN [expected FAIL] subtest: throws if handleEvent is thruthy and not callable
  • OK /css/cssom-view/MediaQueryList-addListener-removeListener.html (#24569)
    • FAIL [expected PASS] subtest: listener that was added twice is called only once

      assert_equals: expected 1 but got 0
      

    • FAIL [expected PASS] subtest: listeners are called in order their MQLs were created

      assert_array_equals: lengths differ, expected array ["mql1", "mql2"] length 2, got [] length 0
      

    • FAIL [expected PASS] subtest: removing listener from one MQL doesn't remove it from all MQLs

      assert_equals: expected 1 but got 0
      

  • OK /css/cssom-view/MediaQueryList-extends-EventTarget-interop.html (#25285)
    • FAIL [expected PASS] subtest: listener added with addListener and addEventListener is called once

      assert_equals: triggerMQLEvent expected 1 but got 0
      

    • FAIL [expected PASS] subtest: removeEventListener (capture) doesn't remove listener added with addListener

      assert_equals: triggerMQLEvent expected 1 but got 0
      

    • FAIL [expected PASS] subtest: removeListener doesn't remove listener added with addEventListener (capture)

      assert_equals: triggerMQLEvent expected 1 but got 0
      

    • FAIL [expected PASS] subtest: capturing event listener fires before non-capturing listener at target

      assert_array_equals: triggerMQLEvent lengths differ, expected array ["addEventListener", "addListener"] length 2, got [] length 0
      

  • TIMEOUT /css/cssom-view/MediaQueryList-extends-EventTarget.html (#25269)
    • TIMEOUT [expected PASS] subtest: onchange removes listener

      Test timed out
      

    • NOTRUN [expected PASS] subtest: listeners for "change" type are called
    • NOTRUN [expected PASS] subtest: listeners with different type are not called
    • NOTRUN [expected TIMEOUT] subtest: addEventListener "once" option is respected
  • TIMEOUT [expected OK] /css/cssom-view/MediaQueryListEvent.html (#25275)
    • TIMEOUT [expected PASS] subtest: argument of onchange

      Test timed out
      

    • NOTRUN [expected PASS] subtest: constructor of "change" event
  • OK /custom-elements/form-associated/ElementInternals-setFormValue.html (#29174)
    • PASS [expected FAIL] subtest: Newline normalization - \r\n in name (urlencoded)
  • TIMEOUT /fetch/metadata/generated/element-img-environment-change.https.sub.html (#30111)
    • TIMEOUT [expected FAIL] subtest: sec-fetch-site - Cross-site, no attributes

      Test timed out
      

  • OK /html/browsers/history/the-history-interface/traverse_the_history_5.html (#21383)
    • FAIL [expected PASS] subtest: Multiple history traversals, last would be aborted

      assert_array_equals: Pages opened during history navigation expected property 1 to be 5 but got 3 (expected array [6, 5] got [6, 3])
      

  • OK [expected CRASH] /html/browsers/windows/embedded-opener-remove-frame.html (#23867)
  • OK [expected CRASH] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_escaping-1.html (#22647)
    • FAIL [expected TIMEOUT] subtest: Check that popups from a sandboxed iframe escape the sandbox if allow-popups-to-escape-sandbox is used

      assert_equals: It came from a sandboxed iframe expected "null" but got "http://web-platform.test:8000"
      

  • CRASH [expected OK] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-3.html (#24066)
  • TIMEOUT [expected OK] /html/semantics/embedded-content/the-iframe-element/sandbox-top-navigation-user-activation-sticky.tentative.sub.window.html (#32154)
    • TIMEOUT [expected FAIL] subtest: Allow top with user activation + user activation

      Test timed out
      

  • OK /html/syntax/parsing/DOMContentLoaded-defer.html (#21550)
    • FAIL [expected PASS] subtest: The end: DOMContentLoaded and defer scripts

      assert_false: DOMContentLoaded should not have fired before executing a task queued from a defer script expected false got true
      

  • TIMEOUT /resource-timing/response-status-code.html (#29309)
    • TIMEOUT [expected FAIL] subtest: This test validates the response status of resources. 79

      Test timed out
      

    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 80
    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 81
    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 82
    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 83
    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 84
    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 85
    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 86
    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 87
    • NOTRUN [expected FAIL] subtest: This test validates the response status of resources. 88
    • And 1 more unexpected results...
  • TIMEOUT [expected OK] /webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.tentative.html (#29053)
    • TIMEOUT [expected PASS] subtest: StorageKey: test 3P about:blank window opened from a 3P iframe

      Test timed out
      

  • OK /workers/WorkerGlobalScope-close.html (#23064)
    • FAIL [expected PASS] subtest: Test sending a message after closing.

      assert_not_equals: got disallowed value "pong"
      

  • OK [expected ERROR] /workers/constructors/Worker/Worker-constructor.html (#22991)
Stable unexpected results (2)
  • OK /html/canvas/element/text/2d.text.drawing.style.measure.rtl.text.html
    • PASS [expected FAIL] subtest: Measurement should follow canvas direction instead text direction
  • OK /html/canvas/element/text/2d.text.drawing.style.measure.textAlign.html
    • PASS [expected FAIL] subtest: Measurement should be related to textAlignment

@github-actions

github-actions Bot commented Jul 5, 2024

Copy link
Copy Markdown

⚠️ Try run (#9807939572) failed.

@mrobinson mrobinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change. A couple things that make this complicated:

  1. We are going to be removing as much of the font-kit dependency as possible, so I don't think it makes sense to add more hooks for font kit into the fonts crate.
  2. Font handling for canvas needs to move back to the script thread, as that is what has access to web fonts.

I'm happy to discuss these constraints on Zulip.

@chocolate-pie
chocolate-pie force-pushed the canvas-measure-text branch 2 times, most recently from e3a2556 to c1a2ec4 Compare July 8, 2024 12:38
@chocolate-pie
chocolate-pie requested a review from mrobinson July 8, 2024 15:14
@chocolate-pie
chocolate-pie force-pushed the canvas-measure-text branch from c1a2ec4 to 7273c40 Compare July 9, 2024 09:31
@chocolate-pie

Copy link
Copy Markdown
Contributor Author

@mrobinson I've addressed the issues you mentioned. I'd be happy to get it reviewed.

@mrobinson mrobinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thing here is that this should be rewritten on top of #32758 which removes the use of font-kit in text layout in Canvas. Thank you so much for this work.

Comment thread components/fonts/shaper.rs Resolved
Comment thread components/fonts/shaper.rs Resolved
Comment thread components/fonts/shaper.rs Resolved
Comment thread components/fonts/shaper.rs Resolved
Comment thread components/fonts/platform/macos/font.rs Resolved
Comment thread components/canvas/canvas_data.rs Resolved
Comment thread components/canvas/canvas_data.rs Resolved
Comment thread components/canvas/canvas_data.rs Resolved
Comment on lines +395 to +412
fn typographic_bounds(&self, glyph_id: GlyphId) -> RectF {
let face = self.face.lock();
assert!(!face.is_null());

let load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING;
let result = unsafe { FT_Load_Glyph(*face, glyph_id as FT_UInt, load_flags) };
if 0 != result {
debug!("Unable to load glyph {}. reason: {:?}", glyph, result);
return RectF::default();
}

let metrics = unsafe { &(*(**face).glyph).metrics };
let rect = RectI::new(
Vector2I::new(
metrics.horiBearingX as i32,
(metrics.horiBearingY - metrics.height) as i32,
),
Vector2I::new(metrics.width as i32, metrics.height as i32),
);
(rect.to_f32() * (1. / 64.)).round()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be replaced with (hb-font-get-glyph-extents)[https://harfbuzz.github.io/harfbuzz-hb-font.html#hb-font-get-glyph-extents]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to work correctly, at least in my environment.

@chocolate-pie
chocolate-pie force-pushed the canvas-measure-text branch 3 times, most recently from bf30be1 to 189b6be Compare July 12, 2024 12:31
@chocolate-pie
chocolate-pie requested a review from mrobinson July 13, 2024 07:49

@mrobinson mrobinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work and I appreciate all the changes. It looks like the main thing missing here is support for fallback, but otherwise this is looking really nice.

Comment thread components/canvas/Cargo.toml Resolved
Comment thread components/canvas/canvas_data.rs Resolved
Comment thread components/canvas/canvas_data.rs Resolved
Comment thread components/canvas/canvas_data.rs Resolved
Comment thread components/canvas/canvas_data.rs Resolved
@chocolate-pie
chocolate-pie force-pushed the canvas-measure-text branch 2 times, most recently from 21f25eb to e4e962f Compare July 16, 2024 03:23
@chocolate-pie
chocolate-pie requested a review from mrobinson July 16, 2024 03:51

@mrobinson mrobinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work!

@mrobinson
mrobinson enabled auto-merge July 17, 2024 15:40
@mrobinson
mrobinson added this pull request to the merge queue Jul 17, 2024
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 17, 2024
Co-authored-by: Martin Robinson <[email protected]>
Signed-off-by: Chocolate Pie <[email protected]>
@mrobinson
mrobinson force-pushed the canvas-measure-text branch from c926ec5 to 5dff4c7 Compare July 17, 2024 18:53
@mrobinson
mrobinson enabled auto-merge July 17, 2024 18:54
@mrobinson
mrobinson added this pull request to the merge queue Jul 17, 2024
Merged via the queue into servo:main with commit 1223335 Jul 17, 2024
@chocolate-pie
chocolate-pie deleted the canvas-measure-text branch July 17, 2024 22:33
Gae24 pushed a commit to Gae24/servo that referenced this pull request Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement CanvasRenderingContext2d.measureText

3 participants