mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[web] Fix SkParagraphBuilder tests for the chromium variant (flutter/engine#40152)
[web] Fix SkParagraphBuilder tests for the chromium variant
This commit is contained in:
parent
fd6958d467
commit
e689699e2a
@ -985,14 +985,7 @@ class CkParagraphBuilder implements ui.ParagraphBuilder {
|
||||
/// Builds the CkParagraph with the builder and deletes the builder.
|
||||
SkParagraph _buildSkParagraph() {
|
||||
if (canvasKitVariant == CanvasKitVariant.chromium) {
|
||||
final String text = _paragraphBuilder.getText();
|
||||
_paragraphBuilder.setWordsUtf16(
|
||||
fragmentUsingIntlSegmenter(text, IntlSegmenterGranularity.word),
|
||||
);
|
||||
_paragraphBuilder.setGraphemeBreaksUtf16(
|
||||
fragmentUsingIntlSegmenter(text, IntlSegmenterGranularity.grapheme),
|
||||
);
|
||||
_paragraphBuilder.setLineBreaksUtf16(fragmentUsingV8LineBreaker(text));
|
||||
injectClientICU(_paragraphBuilder);
|
||||
}
|
||||
final SkParagraph result = _paragraphBuilder.build();
|
||||
_paragraphBuilder.delete();
|
||||
|
||||
@ -7,6 +7,27 @@ import 'dart:typed_data';
|
||||
import '../dom.dart';
|
||||
import '../text/line_breaker.dart';
|
||||
import 'canvaskit_api.dart';
|
||||
import 'renderer.dart';
|
||||
|
||||
/// Injects required ICU data into the [builder].
|
||||
///
|
||||
/// This should only be used with the CanvasKit Chromium variant that's compiled
|
||||
/// without ICU data.
|
||||
void injectClientICU(SkParagraphBuilder builder) {
|
||||
assert(
|
||||
canvasKitVariant == CanvasKitVariant.chromium,
|
||||
'This method should only be used with the CanvasKit Chromium variant.',
|
||||
);
|
||||
|
||||
final String text = builder.getText();
|
||||
builder.setWordsUtf16(
|
||||
fragmentUsingIntlSegmenter(text, IntlSegmenterGranularity.word),
|
||||
);
|
||||
builder.setGraphemeBreaksUtf16(
|
||||
fragmentUsingIntlSegmenter(text, IntlSegmenterGranularity.grapheme),
|
||||
);
|
||||
builder.setLineBreaksUtf16(fragmentUsingV8LineBreaker(text));
|
||||
}
|
||||
|
||||
/// The granularity at which to segment text.
|
||||
///
|
||||
|
||||
@ -1624,6 +1624,9 @@ void _paragraphTests() {
|
||||
builder.pushStyle(
|
||||
canvasKit.TextStyle(SkTextStyleProperties()..halfLeading = true));
|
||||
builder.pop();
|
||||
if (canvasKitVariant == CanvasKitVariant.chromium) {
|
||||
injectClientICU(builder);
|
||||
}
|
||||
final SkParagraph paragraph = builder.build();
|
||||
paragraph.layout(500);
|
||||
|
||||
@ -1739,6 +1742,10 @@ void _paragraphTests() {
|
||||
);
|
||||
builder.addText('hello');
|
||||
|
||||
if (canvasKitVariant == CanvasKitVariant.chromium) {
|
||||
injectClientICU(builder);
|
||||
}
|
||||
|
||||
final SkParagraph paragraph = builder.build();
|
||||
paragraph.layout(500);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user