terminal/src/renderer/inc/FontInfoBase.hpp
Leonard Hecker 95cc7d9625
Add noexcept to all FontInfo structs (#11640)
FontInfoBase and it's descendents are missing noexcept annotations, which
virally forces other code to not be noexcept as well during AuditMode checks.
Apart from adding noexcept, this commit also
* Passes std::wstring_view by reference.
* Pass the FillLegacyNameBuffer argument as a simple pointer-to-array,
  allowing us to fill the buffer with a single memcpy.
  (gsl::span's iterators inhibit any internal STL optimizations.)
* Move operator== declarations inside the class to reduce code size.

All other changes are an effect of the virality of noexcept.

This is an offshoot from #11623.

## Validation Steps Performed
* It still compiles ✔️
2021-10-29 14:08:41 +00:00

63 lines
2 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- FontInfoBase.hpp
Abstract:
- This serves as the structure defining font information.
- FontInfoBase - the base class that holds the font's GDI's LOGFONT
lfFaceName, lfWeight and lfPitchAndFamily, as well as the code page
to use for WideCharToMultiByte and font name.
Author(s):
- Michael Niksa (MiNiksa) 17-Nov-2015
--*/
#pragma once
#include "IFontDefaultList.hpp"
static constexpr wchar_t DEFAULT_TT_FONT_FACENAME[]{ L"__DefaultTTFont__" };
static constexpr wchar_t DEFAULT_RASTER_FONT_FACENAME[]{ L"Terminal" };
class FontInfoBase
{
public:
FontInfoBase(const std::wstring_view& faceName,
const unsigned char family,
const unsigned int weight,
const bool fSetDefaultRasterFont,
const unsigned int uiCodePage) noexcept;
bool operator==(const FontInfoBase& other) noexcept;
unsigned char GetFamily() const noexcept;
unsigned int GetWeight() const noexcept;
const std::wstring& GetFaceName() const noexcept;
unsigned int GetCodePage() const noexcept;
void FillLegacyNameBuffer(wchar_t (&buffer)[LF_FACESIZE]) const noexcept;
bool IsTrueTypeFont() const noexcept;
void SetFromEngine(const std::wstring_view& faceName,
const unsigned char family,
const unsigned int weight,
const bool fSetDefaultRasterFont) noexcept;
bool WasDefaultRasterSetFromEngine() const noexcept;
void ValidateFont() noexcept;
static Microsoft::Console::Render::IFontDefaultList* s_pFontDefaultList;
static void s_SetFontDefaultList(_In_ Microsoft::Console::Render::IFontDefaultList* const pFontDefaultList) noexcept;
protected:
bool IsDefaultRasterFontNoSize() const noexcept;
private:
std::wstring _faceName;
unsigned int _weight;
unsigned char _family;
unsigned int _codePage;
bool _fDefaultRasterSetFromEngine;
};