Skip to content

Commit f941bfa

Browse files
samizdatcoSkCQ
authored andcommitted
Add ParagraphStyle setting to choose whether missing font weight/slant should be faked
### Motivation `OneLineShaper` currently compares each typeface to the requested `FontStyle` and detects cases where there is a mismatch in terms of italic/upright-ness or bold-ness (with a threshold of semibold or heavier counting as 'bold'). If it detects a mismatch it will apply a shear transform to create a fake italic or outdent the strokes to create a fake bold. While there are cases where this automated behavior is desirable, there are also times where it is preferable to use an unmodified typeface (albeit with a different style than requested) rather than a synthetically generated one. ### Changes This PR adds a boolean property to `ParagraphStyle` called `fFakeMissingFontStyles` which defaults to `true` (so as not to change the current default behavior) but can be toggled to `false` by calling the `setFakeMissingFontStyles()` accessor. `OneLineShaper` has been updated to apply its faking routines only if the flag is enabled. This is an imported pull request from #207 GitOrigin-RevId: 80bf189 Change-Id: I26db9217eb034150685ff74824bc65ca8144491a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1044616 Commit-Queue: Julia Lavrova <[email protected]> Reviewed-by: Julia Lavrova <[email protected]>
1 parent 6a70548 commit f941bfa

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

modules/skparagraph/include/ParagraphStyle.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ struct ParagraphStyle {
8484
this->fEllipsisUtf16 == rhs.fEllipsisUtf16 &&
8585
this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
8686
this->fDefaultTextStyle == rhs.fDefaultTextStyle &&
87-
this->fReplaceTabCharacters == rhs.fReplaceTabCharacters;
87+
this->fReplaceTabCharacters == rhs.fReplaceTabCharacters &&
88+
this->fFakeMissingFontStyles == rhs.fFakeMissingFontStyles;
89+
8890
}
8991

9092
const StrutStyle& getStrutStyle() const { return fStrutStyle; }
@@ -121,6 +123,9 @@ struct ParagraphStyle {
121123
bool hintingIsOn() const { return fHintingIsOn; }
122124
void turnHintingOff() { fHintingIsOn = false; }
123125

126+
bool fakeMissingFontStyles() const { return fFakeMissingFontStyles; }
127+
void setFakeMissingFontStyles(bool value) { fFakeMissingFontStyles = value; }
128+
124129
bool getReplaceTabCharacters() const { return fReplaceTabCharacters; }
125130
void setReplaceTabCharacters(bool value) { fReplaceTabCharacters = value; }
126131

@@ -139,6 +144,7 @@ struct ParagraphStyle {
139144
TextHeightBehavior fTextHeightBehavior;
140145
bool fHintingIsOn;
141146
bool fReplaceTabCharacters;
147+
bool fFakeMissingFontStyles;
142148
bool fApplyRoundingHack = true;
143149
};
144150
} // namespace textlayout

modules/skparagraph/src/OneLineShaper.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -657,17 +657,19 @@ bool OneLineShaper::shape() {
657657
font.setHinting(block.fStyle.getFontHinting());
658658
font.setSubpixel(block.fStyle.getSubpixel());
659659

660-
// Apply fake bold and/or italic settings to the font if the
661-
// typeface's attributes do not match the intended font style.
662-
int wantedWeight = block.fStyle.getFontStyle().weight();
663-
bool fakeBold =
664-
wantedWeight >= SkFontStyle::kSemiBold_Weight &&
665-
wantedWeight - font.getTypeface()->fontStyle().weight() >= 200;
666-
bool fakeItalic =
667-
block.fStyle.getFontStyle().slant() == SkFontStyle::kItalic_Slant &&
668-
font.getTypeface()->fontStyle().slant() != SkFontStyle::kItalic_Slant;
669-
font.setEmbolden(fakeBold);
670-
font.setSkewX(fakeItalic ? -SK_Scalar1 / 4 : 0);
660+
if (fParagraph->paragraphStyle().fakeMissingFontStyles()) {
661+
// Apply fake bold and/or italic settings to the font if the
662+
// typeface's attributes do not match the intended font style.
663+
int wantedWeight = block.fStyle.getFontStyle().weight();
664+
bool fakeBold =
665+
wantedWeight >= SkFontStyle::kSemiBold_Weight &&
666+
wantedWeight - font.getTypeface()->fontStyle().weight() >= 200;
667+
bool fakeItalic =
668+
block.fStyle.getFontStyle().slant() == SkFontStyle::kItalic_Slant &&
669+
font.getTypeface()->fontStyle().slant() != SkFontStyle::kItalic_Slant;
670+
font.setEmbolden(fakeBold);
671+
font.setSkewX(fakeItalic ? -SK_Scalar1 / 4 : 0);
672+
}
671673

672674
// Walk through all the currently unresolved blocks
673675
// (ignoring those that appear later)

modules/skparagraph/src/ParagraphStyle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ParagraphStyle::ParagraphStyle() {
2727
fTextHeightBehavior = TextHeightBehavior::kAll;
2828
fHintingIsOn = true;
2929
fReplaceTabCharacters = false;
30+
fFakeMissingFontStyles = true;
3031
}
3132

3233
TextAlign ParagraphStyle::effective_align() const {

0 commit comments

Comments
 (0)