Skip to content

Implement CanvasRenderingContext2d.measureText #5411

Closed

Description

@jdm

Spec: https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-measuretext
Code: components/script/dom/canvasrenderingcontext2d.rs, components/script/dom/weibidls/CanvasRenderingContext2D.webidl, components/canvas/canvas_paint_task.rs

Blocks #5410.

Activity

  1. added
    A-content/dom
    on Mar 27, 2015
  2. leavengood commented on Mar 27, 2015

    @leavengood
    Contributor

    I'd like to work on this.

  3. jdm commented on Mar 28, 2015

    @jdm
    MemberAuthor

    Ok! There are a bunch of different pieces involved, so let me know if you've got any questions :)

  4. added
    C-assigned
    on Mar 28, 2015
  5. leavengood commented on Mar 28, 2015

    @leavengood
    Contributor

    Yes I started working on it last night. I think I've got the messaging between the Dom side and renderer, but I need the IDL for TextMetrics and the Rust implementation. It is very simple with just a lot of double fields, but I'm new to Rust and Servo so I have to learn a lot here. Is there a way to generate the Rust code from the IDL? Also I didn't see many other pieces of canvas that work like this so I don't have much to base this on.

    Lastly I think for this initial implementation I will skip the "text preparation algorithm", since it looks like a beast. Unless there is already code for it somewhere else.

  6. jdm commented on Mar 28, 2015

    @jdm
    MemberAuthor

    Yes, you should add a new TextMetrics.webidl file in components/script/dom/webidls, and create the corresponding textmetrics.rs for it too: http://doc.servo.org/script/dom/index.html#adding-a-new-dom-interface

  7. jdm commented on Mar 28, 2015

    @jdm
    MemberAuthor

    I think starting with a stub of the text preparation algorithm would be preferable to skipping it entirely. That would entail filling in the steps that are simple (ie. whitespace replacement), using sensible defaults for the steps that are more complicated and produce values, and leaving TODO comments for everything that is not spec-compliant.

  8. leavengood commented on Mar 28, 2015

    @leavengood
    Contributor

    Yeah, that makes sense. Certainly the whitespace replacement is pretty easy. But the part that says "Form a hypothetical infinitely-wide CSS line box containing a single inline box containing the text text" seems a bit more tricky. I'll need to look around servo and maybe at other browsers to see how that is supposed to work.

    I like fonts and text rendering stuff so this might be an area of Servo where I could make a good contribution. For example the other text related canvas methods fillText and strokeText. And maybe even a beast like #4901.

    Lastly I'm applying for the Staff Research Engineer position to work on Servo full-time, so if I get that I'll be able to do a lot more, obviously. 😄

  9. jdm commented on Mar 28, 2015

    @jdm
    MemberAuthor

    Heh, I hadn't looked at that step. That is certainly... interesting. It suggests that we may want to extract some of the layout operations related to layout out text into somewhere outside of the layout/ crate. Definitely will require talking with some of the experts, but let's try to proceed without it for now.

  10. leavengood commented on Apr 3, 2015

    @leavengood
    Contributor

    Over the past week I've had some other things keeping me busy, so I have not made much progress on this. I may have some time tonight or tomorrow.

  11. removed
    C-assigned
    on Sep 18, 2015
  12. paulrouget commented on Sep 21, 2019

    @paulrouget
    Contributor

    I'm thinking of implementing a non operational version of MeasureText, behind a pref. It would just return 0 for now.

  13. paulrouget commented on Sep 21, 2019

    @paulrouget
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-content/dom

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions