Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ packages/web_benchmarks/** @yjbanov
packages/webview_flutter/** @bparrishMines
packages/xdg_directories/** @stuartmorgan
third_party/packages/cupertino_icons/** @MitchellGoodwin
third_party/packages/cupertino_icons/test/goldens/** @LongCatIsLooong

# Plugin platform implementation rules. These should stay last, since the last
# matching entry takes precedence.
Expand Down
2 changes: 2 additions & 0 deletions third_party/packages/cupertino_icons/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ environment:
sdk: ^3.3.0

dev_dependencies:
collection: ^1.18.0
flutter:
sdk: flutter
flutter_test:
sdk: flutter
path: 1.9.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this pinned to an exact version? path is allowed as an unpinned dependency in the repo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the change after reading https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#dependencies

If you add a dev_dependency on an external package, pin it to a specific version if at all possible.

But it looks like that only applies to external packages. I'll change it back to any.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be any, it should be a standard ^ dependency.


flutter:
fonts:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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.

import 'dart:io' show File, Platform;

import 'package:collection/collection.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart' as path;

import 'icons_list.dart';

// The EM of the font is 512. Keep this a power of 2 for fixed-point arithmetic.
const double iconSize = 128.0;
const int iconsPerRow = 5;
const int iconsPerCol = 5;
const int iconsPerImage = iconsPerRow * iconsPerCol;

void main() async {
// Do not run on web since this test uses dart:io.
// The golden test runs on Linux only to avoid platform rendering differences.
if (kIsWeb || !Platform.isLinux) {
return;
}
final bool isMainChannel = !Platform.environment.containsKey('CHANNEL')
|| Platform.environment['CHANNEL'] == 'main'
|| Platform.environment['CHANNEL'] == 'master';
// Only test against main to avoid rendering differences between flutter channels.
if (!isMainChannel) {
return;
}
// Load font.
final String effectiveFontFamily = const TextStyle(fontFamily: CupertinoIcons.iconFont, package: CupertinoIcons.iconFontPackage).fontFamily!;
final FontLoader fontLoader = FontLoader(effectiveFontFamily);
final String filePath = path.canonicalize('assets/CupertinoIcons.ttf');
final File file = File(filePath);
fontLoader.addFont(file.readAsBytes().then((Uint8List v) => v.buffer.asByteData()));
await fontLoader.load();

assert(icons.isNotEmpty);
for (int index = 0; index < icons.length;) {
final int groupEndCodePoint = (icons[index].codePoint ~/ iconsPerImage + 1) * iconsPerImage;
final int next = icons.indexWhere((IconData icon) => icon.codePoint >= groupEndCodePoint, index);
final int nextIndex = next < 0 ? icons.length : next;
registerTestForIconGroup(icons.slice(index, nextIndex));
index = nextIndex;
}
}

// Generating goldens for each glyph is very slow. Group the sorted icons
// into codepoint-aligned groups (each of which has a max capacity of
// iconsPerRow * iconsPerCol), so the goldens are easier to review when
// symbols are added or removed.
void registerTestForIconGroup(List<IconData> iconGroup) {
assert(iconGroup.isNotEmpty);
String hexCodePoint(int codePoint) => codePoint.toRadixString(16).toUpperCase().padLeft(4, '0');
final int groupStartCodePoint = (iconGroup.first.codePoint ~/ iconsPerImage) * iconsPerImage;
final String range = 'U+${hexCodePoint(groupStartCodePoint)}-${hexCodePoint(groupStartCodePoint + iconsPerImage - 1)}';

testWidgets('font golden test: $range', (WidgetTester tester) async {
addTearDown(tester.view.reset);
const Size canvasSize = Size(iconSize * iconsPerRow, iconSize * iconsPerCol);
tester.view.physicalSize = canvasSize * tester.view.devicePixelRatio;

const Widget fillerBox = SizedBox.square(dimension: iconSize);
final List<Widget> children = List<Widget>.filled(iconsPerImage, fillerBox);
for (final IconData icon in iconGroup) {
children[icon.codePoint - groupStartCodePoint] = Icon(icon, size: iconSize);
}

final Widget widget = Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
height: iconSize * iconsPerCol,
width: iconSize * iconsPerRow,
child: RepaintBoundary(child: Wrap(children: children)),
),
),
);
await tester.pumpWidget(widget);
await expectLater(find.byType(Wrap) , matchesGoldenFile('goldens/glyph_$range.png'));
});
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions third_party/packages/cupertino_icons/test/icons_list.dart

Large diffs are not rendered by default.