Skip to content

[Impeller] libImpeller: Implement APIs for fetching glyph and line metrics. #165701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2025

Conversation

chinmaygarde
Copy link
Member

This patch adds support in the typography subsystem of the public Impeller API such that users can implement text editing functionality.

  • Line metrics for a fully laid out paragraph can be retrieved. The metrics contain information about offsets into the original code unit buffer used to create the paragraph. These offsets can be used to implement functionality that edits whole lines.
  • Glyph information for a specific code unit offset, as well as a coordinate offset relative to the paragraph origin, can be obtained. This information can be used place decorations (like carets), select words surrounding the caret (a hit-test), and edit the source buffer to re-layout the paragraph.
  • Word boundaries (as specified in Unicode Standard Annex 29) can be retrieved to select and modify paragraph subsets by character, word, and line at caret.

Like in Flutter, the code unit buffers are assumed to be arrays of UTF-16 bytes. I'd have preferred this to be UTF-8 because the initial paragraph construction is using UTF-8 bytes. Also, Skia internally seems to work with UTF-8 too but the interfaces are exposed using UTF-16 (presumably for users like Flutter that work with Dart strings that are UTF-16). Exposing additional APIs in txt::Paragraph to back this out seemed onerous. Instead, a UTF-16 assumption for all APIs that retrieve metrics is made (and documented). It stands to reason that paragraphs should be constructable using UTF-16 buffers in the public API too. I'll add that in a subsequent patch as that has little to do with metrics.

Fixes #165509

…trics.

This patch adds support in the typography subsystem of the public
Impeller API such that users can implement text editing functionality.

* Line metrics for a fully laid out paragraph can be retrieved. The
  metrics contain information about offsets into the original code unit
  buffer used to create the paragraph. These offsets can be used to
  implement functionality that edits whole lines.
* Glyph information for a specific code unit offset, as well as a
  coordinate offset relative to the paragraph origin, can be obtained.
  This information can be used place decorations (like carets), select
  words surrounding the caret (a hit-test), and edit the source buffer
  to re-layout the paragraph.
* Word boundaries (as specified in Unicode Standard Annex 29) can be
  retrieved to select and modify paragraph subsets by character, word,
  and line at caret.

Like in Flutter, the code unit buffers are assumed to be arrays of
UTF-16 bytes. I'd have preferred this to be UTF-8 because the initial
paragraph construction is using UTF-8 bytes. Also, Skia internally seems
to work with UTF-8 too but the interfaces are exposed using UTF-16
(presumably for users like Flutter that work with Dart strings that are
UTF-16). Exposing additional APIs in txt::Paragraph to back this out
seemed onerous. Instead, a UTF-16 assumption for all APIs that retrieve
metrics is made (and documented). It stands to reason that paragraphs
should be constructable using UTF-16 buffers in the public API too. I'll
add that in a subsequent patch as that has little to do with metrics.

Fixes flutter#165509
@github-actions github-actions bot added engine flutter/engine repository. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Mar 21, 2025
@chinmaygarde chinmaygarde added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 25, 2025
Copy link
Contributor

auto-submit bot commented Mar 25, 2025

autosubmit label was removed for flutter/flutter/165701, because - The status or check suite Linux linux_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 25, 2025
@chinmaygarde chinmaygarde added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 25, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 25, 2025
Copy link
Contributor

auto-submit bot commented Mar 25, 2025

autosubmit label was removed for flutter/flutter/165701, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@chinmaygarde chinmaygarde added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 26, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Mar 26, 2025
Merged via the queue into flutter:master with commit 39103d9 Mar 26, 2025
174 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 26, 2025
@chinmaygarde chinmaygarde deleted the textmetrics branch March 26, 2025 19:40
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e: impeller Impeller rendering backend issues and features requests engine flutter/engine repository. See also e: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Impeller] libImpeller: Expose LineMetrics and GetGlyphInfoAt APIs on Paragraph.
2 participants