-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is my attempt to isolate all the dwrite font related thing by introducing a new layer - `DxFontRenderData`. This will free `DxRenderer` & `CustomTextLayout` from the burden of handling fonts & box effects. The logic is more simplified & streamlined. In short I just moved everything fonts-related into `DxFontRenderData` and started from there. There's no modification to code logic. Just pure structural stuff. SGR support tracking issue: #6879 Initial Italic support PR: #8580
- Loading branch information
1 parent
4c53c59
commit eb34993
Showing
10 changed files
with
928 additions
and
875 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "../../renderer/inc/FontInfoDesired.hpp" | ||
#include "BoxDrawingEffect.h" | ||
|
||
#include <dwrite.h> | ||
#include <dwrite_1.h> | ||
#include <dwrite_2.h> | ||
#include <dwrite_3.h> | ||
|
||
#include <wrl.h> | ||
|
||
namespace Microsoft::Console::Render | ||
{ | ||
class DxFontRenderData | ||
{ | ||
public: | ||
struct LineMetrics | ||
{ | ||
float gridlineWidth; | ||
float underlineOffset; | ||
float underlineOffset2; | ||
float underlineWidth; | ||
float strikethroughOffset; | ||
float strikethroughWidth; | ||
}; | ||
|
||
DxFontRenderData(::Microsoft::WRL::ComPtr<IDWriteFactory1> dwriteFactory) noexcept; | ||
|
||
// DirectWrite text analyzer from the factory | ||
[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextAnalyzer1> Analyzer() noexcept; | ||
|
||
[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFallback> SystemFontFallback(); | ||
|
||
[[nodiscard]] til::size GlyphCell() noexcept; | ||
[[nodiscard]] LineMetrics GetLineMetrics() noexcept; | ||
|
||
// The DirectWrite format object representing the size and other text properties to be applied (by default) | ||
[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextFormat> DefaultTextFormat() noexcept; | ||
|
||
// The DirectWrite font face to use while calculating layout (by default) | ||
[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFace1> DefaultFontFace() noexcept; | ||
|
||
// Box drawing scaling effects that are cached for the base font across layouts | ||
[[nodiscard]] Microsoft::WRL::ComPtr<IBoxDrawingEffect> DefaultBoxDrawingEffect() noexcept; | ||
|
||
// The italic variant of the format object representing the size and other text properties for italic text | ||
[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextFormat> ItalicTextFormat() noexcept; | ||
|
||
// The italic variant of the font face to use while calculating layout for italic text | ||
[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFace1> ItalicFontFace() noexcept; | ||
|
||
[[nodiscard]] HRESULT UpdateFont(const FontInfoDesired& desired, FontInfo& fiFontInfo, const int dpi) noexcept; | ||
|
||
[[nodiscard]] static HRESULT STDMETHODCALLTYPE s_CalculateBoxEffect(IDWriteTextFormat* format, size_t widthPixels, IDWriteFontFace1* face, float fontScale, IBoxDrawingEffect** effect) noexcept; | ||
|
||
private: | ||
[[nodiscard]] ::Microsoft::WRL::ComPtr<IDWriteFontFace1> _ResolveFontFaceWithFallback(std::wstring& familyName, | ||
DWRITE_FONT_WEIGHT& weight, | ||
DWRITE_FONT_STRETCH& stretch, | ||
DWRITE_FONT_STYLE& style, | ||
std::wstring& localeName) const; | ||
|
||
[[nodiscard]] ::Microsoft::WRL::ComPtr<IDWriteFontFace1> _FindFontFace(std::wstring& familyName, | ||
DWRITE_FONT_WEIGHT& weight, | ||
DWRITE_FONT_STRETCH& stretch, | ||
DWRITE_FONT_STYLE& style, | ||
std::wstring& localeName) const; | ||
|
||
[[nodiscard]] std::wstring _GetFontFamilyName(gsl::not_null<IDWriteFontFamily*> const fontFamily, | ||
std::wstring& localeName) const; | ||
|
||
// A locale that can be used on construction of assorted DX objects that want to know one. | ||
[[nodiscard]] std::wstring _GetUserLocaleName(); | ||
|
||
::Microsoft::WRL::ComPtr<IDWriteFactory1> _dwriteFactory; | ||
|
||
::Microsoft::WRL::ComPtr<IDWriteTextAnalyzer1> _dwriteTextAnalyzer; | ||
::Microsoft::WRL::ComPtr<IDWriteTextFormat> _dwriteTextFormat; | ||
::Microsoft::WRL::ComPtr<IDWriteTextFormat> _dwriteTextFormatItalic; | ||
::Microsoft::WRL::ComPtr<IDWriteFontFace1> _dwriteFontFace; | ||
::Microsoft::WRL::ComPtr<IDWriteFontFace1> _dwriteFontFaceItalic; | ||
|
||
::Microsoft::WRL::ComPtr<IBoxDrawingEffect> _boxDrawingEffect; | ||
|
||
::Microsoft::WRL::ComPtr<IDWriteFontFallback> _systemFontFallback; | ||
std::wstring _userLocaleName; | ||
|
||
til::size _glyphCell; | ||
|
||
LineMetrics _lineMetrics; | ||
}; | ||
} |
Oops, something went wrong.