WICG / canvas-formatted-text

Other
81 stars 16 forks source link

More efficient way to get total line height #2

Closed travisleithead closed 3 years ago

travisleithead commented 3 years ago

Copied from: https://github.com/MicrosoftEdge/MSEdgeExplainers/issues/370

Based on some early experimentation, developers have discovered that they almost always need to know the total line height (sum height of all lines), in order to calculate vertical placement of the formatted text on the canvas. The simple usage of fillFormattedText does not provide this information, and the advanced API requires iteratively measuring lines (which is slightly cumbersome and has potential performance overhead for all the other unneeded metrics calculations).

It would be nice to have a more convenient way of getting the total height needed for placement.

--

As previously noted in the explainer:

This could be one way of getting the height, but ideally it can be obtained prior to drawing the text on the canvas.

travisleithead commented 3 years ago

Current approach (with metrics) puts retrieving the metrics object in the primary rendering path. The FormattedTextParagraph will have the total line height as blockSize.