Commit 0ebfe96f authored by Phil Plante's avatar Phil Plante

Added a tool to update and generate FontAwesomeIcons definition

Updated to FontAwesome 5.0.13
parent d4c8760d
library font_awesome_flutter;
import 'package:flutter/widgets.dart';
class IconDataBrands extends IconData {
const IconDataBrands(int codePoint)
: super(
codePoint,
fontFamily: 'FontAwesomeBrands',
fontPackage: 'font_awesome_flutter',
);
}
class IconDataSolid extends IconData {
const IconDataSolid(int codePoint)
: super(
codePoint,
fontFamily: 'FontAwesomeSolid',
fontPackage: 'font_awesome_flutter',
);
}
class IconDataRegular extends IconData {
const IconDataRegular(int codePoint)
: super(
codePoint,
fontFamily: 'FontAwesomeRegular',
fontPackage: 'font_awesome_flutter',
);
}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -8,6 +8,9 @@ dependencies: ...@@ -8,6 +8,9 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
dev_dependencies:
recase: "^1.0.0+1"
flutter: flutter:
fonts: fonts:
- family: FontAwesomeBrands - family: FontAwesomeBrands
......
import 'dart:convert';
import 'dart:io';
import 'package:recase/recase.dart';
void main(List<String> arguments) {
var file = new File(arguments.first);
if (!file.existsSync()) {
print('Cannot find the file "${arguments.first}".');
}
var content = file.readAsStringSync();
Map<String, dynamic> icons = json.decode(content);
Map<String, String> iconDefinitions = {};
for (String iconName in icons.keys) {
var icon = icons[iconName];
var unicode = icon['unicode'];
List<String> styles = icon['styles'];
if (styles.length > 1) {
if (styles.contains('regular')) {
styles.remove('regular');
iconDefinitions[iconName] = generateIconDefinition(
iconName,
'regular',
unicode,
);
}
for (String style in styles) {
String name = '${style}_$iconName';
iconDefinitions[name] = generateIconDefinition(
name,
styles.first,
unicode,
);
}
} else {
iconDefinitions[iconName] = generateIconDefinition(
iconName,
styles.first,
unicode,
);
}
}
List<String> generatedOutput = [
'library font_awesome_flutter;',
'',
"import 'package:flutter/widgets.dart';",
"import '_fonts.dart';",
'',
'// THIS FILE IS AUTOMATICALLY GENERATED!',
'',
'class FontAwesomeIcons {',
];
generatedOutput.addAll(iconDefinitions.values);
generatedOutput.add('}');
File output = new File('lib/font_awesome_flutter.dart');
output.writeAsStringSync(generatedOutput.join('\n'));
}
String generateIconDefinition(String iconName, String style, String unicode) {
style = '${style[0].toUpperCase()}${style.substring(1
)}';
String iconDataSource = 'IconData${style}';
if (iconName == '500px') {
iconName = 'fiveHundredPx';
}
iconName = new ReCase(iconName).camelCase;
return 'static const IconData $iconName = const $iconDataSource(0x$unicode);';
}
#!/usr/bin/env bash
pushd assets/
curl -O "https://github.com/FortAwesome/Font-Awesome/raw/master/web-fonts-with-css/webfonts/fa-brands-400.ttf"
curl -O "https://github.com/FortAwesome/Font-Awesome/raw/master/web-fonts-with-css/webfonts/fa-regular-400.ttf"
curl -O "https://github.com/FortAwesome/Font-Awesome/raw/master/web-fonts-with-css/webfonts/fa-solid-900.ttf"
popd
curl -o /tmp/icons.json "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/advanced-options/metadata/icons.json"
dart ./tool/generate_font.dart /tmp/icons.json
dartfmt -w ./lib/font_awesome_flutter.dart
rm /tmp/icons.json
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