Dealing with ghost spaces

Change-Id: I9cf133e915658f17d00f279ee1fa2662effa2021
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231646
Commit-Queue: Julia Lavrova <jlavrova@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Julia Lavrova <jlavrova@google.com>
diff --git a/modules/skparagraph/src/TextStyle.cpp b/modules/skparagraph/src/TextStyle.cpp
index 6304827..16de5b9 100644
--- a/modules/skparagraph/src/TextStyle.cpp
+++ b/modules/skparagraph/src/TextStyle.cpp
@@ -21,6 +21,7 @@
     fLetterSpacing = 0.0;
     fWordSpacing = 0.0;
     fHeight = 1.0;
+    fHeightOverride = false;
     fHasBackground = false;
     fHasForeground = false;
     fTextBaseline = TextBaseline::kAlphabetic;
@@ -121,5 +122,18 @@
     }
 }
 
+void TextStyle::getFontMetrics(SkFontMetrics* metrics) const {
+    SkFont font(fTypeface, fFontSize);
+    font.getMetrics(metrics);
+    if (fHeight == 0 || fHeight == 1) {
+        metrics->fAscent = (metrics->fAscent - metrics->fLeading / 2);
+        metrics->fDescent = (metrics->fDescent + metrics->fLeading / 2);
+    } else {
+        auto height = metrics->fDescent - metrics->fAscent + metrics->fLeading;
+        metrics->fAscent = (metrics->fAscent - metrics->fLeading / 2) * height / fHeight;
+        metrics->fDescent = (metrics->fDescent + metrics->fLeading / 2) * height / fHeight;
+    }
+}
+
 }  // namespace textlayout
 }  // namespace skia