terminal/src/renderer/base/fontinfo.cpp
Dustin L. Howett b664761c79 Allow FontInfo{,Base,Desired} to store a font name > 32 wch (#3107)
We now truncate the font name as it goes out to GDI APIs, in console API
servicing, and in the propsheet.

I attempted to defer truncating the font to as far up the stack as
possible, so as to make FontInfo usable for the broadest set of cases.

There were a couple questions that came up: I know that `Settings` gets
memset (memsat?) by the registry deserializer, and perhaps that's
another place for us to tackle. Right now, this pull request enables
fonts whose names are >= 32 characters _in Windows Terminal only_, but
the underpinnings are there for conhost as well. We'd need to explicitly
break at the API, or perhaps return a failure or log something to
telemetry.

* Should we log truncation at the API boundary to telemetry?
-> Later; followup filed (#3123)

* Should we fix Settings here, or later?
-> Later; followup filed (#3123)

* `TrueTypeFontList` is built out of things in winconp, the private
console header. Concern about interop structures.
-> Not used for interop, followup filed to clean it up (#3123)

* Is `unsigned int` right for codepage? For width?
-> Yes: codepage became UINT (from WORD) when we moved from Win16 to
Win32

This commit also includes a workaround for #3170. Growing
CONSOLE_INFORMATION made us lose the struct layout lottery during
release builds, and this was an expedient fix.

Closes #602.
Related to #3123.
2019-10-14 21:23:45 -07:00

90 lines
2.5 KiB
C++

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "..\inc\FontInfo.hpp"
bool operator==(const FontInfo& a, const FontInfo& b)
{
return (static_cast<FontInfoBase>(a) == static_cast<FontInfoBase>(b) &&
a._coordSize == b._coordSize &&
a._coordSizeUnscaled == b._coordSizeUnscaled);
}
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 */) :
FontInfoBase(faceName, family, weight, fSetDefaultRasterFont, codePage),
_coordSize(coordSize),
_coordSizeUnscaled(coordSize)
{
ValidateFont();
}
FontInfo::FontInfo(const FontInfo& fiFont) :
FontInfoBase(fiFont),
_coordSize(fiFont.GetSize()),
_coordSizeUnscaled(fiFont.GetUnscaledSize())
{
}
COORD FontInfo::GetUnscaledSize() const
{
return _coordSizeUnscaled;
}
COORD FontInfo::GetSize() const
{
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)
{
FontInfoBase::SetFromEngine(faceName,
family,
weight,
fSetDefaultRasterFont);
_coordSize = coordSize;
_coordSizeUnscaled = coordSizeUnscaled;
_ValidateCoordSize();
}
void FontInfo::ValidateFont()
{
_ValidateCoordSize();
}
void FontInfo::_ValidateCoordSize()
{
// 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;
}
}
}