-
Notifications
You must be signed in to change notification settings - Fork 6k
Implement basic text rendering support in CanvasKit backend #13903
Implement basic text rendering support in CanvasKit backend #13903
Conversation
/// CanvasKit does not yet allow us to specify family names when registering | ||
/// fonts. CanvasKit reads the font name from the font's bytes. So, we map | ||
/// some common family names to how they are registered in the Gallery app. | ||
const Map<String, String> _fontFamilyOverrides = <String, String>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave a TODO to clean this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
class SkParagraph implements ui.Paragraph { | ||
SkParagraph(this.skParagraph, this._textDirection, this._fontFamily); | ||
|
||
final js.JsObject skParagraph; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the lifecycle of this object? Does it need to be deallocated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Developers can hold onto it and keep using it with Canvas.drawParagraph
if they wish. We can, however, clean up ParagraphBuilder
after build
is called.
try { | ||
skParagraph.callMethod('layout', <double>[constraints.width]); | ||
} catch (e) { | ||
html.window.console.warn('CanvasKit threw an exception while laying ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fail harder, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to rethrow
canvasKit['ParagraphBuilder'].callMethod('Make', <js.JsObject>[ | ||
skStyle.skParagraphStyle, | ||
skiaFontCollection.skFontMgr, | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think a trailing comma will allow dartfmt do a better job here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* f240462 Implement basic text rendering support in CanvasKit backend (flutter/engine#13903) * ffcd856 Imagefilter wrapper object (flutter/engine#13711) * 176f563 Roll src/third_party/dart eeca3fb1cb..1f933abcee (7 commits) (flutter/engine#13931)
This adds basic text rendering support using the "SkParagraph" module in Skia.