|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include "../../renderer/inc/FontInfoDesired.hpp" |
| 7 | +#include "BoxDrawingEffect.h" |
| 8 | + |
| 9 | +#include <dwrite.h> |
| 10 | +#include <dwrite_1.h> |
| 11 | +#include <dwrite_2.h> |
| 12 | +#include <dwrite_3.h> |
| 13 | + |
| 14 | +#include <wrl.h> |
| 15 | + |
| 16 | +namespace Microsoft::Console::Render |
| 17 | +{ |
| 18 | + class DxFontRenderData |
| 19 | + { |
| 20 | + public: |
| 21 | + struct LineMetrics |
| 22 | + { |
| 23 | + float gridlineWidth; |
| 24 | + float underlineOffset; |
| 25 | + float underlineOffset2; |
| 26 | + float underlineWidth; |
| 27 | + float strikethroughOffset; |
| 28 | + float strikethroughWidth; |
| 29 | + }; |
| 30 | + |
| 31 | + DxFontRenderData(::Microsoft::WRL::ComPtr<IDWriteFactory1> dwriteFactory) noexcept; |
| 32 | + |
| 33 | + // DirectWrite text analyzer from the factory |
| 34 | + [[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextAnalyzer1> Analyzer() noexcept; |
| 35 | + |
| 36 | + [[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFallback> SystemFontFallback(); |
| 37 | + |
| 38 | + [[nodiscard]] til::size GlyphCell() noexcept; |
| 39 | + [[nodiscard]] LineMetrics GetLineMetrics() noexcept; |
| 40 | + |
| 41 | + // The DirectWrite format object representing the size and other text properties to be applied (by default) |
| 42 | + [[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextFormat> DefaultTextFormat() noexcept; |
| 43 | + |
| 44 | + // The DirectWrite font face to use while calculating layout (by default) |
| 45 | + [[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFace1> DefaultFontFace() noexcept; |
| 46 | + |
| 47 | + // Box drawing scaling effects that are cached for the base font across layouts |
| 48 | + [[nodiscard]] Microsoft::WRL::ComPtr<IBoxDrawingEffect> DefaultBoxDrawingEffect() noexcept; |
| 49 | + |
| 50 | + // The italic variant of the format object representing the size and other text properties for italic text |
| 51 | + [[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextFormat> ItalicTextFormat() noexcept; |
| 52 | + |
| 53 | + // The italic variant of the font face to use while calculating layout for italic text |
| 54 | + [[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFace1> ItalicFontFace() noexcept; |
| 55 | + |
| 56 | + [[nodiscard]] HRESULT UpdateFont(const FontInfoDesired& desired, FontInfo& fiFontInfo, const int dpi) noexcept; |
| 57 | + |
| 58 | + [[nodiscard]] static HRESULT STDMETHODCALLTYPE s_CalculateBoxEffect(IDWriteTextFormat* format, size_t widthPixels, IDWriteFontFace1* face, float fontScale, IBoxDrawingEffect** effect) noexcept; |
| 59 | + |
| 60 | + private: |
| 61 | + [[nodiscard]] ::Microsoft::WRL::ComPtr<IDWriteFontFace1> _ResolveFontFaceWithFallback(std::wstring& familyName, |
| 62 | + DWRITE_FONT_WEIGHT& weight, |
| 63 | + DWRITE_FONT_STRETCH& stretch, |
| 64 | + DWRITE_FONT_STYLE& style, |
| 65 | + std::wstring& localeName) const; |
| 66 | + |
| 67 | + [[nodiscard]] ::Microsoft::WRL::ComPtr<IDWriteFontFace1> _FindFontFace(std::wstring& familyName, |
| 68 | + DWRITE_FONT_WEIGHT& weight, |
| 69 | + DWRITE_FONT_STRETCH& stretch, |
| 70 | + DWRITE_FONT_STYLE& style, |
| 71 | + std::wstring& localeName) const; |
| 72 | + |
| 73 | + [[nodiscard]] std::wstring _GetFontFamilyName(gsl::not_null<IDWriteFontFamily*> const fontFamily, |
| 74 | + std::wstring& localeName) const; |
| 75 | + |
| 76 | + // A locale that can be used on construction of assorted DX objects that want to know one. |
| 77 | + [[nodiscard]] std::wstring _GetUserLocaleName(); |
| 78 | + |
| 79 | + ::Microsoft::WRL::ComPtr<IDWriteFactory1> _dwriteFactory; |
| 80 | + |
| 81 | + ::Microsoft::WRL::ComPtr<IDWriteTextAnalyzer1> _dwriteTextAnalyzer; |
| 82 | + ::Microsoft::WRL::ComPtr<IDWriteTextFormat> _dwriteTextFormat; |
| 83 | + ::Microsoft::WRL::ComPtr<IDWriteTextFormat> _dwriteTextFormatItalic; |
| 84 | + ::Microsoft::WRL::ComPtr<IDWriteFontFace1> _dwriteFontFace; |
| 85 | + ::Microsoft::WRL::ComPtr<IDWriteFontFace1> _dwriteFontFaceItalic; |
| 86 | + |
| 87 | + ::Microsoft::WRL::ComPtr<IBoxDrawingEffect> _boxDrawingEffect; |
| 88 | + |
| 89 | + ::Microsoft::WRL::ComPtr<IDWriteFontFallback> _systemFontFallback; |
| 90 | + std::wstring _userLocaleName; |
| 91 | + |
| 92 | + til::size _glyphCell; |
| 93 | + |
| 94 | + LineMetrics _lineMetrics; |
| 95 | + }; |
| 96 | +} |
0 commit comments