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

Commit 359ee48

Browse files
fix internal failures
1 parent eee4f73 commit 359ee48

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

lib/ui/text.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,8 @@ class ParagraphStyle {
22492249
// compactness. The first 8 bits is a bitmask that records which properties
22502250
// are null. The rest of the values are encoded in the same order encountered
22512251
// in the bitmask. The final returned value truncates any unused bytes
2252-
// at the end.
2252+
// at the end. For ease of decoding, all 8 bit ints are stored before any 32 bit
2253+
// ints.
22532254
//
22542255
// We serialize this more thoroughly than ParagraphStyle because it is
22552256
// much more likely that the strut is empty/null and we wish to add
@@ -2291,35 +2292,35 @@ ByteData _encodeStrut(
22912292
bitmask |= 1 << 2;
22922293
// passed separately to native
22932294
}
2294-
if (fontSize != null) {
2295+
if (leadingDistribution != null) {
22952296
bitmask |= 1 << 3;
2297+
data.setInt8(byteCount, leadingDistribution.index);
2298+
byteCount += 1;
2299+
}
2300+
if (fontSize != null) {
2301+
bitmask |= 1 << 4;
22962302
data.setFloat32(byteCount, fontSize, _kFakeHostEndian);
22972303
byteCount += 4;
22982304
}
22992305
if (height != null) {
2300-
bitmask |= 1 << 4;
2306+
bitmask |= 1 << 5;
23012307
data.setFloat32(byteCount, height, _kFakeHostEndian);
23022308
byteCount += 4;
2303-
if (leadingDistribution != null) {
2304-
bitmask |= 1 << 5;
2305-
data.setInt8(byteCount, leadingDistribution.index);
2306-
byteCount += 4;
2307-
}
2309+
23082310
}
23092311
if (leading != null) {
23102312
bitmask |= 1 << 6;
23112313
data.setFloat32(byteCount, leading, _kFakeHostEndian);
23122314
byteCount += 4;
23132315
}
2314-
if (forceStrutHeight != null) {
2316+
if (forceStrutHeight ?? false) {
23152317
bitmask |= 1 << 7;
2316-
// We store this boolean directly in the bitmask since there is
2317-
// extra space in the 16 bit int.
2318-
bitmask |= (forceStrutHeight ? 1 : 0) << 8;
23192318
}
23202319

23212320
data.setInt8(0, bitmask);
23222321

2322+
assert(byteCount == 16);
2323+
assert(bitmask >> 7 == 0, 'bitmask overflow: $bitmask');
23232324
return ByteData.view(data.buffer, 0, byteCount);
23242325
}
23252326

lib/ui/text/paragraph_builder.cc

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ constexpr uint32_t kFontFeatureTagLength = 4;
118118
const int sFontWeightIndex = 0;
119119
const int sFontStyleIndex = 1;
120120
const int sFontFamilyIndex = 2;
121-
const int sFontSizeIndex = 3;
122-
const int sHeightIndex = 4;
123-
const int sLeadingDistributionIndex = 5;
121+
const int sLeadingDistributionIndex = 3;
122+
const int sFontSizeIndex = 4;
123+
const int sHeightIndex = 5;
124124
const int sLeadingIndex = 6;
125125
const int sForceStrutHeightIndex = 7;
126126

127127
const int sFontWeightMask = 1 << sFontWeightIndex;
128128
const int sFontStyleMask = 1 << sFontStyleIndex;
129129
const int sFontFamilyMask = 1 << sFontFamilyIndex;
130+
const int sLeadingDistributionMask = 1 << sLeadingDistributionIndex;
130131
const int sFontSizeMask = 1 << sFontSizeIndex;
131132
const int sHeightMask = 1 << sHeightIndex;
132-
const int sLeadingDistributionMask = 1 << sLeadingDistributionIndex;
133133
const int sLeadingMask = 1 << sLeadingIndex;
134134
const int sForceStrutHeightMask = 1 << sForceStrutHeightIndex;
135135

@@ -201,6 +201,10 @@ void decodeStrut(Dart_Handle strut_data,
201201
paragraph_style.strut_font_style =
202202
static_cast<txt::FontStyle>(uint8_data[byte_count++]);
203203
}
204+
if (mask & sLeadingDistributionMask) {
205+
paragraph_style.strut_has_leading_distribution_override = true;
206+
paragraph_style.strut_half_leading = uint8_data[byte_count++];
207+
}
204208

205209
std::vector<float> float_data;
206210
float_data.resize((byte_data.length_in_bytes() - byte_count) / 4);
@@ -214,20 +218,13 @@ void decodeStrut(Dart_Handle strut_data,
214218
if (mask & sHeightMask) {
215219
paragraph_style.strut_height = float_data[float_count++];
216220
paragraph_style.strut_has_height_override = true;
217-
218-
// LeadingDistribution does not affect layout if height is not set.
219-
if (mask & sLeadingDistributionMask) {
220-
paragraph_style.strut_half_leading = uint8_data[byte_count];
221-
paragraph_style.strut_has_leading_distribution_override = true;
222-
}
223221
}
224222
if (mask & sLeadingMask) {
225223
paragraph_style.strut_leading = float_data[float_count++];
226224
}
227-
if (mask & sForceStrutHeightMask) {
228-
// The boolean is stored as the last bit in the bitmask.
229-
paragraph_style.force_strut_height = (mask & 1 << 7) != 0;
230-
}
225+
226+
// The boolean is stored as the last bit in the bitmask.
227+
paragraph_style.force_strut_height = mask & sForceStrutHeightMask;
231228

232229
if (mask & sFontFamilyMask) {
233230
paragraph_style.strut_font_families = strut_font_families;

0 commit comments

Comments
 (0)