Skip to content

Commit

Permalink
[Skia] Fix font style values passed to matchFamilyStyle
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271049

Reviewed by Alejandro G. Castro.

We are doing a very simple conversion, but we should check values and
thresholds.

* Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp:
(WebCore::skiaFontStyle):
(WebCore::FontCache::createFontPlatformData):

Canonical link: https://commits.webkit.org/276149@main
  • Loading branch information
carlosgcampos committed Mar 15, 2024
1 parent c9712ea commit 7600623
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,47 @@ Vector<hb_feature_t> FontCache::computeFeatures(const FontDescription& fontDescr
return features;
}

std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomString& family, const FontCreationContext& fontCreationContext)
static SkFontStyle skiaFontStyle(const FontDescription& fontDescription)
{
auto width = SkFontStyle::kNormal_Width;

auto weight = SkFontStyle::kNormal_Weight;
if (isFontWeightBold(fontDescription.weight()))
weight = SkFontStyle::kBold_Weight;
int skWeight = SkFontStyle::kNormal_Weight;
auto weight = fontDescription.weight();
if (weight > FontSelectionValue(SkFontStyle::kInvisible_Weight) && weight <= FontSelectionValue(SkFontStyle::kExtraBlack_Weight))
skWeight = static_cast<int>(weight);

int skWidth = SkFontStyle::kNormal_Width;
auto stretch = fontDescription.stretch();
if (stretch <= ultraCondensedStretchValue())
skWidth = SkFontStyle::kUltraCondensed_Width;
else if (stretch <= extraCondensedStretchValue())
skWidth = SkFontStyle::kExtraCondensed_Width;
else if (stretch <= condensedStretchValue())
skWidth = SkFontStyle::kCondensed_Width;
else if (stretch <= semiCondensedStretchValue())
skWidth = SkFontStyle::kSemiCondensed_Width;
else if (stretch >= semiExpandedStretchValue())
skWidth = SkFontStyle::kSemiExpanded_Width;
else if (stretch >= expandedStretchValue())
skWidth = SkFontStyle::kExpanded_Width;
if (stretch >= extraExpandedStretchValue())
skWidth = SkFontStyle::kExtraExpanded_Width;
if (stretch >= ultraExpandedStretchValue())
skWidth = SkFontStyle::kUltraExpanded_Width;

SkFontStyle::Slant skSlant = SkFontStyle::kUpright_Slant;
if (auto italic = fontDescription.italic()) {
if (italic.value() > normalItalicValue() && italic.value() <= italicThreshold())
skSlant = SkFontStyle::kItalic_Slant;
else if (italic.value() > italicThreshold())
skSlant = SkFontStyle::kOblique_Slant;
}

auto slant = SkFontStyle::kUpright_Slant;
if (fontDescription.italic())
slant = SkFontStyle::kItalic_Slant;
return SkFontStyle(skWeight, skWidth, skSlant);
}

std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomString& family, const FontCreationContext& fontCreationContext)
{
auto familyName = getFamilyNameStringFromFamily(family);
auto typeface = m_fontManager->matchFamilyStyle(familyName.utf8().data(), SkFontStyle { weight, width, slant });
auto typeface = m_fontManager->matchFamilyStyle(familyName.utf8().data(), skiaFontStyle(fontDescription));
if (!typeface)
return nullptr;

Expand Down

0 comments on commit 7600623

Please sign in to comment.