Skip to content

Commit

Permalink
Merge pull request #261 from JudahMcNicholl/SharpIcon
Browse files Browse the repository at this point in the history
Fix to use Sharp Icons
  • Loading branch information
michaelspiss authored Nov 3, 2024
2 parents 01bac00 + d790bfd commit abc02ce
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 7 deletions.
52 changes: 52 additions & 0 deletions lib/src/icon_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,55 @@ class IconDataThin extends IconData {
fontPackage: 'font_awesome_flutter',
);
}

/// [IconData] for a font awesome sharp thin icon from a code point. Only works if
/// thin icons (font awesome pro, v6+) have been installed.
///
/// Code points can be obtained from fontawesome.com
class IconDataSharpThin extends IconData {
const IconDataSharpThin(int codePoint)
: super(
codePoint,
fontFamily: 'FontAwesomeSharpThin',
fontPackage: 'font_awesome_flutter',
);
}

/// [IconData] for a font awesome sharp light icon from a code point. Only works if
/// thin icons (font awesome pro, v6+) have been installed.
///
/// Code points can be obtained from fontawesome.com
class IconDataSharpLight extends IconData {
const IconDataSharpLight(int codePoint)
: super(
codePoint,
fontFamily: 'FontAwesomeSharpLight',
fontPackage: 'font_awesome_flutter',
);
}

/// [IconData] for a font awesome sharp regular icon from a code point. Only works if
/// thin icons (font awesome pro, v6+) have been installed.
///
/// Code points can be obtained from fontawesome.com
class IconDataSharpRegular extends IconData {
const IconDataSharpRegular(int codePoint)
: super(
codePoint,
fontFamily: 'FontAwesomeSharpRegular',
fontPackage: 'font_awesome_flutter',
);
}

/// [IconData] for a font awesome sharp solid icon from a code point. Only works if
/// thin icons (font awesome pro, v6+) have been installed.
///
/// Code points can be obtained from fontawesome.com
class IconDataSharpSolid extends IconData {
const IconDataSharpSolid(int codePoint)
: super(
codePoint,
fontFamily: 'FontAwesomeSharpSolid',
fontPackage: 'font_awesome_flutter',
);
}
18 changes: 17 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ flutter:
# - family: FontAwesomeThin
# fonts:
# - asset: lib/fonts/fa-thin-100.ttf
# weight: 100
# weight: 100
# - family: FontAwesomeSharpThin
# fonts:
# - asset: lib/fonts/fa-sharp-thin-100.ttf
# weight: 100
# - family: FontAwesomeSharpLight
# fonts:
# - asset: lib/fonts/fa-sharp-light-300.ttf
# weight: 300
# - family: FontAwesomeSharpRegular
# fonts:
# - asset: lib/fonts/fa-sharp-regular-400.ttf
# weight: 400
# - family: FontAwesomeSharpSolid
# fonts:
# - asset: lib/fonts/fa-sharp-solid-900.ttf
# weight: 900
24 changes: 18 additions & 6 deletions util/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void adjustPubspecFontIncludes(Set<String> styles) {
if (!line.trimLeft().startsWith('- family:')) continue;

styleName = line.substring(25).toLowerCase(); // - family: FontAwesomeXXXXXX
if (styles.contains(styleName)) {
if (styles.any((element) => element.replaceAll(' ', '') == styleName)) { //Because of 'sharp thin' we need to remove spaces here
pubspec[i] = uncommentYamlLine(pubspec[i]);
pubspec[i + 1] = uncommentYamlLine(pubspec[i + 1]);
pubspec[i + 2] = uncommentYamlLine(pubspec[i + 2]);
Expand Down Expand Up @@ -445,7 +445,7 @@ String normalizeIconName(String iconName, String style, int styleCompetitors) {

/// Utility function to generate the correct 'IconData' subclass for a [style]
String styleToDataSource(String style) {
return 'IconData${style[0].toUpperCase()}${style.substring(1)}';
return 'IconData${style.split(' ').map((word) => word.isNotEmpty ? word[0].toUpperCase() + word.substring(1) : '').toList().join('')}';
}

/// Gets the default branch from github's metadata
Expand Down Expand Up @@ -556,13 +556,25 @@ bool readAndPickMetadata(File iconsJson, List<IconMetadata> metadata,
versions.add(v);
}

List<String> iconStyles = (icon['styles'] as List).cast<String>();

List<String> iconStyles = [];
if (icon.containsKey("styles")) {
iconStyles = (icon['styles'] as List).cast<String>();
} else if (icon.containsKey("svgs")) {
iconStyles.addAll((icon['svgs']['classic'] as Map<String, dynamic>).keys);
if (icon['svgs']?['sharp'] != null) {
iconStyles.addAll((icon['svgs']['sharp'] as Map<String, dynamic>).keys.map((key) => 'sharp $key')); //"sharp thin ..."
}
}
//TODO: Remove line once duotone support discontinuation notice is removed
if (iconStyles.contains('duotone')) hasDuotoneIcons = true;

for (var excluded in excludedStyles) {
iconStyles.remove(excluded);
if (excluded == 'sharp') {
//Since it's 'sharp thin' then remove any containing sharp
iconStyles.removeWhere((element) => element.contains('sharp'));
} else {
iconStyles.remove(excluded);
}
}

if (iconStyles.isEmpty) continue;
Expand Down Expand Up @@ -628,7 +640,7 @@ ArgParser setUpArgParser() {
argParser.addMultiOption('exclude',
abbr: 'e',
defaultsTo: [],
allowed: ['brands', 'regular', 'solid', 'duotone', 'light', 'thin'],
allowed: ['brands', 'regular', 'solid', 'duotone', 'light', 'thin', 'sharp'],
help: 'icon styles which are excluded by the generator');

argParser.addFlag('dynamic',
Expand Down

0 comments on commit abc02ce

Please sign in to comment.