Skip to content

Commit

Permalink
SkTypeface_fontconfig::onMakeClone to keep pattern
Browse files Browse the repository at this point in the history
Fix the long standing TODO that FC_MATRIX and FC_EMOBOLDEN need to be
passed on through clones. Do so by having onMakeClone return a
SkTypeface_fontconfig with a reference to fPattern. Correct the style by
keeping any weight or width offset and slant override.

Note that this fixes onMakeClone, but does not fix the similar issue
(and TODO in onGetFontDescriptor) with serialization and
deserialization.

Change-Id: I4869d886b2c9bb2ae4df519488d92d4e5adb147b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/948176
Commit-Queue: Ben Wagner <[email protected]>
Reviewed-by: Julia Lavrova <[email protected]>
  • Loading branch information
Ben Wagner authored and SkCQ committed Feb 10, 2025
1 parent 0986953 commit 8c377e8
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/ports/SkFontMgr_fontconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,14 @@ class SkTypeface_fontconfig : public SkTypeface_proxy {
if (!realTypeface) {
return nullptr;
}

SkFontStyle proxyStyle = skfontstyle_from_fcpattern(pattern);
return sk_sp(new SkTypeface_fontconfig(std::move(realTypeface), std::move(pattern),
std::move(sysroot), scanner));
proxyStyle, nullptr));
}

mutable SkAutoFcPattern fPattern; // Mutable for passing to FontConfig API.
const SkString fSysroot;
SkFontStyle fOriginalRealStyle;

protected:
void onGetFamilyName(SkString* familyName) const override {
Expand Down Expand Up @@ -507,17 +509,36 @@ class SkTypeface_fontconfig : public SkTypeface_proxy {
}

sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
// TODO: need to clone FC_MATRIX and FC_EMBOLDEN by wrapping this
return SkTypeface_proxy::onMakeClone(args);
sk_sp<SkTypeface> realTypeface = SkTypeface_proxy::onMakeClone(args);
SkAutoFcPattern pattern;
{
FCLocker lock;
FcPatternReference(fPattern);
pattern.reset(fPattern.get());
}

SkFontStyle newRealStyle = realTypeface->fontStyle();
SkFontStyle originalProxyStyle = skfontstyle_from_fcpattern(pattern);
SkFontStyle newProxyStyle(
// keep consistent weight and width offsets (though they will be clamped)
originalProxyStyle.weight() + (newRealStyle.weight() - fOriginalRealStyle.weight()),
originalProxyStyle.width() + (newRealStyle.width() - fOriginalRealStyle.width()),
// the originalProxyStyle's slant is an override for the originalRealStyle's slant
newRealStyle.slant() == fOriginalRealStyle.slant() ? originalProxyStyle.slant()
: newRealStyle.slant());

return sk_sp(new SkTypeface_fontconfig(std::move(realTypeface), std::move(pattern),
newProxyStyle, &fOriginalRealStyle));
}

private:
SkTypeface_fontconfig(sk_sp<SkTypeface> realTypeface, SkAutoFcPattern pattern, SkString sysroot,
SkFontScanner* fontScanner)
: SkTypeface_proxy(realTypeface, skfontstyle_from_fcpattern(pattern),
SkTypeface_fontconfig(sk_sp<SkTypeface> realTypeface, SkAutoFcPattern pattern,
const SkFontStyle& proxyStyle, const SkFontStyle* originalRealStyle)
: SkTypeface_proxy(realTypeface, proxyStyle,
FC_PROPORTIONAL != get_int(pattern, FC_SPACING, FC_PROPORTIONAL))
, fPattern(std::move(pattern))
, fSysroot(std::move(sysroot))
, fOriginalRealStyle(originalRealStyle ? *originalRealStyle
: SkTypeface_proxy::onGetFontStyle())
{}
};

Expand Down

0 comments on commit 8c377e8

Please sign in to comment.