terminal/src/renderer/base/fontinfo.cpp
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

92 lines
2.5 KiB
C++

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "../inc/FontInfo.hpp"
FontInfo::FontInfo(const std::wstring_view& faceName,
const unsigned char family,
const unsigned int weight,
const COORD coordSize,
const unsigned int codePage,
const bool fSetDefaultRasterFont /* = false */) noexcept :
FontInfoBase(faceName, family, weight, fSetDefaultRasterFont, codePage),
_coordSize(coordSize),
_coordSizeUnscaled(coordSize),
_didFallback(false)
{
ValidateFont();
}
bool FontInfo::operator==(const FontInfo& other) noexcept
{
return FontInfoBase::operator==(other) &&
_coordSize == other._coordSize &&
_coordSizeUnscaled == other._coordSizeUnscaled;
}
COORD FontInfo::GetUnscaledSize() const noexcept
{
return _coordSizeUnscaled;
}
COORD FontInfo::GetSize() const noexcept
{
return _coordSize;
}
void FontInfo::SetFromEngine(const std::wstring_view& faceName,
const unsigned char family,
const unsigned int weight,
const bool fSetDefaultRasterFont,
const COORD coordSize,
const COORD coordSizeUnscaled) noexcept
{
FontInfoBase::SetFromEngine(faceName,
family,
weight,
fSetDefaultRasterFont);
_coordSize = coordSize;
_coordSizeUnscaled = coordSizeUnscaled;
_ValidateCoordSize();
}
bool FontInfo::GetFallback() const noexcept
{
return _didFallback;
}
void FontInfo::SetFallback(const bool didFallback) noexcept
{
_didFallback = didFallback;
}
void FontInfo::ValidateFont() noexcept
{
_ValidateCoordSize();
}
void FontInfo::_ValidateCoordSize() noexcept
{
// a (0,0) font is okay for the default raster font, as we will eventually set the dimensions based on the font GDI
// passes back to us.
if (!IsDefaultRasterFontNoSize())
{
// Initialize X to 1 so we don't divide by 0
if (_coordSize.X == 0)
{
_coordSize.X = 1;
}
// If we have no font size, we want to use 8x12 by default
if (_coordSize.Y == 0)
{
_coordSize.X = 8;
_coordSize.Y = 12;
_coordSizeUnscaled = _coordSize;
}
}
}