Skip to content
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

Introduce DxFontInfo #9201

Merged
21 commits merged into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Collaborator Author

@skyline75489 skyline75489 May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some consideration I decided to refactor this using std::unordered_map, which makes it super easy to add new attributed font. This is how bold is done:

if (drawingContext->useBoldFont)
{
    // TODO: "relative" bold?
    weight = DWRITE_FONT_WEIGHT_BOLD;
}

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

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is really close to @DHowett 's vision in #8580 (comment), if I understand it correctly.

_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()
skyline75489 marked this conversation as resolved.
Show resolved Hide resolved

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