Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bd7c9d7

Browse files
Pass the missing strut half leading flag over to skia paragraph builder (#50385)
Not sure how this can be tested. Part of flutter/flutter#142969 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 3ee6f25 commit bd7c9d7

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

third_party/txt/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ if (enable_unittests) {
147147

148148
sources = [
149149
"tests/font_collection_tests.cc",
150+
"tests/paragraph_builder_skia_tests.cc",
150151
"tests/paragraph_unittests.cc",
151152
"tests/txt_run_all_unittests.cc",
152153
]

third_party/txt/src/skia/paragraph_builder_skia.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ skt::ParagraphStyle ParagraphBuilderSkia::TxtToSkia(const ParagraphStyle& txt) {
119119
strut_style.setFontSize(SkDoubleToScalar(txt.strut_font_size));
120120
strut_style.setHeight(SkDoubleToScalar(txt.strut_height));
121121
strut_style.setHeightOverride(txt.strut_has_height_override);
122+
strut_style.setHalfLeading(txt.strut_half_leading);
122123

123124
std::vector<SkString> strut_fonts;
124125
std::transform(txt.strut_font_families.begin(), txt.strut_font_families.end(),

third_party/txt/src/skia/paragraph_builder_skia.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class ParagraphBuilderSkia : public ParagraphBuilder {
4545
virtual std::unique_ptr<Paragraph> Build() override;
4646

4747
private:
48+
friend class SkiaParagraphBuilderTests_ParagraphStrutStyle_Test;
49+
4850
skia::textlayout::ParagraphPainter::PaintID CreatePaintID(
4951
const flutter::DlPaint& dl_paint);
5052
skia::textlayout::ParagraphStyle TxtToSkia(const ParagraphStyle& txt);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2017 Google, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "gtest/gtest.h"
18+
19+
#include <sstream>
20+
21+
#include "skia/paragraph_builder_skia.h"
22+
#include "txt/paragraph_style.h"
23+
24+
namespace txt {
25+
26+
class SkiaParagraphBuilderTests : public ::testing::Test {
27+
public:
28+
SkiaParagraphBuilderTests() {}
29+
30+
void SetUp() override {}
31+
};
32+
33+
TEST_F(SkiaParagraphBuilderTests, ParagraphStrutStyle) {
34+
ParagraphStyle style = ParagraphStyle();
35+
auto collection = std::make_shared<FontCollection>();
36+
auto builder = ParagraphBuilderSkia(style, collection, false);
37+
38+
auto strut_style = builder.TxtToSkia(style).getStrutStyle();
39+
ASSERT_FALSE(strut_style.getHalfLeading());
40+
41+
style.strut_half_leading = true;
42+
strut_style = builder.TxtToSkia(style).getStrutStyle();
43+
ASSERT_TRUE(strut_style.getHalfLeading());
44+
}
45+
} // namespace txt

0 commit comments

Comments
 (0)