Commit cc9b140d authored by Jason Simmons's avatar Jason Simmons

Merge pull request #2902 from jason-simmons/roboto_manifest

Add all variants of the Roboto font as assets to Material Design apps
parents b070be22 d4bc6d5e
https://storage.googleapis.com/flutter_infra/flutter/fonts/b1e27075635f686ce12784a90125de693b4c360c/fonts.zip https://storage.googleapis.com/flutter_infra/flutter/fonts/1f5dd1af1b8e0672c7303a2f6197a29375ad1385/fonts.zip
...@@ -286,7 +286,8 @@ class AndroidDevice extends Device { ...@@ -286,7 +286,8 @@ class AndroidDevice extends Device {
String localBundlePath = await flx.buildFlx( String localBundlePath = await flx.buildFlx(
toolchain, toolchain,
mainPath: mainPath mainPath: mainPath,
includeRobotoFonts: false
); );
printTrace('Starting bundle for $this.'); printTrace('Starting bundle for $this.');
......
...@@ -435,7 +435,10 @@ Future<int> buildAndroid( ...@@ -435,7 +435,10 @@ Future<int> buildAndroid(
} else { } else {
// Find the path to the main Dart file; build the FLX. // Find the path to the main Dart file; build the FLX.
String mainPath = findMainDartFile(target); String mainPath = findMainDartFile(target);
String localBundlePath = await flx.buildFlx(toolchain, mainPath: mainPath); String localBundlePath = await flx.buildFlx(
toolchain,
mainPath: mainPath,
includeRobotoFonts: false);
return _buildApk(platform, components, localBundlePath, keystore, outputFile); return _buildApk(platform, components, localBundlePath, keystore, outputFile);
} }
......
...@@ -23,6 +23,7 @@ class BuildFlxCommand extends FlutterCommand { ...@@ -23,6 +23,7 @@ class BuildFlxCommand extends FlutterCommand {
argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath); argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath);
argParser.addOption('depfile', defaultsTo: defaultDepfilePath); argParser.addOption('depfile', defaultsTo: defaultDepfilePath);
argParser.addOption('working-dir', defaultsTo: defaultWorkingDirPath); argParser.addOption('working-dir', defaultsTo: defaultWorkingDirPath);
argParser.addFlag('include-roboto-fonts', defaultsTo: true);
usesPubOption(); usesPubOption();
} }
...@@ -56,7 +57,8 @@ class BuildFlxCommand extends FlutterCommand { ...@@ -56,7 +57,8 @@ class BuildFlxCommand extends FlutterCommand {
depfilePath: argResults['depfile'], depfilePath: argResults['depfile'],
privateKeyPath: argResults['private-key'], privateKeyPath: argResults['private-key'],
workingDirPath: argResults['working-dir'], workingDirPath: argResults['working-dir'],
precompiledSnapshot: argResults['precompiled'] precompiledSnapshot: argResults['precompiled'],
includeRobotoFonts: argResults['include-roboto-fonts']
).then((int result) { ).then((int result) {
if (result == 0) if (result == 0)
printStatus('Built $outputPath.'); printStatus('Built $outputPath.');
......
...@@ -29,6 +29,9 @@ const String defaultWorkingDirPath = 'build/flx'; ...@@ -29,6 +29,9 @@ const String defaultWorkingDirPath = 'build/flx';
const String _kSnapshotKey = 'snapshot_blob.bin'; const String _kSnapshotKey = 'snapshot_blob.bin';
const String _kFontSetMaterial = 'material';
const String _kFontSetRoboto = 'roboto';
class _Asset { class _Asset {
final String source; final String source;
final String base; final String base;
...@@ -37,25 +40,34 @@ class _Asset { ...@@ -37,25 +40,34 @@ class _Asset {
_Asset({ this.source, this.base, this.key }); _Asset({ this.source, this.base, this.key });
} }
const String _kMaterialIconsKey = 'fonts/MaterialIcons-Regular.ttf'; Map<String, dynamic> _readMaterialFontsManifest() {
String fontsPath = path.join(path.absolute(ArtifactStore.flutterRoot),
'packages', 'flutter_tools', 'schema', 'material_fonts.yaml');
List<Map<String, dynamic>> _getMaterialFonts() { return loadYaml(new File(fontsPath).readAsStringSync());
return [{
'family': 'MaterialIcons',
'fonts': [{
'asset': _kMaterialIconsKey
}]
}];
} }
List<_Asset> _getMaterialAssets() { final Map<String, dynamic> _materialFontsManifest = _readMaterialFontsManifest();
return <_Asset>[
new _Asset( List<Map<String, dynamic>> _getMaterialFonts(String fontSet) {
base: '${ArtifactStore.flutterRoot}/bin/cache/artifacts/material_fonts', return _materialFontsManifest[fontSet];
source: 'MaterialIcons-Regular.ttf', }
key: _kMaterialIconsKey
) List<_Asset> _getMaterialAssets(String fontSet) {
]; List<_Asset> result = <_Asset>[];
for (Map<String, dynamic> family in _getMaterialFonts(fontSet)) {
for (Map<String, dynamic> font in family['fonts']) {
String assetKey = font['asset'];
result.add(new _Asset(
base: '${ArtifactStore.flutterRoot}/bin/cache/artifacts/material_fonts',
source: path.basename(assetKey),
key: assetKey
));
}
}
return result;
} }
Map<_Asset, List<_Asset>> _parseAssets(Map<String, dynamic> manifestDescriptor, String assetBase) { Map<_Asset, List<_Asset>> _parseAssets(Map<String, dynamic> manifestDescriptor, String assetBase) {
...@@ -144,10 +156,15 @@ ZipEntry _createAssetManifest(Map<_Asset, List<_Asset>> assets) { ...@@ -144,10 +156,15 @@ ZipEntry _createAssetManifest(Map<_Asset, List<_Asset>> assets) {
return new ZipEntry.fromString('AssetManifest.json', JSON.encode(json)); return new ZipEntry.fromString('AssetManifest.json', JSON.encode(json));
} }
ZipEntry _createFontManifest(Map<String, dynamic> manifestDescriptor, List<Map<String, dynamic>> additionalFonts) { ZipEntry _createFontManifest(Map<String, dynamic> manifestDescriptor,
bool usesMaterialDesign,
bool includeRobotoFonts) {
List<Map<String, dynamic>> fonts = <Map<String, dynamic>>[]; List<Map<String, dynamic>> fonts = <Map<String, dynamic>>[];
if (additionalFonts != null) if (usesMaterialDesign) {
fonts.addAll(additionalFonts); fonts.addAll(_getMaterialFonts(_kFontSetMaterial));
if (includeRobotoFonts)
fonts.addAll(_getMaterialFonts(_kFontSetRoboto));
}
if (manifestDescriptor != null && manifestDescriptor.containsKey('fonts')) if (manifestDescriptor != null && manifestDescriptor.containsKey('fonts'))
fonts.addAll(manifestDescriptor['fonts']); fonts.addAll(manifestDescriptor['fonts']);
if (fonts.isEmpty) if (fonts.isEmpty)
...@@ -158,7 +175,8 @@ ZipEntry _createFontManifest(Map<String, dynamic> manifestDescriptor, List<Map<S ...@@ -158,7 +175,8 @@ ZipEntry _createFontManifest(Map<String, dynamic> manifestDescriptor, List<Map<S
/// Build the flx in the build/ directory and return `localBundlePath` on success. /// Build the flx in the build/ directory and return `localBundlePath` on success.
Future<String> buildFlx( Future<String> buildFlx(
Toolchain toolchain, { Toolchain toolchain, {
String mainPath: defaultMainPath String mainPath: defaultMainPath,
bool includeRobotoFonts: true
}) async { }) async {
int result; int result;
String localBundlePath = path.join('build', 'app.flx'); String localBundlePath = path.join('build', 'app.flx');
...@@ -167,7 +185,8 @@ Future<String> buildFlx( ...@@ -167,7 +185,8 @@ Future<String> buildFlx(
toolchain, toolchain,
snapshotPath: localSnapshotPath, snapshotPath: localSnapshotPath,
outputPath: localBundlePath, outputPath: localBundlePath,
mainPath: mainPath mainPath: mainPath,
includeRobotoFonts: includeRobotoFonts
); );
if (result == 0) if (result == 0)
return localBundlePath; return localBundlePath;
...@@ -197,7 +216,8 @@ Future<int> build( ...@@ -197,7 +216,8 @@ Future<int> build(
String depfilePath: defaultDepfilePath, String depfilePath: defaultDepfilePath,
String privateKeyPath: defaultPrivateKeyPath, String privateKeyPath: defaultPrivateKeyPath,
String workingDirPath: defaultWorkingDirPath, String workingDirPath: defaultWorkingDirPath,
bool precompiledSnapshot: false bool precompiledSnapshot: false,
bool includeRobotoFonts: true
}) async { }) async {
Object manifest = _loadManifest(manifestPath); Object manifest = _loadManifest(manifestPath);
if (manifest != null) { if (manifest != null) {
...@@ -235,7 +255,8 @@ Future<int> build( ...@@ -235,7 +255,8 @@ Future<int> build(
assetBasePath: assetBasePath, assetBasePath: assetBasePath,
outputPath: outputPath, outputPath: outputPath,
privateKeyPath: privateKeyPath, privateKeyPath: privateKeyPath,
workingDirPath: workingDirPath workingDirPath: workingDirPath,
includeRobotoFonts: includeRobotoFonts
); );
} }
...@@ -245,7 +266,8 @@ Future<int> assemble({ ...@@ -245,7 +266,8 @@ Future<int> assemble({
String assetBasePath: defaultAssetBasePath, String assetBasePath: defaultAssetBasePath,
String outputPath: defaultFlxOutputPath, String outputPath: defaultFlxOutputPath,
String privateKeyPath: defaultPrivateKeyPath, String privateKeyPath: defaultPrivateKeyPath,
String workingDirPath: defaultWorkingDirPath String workingDirPath: defaultWorkingDirPath,
bool includeRobotoFonts: true
}) async { }) async {
printTrace('Building $outputPath'); printTrace('Building $outputPath');
...@@ -272,18 +294,22 @@ Future<int> assemble({ ...@@ -272,18 +294,22 @@ Future<int> assemble({
} }
} }
List<_Asset> materialAssets = <_Asset>[];
if (usesMaterialDesign) { if (usesMaterialDesign) {
for (_Asset asset in _getMaterialAssets()) { materialAssets.addAll(_getMaterialAssets(_kFontSetMaterial));
ZipEntry assetEntry = _createAssetEntry(asset); if (includeRobotoFonts)
if (assetEntry == null) materialAssets.addAll(_getMaterialAssets(_kFontSetRoboto));
return 1; }
zipBuilder.addEntry(assetEntry); for (_Asset asset in materialAssets) {
} ZipEntry assetEntry = _createAssetEntry(asset);
if (assetEntry == null)
return 1;
zipBuilder.addEntry(assetEntry);
} }
zipBuilder.addEntry(_createAssetManifest(assets)); zipBuilder.addEntry(_createAssetManifest(assets));
ZipEntry fontManifest = _createFontManifest(manifestDescriptor, usesMaterialDesign ? _getMaterialFonts() : null); ZipEntry fontManifest = _createFontManifest(manifestDescriptor, usesMaterialDesign, includeRobotoFonts);
if (fontManifest != null) if (fontManifest != null)
zipBuilder.addEntry(fontManifest); zipBuilder.addEntry(fontManifest);
......
material:
- family: MaterialIcons
fonts:
- asset: fonts/MaterialIcons-Regular.ttf
roboto:
- family: Roboto
fonts:
- asset: fonts/Roboto-Regular.ttf
- asset: fonts/Roboto-Italic.ttf
style: italic
- asset: fonts/Roboto-Thin.ttf
weight: 100
- asset: fonts/Roboto-ThinItalic.ttf
weight: 100
style: italic
- asset: fonts/Roboto-Light.ttf
weight: 300
- asset: fonts/Roboto-LightItalic.ttf
weight: 300
style: italic
- asset: fonts/Roboto-Medium.ttf
weight: 500
- asset: fonts/Roboto-MediumItalic.ttf
weight: 500
style: italic
- asset: fonts/Roboto-Bold.ttf
weight: 700
- asset: fonts/Roboto-BoldItalic.ttf
weight: 700
style: italic
- asset: fonts/Roboto-Black.ttf
weight: 900
- asset: fonts/Roboto-BlackItalic.ttf
weight: 900
style: italic
- family: RobotoCondensed
fonts:
- asset: fonts/RobotoCondensed-Regular.ttf
- asset: fonts/RobotoCondensed-Italic.ttf
style: italic
- asset: fonts/RobotoCondensed-Light.ttf
weight: 300
- asset: fonts/RobotoCondensed-LightItalic.ttf
weight: 300
style: italic
- asset: fonts/RobotoCondensed-Bold.ttf
weight: 700
- asset: fonts/RobotoCondensed-BoldItalic.ttf
weight: 700
style: italic
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