Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev/lhecker/16297-fon…
Browse files Browse the repository at this point in the history
…tdlg-preview
  • Loading branch information
lhecker committed Nov 21, 2023
2 parents 04c2408 + 376737e commit ed90566
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 30 deletions.
6 changes: 5 additions & 1 deletion src/common.build.pre.props
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@
C26456: Operator 'A' hides a non-virtual operator 'B' (c.128)
I think these rules are for when you fully bought into OOP?
We didn't and it breaks WRL and large parts of conhost code.
C26478: Don't use std::move on constant variables. (es.56).
This diagnostic is broken in VS 17.7 which our CI currently uses. It's fixed in 17.8.
C26494: Variable 'index' is uninitialized. Always initialize an object (type. 5).
This diagnostic is broken in VS 17.7 which our CI currently uses. It's fixed in 17.8.
-->
<DisableSpecificWarnings>4201;4312;4467;5105;26434;26445;26456;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<DisableSpecificWarnings>4201;4312;4467;5105;26434;26445;26456;26478;26494;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<PreprocessorDefinitions>_WINDOWS;EXTERNAL_BUILD;_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<PrecompiledHeaderFile>precomp.h</PrecompiledHeaderFile>
Expand Down
71 changes: 42 additions & 29 deletions src/renderer/dx/DxFontInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,44 +126,52 @@ void DxFontInfo::SetFromEngine(const std::wstring_view familyName,
try
{
face = _FindFontFace(localeName);
}
CATCH_LOG();

if (!face)
if constexpr (Feature_NearbyFontLoading::IsEnabled())
{
try
{
// If we missed, try looking a little more by trimming the last word off the requested family name a few times.
// Quite often, folks are specifying weights or something in the familyName and it causes failed resolution and
// an unexpected error dialog. We theoretically could detect the weight words and convert them, but this
// is the quick fix for the majority scenario.
// The long/full fix is backlogged to GH#9744
// Also this doesn't count as a fallback because we don't want to annoy folks with the warning dialog over
// this resolution.
while (!face && !_familyName.empty())
if (!face)
{
const auto lastSpace = _familyName.find_last_of(UNICODE_SPACE);

// value is unsigned and npos will be greater than size.
// if we didn't find anything to trim, leave.
if (lastSpace >= _familyName.size())
{
break;
}

// trim string down to just before the found space
// (space found at 6... trim from 0 for 6 length will give us 0-5 as the new string)
_familyName = _familyName.substr(0, lastSpace);

// Try to find it with the shortened family name
_fontCollection = FontCache::GetCached();
face = _FindFontFace(localeName);
}
}
CATCH_LOG();
}
CATCH_LOG();

if constexpr (Feature_NearbyFontLoading::IsEnabled())
if (!face)
{
if (!face)
// If we missed, try looking a little more by trimming the last word off the requested family name a few times.
// Quite often, folks are specifying weights or something in the familyName and it causes failed resolution and
// an unexpected error dialog. We theoretically could detect the weight words and convert them, but this
// is the quick fix for the majority scenario.
// The long/full fix is backlogged to GH#9744
// Also this doesn't count as a fallback because we don't want to annoy folks with the warning dialog over
// this resolution.
while (!face && !_familyName.empty())
{
_fontCollection = FontCache::GetCached();
face = _FindFontFace(localeName);
const auto lastSpace = _familyName.find_last_of(UNICODE_SPACE);

// value is unsigned and npos will be greater than size.
// if we didn't find anything to trim, leave.
if (lastSpace >= _familyName.size())
{
break;
}

// trim string down to just before the found space
// (space found at 6... trim from 0 for 6 length will give us 0-5 as the new string)
_familyName = _familyName.substr(0, lastSpace);

try
{
// Try to find it with the shortened family name
face = _FindFontFace(localeName);
}
CATCH_LOG();
}
}

Expand All @@ -176,7 +184,12 @@ void DxFontInfo::SetFromEngine(const std::wstring_view familyName,
{
_familyName = fallbackFace;

face = _FindFontFace(localeName);
try
{
face = _FindFontFace(localeName);
}
CATCH_LOG();

if (face)
{
_didFallback = true;
Expand Down

0 comments on commit ed90566

Please sign in to comment.