Skip to content

Commit

Permalink
Introduce DxFontInfo (#9201)
Browse files Browse the repository at this point in the history
This PR Introduces `DxFontInfo` to simplify the logic in
`DxFontRenderData`. 

`DxFontInfo` aims to be the DWrite equivalent of `FontInfo` &
`FontInfoBase` in GDI. It encapsulates the needed information to
represent a displayable font face. It also provides the ability to
resolve a font face based on the available fonts on the system.

## References

This is a follow-up of #9096.
Initial Italic support was introduced by #8580.

The motivation behind this is to support bold & bold-italic text in
Windows Terminal.
  • Loading branch information
skyline75489 authored Jun 22, 2021
1 parent 1b79cc8 commit 85c485e
Show file tree
Hide file tree
Showing 7 changed files with 864 additions and 595 deletions.
16 changes: 14 additions & 2 deletions src/renderer/dx/CustomTextLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,21 @@ CATCH_RETURN()
_In_ IDWriteTextRenderer* renderer,
FLOAT originX,
FLOAT originY) noexcept
try
{
const auto drawingContext = static_cast<const DrawingContext*>(clientDrawingContext);
_formatInUse = drawingContext->useItalicFont ? _fontRenderData->ItalicTextFormat().Get() : _fontRenderData->DefaultTextFormat().Get();
_fontInUse = drawingContext->useItalicFont ? _fontRenderData->ItalicFontFace().Get() : _fontRenderData->DefaultFontFace().Get();

const DWRITE_FONT_WEIGHT weight = _fontRenderData->DefaultFontWeight();
DWRITE_FONT_STYLE style = _fontRenderData->DefaultFontStyle();
const DWRITE_FONT_STRETCH stretch = _fontRenderData->DefaultFontStretch();

if (drawingContext->useItalicFont)
{
style = DWRITE_FONT_STYLE_ITALIC;
}

_formatInUse = _fontRenderData->TextFormatWithAttribute(weight, style, stretch).Get();
_fontInUse = _fontRenderData->FontFaceWithAttribute(weight, style, stretch).Get();

RETURN_IF_FAILED(_AnalyzeTextComplexity());
RETURN_IF_FAILED(_AnalyzeRuns());
Expand All @@ -151,6 +162,7 @@ CATCH_RETURN()

return S_OK;
}
CATCH_RETURN()

// Routine Description:
// - Uses the internal text information and the analyzers/font information from construction
Expand Down
Loading

0 comments on commit 85c485e

Please sign in to comment.