Skip to content

Commit

Permalink
update PR based on facebook#35949
Browse files Browse the repository at this point in the history
  • Loading branch information
fabOnReact committed Feb 20, 2023
1 parent 95324ec commit e59529d
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,18 @@ private static void apply(
return;
}

// https://stackoverflow.com/a/27631737/7295772
// top ------------- -10
// ascent ------------- -5
// baseline __my Text____ 0
// descent _____________ 2
// bottom _____________ 5
TextPaint textPaintCopy = new TextPaint();
textPaintCopy.set(ds);
if (textSize > 0) {
textPaintCopy.setTextSize(textSize);
}

if (textSize == highestFontSize) {
// aligns text vertically in the lineHeight
// and adjust their position depending on the fontSize
Expand All @@ -163,6 +170,9 @@ private static void apply(
ds.baselineShift -=
highestLineHeight / 2
- highestFontSize / 2
// smaller font aligns on the baseline of bigger font
// moves the baseline of text with smaller font up
// so it aligns on the top of the larger font
+ (highestFontSize - textSize)
+ (textPaintCopy.getFontMetrics().top - textPaintCopy.ascent());
}
Expand Down

0 comments on commit e59529d

Please sign in to comment.