Skip to content

Commit c3c8727

Browse files
authored
Revert "[web] roll CanvasKit to 0.36.1 (#35747)" (#35837)
This reverts commit d782c33.
1 parent ef039c1 commit c3c8727

File tree

8 files changed

+63
-110
lines changed

8 files changed

+63
-110
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ vars = {
2222

2323
# WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY
2424
# See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
25-
'canvaskit_cipd_instance': '8wh6J7ZXGCgo1vvCQIqkmskYQZfjhcXQG1YCKFNrzRUC',
25+
'canvaskit_cipd_instance': 'yrsfF-vTvu4jzBBm1o6tDl70dky-l4G29Dnj75UvRDgC',
2626

2727
# Do not download the Emscripten SDK by default.
2828
# This prevents us from downloading the Emscripten toolchain for builds

lib/web_ui/dev/canvaskit_lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Specifies the version of CanvasKit to use for Flutter Web apps.
22
#
33
# See `lib/web_ui/README.md` for how to update this file.
4-
canvaskit_version: "0.36.1"
4+
canvaskit_version: "0.35.0"

lib/web_ui/lib/src/engine/assets.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ import 'dart:convert';
66
import 'dart:typed_data';
77

88
import 'dom.dart';
9+
import 'text/font_collection.dart';
910
import 'util.dart';
1011

11-
const String ahemFontFamily = 'Ahem';
12-
const String ahemFontUrl = '/assets/fonts/ahem.ttf';
13-
const String robotoFontFamily = 'Roboto';
14-
const String robotoTestFontUrl = '/assets/fonts/Roboto-Regular.ttf';
15-
const String robotoVariableFontFamily = 'RobotoVariable';
16-
const String robotoVariableTestFontUrl = '/assets/fonts/RobotoSlab-VariableFont_wght.ttf';
17-
1812
/// This class downloads assets over the network.
1913
///
2014
/// The assets are resolved relative to [assetsDir] inside the directory

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,11 @@ extension SkPictureExtension on SkPicture {
18531853
class SkParagraphBuilderNamespace {}
18541854

18551855
extension SkParagraphBuilderNamespaceExtension on SkParagraphBuilderNamespace {
1856+
external SkParagraphBuilder Make(
1857+
SkParagraphStyle paragraphStyle,
1858+
SkFontMgr? fontManager,
1859+
);
1860+
18561861
external SkParagraphBuilder MakeFromFontProvider(
18571862
SkParagraphStyle paragraphStyle,
18581863
TypefaceFontProvider? fontManager,

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import 'font_fallbacks.dart';
2020
const String _robotoUrl =
2121
'https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf';
2222

23+
// URL for the Ahem font, only used in tests.
24+
const String _ahemUrl = '/assets/fonts/ahem.ttf';
25+
2326
/// Manages the fonts used in the Skia-based backend.
2427
class SkiaFontCollection implements FontCollection {
2528
final Set<String> _registeredFontFamilies = <String>{};
@@ -167,19 +170,13 @@ class SkiaFontCollection implements FontCollection {
167170
/// different URLs.
168171
@override
169172
void debugRegisterTestFonts() {
170-
if (!_isFontFamilyRegistered(ahemFontFamily)) {
171-
_registerFont(ahemFontUrl, ahemFontFamily);
172-
}
173-
if (!_isFontFamilyRegistered(robotoFontFamily)) {
174-
_registerFont(robotoTestFontUrl, robotoFontFamily);
175-
}
176-
if (!_isFontFamilyRegistered(robotoVariableFontFamily)) {
177-
_registerFont(robotoVariableTestFontUrl, robotoVariableFontFamily);
173+
if (!_isFontFamilyRegistered('Ahem')) {
174+
_registerFont(_ahemUrl, 'Ahem');
178175
}
179176

180177
// Ahem must be added to font fallbacks list regardless of where it was
181178
// downloaded from.
182-
FontFallbackData.instance.globalFontFallbacks.add(ahemFontFamily);
179+
FontFallbackData.instance.globalFontFallbacks.add('Ahem');
183180
}
184181

185182
void _registerFont(String url, String family) {
@@ -224,6 +221,7 @@ class SkiaFontCollection implements FontCollection {
224221
.then<ByteBuffer>((dynamic x) => x as ByteBuffer);
225222
}
226223

224+
SkFontMgr? skFontMgr;
227225
TypefaceFontProvider? fontProvider;
228226

229227
@override

lib/web_ui/lib/src/engine/configuration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import 'package:js/js.dart';
3232
/// The version of CanvasKit used by the web engine by default.
3333
// DO NOT EDIT THE NEXT LINE OF CODE MANUALLY
3434
// See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
35-
const String _canvaskitVersion = '0.36.1';
35+
const String _canvaskitVersion = '0.35.0';
3636

3737
/// The Web Engine configuration for the current application.
3838
FlutterConfiguration get configuration => _configuration ??= FlutterConfiguration(_jsConfiguration);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import '../safe_browser_api.dart';
1414
import '../util.dart';
1515
import 'layout_service.dart';
1616

17+
const String ahemFontFamily = 'Ahem';
18+
const String ahemFontUrl = '/assets/fonts/ahem.ttf';
19+
const String robotoFontFamily = 'Roboto';
20+
const String robotoTestFontUrl = '/assets/fonts/Roboto-Regular.ttf';
21+
const String robotoVariableFontFamily = 'RobotoVariable';
22+
const String robotoVariableTestFontUrl = '/assets/fonts/RobotoSlab-VariableFont_wght.ttf';
23+
1724
/// This class is responsible for registering and loading fonts.
1825
///
1926
/// Once an asset manager has been set in the framework, call

lib/web_ui/test/canvaskit/canvaskit_api_test.dart

Lines changed: 40 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:test/test.dart';
1010

1111
import 'package:ui/src/engine.dart';
1212
import 'package:ui/ui.dart' as ui;
13-
import 'package:web_engine_tester/golden_tester.dart';
1413

1514
import '../matchers.dart';
1615
import 'common.dart';
@@ -50,9 +49,7 @@ void testMain() {
5049
_matrix4x4CompositionTests();
5150
_toSkRectTests();
5251
_skVerticesTests();
53-
group('SkParagraph', () {
54-
_paragraphTests();
55-
});
52+
_paragraphTests();
5653
group('SkPath', () {
5754
_pathTests();
5855
});
@@ -1450,36 +1447,31 @@ void _textStyleTests() {
14501447
}
14511448

14521449
void _paragraphTests() {
1453-
setUpAll(() async {
1454-
CanvasKitRenderer.instance.fontCollection.debugRegisterTestFonts();
1455-
await CanvasKitRenderer.instance.fontCollection.ensureFontsLoaded();
1456-
});
1457-
14581450
// This test is just a kitchen sink that blasts CanvasKit with all paragraph
14591451
// properties all at once, making sure CanvasKit doesn't choke on anything.
14601452
// In particular, this tests that our JS bindings are correct, such as that
14611453
// arguments are of acceptable types and passed in the correct order.
1462-
test('kitchensink', () async {
1454+
test('SkParagraph API kitchensink', () {
14631455
final SkParagraphStyleProperties props = SkParagraphStyleProperties();
1464-
props.textAlign = canvasKit.TextAlign.Left;
1456+
props.textAlign = canvasKit.TextAlign.Center;
14651457
props.textDirection = canvasKit.TextDirection.RTL;
14661458
props.heightMultiplier = 3;
14671459
props.textHeightBehavior = canvasKit.TextHeightBehavior.All;
14681460
props.maxLines = 4;
14691461
props.ellipsis = '___';
14701462
props.textStyle = SkTextStyleProperties()
1471-
..backgroundColor = Float32List.fromList(<double>[0.2, 0, 0, 0.5])
1472-
..color = Float32List.fromList(<double>[0, 1, 0, 1])
1473-
..foregroundColor = Float32List.fromList(<double>[1, 0, 1, 1])
1463+
..backgroundColor = Float32List.fromList(<double>[1, 2, 3, 4])
1464+
..color = Float32List.fromList(<double>[5, 6, 7, 8])
1465+
..foregroundColor = Float32List.fromList(<double>[9, 10, 11, 12])
14741466
..decoration = 0x2
14751467
..decorationThickness = 2.0
14761468
..decorationColor = Float32List.fromList(<double>[13, 14, 15, 16])
14771469
..decorationStyle = canvasKit.DecorationStyle.Dotted
14781470
..textBaseline = canvasKit.TextBaseline.Ideographic
1479-
..fontSize = 48
1471+
..fontSize = 24
14801472
..letterSpacing = 5
14811473
..wordSpacing = 10
1482-
..heightMultiplier = 1.3
1474+
..heightMultiplier = 2.5
14831475
..halfLeading = true
14841476
..locale = 'en_CA'
14851477
..fontFamilies = <String>['Roboto', 'serif']
@@ -1494,24 +1486,23 @@ void _paragraphTests() {
14941486
SkFontFeature()
14951487
..name = 'tnum'
14961488
..value = 1,
1497-
]
1498-
;
1489+
];
14991490
props.strutStyle = SkStrutStyleProperties()
15001491
..fontFamilies = <String>['Roboto', 'Noto']
15011492
..fontStyle = (SkFontStyle()
15021493
..slant = canvasKit.FontSlant.Italic
15031494
..weight = canvasKit.FontWeight.Bold)
1504-
..fontSize = 72
1505-
..heightMultiplier = 1.5
1495+
..fontSize = 23
1496+
..heightMultiplier = 5
15061497
..halfLeading = true
1507-
..leading = 0
1498+
..leading = 6
15081499
..strutEnabled = true
15091500
..forceStrutHeight = false;
15101501

15111502
final SkParagraphStyle paragraphStyle = canvasKit.ParagraphStyle(props);
1512-
final SkParagraphBuilder builder = canvasKit.ParagraphBuilder.MakeFromFontProvider(
1503+
final SkParagraphBuilder builder = canvasKit.ParagraphBuilder.Make(
15131504
paragraphStyle,
1514-
CanvasKitRenderer.instance.fontCollection.fontProvider,
1505+
CanvasKitRenderer.instance.fontCollection.skFontMgr,
15151506
);
15161507

15171508
builder.addText('Hello');
@@ -1522,93 +1513,51 @@ void _paragraphTests() {
15221513
canvasKit.TextBaseline.Ideographic,
15231514
4.0,
15241515
);
1525-
builder.pushStyle(canvasKit.TextStyle(SkTextStyleProperties()
1526-
..color = Float32List.fromList(<double>[1, 0, 0, 1])
1527-
..fontSize = 24
1528-
..fontFamilies = <String>['Roboto', 'serif']
1529-
));
1516+
builder
1517+
.pushStyle(canvasKit.TextStyle(SkTextStyleProperties()..fontSize = 12));
15301518
builder.addText('World');
15311519
builder.pop();
15321520
builder.pushPaintStyle(
1533-
canvasKit.TextStyle(SkTextStyleProperties()
1534-
..color = Float32List.fromList(<double>[1, 0, 0, 1])
1535-
..fontSize = 60
1536-
..fontFamilies = <String>['Roboto', 'serif']
1537-
),
1538-
SkPaint()..setColorInt(0xFF0000FF),
1539-
SkPaint()..setColorInt(0xFFFF0000),
1540-
);
1521+
canvasKit.TextStyle(SkTextStyleProperties()..fontSize = 12),
1522+
SkPaint(),
1523+
SkPaint());
15411524
builder.addText('!');
15421525
builder.pop();
15431526
builder.pushStyle(
15441527
canvasKit.TextStyle(SkTextStyleProperties()..halfLeading = true));
15451528
builder.pop();
15461529
final SkParagraph paragraph = builder.build();
1547-
paragraph.layout(500);
1548-
1549-
final DomCanvasElement canvas = createDomCanvasElement(
1550-
width: 400,
1551-
height: 160,
1552-
);
1553-
domDocument.body!.append(canvas);
1554-
1555-
// TODO(yjbanov): WebGL screenshot tests do not work on Firefox - https://github.com/flutter/flutter/issues/109265
1556-
if (!isFirefox) {
1557-
final SkSurface surface = canvasKit.MakeWebGLCanvasSurface(canvas);
1558-
final SkCanvas skCanvas = surface.getCanvas();
1559-
skCanvas.drawColorInt(0xFFCCCCCC, toSkBlendMode(ui.BlendMode.srcOver));
1560-
skCanvas.drawParagraph(paragraph, 20, 20);
1561-
skCanvas.drawRect(
1562-
Float32List.fromList(<double>[20, 20, 20 + paragraph.getMaxIntrinsicWidth(), 20 + paragraph.getHeight()]),
1563-
SkPaint()
1564-
..setStyle(toSkPaintStyle(ui.PaintingStyle.stroke))
1565-
..setStrokeWidth(1)
1566-
..setColorInt(0xFF00FF00),
1567-
);
1568-
surface.flush();
1569-
1570-
await matchGoldenFile(
1571-
'paragraph_kitchen_sink.png',
1572-
region: const ui.Rect.fromLTRB(0, 0, 400, 160),
1573-
maxDiffRatePercent: 0.0,
1574-
write: true,
1575-
);
1576-
}
1577-
1578-
void expectAlmost(double actual, double expected) {
1579-
expect(actual, within<double>(distance: actual / 100, from: expected));
1580-
}
1581-
1582-
expectAlmost(paragraph.getAlphabeticBaseline(), 85.5);
1530+
paragraph.layout(55);
1531+
expect(paragraph.getAlphabeticBaseline(),
1532+
within<double>(distance: 0.5, from: 20.7));
15831533
expect(paragraph.didExceedMaxLines(), isFalse);
1584-
expectAlmost(paragraph.getHeight(), 108);
1585-
expectAlmost(paragraph.getIdeographicBaseline(), 108);
1586-
expectAlmost(paragraph.getLongestLine(), 263);
1587-
expectAlmost(paragraph.getMaxIntrinsicWidth(), 263);
1588-
expectAlmost(paragraph.getMinIntrinsicWidth(), 135);
1589-
expectAlmost(paragraph.getMaxWidth(), 500);
1534+
expect(paragraph.getHeight(), 25);
1535+
expect(paragraph.getIdeographicBaseline(),
1536+
within<double>(distance: 0.5, from: 25));
1537+
expect(paragraph.getLongestLine(), 50);
1538+
expect(paragraph.getMaxIntrinsicWidth(), 50);
1539+
expect(paragraph.getMinIntrinsicWidth(), 50);
1540+
expect(paragraph.getMaxWidth(), 55);
15901541
expect(
1591-
paragraph.getRectsForRange(1, 3, canvasKit.RectHeightStyle.Tight, canvasKit.RectWidthStyle.Max).single,
1592-
hasLength(4),
1593-
);
1542+
paragraph.getRectsForRange(1, 3, canvasKit.RectHeightStyle.Tight,
1543+
canvasKit.RectWidthStyle.Max),
1544+
<double>[]);
15941545
expect(paragraph.getRectsForPlaceholders(), hasLength(1));
15951546
expect(paragraph.getLineMetrics(), hasLength(1));
15961547

15971548
final SkLineMetrics lineMetrics =
15981549
paragraph.getLineMetrics().cast<SkLineMetrics>().single;
1599-
expectAlmost(lineMetrics.ascent, 55.6);
1600-
expectAlmost(lineMetrics.descent, 14.8);
1550+
expect(lineMetrics.ascent, within<double>(distance: 0.5, from: 20.7));
1551+
expect(lineMetrics.descent, within<double>(distance: 0.2, from: 4.3));
16011552
expect(lineMetrics.isHardBreak, isTrue);
1602-
expectAlmost(lineMetrics.baseline, 85.5);
1603-
expectAlmost(lineMetrics.height, 108);
1604-
expectAlmost(lineMetrics.left, 2.5);
1605-
expectAlmost(lineMetrics.width, 263);
1553+
expect(lineMetrics.baseline, within<double>(distance: 0.5, from: 20.7));
1554+
expect(lineMetrics.height, 25);
1555+
expect(lineMetrics.left, 2.5);
1556+
expect(lineMetrics.width, 50);
16061557
expect(lineMetrics.lineNumber, 0);
16071558

1608-
expect(
1609-
paragraph.getGlyphPositionAtCoordinate(5, 5).affinity,
1610-
canvasKit.Affinity.Upstream,
1611-
);
1559+
expect(paragraph.getGlyphPositionAtCoordinate(5, 5).affinity,
1560+
canvasKit.Affinity.Downstream);
16121561

16131562
// "Hello"
16141563
for (int i = 0; i < 5; i++) {

0 commit comments

Comments
 (0)