-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 DxFontRenderData #9096
Merged
16 commits merged into
microsoft:main
from
skyline75489:chesterliu/dev/font-render-data
Feb 18, 2021
Merged
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bc6ab94
Initialize IFontRenderData & DxFontRenderData
skyline75489 1440ae7
vcxprojc
skyline75489 ba43e8c
Refactor
skyline75489 9a7413e
Feedback
skyline75489 5b65094
Format
skyline75489 c9a43be
Unused
skyline75489 36e7463
Feedback
skyline75489 d651886
Merge branch 'main' into chesterliu/dev/font-render-data
skyline75489 3a44c44
Fix locale name
skyline75489 149951b
Hide UserLocaleName
skyline75489 11ecfa6
Clean
skyline75489 d414f1e
Format
skyline75489 6e2debb
Feedback
skyline75489 e7b7550
Merge branch 'main' into chesterliu/dev/font-render-data
skyline75489 8521023
Naming
skyline75489 afba98d
Damn, what is it..
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
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(); | ||
|
||
// A locale that can be used on construction of assorted DX objects that want to know one. | ||
[[nodiscard]] std::wstring UserLocaleName(); | ||
|
||
[[nodiscard]] til::size GlyphCell() noexcept; | ||
[[nodiscard]] LineMetrics GetLineMetrics() noexcept; | ||
skyline75489 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// The DirectWrite format object representing the size and other text properties to be applied (by default) | ||
[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextFormat> DefaultTextFormat() noexcept; | ||
skyline75489 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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; | ||
|
||
::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.
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.
If you’re wondering why this is modified, originally I added an “interface” class here but then found it useless. VS modified the line ending anyway
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.
Since this is the only change in the file, would you mind reverting it?
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.
Sure. Will do
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.
It took a while for me to realize I'm actually changing the LF here to CRLF, to make it 'correct'. Do you still want me to revert this?...
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.
Oh. Since this makes it correct, you can keep it.