Skip to content

Commit 886e850

Browse files
jason-simmonsSkia Commit-Bot
authored andcommitted
Apply fake bold and italic settings to the SkFont if the typeface needs them
The rules for setting fake bold and italic are based on the implementation used in Minikin. Change-Id: I9bbecdbd0198363db0296fa9c68046b4724fbded Reviewed-on: https://skia-review.googlesource.com/c/skia/+/269429 Commit-Queue: Jason Simmons <jsimmons@google.com> Reviewed-by: Julia Lavrova <jlavrova@google.com>
1 parent 251eff6 commit 886e850

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

modules/skparagraph/src/OneLineShaper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,18 @@ bool OneLineShaper::shape() {
524524
font.setHinting(SkFontHinting::kSlight);
525525
font.setSubpixel(true);
526526

527+
// Apply fake bold and/or italic settings to the font if the
528+
// typeface's attributes do not match the intended font style.
529+
int wantedWeight = block.fStyle.getFontStyle().weight();
530+
bool fakeBold =
531+
wantedWeight >= SkFontStyle::kSemiBold_Weight &&
532+
wantedWeight - font.getTypeface()->fontStyle().weight() >= 200;
533+
bool fakeItalic =
534+
block.fStyle.getFontStyle().slant() == SkFontStyle::kItalic_Slant &&
535+
font.getTypeface()->fontStyle().slant() != SkFontStyle::kItalic_Slant;
536+
font.setEmbolden(fakeBold);
537+
font.setSkewX(fakeItalic ? -SK_Scalar1 / 4 : 0);
538+
527539
// Walk through all the currently unresolved blocks
528540
// (ignoring those that appear later)
529541
auto count = fUnresolvedBlocks.size();

0 commit comments

Comments
 (0)