Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Implement basic text rendering support in CanvasKit backend #13903

Merged
merged 5 commits into from
Nov 19, 2019

Conversation

harryterkelsen
Copy link
Contributor

This adds basic text rendering support using the "SkParagraph" module in Skia.

/// 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>{
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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 '
Copy link
Contributor

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?

Copy link
Contributor Author

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,
]);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@harryterkelsen harryterkelsen merged commit f240462 into flutter:master Nov 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 20, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 20, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 20, 2019
tvolkert pushed a commit to flutter/flutter that referenced this pull request Nov 20, 2019
* 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)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants