Repository: microsoft/terminal
File: src/renderer/gdi/gdirenderer.hpp (C++)

Code before:
        [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* const pFontSize) noexcept override;
        [[nodiscard]] HRESULT IsGlyphWideByFont(const std::wstring_view glyph, _Out_ bool* const pResult) noexcept override;

    protected:
        [[nodiscard]] HRESULT _DoUpdateTitle(_In_ const std::wstring_view newTitle) noexcept override;

    private:
        HWND _hwndTargetWindow;

        [[nodiscard]] static HRESULT s_SetWindowLongWHelper(const HWND hWnd,
                                                            const int nIndex,
                                                            const LONG dwNewLong) noexcept;

        static bool FontHasWesternScript(HDC hdc);

        bool _fPaintStarted;

        til::rect _invalidCharacters;
        PAINTSTRUCT _psInvalidData;
        HDC _hdcMemoryContext;
        bool _isTrueTypeFont;
        UINT _fontCodepage;
        HFONT _hfont;
        HFONT _hfontBold;
        HFONT _hfontItalic;
        HFONT _hfontBoldItalic;
        TEXTMETRICW _tmFontMetrics;
        FontResource _softFont;

        static const size_t s_cPolyTextCache = 80;
        POLYTEXTW _pPolyText[s_cPolyTextCache];
        size_t _cPolyText;
        [[nodiscard]] HRESULT _FlushBufferLines() noexcept;

        std::vector<RECT> cursorInvertRects;
        XFORM cursorInvertTransform;

        struct LineMetrics
        {
            int gridlineWidth;
            int underlineCenter;
            int underlineWidth;
            int doubleUnderlinePosTop;
            int doubleUnderlinePosBottom;
            int doubleUnderlineWidth;
            int strikethroughOffset;
            int strikethroughWidth;
            int curlyLineCenter;
            int curlyLinePeriod;
            int curlyLineControlPointOffset;
        };

Review comment (suggestion):
I suppose at this point we could consider making this an `HFONT[4]` array so that we can replace things like the DeleteObject code with loops. `FontType` could be changed to map the 4 styles to 0-3.

Code after:
        [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* const pFontSize) noexcept override;
        [[nodiscard]] HRESULT IsGlyphWideByFont(const std::wstring_view glyph, _Out_ bool* const pResult) noexcept override;

    protected:
        [[nodiscard]] HRESULT _DoUpdateTitle(_In_ const std::wstring_view newTitle) noexcept override;

    private:
        HWND _hwndTargetWindow;

        [[nodiscard]] static HRESULT s_SetWindowLongWHelper(const HWND hWnd,
                                                            const int nIndex,
                                                            const LONG dwNewLong) noexcept;

        static bool FontHasWesternScript(HDC hdc);

        bool _fPaintStarted;

        til::rect _invalidCharacters;
        PAINTSTRUCT _psInvalidData;
        HDC _hdcMemoryContext;
        bool _isTrueTypeFont;
        UINT _fontCodepage;

        enum class FontType : uint8_t
        {
            // Indices for _hfonts array below
            Default,
            Bold,
            Italic,
            BoldItalic,

            // The number of fonts in _hfonts array below
            FontCount,

            // Other
            Undefined = FontCount,
            Soft
        };

        std::array<HFONT, static_cast<size_t>(FontType::FontCount)> _hfonts{};

        TEXTMETRICW _tmFontMetrics;
        FontResource _softFont;

        static const size_t s_cPolyTextCache = 80;
        POLYTEXTW _pPolyText[s_cPolyTextCache];
        size_t _cPolyText;
        [[nodiscard]] HRESULT _FlushBufferLines() noexcept;

        std::vector<RECT> cursorInvertRects;
        XFORM cursorInvertTransform;