Unverified Commit f2574ba1 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Use the new rounding hack migration flag in TextPainter (#130548)

parent d5c724eb
......@@ -278,13 +278,10 @@ class _TextLayout {
// object when it's no logner needed.
ui.Paragraph _paragraph;
/// Whether to enable the rounding in _applyFloatingPointHack and SkParagraph.
static const bool _shouldApplyFloatingPointHack = !bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK');
// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/31707
// remove this hack as well as the flooring in `layout`.
@pragma('vm:prefer-inline')
static double _applyFloatingPointHack(double layoutValue) => _shouldApplyFloatingPointHack ? layoutValue.ceilToDouble() : layoutValue;
static double _applyFloatingPointHack(double layoutValue) => ui.ParagraphBuilder.shouldDisableRoundingHack ? layoutValue : layoutValue.ceilToDouble();
/// Whether this layout has been invalidated and disposed.
///
......@@ -362,7 +359,7 @@ class _TextPainterLayoutCacheWithOffset {
static double _contentWidthFor(double minWidth, double maxWidth, TextWidthBasis widthBasis, _TextLayout layout) {
// TODO(LongCatIsLooong): remove the rounding when _applyFloatingPointHack
// is removed.
if (_TextLayout._shouldApplyFloatingPointHack) {
if (!ui.ParagraphBuilder.shouldDisableRoundingHack) {
minWidth = minWidth.floorToDouble();
maxWidth = maxWidth.floorToDouble();
}
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show ParagraphBuilder;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -50,7 +52,7 @@ void main() {
expect(tester.getTopLeft(find.text('0')), const Offset(16, -4));
final RenderBox box = tester.renderObject(find.byType(Badge));
final RRect rrect = const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
final RRect rrect = ui.ParagraphBuilder.shouldDisableRoundingHack
? RRect.fromLTRBR(12, -4, 31.5, 12, const Radius.circular(8))
: RRect.fromLTRBR(12, -4, 32, 12, const Radius.circular(8));
expect(box, paints..rrect(rrect: rrect, color: theme.colorScheme.error));
......@@ -92,7 +94,7 @@ void main() {
expect(tester.getTopLeft(find.text('0')), const Offset(0, -4));
final RenderBox box = tester.renderObject(find.byType(Badge));
final RRect rrect = const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
final RRect rrect = ui.ParagraphBuilder.shouldDisableRoundingHack
? RRect.fromLTRBR(-4, -4, 15.5, 12, const Radius.circular(8))
: RRect.fromLTRBR(-4, -4, 16, 12, const Radius.circular(8));
expect(box, paints..rrect(rrect: rrect, color: theme.colorScheme.error));
......@@ -149,7 +151,7 @@ void main() {
// T = alignment.top
// R = L + '0'.width + padding.width
// B = T + largeSize, R = largeSize/2
final RRect rrect = const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
final RRect rrect = ui.ParagraphBuilder.shouldDisableRoundingHack
? RRect.fromLTRBR(12, -4, 31.5, 12, const Radius.circular(8))
: RRect.fromLTRBR(12, -4, 32, 12, const Radius.circular(8));
expect(box, paints..rrect(rrect: rrect, color: theme.colorScheme.error));
......
......@@ -134,7 +134,7 @@ void main() {
);
expect(
saveButtonBottomLeft.dx,
const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK') ? moreOrLessEquals(711.6, epsilon: 1e-5) : (800 - 89.0),
ParagraphBuilder.shouldDisableRoundingHack ? moreOrLessEquals(711.6, epsilon: 1e-5) : (800 - 89.0),
);
expect(saveButtonBottomLeft.dy, helpTextTopLeft.dy);
expect(entryButtonBottomLeft.dx, saveButtonBottomLeft.dx - 48.0);
......
......@@ -7,6 +7,8 @@
@Tags(<String>['reduced-test-set'])
library;
import 'dart:ui' as ui show ParagraphBuilder;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -470,7 +472,7 @@ void main() {
),
);
final double textWidth = const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
final double textWidth = ui.ParagraphBuilder.shouldDisableRoundingHack
? width
: (width / 1.5).floorToDouble() * 1.5;
// The title is scaled and transformed to be 1.5 times bigger, when the
......@@ -541,7 +543,7 @@ void main() {
// bottom edge.
const double bottomMargin = titleFontSize * (expandedTitleScale - 1);
final double textWidth = const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
final double textWidth = ui.ParagraphBuilder.shouldDisableRoundingHack
? collapsedWidth
: (collapsedWidth / 3).floorToDouble() * 3;
// The title is scaled and transformed to be 3 times bigger, when the
......
......@@ -5928,10 +5928,10 @@ void main() {
}
final Rect clipRect = arguments[0] as Rect;
// _kFinalLabelScale = 0.75
const double width = bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
final double width = ParagraphBuilder.shouldDisableRoundingHack
? 100 / 0.75
: 133.0;
expect(clipRect, rectMoreOrLessEquals(const Rect.fromLTWH(0, 0, width, 16.0), epsilon: 1e-5));
expect(clipRect, rectMoreOrLessEquals(Rect.fromLTWH(0, 0, width, 16.0), epsilon: 1e-5));
return true;
}),
);
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show ParagraphBuilder;
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
......@@ -583,7 +585,7 @@ void main() {
// Padding at the top of the rail.
const double topPadding = 8.0;
// Width of a destination.
const double destinationWidth = bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK') ? 125.5 : 126.0;
final double destinationWidth = ui.ParagraphBuilder.shouldDisableRoundingHack ? 125.5 : 126.0;
// Height of a destination indicator with icon.
const double destinationHeight = 32.0;
// Space between the indicator and label.
......@@ -858,7 +860,7 @@ void main() {
// Padding at the top of the rail.
const double topPadding = 8.0;
// Width of a destination.
const double destinationWidth = bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK') ? 125.5 : 126.0;
final double destinationWidth = ui.ParagraphBuilder.shouldDisableRoundingHack ? 125.5 : 126.0;
// Height of a destination indicator with icon.
const double destinationHeight = 32.0;
// Space between the indicator and label.
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show ParagraphBuilder;
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
......@@ -1066,8 +1068,8 @@ void main() {
);
expect(tester.getSize(find.byType(OutlinedButton)), equals(const Size(88.0, 48.0)));
expect(tester.getSize(find.byType(Text)), const Size(
bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK') ? 52.5 : 53.0,
expect(tester.getSize(find.byType(Text)), Size(
ui.ParagraphBuilder.shouldDisableRoundingHack ? 52.5 : 53.0,
18.0,
));
......
......@@ -7,6 +7,8 @@
@Tags(<String>['reduced-test-set'])
library;
import 'dart:ui' as ui show ParagraphBuilder;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -607,8 +609,8 @@ void main() {
..line(
color: theme.colorScheme.primary,
strokeWidth: indicatorWeight,
p1: const Offset(bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK') ? 65.75 : 65.5, indicatorY),
p2: const Offset(bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK') ? 134.25 : 134.5, indicatorY),
p1: Offset(ui.ParagraphBuilder.shouldDisableRoundingHack ? 65.75 : 65.5, indicatorY),
p2: Offset(ui.ParagraphBuilder.shouldDisableRoundingHack ? 134.25 : 134.5, indicatorY),
),
);
});
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show ParagraphBuilder;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -489,7 +491,7 @@ void main() {
const double indicatorWeight = 3.0;
final RRect rrect = const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
final RRect rrect = ui.ParagraphBuilder.shouldDisableRoundingHack
? RRect.fromLTRBAndCorners(
64.75,
tabBarBox.size.height - indicatorWeight,
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show ParagraphBuilder;
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
......@@ -618,12 +620,12 @@ void main() {
),
);
const Size textButtonSize = bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
? Size(68.5, 48.0)
: Size(69.0, 48.0);
const Size textSize = bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')
? Size(52.5, 18.0)
: Size(53.0, 18.0);
final Size textButtonSize = ui.ParagraphBuilder.shouldDisableRoundingHack
? const Size(68.5, 48.0)
: const Size(69.0, 48.0);
final Size textSize = ui.ParagraphBuilder.shouldDisableRoundingHack
? const Size(52.5, 18.0)
: const Size(53.0, 18.0);
expect(tester.getSize(find.byType(TextButton)), textButtonSize);
expect(tester.getSize(find.byType(Text)), textSize);
......
......@@ -746,7 +746,7 @@ void main() {
case MaterialType.material2:
expect(tester.getTopLeft(find.text(selectTimeString)), equals(const Offset(154, 155)));
expect(tester.getBottomRight(find.text(selectTimeString)), equals(
const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK') ? const Offset(280.5, 165) : const Offset(281, 165),
ParagraphBuilder.shouldDisableRoundingHack ? const Offset(280.5, 165) : const Offset(281, 165),
));
expect(tester.getBottomRight(find.text(okString)).dx, 644);
expect(tester.getBottomLeft(find.text(okString)).dx, 616);
......@@ -768,7 +768,7 @@ void main() {
switch (materialType) {
case MaterialType.material2:
expect(tester.getTopLeft(find.text(selectTimeString)), equals(
const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK') ? const Offset(519.5, 155) : const Offset(519, 155),
ParagraphBuilder.shouldDisableRoundingHack ? const Offset(519.5, 155) : const Offset(519, 155),
));
expect(tester.getBottomRight(find.text(selectTimeString)), equals(const Offset(646, 165)));
expect(tester.getBottomLeft(find.text(okString)).dx, 156);
......
......@@ -1509,7 +1509,7 @@ void main() {
});
test('TextPainter line breaking does not round to integers', () {
if (! const bool.hasEnvironment('SKPARAGRAPH_REMOVE_ROUNDING_HACK')) {
if (!ui.ParagraphBuilder.shouldDisableRoundingHack) {
return;
}
const double fontSize = 1.25;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment