Conversation
shallawa
force-pushed
the
canvas-text-shaping
branch
from
September 14, 2026 23:25
7811917 to
d17b4dd
Compare
Add an explainer for WebKit proposal for Canvas Text shaping. Another proposal has been discussed here[1]. [1] https://github.com/fserb/canvas2D/blob/master/spec/enhanced-textmetrics.md * CanvasTextShaping/CanvasTextShaping.md: Added. * CanvasTextShaping/drawing-colored-clusters-display.png: Added. * CanvasTextShaping/drawing-colored-justified-words-display.png: Added. * CanvasTextShaping/drawing-text.png: Added. * CanvasTextShaping/drawing-text-with-styles.png: Added. * CanvasTextShaping/drawing-text-with-styles-display.png: Added. * CanvasTextShaping/drawing-wrapped-justified-text-with-styled-display.png: Added.
shallawa
force-pushed
the
canvas-text-shaping
branch
from
September 14, 2026 23:30
d17b4dd to
ca43216
Compare
Add an explainer for WebKit proposal for Canvas Text shaping. Another proposal from Google has been discussed here[1]. [1] https://github.com/fserb/canvas2D/blob/master/spec/enhanced-textmetrics.md Reviewed by NOBODY (OOPS!). Explanation of why this fixes the bug (OOPS!). * CanvasTextShaping/CanvasTextShaping.md: Added. * CanvasTextShaping/drawing-colored-clusters-display.png: Added. * CanvasTextShaping/drawing-colored-justified-words-display.png: Added. * CanvasTextShaping/drawing-text.png: Added. * CanvasTextShaping/drawing-text-with-styles.png: Added. * CanvasTextShaping/drawing-text-with-styles-display.png: Added. * CanvasTextShaping/drawing-wrapped-justified-text-with-styled-display.png: Added.
| } | ||
| ``` | ||
|
|
||
| ## Examples |
There was a problem hiding this comment.
Could you add an example of text-on-path? I'm having trouble seeing how you would draw a sequence of GlyphRun along a non-linear path.
Author
There was a problem hiding this comment.
It can be something like this:
function fillClustersOnCircle(ctx, text, centerX, centerY, radius)
{
const clusters = ctx.splitText(text);
const clustersWidth = clusters.reduce((width, cluster) => width + cluster.textMetrics().width, 0);
let distance = 0;
for (const cluster of clusters) {
const ratio = distance / clustersWidth;
const angle = 2 * Math.PI * ratio;
const x = radius * Math.cos(angle) + centerX;
const y = radius * Math.sin(angle) + centerY;
ctx.save();
ctx.translate(x, y);
ctx.rotate(angle + Math.PI / 2);
ctx.fillGlyphRun(cluster, 0, 0);
ctx.restore();
distance += cluster.textMetrics().width;
}
}
Author
There was a problem hiding this comment.
Having fillText(), fillGlyphRuns() and fillGlyphRun() give freedom to do different scenarios:
fillText()can be used when no special breaking or styling is required. All text can be displayed in one call.fillGlyphRuns()can be used when special breaking (like clusters or word boundaries) or styling is required. But the text is displayed in the increasing horizontal direction of the context.fillGlyphRun()can be used similar tofillGlyphRuns()but the display position is customizable.
Add an explainer for WebKit proposal for Canvas Text shaping. Another proposal from Google has been discussed here[1]. [1] https://github.com/fserb/canvas2D/blob/master/spec/enhanced-textmetrics.md Reviewed by NOBODY (OOPS!). * CanvasTextShaping/CanvasTextShaping.md: Added. * CanvasTextShaping/drawing-clusters-on-circle-display.png: Added. * CanvasTextShaping/drawing-colored-clusters-display.png * CanvasTextShaping/drawing-colored-justified-words-display.png * CanvasTextShaping/drawing-text-with-styles-display.png * CanvasTextShaping/drawing-text-with-styles.png * CanvasTextShaping/drawing-text.png * CanvasTextShaping/drawing-wrapped-justified-text-with-styled-display.png
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an explainer for WebKit proposal for Canvas Text shaping. Another proposal has been discussed here[1].
[1] https://github.com/fserb/canvas2D/blob/master/spec/enhanced-textmetrics.md