From 9ceed34986c1db44614a15814ab1d74a40c5fc5c Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 23 Oct 2024 12:22:03 -0700 Subject: [PATCH] [Impeller] libImpeller: Respect the paragraph style line height specification. --- impeller/toolkit/interop/impeller.h | 7 ++++++- impeller/toolkit/interop/impeller_unittests.cc | 1 + impeller/toolkit/interop/paragraph_style.cc | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/impeller/toolkit/interop/impeller.h b/impeller/toolkit/interop/impeller.h index e009ac475eb56..aed8a8beb1ea7 100644 --- a/impeller/toolkit/interop/impeller.h +++ b/impeller/toolkit/interop/impeller.h @@ -2143,7 +2143,12 @@ void ImpellerParagraphStyleSetFontSize( float size); //------------------------------------------------------------------------------ -/// @brief Set the paragraph height. +/// @brief The height of the text as a multiple of text size. +/// +/// When height is 0.0, the line height will be determined by the +/// font's metrics directly, which may differ from the font size. +/// Otherwise the line height of the text will be a multiple of font +/// size, and be exactly fontSize * height logical pixels tall. /// /// @param[in] paragraph_style The paragraph style. /// @param[in] height The height. diff --git a/impeller/toolkit/interop/impeller_unittests.cc b/impeller/toolkit/interop/impeller_unittests.cc index 83a084e25ebb4..e45389eb502e6 100644 --- a/impeller/toolkit/interop/impeller_unittests.cc +++ b/impeller/toolkit/interop/impeller_unittests.cc @@ -207,6 +207,7 @@ TEST_P(InteropPlaygroundTest, CanCreateParagraphs) { auto style = Adopt(ImpellerParagraphStyleNew()); ASSERT_TRUE(style); ImpellerParagraphStyleSetFontSize(style.GetC(), 150.0f); + ImpellerParagraphStyleSetHeight(style.GetC(), 2.0f); { auto paint = Adopt(ImpellerPaintNew()); diff --git a/impeller/toolkit/interop/paragraph_style.cc b/impeller/toolkit/interop/paragraph_style.cc index 55a7fcdfdc8fc..d18943efcbf88 100644 --- a/impeller/toolkit/interop/paragraph_style.cc +++ b/impeller/toolkit/interop/paragraph_style.cc @@ -28,6 +28,7 @@ void ParagraphStyle::SetFontSize(double size) { void ParagraphStyle::SetHeight(double height) { style_.height = height; + style_.has_height_override = (height != 0.0); } void ParagraphStyle::SetTextAlignment(txt::TextAlign alignment) {