mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove migration flag and unused header files (flutter/engine#50216)
The `applyRoundingHack` flag is no longer used by the framework. This also removes the [lib/ui/text/line_metrics.h](https://github.com/flutter/engine/pull/50216/files#diff-9175619f2b114dffef67eba38511b34afe6abefd4f697f4758647133895b34f5) file which doesn't seem to be referenced anywhere. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
parent
e858c7847f
commit
737437f718
@ -5859,7 +5859,6 @@ ORIGIN: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc + ../../../f
|
||||
ORIGIN: ../../../flutter/lib/ui/text/asset_manager_font_provider.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/ui/text/font_collection.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/ui/text/font_collection.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/ui/text/line_metrics.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/ui/text/paragraph.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/ui/text/paragraph.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/ui/text/paragraph_builder.cc + ../../../flutter/LICENSE
|
||||
@ -8722,7 +8721,6 @@ FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc
|
||||
FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.h
|
||||
FILE: ../../../flutter/lib/ui/text/font_collection.cc
|
||||
FILE: ../../../flutter/lib/ui/text/font_collection.h
|
||||
FILE: ../../../flutter/lib/ui/text/line_metrics.h
|
||||
FILE: ../../../flutter/lib/ui/text/paragraph.cc
|
||||
FILE: ../../../flutter/lib/ui/text/paragraph.h
|
||||
FILE: ../../../flutter/lib/ui/text/paragraph_builder.cc
|
||||
|
||||
@ -123,7 +123,6 @@ source_set("ui") {
|
||||
"text/asset_manager_font_provider.h",
|
||||
"text/font_collection.cc",
|
||||
"text/font_collection.h",
|
||||
"text/line_metrics.h",
|
||||
"text/paragraph.cc",
|
||||
"text/paragraph.h",
|
||||
"text/paragraph_builder.cc",
|
||||
|
||||
@ -3355,23 +3355,6 @@ abstract class ParagraphBuilder {
|
||||
/// [Paragraph].
|
||||
factory ParagraphBuilder(ParagraphStyle style) = _NativeParagraphBuilder;
|
||||
|
||||
/// Whether the rounding hack enabled by default in SkParagraph and TextPainter
|
||||
/// is disabled.
|
||||
///
|
||||
/// Do not rely on this getter as it exists for migration purposes only and
|
||||
/// will soon be removed.
|
||||
@Deprecated('''
|
||||
The shouldDisableRoundingHack flag is for internal migration purposes only and should not be used.
|
||||
''')
|
||||
static bool get shouldDisableRoundingHack => _shouldDisableRoundingHack;
|
||||
static bool _shouldDisableRoundingHack = true;
|
||||
/// Do not call this method as it is for migration purposes only and will soon
|
||||
/// be removed.
|
||||
// ignore: use_setters_to_change_properties
|
||||
static void setDisableRoundingHack(bool disableRoundingHack) {
|
||||
_shouldDisableRoundingHack = disableRoundingHack;
|
||||
}
|
||||
|
||||
/// The number of placeholders currently in the paragraph.
|
||||
int get placeholderCount;
|
||||
|
||||
@ -3489,11 +3472,10 @@ base class _NativeParagraphBuilder extends NativeFieldWrapperClass1 implements P
|
||||
style._height ?? 0,
|
||||
style._ellipsis ?? '',
|
||||
_encodeLocale(style._locale),
|
||||
!ParagraphBuilder.shouldDisableRoundingHack,
|
||||
);
|
||||
}
|
||||
|
||||
@Native<Void Function(Handle, Handle, Handle, Handle, Handle, Double, Double, Handle, Handle, Bool)>(symbol: 'ParagraphBuilder::Create')
|
||||
@Native<Void Function(Handle, Handle, Handle, Handle, Handle, Double, Double, Handle, Handle)>(symbol: 'ParagraphBuilder::Create')
|
||||
external void _constructor(
|
||||
Int32List encoded,
|
||||
ByteData? strutData,
|
||||
@ -3503,7 +3485,7 @@ base class _NativeParagraphBuilder extends NativeFieldWrapperClass1 implements P
|
||||
double height,
|
||||
String ellipsis,
|
||||
String locale,
|
||||
bool applyRoundingHack);
|
||||
);
|
||||
|
||||
@override
|
||||
int get placeholderCount => _placeholderCount;
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_
|
||||
#define FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_
|
||||
|
||||
#include "third_party/dart/runtime/include/dart_api.h"
|
||||
#include "third_party/tonic/converter/dart_converter.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
struct LineMetrics {
|
||||
const bool* hard_break;
|
||||
|
||||
// The final computed ascent and descent for the line. This can be impacted by
|
||||
// the strut, height, scaling, as well as outlying runs that are very tall.
|
||||
//
|
||||
// The top edge is `baseline - ascent` and the bottom edge is `baseline +
|
||||
// descent`. Ascent and descent are provided as positive numbers. Raw numbers
|
||||
// for specific runs of text can be obtained in run_metrics_map. These values
|
||||
// are the cumulative metrics for the entire line.
|
||||
const double* ascent;
|
||||
const double* descent;
|
||||
const double* unscaled_ascent;
|
||||
// Height of the line.
|
||||
const double* height;
|
||||
// Width of the line.
|
||||
const double* width;
|
||||
// The left edge of the line. The right edge can be obtained with `left +
|
||||
// width`
|
||||
const double* left;
|
||||
// The y position of the baseline for this line from the top of the paragraph.
|
||||
const double* baseline;
|
||||
// Zero indexed line number.
|
||||
const size_t* line_number;
|
||||
|
||||
LineMetrics();
|
||||
|
||||
LineMetrics(const bool* hard_break,
|
||||
const double* ascent,
|
||||
const double* descent,
|
||||
const double* unscaled_ascent,
|
||||
const double* height,
|
||||
const double* width,
|
||||
const double* left,
|
||||
const double* baseline,
|
||||
const size_t* line_number)
|
||||
: hard_break(hard_break),
|
||||
ascent(ascent),
|
||||
descent(descent),
|
||||
unscaled_ascent(unscaled_ascent),
|
||||
height(height),
|
||||
width(width),
|
||||
left(left),
|
||||
baseline(baseline),
|
||||
line_number(line_number) {}
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_
|
||||
@ -8,7 +8,6 @@
|
||||
#include "flutter/fml/message_loop.h"
|
||||
#include "flutter/lib/ui/dart_wrapper.h"
|
||||
#include "flutter/lib/ui/painting/canvas.h"
|
||||
#include "flutter/lib/ui/text/line_metrics.h"
|
||||
#include "flutter/third_party/txt/src/txt/paragraph.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
@ -151,12 +151,11 @@ void ParagraphBuilder::Create(Dart_Handle wrapper,
|
||||
double fontSize,
|
||||
double height,
|
||||
const std::u16string& ellipsis,
|
||||
const std::string& locale,
|
||||
bool applyRoundingHack) {
|
||||
const std::string& locale) {
|
||||
UIDartState::ThrowIfUIOperationsProhibited();
|
||||
auto res = fml::MakeRefCounted<ParagraphBuilder>(
|
||||
encoded_handle, strutData, fontFamily, strutFontFamilies, fontSize,
|
||||
height, ellipsis, locale, applyRoundingHack);
|
||||
height, ellipsis, locale);
|
||||
res->AssociateWithDartWrapper(wrapper);
|
||||
}
|
||||
|
||||
@ -231,8 +230,7 @@ ParagraphBuilder::ParagraphBuilder(
|
||||
double fontSize,
|
||||
double height,
|
||||
const std::u16string& ellipsis,
|
||||
const std::string& locale,
|
||||
bool applyRoundingHack) {
|
||||
const std::string& locale) {
|
||||
int32_t mask = 0;
|
||||
txt::ParagraphStyle style;
|
||||
{
|
||||
@ -293,7 +291,6 @@ ParagraphBuilder::ParagraphBuilder(
|
||||
if (mask & kPSLocaleMask) {
|
||||
style.locale = locale;
|
||||
}
|
||||
style.apply_rounding_hack = applyRoundingHack;
|
||||
|
||||
FontCollection& font_collection = UIDartState::Current()
|
||||
->platform_configuration()
|
||||
|
||||
@ -30,8 +30,7 @@ class ParagraphBuilder : public RefCountedDartWrappable<ParagraphBuilder> {
|
||||
double fontSize,
|
||||
double height,
|
||||
const std::u16string& ellipsis,
|
||||
const std::string& locale,
|
||||
bool applyRoundingHack);
|
||||
const std::string& locale);
|
||||
|
||||
~ParagraphBuilder() override;
|
||||
|
||||
@ -77,8 +76,7 @@ class ParagraphBuilder : public RefCountedDartWrappable<ParagraphBuilder> {
|
||||
double fontSize,
|
||||
double height,
|
||||
const std::u16string& ellipsis,
|
||||
const std::string& locale,
|
||||
bool applyRoundingHack);
|
||||
const std::string& locale);
|
||||
|
||||
std::unique_ptr<txt::ParagraphBuilder> m_paragraph_builder_;
|
||||
};
|
||||
|
||||
@ -379,7 +379,6 @@ class CanvasKitRenderer implements Renderer {
|
||||
strutStyle: strutStyle,
|
||||
ellipsis: ellipsis,
|
||||
locale: locale,
|
||||
applyRoundingHack: !ui.ParagraphBuilder.shouldDisableRoundingHack,
|
||||
);
|
||||
|
||||
@override
|
||||
|
||||
@ -33,7 +33,6 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
ui.StrutStyle? strutStyle,
|
||||
String? ellipsis,
|
||||
ui.Locale? locale,
|
||||
bool applyRoundingHack = true,
|
||||
}) : skParagraphStyle = toSkParagraphStyle(
|
||||
textAlign,
|
||||
textDirection,
|
||||
@ -47,7 +46,6 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
strutStyle,
|
||||
ellipsis,
|
||||
locale,
|
||||
applyRoundingHack,
|
||||
),
|
||||
_textAlign = textAlign,
|
||||
_textDirection = textDirection,
|
||||
@ -163,7 +161,6 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
ui.StrutStyle? strutStyle,
|
||||
String? ellipsis,
|
||||
ui.Locale? locale,
|
||||
bool applyRoundingHack,
|
||||
) {
|
||||
final SkParagraphStyleProperties properties = SkParagraphStyleProperties();
|
||||
|
||||
@ -200,7 +197,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
properties.replaceTabCharacters = true;
|
||||
properties.textStyle = toSkTextStyleProperties(
|
||||
fontFamily, fontSize, height, fontWeight, fontStyle);
|
||||
properties.applyRoundingHack = applyRoundingHack;
|
||||
properties.applyRoundingHack = false;
|
||||
|
||||
return canvasKit.ParagraphStyle(properties);
|
||||
}
|
||||
|
||||
@ -87,17 +87,6 @@ class CanvasParagraph implements ui.Paragraph {
|
||||
|
||||
@override
|
||||
void layout(ui.ParagraphConstraints constraints) {
|
||||
// When constraint width has a decimal place, we floor it to avoid getting
|
||||
// a layout width that's higher than the constraint width.
|
||||
//
|
||||
// For example, if constraint width is `30.8` and the text has a width of
|
||||
// `30.5` then the TextPainter in the framework will ceil the `30.5` width
|
||||
// which will result in a width of `40.0` that's higher than the constraint
|
||||
// width.
|
||||
if (!ui.ParagraphBuilder.shouldDisableRoundingHack) {
|
||||
constraints = ui.ParagraphConstraints(width: constraints.width.floorToDouble());
|
||||
}
|
||||
|
||||
if (constraints == _lastUsedConstraints) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -733,13 +733,6 @@ abstract class ParagraphBuilder {
|
||||
factory ParagraphBuilder(ParagraphStyle style) =>
|
||||
engine.renderer.createParagraphBuilder(style);
|
||||
|
||||
static bool get shouldDisableRoundingHack => _shouldDisableRoundingHack;
|
||||
static bool _shouldDisableRoundingHack = true;
|
||||
// ignore: use_setters_to_change_properties
|
||||
static void setDisableRoundingHack(bool disableRoundingHack) {
|
||||
_shouldDisableRoundingHack = disableRoundingHack;
|
||||
}
|
||||
|
||||
void pushStyle(TextStyle style);
|
||||
void pop();
|
||||
void addText(String text);
|
||||
|
||||
@ -204,9 +204,7 @@ void testMain() {
|
||||
expect(bottomRight?.writingDirection, ui.TextDirection.ltr);
|
||||
});
|
||||
|
||||
test('rounding hack disabled by default', () {
|
||||
expect(ui.ParagraphBuilder.shouldDisableRoundingHack, isTrue);
|
||||
|
||||
test('rounding hack disabled', () {
|
||||
const double fontSize = 1.25;
|
||||
const String text = '12345';
|
||||
assert((fontSize * text.length).truncate() != fontSize * text.length);
|
||||
@ -226,32 +224,6 @@ void testMain() {
|
||||
}
|
||||
});
|
||||
|
||||
test('setDisableRoundinghHack to false works in tests', () {
|
||||
bool assertsEnabled = false;
|
||||
assert(() {
|
||||
assertsEnabled = true;
|
||||
return true;
|
||||
}());
|
||||
if (!assertsEnabled){
|
||||
return;
|
||||
}
|
||||
|
||||
if (ui.ParagraphBuilder.shouldDisableRoundingHack) {
|
||||
ui.ParagraphBuilder.setDisableRoundingHack(false);
|
||||
addTearDown(() => ui.ParagraphBuilder.setDisableRoundingHack(true));
|
||||
}
|
||||
|
||||
assert(!ui.ParagraphBuilder.shouldDisableRoundingHack);
|
||||
const double fontSize = 1.25;
|
||||
const String text = '12345';
|
||||
assert((fontSize * text.length).truncate() != fontSize * text.length);
|
||||
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(fontSize: fontSize, fontFamily: 'FlutterTest'));
|
||||
builder.addText(text);
|
||||
final ui.Paragraph paragraph = builder.build()
|
||||
..layout(const ui.ParagraphConstraints(width: text.length * fontSize));
|
||||
expect(paragraph.computeLineMetrics().length, greaterThan(1));
|
||||
});
|
||||
|
||||
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/71520
|
||||
}, skip: isSafari || isFirefox);
|
||||
}
|
||||
|
||||
@ -777,21 +777,6 @@ Future<void> testMain() async {
|
||||
expect(paragraph.longestLine, 50.0);
|
||||
});
|
||||
|
||||
test('$CanvasParagraph.width should be a whole integer when shouldDisableRoundingHack is false', () {
|
||||
if (ui.ParagraphBuilder.shouldDisableRoundingHack) {
|
||||
ui.ParagraphBuilder.setDisableRoundingHack(false);
|
||||
addTearDown(() => ui.ParagraphBuilder.setDisableRoundingHack(true));
|
||||
}
|
||||
// The paragraph width is only rounded to a whole integer if
|
||||
// shouldDisableRoundingHack is false.
|
||||
assert(!ui.ParagraphBuilder.shouldDisableRoundingHack);
|
||||
final ui.Paragraph paragraph = plain(ahemStyle, 'abc');
|
||||
paragraph.layout(const ui.ParagraphConstraints(width: 30.8));
|
||||
|
||||
expect(paragraph.width, 30);
|
||||
expect(paragraph.height, 10);
|
||||
});
|
||||
|
||||
test('Render after dispose', () async {
|
||||
final ui.Paragraph paragraph = plain(ahemStyle, 'abc');
|
||||
paragraph.layout(const ui.ParagraphConstraints(width: 30.8));
|
||||
|
||||
@ -200,12 +200,7 @@ Future<void> testMain() async {
|
||||
expect(bottomRight?.graphemeClusterLayoutBounds, const Rect.fromLTWH(0.0, 0.0, 10.0, 10.0));
|
||||
}, skip: domIntl.v8BreakIterator == null); // Intended: Intl.v8breakiterator is needed for correctly breaking grapheme clusters.
|
||||
|
||||
test('Can disable rounding hack', () {
|
||||
if (!ParagraphBuilder.shouldDisableRoundingHack) {
|
||||
ParagraphBuilder.setDisableRoundingHack(true);
|
||||
addTearDown(() => ParagraphBuilder.setDisableRoundingHack(false));
|
||||
}
|
||||
assert(ParagraphBuilder.shouldDisableRoundingHack);
|
||||
test('disable rounding hack', () {
|
||||
const double fontSize = 1;
|
||||
const String text = '12345';
|
||||
const double letterSpacing = 0.25;
|
||||
|
||||
@ -333,42 +333,10 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('can set disableRoundingHack to false in tests', () {
|
||||
bool assertsEnabled = false;
|
||||
assert(() {
|
||||
assertsEnabled = true;
|
||||
return true;
|
||||
}());
|
||||
if (!assertsEnabled){
|
||||
return;
|
||||
}
|
||||
test('rounding hack disabled', () {
|
||||
const double fontSize = 1.25;
|
||||
const String text = '12345';
|
||||
assert((fontSize * text.length).truncate() != fontSize * text.length);
|
||||
// ignore: deprecated_member_use
|
||||
final bool roundingHackWasDisabled = ParagraphBuilder.shouldDisableRoundingHack;
|
||||
if (roundingHackWasDisabled) {
|
||||
ParagraphBuilder.setDisableRoundingHack(false);
|
||||
}
|
||||
// ignore: deprecated_member_use
|
||||
assert(!ParagraphBuilder.shouldDisableRoundingHack);
|
||||
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
|
||||
builder.addText(text);
|
||||
final Paragraph paragraph = builder.build()
|
||||
..layout(const ParagraphConstraints(width: text.length * fontSize));
|
||||
expect(paragraph.computeLineMetrics().length, greaterThan(1));
|
||||
|
||||
if (roundingHackWasDisabled) {
|
||||
ParagraphBuilder.setDisableRoundingHack(true);
|
||||
}
|
||||
});
|
||||
|
||||
test('rounding hack disabled by default', () {
|
||||
const double fontSize = 1.25;
|
||||
const String text = '12345';
|
||||
assert((fontSize * text.length).truncate() != fontSize * text.length);
|
||||
// ignore: deprecated_member_use
|
||||
expect(ParagraphBuilder.shouldDisableRoundingHack, isTrue);
|
||||
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize));
|
||||
builder.addText(text);
|
||||
final Paragraph paragraph = builder.build()
|
||||
|
||||
@ -139,7 +139,7 @@ skt::ParagraphStyle ParagraphBuilderSkia::TxtToSkia(const ParagraphStyle& txt) {
|
||||
|
||||
skia.turnHintingOff();
|
||||
skia.setReplaceTabCharacters(true);
|
||||
skia.setApplyRoundingHack(txt.apply_rounding_hack);
|
||||
skia.setApplyRoundingHack(false);
|
||||
|
||||
return skia;
|
||||
}
|
||||
|
||||
@ -95,14 +95,6 @@ class ParagraphStyle {
|
||||
std::u16string ellipsis;
|
||||
std::string locale;
|
||||
|
||||
// Temporary flag that indicates whether the Paragraph should report its
|
||||
// metrics with rounding hacks applied.
|
||||
//
|
||||
// This flag currently defaults to true and will be flipped to false once the
|
||||
// migration is complete.
|
||||
// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/31707
|
||||
bool apply_rounding_hack = true;
|
||||
|
||||
TextStyle GetTextStyle() const;
|
||||
|
||||
bool unlimited_lines() const;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user