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