-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Skip glyph shaping analysis when the entire text is simple #6206
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ca454f
Skip glyph shaping analysis when the entire text is simple
skyline75489 fa789b3
Resolve comments
skyline75489 4443652
Oh Mr.Static
skyline75489 73ac330
Merge branch 'master' of https://github.com/microsoft/terminal into f…
skyline75489 5b2d4cb
Resolve comments
skyline75489 b450173
Static
skyline75489 5046746
Format
skyline75489 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 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 |
---|---|---|
|
@@ -63,6 +63,19 @@ CustomTextLayout::CustomTextLayout(gsl::not_null<IDWriteFactory1*> const factory | |
|
||
_text += text; | ||
} | ||
|
||
const auto textLength = gsl::narrow<UINT32>(_text.size()); | ||
|
||
BOOL isTextSimple = FALSE; | ||
UINT32 uiLengthRead = 0; | ||
UINT32 glyphStart = 0; | ||
|
||
HRESULT hr = S_OK; | ||
|
||
_glyphIndices.resize(textLength); | ||
|
||
hr = _analyzer->GetTextComplexity(_text.c_str(), textLength, _font.Get(), &isTextSimple, &uiLengthRead, &_glyphIndices.at(glyphStart)); | ||
_isEntireTextSimple = isTextSimple && uiLengthRead == textLength; | ||
} | ||
|
||
// Routine Description: | ||
|
@@ -149,11 +162,7 @@ CustomTextLayout::CustomTextLayout(gsl::not_null<IDWriteFactory1*> const factory | |
// Allocate enough room to have one breakpoint per code unit. | ||
_breakpoints.resize(_text.size()); | ||
|
||
BOOL isTextSimple = FALSE; | ||
UINT32 uiLengthRead = 0; | ||
RETURN_IF_FAILED(_analyzer->GetTextComplexity(_text.c_str(), textLength, _font.Get(), &isTextSimple, &uiLengthRead, NULL)); | ||
|
||
if (!(isTextSimple && uiLengthRead == _text.size())) | ||
if (!_isEntireTextSimple) | ||
{ | ||
// Call each of the analyzers in sequence, recording their results. | ||
RETURN_IF_FAILED(_analyzer->AnalyzeLineBreakpoints(this, 0, textLength, this)); | ||
|
@@ -274,6 +283,39 @@ CustomTextLayout::CustomTextLayout(gsl::not_null<IDWriteFactory1*> const factory | |
_glyphIndices.resize(totalGlyphsArrayCount); | ||
} | ||
|
||
if (_isEntireTextSimple) | ||
{ | ||
// When the entire text is simple, we can skip GetGlyphs and directly retrieve glyph indices and | ||
// advances(in font design unit). With the help of font metrics, we can calculate the actual glyph | ||
// advances without the need of GetGlyphPlacements. This shortcut will significantly reduce the time | ||
// needed for text analysis. | ||
DWRITE_FONT_METRICS1 metrics; | ||
run.fontFace->GetMetrics(&metrics); | ||
|
||
// With simple text, there's only one run. The actual glyph count is the same as textLength. | ||
_glyphDesignUnitAdvances.resize(textLength); | ||
_glyphAdvances.resize(textLength); | ||
_glyphOffsets.resize(textLength); | ||
|
||
USHORT designUnitsPerEm = metrics.designUnitsPerEm; | ||
|
||
RETURN_IF_FAILED(_font->GetDesignGlyphAdvances( | ||
textLength, | ||
&_glyphIndices.at(glyphStart), | ||
&_glyphDesignUnitAdvances.at(glyphStart), | ||
run.isSideways)); | ||
|
||
for (size_t i = glyphStart; i < _glyphAdvances.size(); i++) | ||
{ | ||
_glyphAdvances.at(i) = (float)_glyphDesignUnitAdvances.at(i) / designUnitsPerEm * _format->GetFontSize() * run.fontScale; | ||
} | ||
|
||
run.glyphCount = textLength; | ||
glyphStart += textLength; | ||
|
||
return S_OK; | ||
} | ||
|
||
miniksa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::vector<DWRITE_SHAPING_TEXT_PROPERTIES> textProps(textLength); | ||
std::vector<DWRITE_SHAPING_GLYPH_PROPERTIES> glyphProps(maxGlyphCount); | ||
|
||
|
@@ -369,6 +411,11 @@ CustomTextLayout::CustomTextLayout(gsl::not_null<IDWriteFactory1*> const factory | |
// - S_OK or suitable DirectWrite or STL error code | ||
[[nodiscard]] HRESULT CustomTextLayout::_CorrectGlyphRuns() noexcept | ||
{ | ||
if (_isEntireTextSimple) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave a comment why this is OK. |
||
{ | ||
return S_OK; | ||
} | ||
|
||
try | ||
{ | ||
// Correct each run separately. This is needed whenever script, locale, | ||
|
@@ -508,9 +555,6 @@ try | |
|
||
// We're going to walk through and check for advances that don't match the space that we expect to give out. | ||
|
||
DWRITE_FONT_METRICS1 metrics; | ||
miniksa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
run.fontFace->GetMetrics(&metrics); | ||
|
||
// Glyph Indices represents the number inside the selected font where the glyph image/paths are found. | ||
// Text represents the original text we gave in. | ||
// Glyph Clusters represents the map between Text and Glyph Indices. | ||
|
This file contains 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
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'm not sure how to handle the HR faliure 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.
Maybe we'd want to do a
SUCCEEDED(hr) && isTextSimple && uiLengthRead == textLength
in the line below?