From 97be50d961add7b5e687f9f768acebd7b803c891 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 24 Oct 2024 17:19:24 -0700 Subject: [PATCH] [Impeller] libImpeller: Respect the paragraph style line height specification. (flutter/engine#56066) cc @lyceel --- engine/src/flutter/impeller/toolkit/interop/impeller.h | 7 ++++++- .../flutter/impeller/toolkit/interop/impeller_unittests.cc | 1 + .../flutter/impeller/toolkit/interop/paragraph_style.cc | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/impeller/toolkit/interop/impeller.h b/engine/src/flutter/impeller/toolkit/interop/impeller.h index e009ac475e..aed8a8beb1 100644 --- a/engine/src/flutter/impeller/toolkit/interop/impeller.h +++ b/engine/src/flutter/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/engine/src/flutter/impeller/toolkit/interop/impeller_unittests.cc b/engine/src/flutter/impeller/toolkit/interop/impeller_unittests.cc index 83a084e25e..e45389eb50 100644 --- a/engine/src/flutter/impeller/toolkit/interop/impeller_unittests.cc +++ b/engine/src/flutter/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/engine/src/flutter/impeller/toolkit/interop/paragraph_style.cc b/engine/src/flutter/impeller/toolkit/interop/paragraph_style.cc index 55a7fcdfdc..d18943efcb 100644 --- a/engine/src/flutter/impeller/toolkit/interop/paragraph_style.cc +++ b/engine/src/flutter/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) {