Skip to content

Commit

Permalink
Reduce CPU usage when font fallback in not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
skyline75489 committed Oct 2, 2019
1 parent abf3ee5 commit e566a4a
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/renderer/dx/CustomTextLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,30 @@ CustomTextLayout::CustomTextLayout(gsl::not_null<IDWriteFactory1*> const factory
// Allocate enough room to have one breakpoint per code unit.
_breakpoints.resize(_text.size());

// Call each of the analyzers in sequence, recording their results.
RETURN_IF_FAILED(_analyzer->AnalyzeLineBreakpoints(this, 0, textLength, this));
RETURN_IF_FAILED(_analyzer->AnalyzeBidi(this, 0, textLength, this));
RETURN_IF_FAILED(_analyzer->AnalyzeScript(this, 0, textLength, this));
RETURN_IF_FAILED(_analyzer->AnalyzeNumberSubstitution(this, 0, textLength, this));
// Perform our custom font fallback analyzer that mimics the pattern of the real analyzers.
RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength));
const bool whiteSpacesOnly = std::all_of(
_text.begin(), _text.end(), [](wchar_t c) noexcept {
return iswspace(c);
});

if (!whiteSpacesOnly)
{
// Call each of the analyzers in sequence, recording their results.
RETURN_IF_FAILED(_analyzer->AnalyzeLineBreakpoints(this, 0, textLength, this));
RETURN_IF_FAILED(_analyzer->AnalyzeBidi(this, 0, textLength, this));
RETURN_IF_FAILED(_analyzer->AnalyzeScript(this, 0, textLength, this));
RETURN_IF_FAILED(_analyzer->AnalyzeNumberSubstitution(this, 0, textLength, this));

const bool asciiOnly = std::all_of(
_text.begin(), _text.end(), [](wchar_t c) noexcept {
return iswascii(c);
});

if (!asciiOnly)
{
// Perform our custom font fallback analyzer that mimics the pattern of the real analyzers.
RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength));
}
}

// Ensure that a font face is attached to every run
for (auto& run : _runs)
Expand Down

0 comments on commit e566a4a

Please sign in to comment.