From f7353190b9ae46b1d0786018d25c5e23212ecf6f Mon Sep 17 00:00:00 2001 From: Christian Swinehart Date: Sun, 24 Aug 2025 18:03:24 -0400 Subject: [PATCH] add flag to control whether font weight/slant are faked - defaults to true --- modules/skparagraph/include/ParagraphStyle.h | 8 ++++++- modules/skparagraph/src/OneLineShaper.cpp | 24 +++++++++++--------- modules/skparagraph/src/ParagraphStyle.cpp | 1 + 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/modules/skparagraph/include/ParagraphStyle.h b/modules/skparagraph/include/ParagraphStyle.h index 98ec228ffb71..77e17da981ce 100644 --- a/modules/skparagraph/include/ParagraphStyle.h +++ b/modules/skparagraph/include/ParagraphStyle.h @@ -84,7 +84,9 @@ struct ParagraphStyle { this->fEllipsisUtf16 == rhs.fEllipsisUtf16 && this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign && this->fDefaultTextStyle == rhs.fDefaultTextStyle && - this->fReplaceTabCharacters == rhs.fReplaceTabCharacters; + this->fReplaceTabCharacters == rhs.fReplaceTabCharacters && + this->fFakeMissingFontStyles == rhs.fFakeMissingFontStyles; + } const StrutStyle& getStrutStyle() const { return fStrutStyle; } @@ -121,6 +123,9 @@ struct ParagraphStyle { bool hintingIsOn() const { return fHintingIsOn; } void turnHintingOff() { fHintingIsOn = false; } + bool fakeMissingFontStyles() const { return fFakeMissingFontStyles; } + void setFakeMissingFontStyles(bool value) { fFakeMissingFontStyles = value; } + bool getReplaceTabCharacters() const { return fReplaceTabCharacters; } void setReplaceTabCharacters(bool value) { fReplaceTabCharacters = value; } @@ -139,6 +144,7 @@ struct ParagraphStyle { TextHeightBehavior fTextHeightBehavior; bool fHintingIsOn; bool fReplaceTabCharacters; + bool fFakeMissingFontStyles; bool fApplyRoundingHack = true; }; } // namespace textlayout diff --git a/modules/skparagraph/src/OneLineShaper.cpp b/modules/skparagraph/src/OneLineShaper.cpp index 1bbc87a3ae21..b023f18505ac 100644 --- a/modules/skparagraph/src/OneLineShaper.cpp +++ b/modules/skparagraph/src/OneLineShaper.cpp @@ -657,17 +657,19 @@ bool OneLineShaper::shape() { font.setHinting(block.fStyle.getFontHinting()); font.setSubpixel(block.fStyle.getSubpixel()); - // Apply fake bold and/or italic settings to the font if the - // typeface's attributes do not match the intended font style. - int wantedWeight = block.fStyle.getFontStyle().weight(); - bool fakeBold = - wantedWeight >= SkFontStyle::kSemiBold_Weight && - wantedWeight - font.getTypeface()->fontStyle().weight() >= 200; - bool fakeItalic = - block.fStyle.getFontStyle().slant() == SkFontStyle::kItalic_Slant && - font.getTypeface()->fontStyle().slant() != SkFontStyle::kItalic_Slant; - font.setEmbolden(fakeBold); - font.setSkewX(fakeItalic ? -SK_Scalar1 / 4 : 0); + if (fParagraph->paragraphStyle().fakeMissingFontStyles()) { + // Apply fake bold and/or italic settings to the font if the + // typeface's attributes do not match the intended font style. + int wantedWeight = block.fStyle.getFontStyle().weight(); + bool fakeBold = + wantedWeight >= SkFontStyle::kSemiBold_Weight && + wantedWeight - font.getTypeface()->fontStyle().weight() >= 200; + bool fakeItalic = + block.fStyle.getFontStyle().slant() == SkFontStyle::kItalic_Slant && + font.getTypeface()->fontStyle().slant() != SkFontStyle::kItalic_Slant; + font.setEmbolden(fakeBold); + font.setSkewX(fakeItalic ? -SK_Scalar1 / 4 : 0); + } // Walk through all the currently unresolved blocks // (ignoring those that appear later) diff --git a/modules/skparagraph/src/ParagraphStyle.cpp b/modules/skparagraph/src/ParagraphStyle.cpp index c635036ac5d1..16104e3aacef 100644 --- a/modules/skparagraph/src/ParagraphStyle.cpp +++ b/modules/skparagraph/src/ParagraphStyle.cpp @@ -27,6 +27,7 @@ ParagraphStyle::ParagraphStyle() { fTextHeightBehavior = TextHeightBehavior::kAll; fHintingIsOn = true; fReplaceTabCharacters = false; + fFakeMissingFontStyles = true; } TextAlign ParagraphStyle::effective_align() const {