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

Commit 44d7744

Browse files
Revert "Add a flag to ParagraphBuilder for rounding hack migration (#43118)"
This reverts commit f55f087.
1 parent dd29608 commit 44d7744

12 files changed

Lines changed: 11 additions & 112 deletions

File tree

lib/ui/dart_ui.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ typedef CanvasPath Path;
7878
V(Gradient::Create, 1) \
7979
V(ImageFilter::Create, 1) \
8080
V(ImageShader::Create, 1) \
81-
V(ParagraphBuilder::Create, 10) \
81+
V(ParagraphBuilder::Create, 9) \
8282
V(PathMeasure::Create, 3) \
8383
V(Path::Create, 1) \
8484
V(PictureRecorder::Create, 1) \

lib/ui/text.dart

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,7 +2798,7 @@ abstract class Paragraph {
27982798
/// This only returns a valid value if asserts are enabled, and must not be
27992799
/// used otherwise.
28002800
bool get debugDisposed;
2801-
}
2801+
}
28022802

28032803
@pragma('vm:entry-point')
28042804
base class _NativeParagraph extends NativeFieldWrapperClass1 implements Paragraph {
@@ -3015,28 +3015,6 @@ abstract class ParagraphBuilder {
30153015
/// [Paragraph].
30163016
factory ParagraphBuilder(ParagraphStyle style) = _NativeParagraphBuilder;
30173017

3018-
/// Whether the rounding hack enabled by default in SkParagraph and TextPainter
3019-
/// is disabled.
3020-
///
3021-
/// Do not rely on this getter as it exists for migration purposes only and
3022-
/// will soon be removed.
3023-
static bool get shouldDisableRoundingHack {
3024-
return const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
3025-
|| _roundingHackDisabledInDebugMode;
3026-
}
3027-
static bool _roundingHackDisabledInDebugMode = true;
3028-
3029-
/// Only works in debug mode. Do not call this method as it is for migration
3030-
/// purposes only and will soon be removed.
3031-
static void setDisableRoundingHack(bool disableRoundingHack) {
3032-
// bool.hasEnvironment does not work in internal tests so an additional flag
3033-
// is needed for tests.
3034-
assert(() {
3035-
_roundingHackDisabledInDebugMode = disableRoundingHack;
3036-
return true;
3037-
}());
3038-
}
3039-
30403018
/// The number of placeholders currently in the paragraph.
30413019
int get placeholderCount;
30423020

@@ -3154,12 +3132,11 @@ base class _NativeParagraphBuilder extends NativeFieldWrapperClass1 implements P
31543132
style._fontSize ?? 0,
31553133
style._height ?? 0,
31563134
style._ellipsis ?? '',
3157-
_encodeLocale(style._locale),
3158-
!ParagraphBuilder.shouldDisableRoundingHack,
3135+
_encodeLocale(style._locale)
31593136
);
31603137
}
31613138

3162-
@Native<Void Function(Handle, Handle, Handle, Handle, Handle, Double, Double, Handle, Handle, Bool)>(symbol: 'ParagraphBuilder::Create')
3139+
@Native<Void Function(Handle, Handle, Handle, Handle, Handle, Double, Double, Handle, Handle)>(symbol: 'ParagraphBuilder::Create')
31633140
external void _constructor(
31643141
Int32List encoded,
31653142
ByteData? strutData,
@@ -3168,8 +3145,7 @@ base class _NativeParagraphBuilder extends NativeFieldWrapperClass1 implements P
31683145
double fontSize,
31693146
double height,
31703147
String ellipsis,
3171-
String locale,
3172-
bool applyRoundingHack);
3148+
String locale);
31733149

31743150
@override
31753151
int get placeholderCount => _placeholderCount;

lib/ui/text/paragraph_builder.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,11 @@ void ParagraphBuilder::Create(Dart_Handle wrapper,
151151
double fontSize,
152152
double height,
153153
const std::u16string& ellipsis,
154-
const std::string& locale,
155-
bool applyRoundingHack) {
154+
const std::string& locale) {
156155
UIDartState::ThrowIfUIOperationsProhibited();
157156
auto res = fml::MakeRefCounted<ParagraphBuilder>(
158157
encoded_handle, strutData, fontFamily, strutFontFamilies, fontSize,
159-
height, ellipsis, locale, applyRoundingHack);
158+
height, ellipsis, locale);
160159
res->AssociateWithDartWrapper(wrapper);
161160
}
162161

@@ -231,8 +230,7 @@ ParagraphBuilder::ParagraphBuilder(
231230
double fontSize,
232231
double height,
233232
const std::u16string& ellipsis,
234-
const std::string& locale,
235-
bool applyRoundingHack) {
233+
const std::string& locale) {
236234
int32_t mask = 0;
237235
txt::ParagraphStyle style;
238236
{
@@ -293,7 +291,6 @@ ParagraphBuilder::ParagraphBuilder(
293291
if (mask & kPSLocaleMask) {
294292
style.locale = locale;
295293
}
296-
style.apply_rounding_hack = applyRoundingHack;
297294

298295
FontCollection& font_collection = UIDartState::Current()
299296
->platform_configuration()

lib/ui/text/paragraph_builder.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ class ParagraphBuilder : public RefCountedDartWrappable<ParagraphBuilder> {
3030
double fontSize,
3131
double height,
3232
const std::u16string& ellipsis,
33-
const std::string& locale,
34-
bool applyRoundingHack);
33+
const std::string& locale);
3534

3635
~ParagraphBuilder() override;
3736

@@ -77,8 +76,7 @@ class ParagraphBuilder : public RefCountedDartWrappable<ParagraphBuilder> {
7776
double fontSize,
7877
double height,
7978
const std::u16string& ellipsis,
80-
const std::string& locale,
81-
bool applyRoundingHack);
79+
const std::string& locale);
8280

8381
std::unique_ptr<txt::ParagraphBuilder> m_paragraphBuilder;
8482
};

lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,8 +2722,6 @@ extension SkParagraphStylePropertiesExtension on SkParagraphStyleProperties {
27222722
@JS('replaceTabCharacters')
27232723
external set _replaceTabCharacters(JSBoolean? bool);
27242724
set replaceTabCharacters(bool? bool) => _replaceTabCharacters = bool?.toJS;
2725-
2726-
external set applyRoundingHack(bool applyRoundingHack);
27272725
}
27282726

27292727
@JS()

lib/web_ui/lib/src/engine/canvaskit/renderer.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ class CanvasKitRenderer implements Renderer {
328328
strutStyle: strutStyle,
329329
ellipsis: ellipsis,
330330
locale: locale,
331-
applyRoundingHack: !ui.ParagraphBuilder.shouldDisableRoundingHack,
332331
);
333332

334333
@override

lib/web_ui/lib/src/engine/canvaskit/text.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class CkParagraphStyle implements ui.ParagraphStyle {
3333
ui.StrutStyle? strutStyle,
3434
String? ellipsis,
3535
ui.Locale? locale,
36-
bool applyRoundingHack = true,
3736
}) : skParagraphStyle = toSkParagraphStyle(
3837
textAlign,
3938
textDirection,
@@ -47,7 +46,6 @@ class CkParagraphStyle implements ui.ParagraphStyle {
4746
strutStyle,
4847
ellipsis,
4948
locale,
50-
applyRoundingHack,
5149
),
5250
_fontFamily = _effectiveFontFamily(fontFamily),
5351
_fontSize = fontSize,
@@ -147,7 +145,6 @@ class CkParagraphStyle implements ui.ParagraphStyle {
147145
ui.StrutStyle? strutStyle,
148146
String? ellipsis,
149147
ui.Locale? locale,
150-
bool applyRoundingHack,
151148
) {
152149
final SkParagraphStyleProperties properties = SkParagraphStyleProperties();
153150

@@ -184,7 +181,6 @@ class CkParagraphStyle implements ui.ParagraphStyle {
184181
properties.replaceTabCharacters = true;
185182
properties.textStyle = toSkTextStyleProperties(
186183
fontFamily, fontSize, height, fontWeight, fontStyle);
187-
properties.applyRoundingHack = applyRoundingHack;
188184

189185
return canvasKit.ParagraphStyle(properties);
190186
}

lib/web_ui/lib/text.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -685,19 +685,6 @@ abstract class Paragraph {
685685
abstract class ParagraphBuilder {
686686
factory ParagraphBuilder(ParagraphStyle style) =>
687687
engine.renderer.createParagraphBuilder(style);
688-
689-
static bool get shouldDisableRoundingHack {
690-
return const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
691-
|| _roundingHackDisabledInDebugMode;
692-
}
693-
static bool _roundingHackDisabledInDebugMode = true;
694-
static void setDisableRoundingHack(bool disableRoundingHack) {
695-
assert(() {
696-
_roundingHackDisabledInDebugMode = disableRoundingHack;
697-
return true;
698-
}());
699-
}
700-
701688
void pushStyle(TextStyle style);
702689
void pop();
703690
void addText(String text);

lib/web_ui/test/canvaskit/text_test.dart

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,7 @@ void testMain() {
123123
}
124124
});
125125
});
126-
127-
test('applyRoundingHack works', () {
128-
const double fontSize = 1.25;
129-
const String text = '12345';
130-
assert((fontSize * text.length).truncate() != fontSize * text.length);
131-
final bool roundingHackWasDisabled = ui.ParagraphBuilder.shouldDisableRoundingHack;
132-
ui.ParagraphBuilder.setDisableRoundingHack(true);
133-
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(
134-
ui.ParagraphStyle(fontSize: fontSize, fontFamily: 'FlutterTest'),
135-
);
136-
builder.addText(text);
137-
final ui.Paragraph paragraph = builder.build()
138-
..layout(const ui.ParagraphConstraints(width: text.length * fontSize));
139-
140-
expect(paragraph.maxIntrinsicWidth, text.length * fontSize);
141-
switch (paragraph.computeLineMetrics()) {
142-
case [ui.LineMetrics(width: final double width)]:
143-
expect(width, text.length * fontSize);
144-
case final List<ui.LineMetrics> metrics:
145-
expect(metrics, hasLength(1));
146-
}
147-
ui.ParagraphBuilder.setDisableRoundingHack(roundingHackWasDisabled);
148-
});
149126
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/71520
150127
}, skip: isSafari || isFirefox);
128+
151129
}

testing/dart/paragraph_test.dart

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,4 @@ void main() {
233233
expect(callback, throwsStateError);
234234
}
235235
});
236-
237-
test('disableRoundingHack works', () {
238-
const double fontSize = 1.25;
239-
const String text = '12345';
240-
assert((fontSize * text.length).truncate() != fontSize * text.length);
241-
final bool roundingHackWasDisabled = ParagraphBuilder.shouldDisableRoundingHack;
242-
ParagraphBuilder.setDisableRoundingHack(true);
243-
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
244-
builder.addText(text);
245-
final Paragraph paragraph = builder.build()
246-
..layout(const ParagraphConstraints(width: text.length * fontSize));
247-
248-
expect(paragraph.maxIntrinsicWidth, text.length * fontSize);
249-
switch (paragraph.computeLineMetrics()) {
250-
case [LineMetrics(width: final double width)]:
251-
expect(width, text.length * fontSize);
252-
case final List<LineMetrics> metrics:
253-
expect(metrics, hasLength(1));
254-
}
255-
ParagraphBuilder.setDisableRoundingHack(roundingHackWasDisabled);
256-
});
257236
}

0 commit comments

Comments
 (0)