This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Custom RTL handling for ghost runs, NotoNaskhArabic test font #8638
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bc6e45e
Custom RTL handling for ghost runs
GaryQian 34a9c86
New ghost run algo
GaryQian 1d1fcdf
Cleanup
GaryQian 25d0a01
Refactor line_runs generation.
GaryQian 63fe76f
refactor ghost run advance calculation
GaryQian 2971df2
Comments fix
GaryQian d3128ed
Comments fix
GaryQian 3b7ed0a
Remove unused var
GaryQian 3f3d689
reorder ghost offset, comments to explain.
GaryQian 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,14 +17,15 @@ | |
| #include "paragraph.h" | ||
|
|
||
| #include <hb.h> | ||
| #include <minikin/Layout.h> | ||
|
|
||
| #include <algorithm> | ||
| #include <limits> | ||
| #include <map> | ||
| #include <numeric> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include <minikin/Layout.h> | ||
| #include "flutter/fml/logging.h" | ||
| #include "font_collection.h" | ||
| #include "font_skia.h" | ||
|
|
@@ -34,9 +35,6 @@ | |
| #include "minikin/LayoutUtils.h" | ||
| #include "minikin/LineBreaker.h" | ||
| #include "minikin/MinikinFont.h" | ||
| #include "unicode/ubidi.h" | ||
| #include "unicode/utf16.h" | ||
|
|
||
| #include "third_party/skia/include/core/SkCanvas.h" | ||
| #include "third_party/skia/include/core/SkFont.h" | ||
| #include "third_party/skia/include/core/SkFontMetrics.h" | ||
|
|
@@ -46,6 +44,8 @@ | |
| #include "third_party/skia/include/core/SkTypeface.h" | ||
| #include "third_party/skia/include/effects/SkDashPathEffect.h" | ||
| #include "third_party/skia/include/effects/SkDiscretePathEffect.h" | ||
| #include "unicode/ubidi.h" | ||
| #include "unicode/utf16.h" | ||
|
|
||
| namespace txt { | ||
| namespace { | ||
|
|
@@ -549,6 +549,19 @@ void Paragraph::Layout(double width, bool force) { | |
| ? line_range.end_excluding_whitespace | ||
| : line_range.end; | ||
|
|
||
| // Build a map of styled runs indexed by start position to TextDirection. | ||
| // Once the direction of a non-ghost line run has been established for the | ||
| // styled run, we will enforce that the ghost run use the direction of the | ||
| // most recently seen bidi run that is part of the styled run. This is to | ||
| // ensure that default-LTR whitespace gets the proper directionality when | ||
| // used in a RTL run. | ||
| std::map<size_t, TextDirection> styled_run_direction_map; | ||
| for (size_t i = 0; i < runs_.size(); ++i) { | ||
| StyledRuns::Run run = runs_.GetRun(i); | ||
| // Initialize TextDirection to LTR as that is what ICU initializes it to. | ||
| styled_run_direction_map.emplace( | ||
| std::make_pair(run.start, TextDirection::ltr)); | ||
| } | ||
| // Find the runs comprising this line. | ||
| std::vector<BidiRun> line_runs; | ||
| for (const BidiRun& bidi_run : bidi_runs) { | ||
|
|
@@ -557,6 +570,11 @@ void Paragraph::Layout(double width, bool force) { | |
| line_runs.emplace_back(std::max(bidi_run.start(), line_range.start), | ||
| std::min(bidi_run.end(), line_end_index), | ||
| bidi_run.direction(), bidi_run.style()); | ||
| // Track the the most recently used text direction for the styled run. | ||
| styled_run_direction_map[styled_run_direction_map | ||
| .lower_bound(std::max(bidi_run.start(), | ||
| line_range.start)) | ||
| ->first] = bidi_run.direction(); | ||
| } | ||
| // A "ghost" run is a run that does not impact the layout, breaking, | ||
| // alignment, width, etc but is still "visible" though getRectsForRange. | ||
|
|
@@ -571,9 +589,15 @@ void Paragraph::Layout(double width, bool force) { | |
| line_range.end_excluding_whitespace < line_range.end && | ||
| bidi_run.start() <= line_range.end && | ||
| bidi_run.end() > line_end_index) { | ||
| // Use the most recent TextDirection instead of the defaulted LTR value | ||
|
||
| // ICU provides. | ||
| TextDirection run_direction = styled_run_direction_map | ||
| [styled_run_direction_map | ||
| .lower_bound(std::max(bidi_run.start(), line_range.start)) | ||
| ->first]; | ||
| line_runs.emplace_back(std::max(bidi_run.start(), line_end_index), | ||
| std::min(bidi_run.end(), line_range.end), | ||
| bidi_run.direction(), bidi_run.style(), true); | ||
| run_direction, bidi_run.style(), true); | ||
| } | ||
| } | ||
| bool line_runs_all_rtl = | ||
|
|
@@ -808,12 +832,25 @@ void Paragraph::Layout(double width, bool force) { | |
| [](const GlyphPosition& a, const GlyphPosition& b) { | ||
| return a.code_units.start < b.code_units.start; | ||
| }); | ||
| line_code_unit_runs.emplace_back( | ||
| std::move(code_unit_positions), | ||
| Range<size_t>(run.start(), run.end()), | ||
| Range<double>(glyph_positions.front().x_pos.start, | ||
| glyph_positions.back().x_pos.end), | ||
| line_number, metrics, run.direction()); | ||
| if (!(run.is_ghost() && run.is_rtl())) { | ||
| line_code_unit_runs.emplace_back( | ||
| std::move(code_unit_positions), | ||
| Range<size_t>(run.start(), run.end()), | ||
| Range<double>(glyph_positions.front().x_pos.start, | ||
| glyph_positions.back().x_pos.end), | ||
| line_number, metrics, run.direction()); | ||
| } else { | ||
| // We custom handle ghost run for RTL as ICU interprets trailing | ||
| // whitespace as LTR, which causes trailing space to appear at the | ||
| // right side instead of the (correct) left side. Here, we manually | ||
| // add the equivalent width to the left side instead. | ||
| line_code_unit_runs.emplace_back( | ||
| std::move(code_unit_positions), | ||
| Range<size_t>(run.start(), run.end()), | ||
| Range<double>(run_x_offset - glyph_positions.back().x_pos.start, | ||
| run_x_offset - glyph_positions.back().x_pos.end), | ||
| line_number, metrics, run.direction()); | ||
| } | ||
|
|
||
| min_left_ = std::min(min_left_, glyph_positions.front().x_pos.start); | ||
| max_right_ = std::max(max_right_, glyph_positions.back().x_pos.end); | ||
|
|
||
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
92 changes: 92 additions & 0 deletions
92
third_party/txt/third_party/fonts/NotoNaskhArabic-LICENSE.txt
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,92 @@ | ||
| This Font Software is licensed under the SIL Open Font License, | ||
| Version 1.1. | ||
|
|
||
| This license is copied below, and is also available with a FAQ at: | ||
| http://scripts.sil.org/OFL | ||
|
|
||
| ----------------------------------------------------------- | ||
| SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 | ||
| ----------------------------------------------------------- | ||
|
|
||
| PREAMBLE | ||
| The goals of the Open Font License (OFL) are to stimulate worldwide | ||
| development of collaborative font projects, to support the font | ||
| creation efforts of academic and linguistic communities, and to | ||
| provide a free and open framework in which fonts may be shared and | ||
| improved in partnership with others. | ||
|
|
||
| The OFL allows the licensed fonts to be used, studied, modified and | ||
| redistributed freely as long as they are not sold by themselves. The | ||
| fonts, including any derivative works, can be bundled, embedded, | ||
| redistributed and/or sold with any software provided that any reserved | ||
| names are not used by derivative works. The fonts and derivatives, | ||
| however, cannot be released under any other type of license. The | ||
| requirement for fonts to remain under this license does not apply to | ||
| any document created using the fonts or their derivatives. | ||
|
|
||
| DEFINITIONS | ||
| "Font Software" refers to the set of files released by the Copyright | ||
| Holder(s) under this license and clearly marked as such. This may | ||
| include source files, build scripts and documentation. | ||
|
|
||
| "Reserved Font Name" refers to any names specified as such after the | ||
| copyright statement(s). | ||
|
|
||
| "Original Version" refers to the collection of Font Software | ||
| components as distributed by the Copyright Holder(s). | ||
|
|
||
| "Modified Version" refers to any derivative made by adding to, | ||
| deleting, or substituting -- in part or in whole -- any of the | ||
| components of the Original Version, by changing formats or by porting | ||
| the Font Software to a new environment. | ||
|
|
||
| "Author" refers to any designer, engineer, programmer, technical | ||
| writer or other person who contributed to the Font Software. | ||
|
|
||
| PERMISSION & CONDITIONS | ||
| Permission is hereby granted, free of charge, to any person obtaining | ||
| a copy of the Font Software, to use, study, copy, merge, embed, | ||
| modify, redistribute, and sell modified and unmodified copies of the | ||
| Font Software, subject to the following conditions: | ||
|
|
||
| 1) Neither the Font Software nor any of its individual components, in | ||
| Original or Modified Versions, may be sold by itself. | ||
|
|
||
| 2) Original or Modified Versions of the Font Software may be bundled, | ||
| redistributed and/or sold with any software, provided that each copy | ||
| contains the above copyright notice and this license. These can be | ||
| included either as stand-alone text files, human-readable headers or | ||
| in the appropriate machine-readable metadata fields within text or | ||
| binary files as long as those fields can be easily viewed by the user. | ||
|
|
||
| 3) No Modified Version of the Font Software may use the Reserved Font | ||
| Name(s) unless explicit written permission is granted by the | ||
| corresponding Copyright Holder. This restriction only applies to the | ||
| primary font name as presented to the users. | ||
|
|
||
| 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font | ||
| Software shall not be used to promote, endorse or advertise any | ||
| Modified Version, except to acknowledge the contribution(s) of the | ||
| Copyright Holder(s) and the Author(s) or with their explicit written | ||
| permission. | ||
|
|
||
| 5) The Font Software, modified or unmodified, in part or in whole, | ||
| must be distributed entirely under this license, and must not be | ||
| distributed under any other license. The requirement for fonts to | ||
| remain under this license does not apply to any document created using | ||
| the Font Software. | ||
|
|
||
| TERMINATION | ||
| This license becomes null and void if any of the above conditions are | ||
| not met. | ||
|
|
||
| DISCLAIMER | ||
| THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
| OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
| COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
| DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM | ||
| OTHER DEALINGS IN THE FONT SOFTWARE. |
Binary file not shown.
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.
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.
I don't think the emplace adds much value here as the enum value is not expensive to copy.