terminal/src/renderer/base/fontinfo.cpp
Leonard Hecker 0bd5ddd7a5 wip
2021-11-23 03:44:12 +01:00

81 lines
2.3 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)
{
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();
}
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;
}
}
}