Commit 82494ce7 authored by Dominik Röttsches's avatar Dominik Röttsches Committed by Commit Bot

Guard for null typefaces in Mac system font instantiation

The previous change [1] to always apply opsz to Mac system fonts did not
handle a situation in which loading a system font comes back with a null
result. Cover this case for the base typeface as well as for the case
where instantiating the variable font fails.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2020767

Bug: 1049391
Change-Id: I2aad15c31f7ad793abc389f66afab3fbdf963df7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2041667Reviewed-by: default avatarBen Wagner <bungeman@chromium.org>
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739391}
parent f4662c0e
......@@ -224,6 +224,9 @@ scoped_refptr<SimpleFontData> FontCache::PlatformFallbackFontForCharacter(
platform_data.Orientation(), font_description.FontOpticalSizing(),
nullptr); // No variation paramaters in fallback.
if (!alternate_font)
return nullptr;
return FontDataFromFontPlatformData(alternate_font.get(), kDoNotRetain);
}
......@@ -297,7 +300,7 @@ std::unique_ptr<FontPlatformData> FontCache::CreateFontPlatformData(
platform_font, size, synthetic_bold, synthetic_italic,
font_description.Orientation(), font_description.FontOpticalSizing(),
font_description.VariationSettings());
if (!platform_data->Typeface()) {
if (!platform_data || !platform_data->Typeface()) {
return nullptr;
}
return platform_data;
......
......@@ -151,6 +151,9 @@ std::unique_ptr<FontPlatformData> FontPlatformDataFromNSFont(
if (!valid_configured_axes && optical_sizing == kNoneOpticalSizing)
return make_typeface_fontplatformdata();
if (!typeface)
return nullptr;
int existing_axes = typeface->getVariationDesignPosition(nullptr, 0);
// Don't apply variation parameters if the font does not have axes or we
// fail to retrieve the existing ones.
......@@ -196,9 +199,14 @@ std::unique_ptr<FontPlatformData> FontPlatformDataFromNSFont(
SkFontArguments::VariationPosition variation_design_position{
coordinates_to_set.data(), coordinates_to_set.size()};
typeface = typeface->makeClone(
SkFontArguments().setVariationDesignPosition(variation_design_position));
sk_sp<SkTypeface> cloned_typeface(typeface->makeClone(
SkFontArguments().setVariationDesignPosition(variation_design_position)));
if (!cloned_typeface) {
// Applying varition parameters failed, return original typeface.
return make_typeface_fontplatformdata();
}
typeface = cloned_typeface;
return make_typeface_fontplatformdata();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment