-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[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
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
[Impeller] libImpeller: Implement APIs for fetching glyph and line me…
…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 #165509
- Loading branch information
commit 5b17a0c964ac459c30228ea903fb28a5b3f224ff
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "impeller/toolkit/interop/glyph_info.h" | ||
|
|
||
| namespace impeller::interop { | ||
|
|
||
| GlyphInfo::~GlyphInfo() = default; | ||
|
|
||
| size_t GlyphInfo::GetGraphemeClusterCodeUnitRangeBegin() const { | ||
| return info_.fGraphemeClusterTextRange.start; | ||
| } | ||
|
|
||
| size_t GlyphInfo::GetGraphemeClusterCodeUnitRangeEnd() const { | ||
| return info_.fGraphemeClusterTextRange.end; | ||
| } | ||
|
|
||
| ImpellerRect GlyphInfo::GetGraphemeClusterBounds() const { | ||
| return ImpellerRect{ | ||
| info_.fGraphemeLayoutBounds.y(), | ||
| info_.fGraphemeLayoutBounds.x(), | ||
| info_.fGraphemeLayoutBounds.width(), | ||
| info_.fGraphemeLayoutBounds.height(), | ||
| }; | ||
| } | ||
|
|
||
| bool GlyphInfo::IsEllipsis() const { | ||
| return info_.fIsEllipsis; | ||
| } | ||
|
|
||
| ImpellerTextDirection GlyphInfo::GetTextDirection() const { | ||
| switch (info_.fDirection) { | ||
| case skia::textlayout::TextDirection::kRtl: | ||
| return kImpellerTextDirectionRTL; | ||
| case skia::textlayout::TextDirection::kLtr: | ||
| return kImpellerTextDirectionLTR; | ||
| } | ||
| return kImpellerTextDirectionLTR; | ||
| } | ||
|
|
||
| } // namespace impeller::interop |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_IMPELLER_TOOLKIT_INTEROP_GLYPH_INFO_H_ | ||
| #define FLUTTER_IMPELLER_TOOLKIT_INTEROP_GLYPH_INFO_H_ | ||
|
|
||
| #include "flutter/third_party/skia/modules/skparagraph/include/Paragraph.h" | ||
| #include "impeller/toolkit/interop/impeller.h" | ||
| #include "impeller/toolkit/interop/object.h" | ||
|
|
||
| namespace impeller::interop { | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| /// @brief Internal C++ peer of ImpellerGlyphInfo. For detailed | ||
| /// documentation, refer to the headerdocs in the public API in | ||
| /// impeller.h. | ||
| /// | ||
| class GlyphInfo final | ||
| : public Object<GlyphInfo, | ||
| IMPELLER_INTERNAL_HANDLE_NAME(ImpellerGlyphInfo)> { | ||
| public: | ||
| GlyphInfo(skia::textlayout::Paragraph::GlyphInfo info) | ||
| : info_(std::move(info)) {} | ||
|
|
||
| ~GlyphInfo(); | ||
|
|
||
| GlyphInfo(const GlyphInfo&) = delete; | ||
|
|
||
| GlyphInfo& operator=(const GlyphInfo&) = delete; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @see ImpellerGlpyhInfoGetGraphemeClusterCodeUnitRangeBegin. | ||
| /// | ||
| size_t GetGraphemeClusterCodeUnitRangeBegin() const; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @see ImpellerGlpyhInfoGetGraphemeClusterCodeUnitRangeEnd. | ||
| /// | ||
| size_t GetGraphemeClusterCodeUnitRangeEnd() const; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @see ImpellerGlpyhInfoGetGraphemeClusterBounds. | ||
| /// | ||
| ImpellerRect GetGraphemeClusterBounds() const; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @see ImpellerGlyphInfoIsEllipsis. | ||
| /// | ||
| bool IsEllipsis() const; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @see ImpellerGlyphInfoGetTextDirection. | ||
| /// | ||
| ImpellerTextDirection GetTextDirection() const; | ||
|
|
||
| private: | ||
| const skia::textlayout::Paragraph::GlyphInfo info_; | ||
| }; | ||
|
|
||
| } // namespace impeller::interop | ||
|
|
||
| #endif // FLUTTER_IMPELLER_TOOLKIT_INTEROP_GLYPH_INFO_H_ | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.