Showing
4 changed files
with
90 additions
and
50 deletions
This diff could not be displayed because it is too large.
| @@ -6,7 +6,7 @@ description: > | @@ -6,7 +6,7 @@ description: > | ||
| 6 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing | 6 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing |
| 7 | repository: https://github.com/DavBfr/dart_pdf | 7 | repository: https://github.com/DavBfr/dart_pdf |
| 8 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 8 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
| 9 | -version: 5.7.0 | 9 | +version: 5.7.1 |
| 10 | 10 | ||
| 11 | environment: | 11 | environment: |
| 12 | sdk: ">=2.12.0 <3.0.0" | 12 | sdk: ">=2.12.0 <3.0.0" |
| @@ -27,6 +27,81 @@ String _uncapitalize(String s) { | @@ -27,6 +27,81 @@ String _uncapitalize(String s) { | ||
| 27 | return '${s[0].toLowerCase()}${s.substring(1)}'; | 27 | return '${s[0].toLowerCase()}${s.substring(1)}'; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | +class FontDesc { | ||
| 31 | + FontDesc({ | ||
| 32 | + this.family, | ||
| 33 | + required this.key, | ||
| 34 | + this.sub, | ||
| 35 | + required this.uri, | ||
| 36 | + required this.name, | ||
| 37 | + }); | ||
| 38 | + | ||
| 39 | + final String? family; | ||
| 40 | + final String? sub; | ||
| 41 | + final String key; | ||
| 42 | + final Uri uri; | ||
| 43 | + final String name; | ||
| 44 | + | ||
| 45 | + String get dartFamily => | ||
| 46 | + _uncapitalize(family == null ? key : family!.replaceAll(' ', '')); | ||
| 47 | + | ||
| 48 | + String get fontDartName => dartFamily + (sub ?? ''); | ||
| 49 | + | ||
| 50 | + String get fontName => family == null ? key : '$family $key'; | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +Iterable<FontDesc> getFonts(Map m) sync* { | ||
| 54 | + for (final f in m['items']) { | ||
| 55 | + final family = _uncapitalize(f['family'].replaceAll(' ', '')); | ||
| 56 | + | ||
| 57 | + for (final s in f['files'].entries) { | ||
| 58 | + var sub = _capitalize(s.key); | ||
| 59 | + | ||
| 60 | + sub = sub.replaceAll('100', 'Thin '); | ||
| 61 | + sub = sub.replaceAll('200', 'ExtraLight '); | ||
| 62 | + sub = sub.replaceAll('300', 'Light '); | ||
| 63 | + sub = sub.replaceAll('400', 'Regular '); | ||
| 64 | + sub = sub.replaceAll('500', 'Medium '); | ||
| 65 | + sub = sub.replaceAll('600', 'SemiBold '); | ||
| 66 | + sub = sub.replaceAll('700', 'Bold '); | ||
| 67 | + sub = sub.replaceAll('800', 'ExtraBold '); | ||
| 68 | + sub = sub.replaceAll('900', 'Black '); | ||
| 69 | + sub = sub.split(' ').map<String>((String e) => _capitalize(e)).join(''); | ||
| 70 | + | ||
| 71 | + final name = _capitalize(family) + '-' + sub; | ||
| 72 | + | ||
| 73 | + var uri = Uri.parse(s.value); | ||
| 74 | + if (uri.isScheme('http')) { | ||
| 75 | + uri = uri.replace(scheme: 'https'); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + if (!uri.path.endsWith('.ttf')) { | ||
| 79 | + continue; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + yield FontDesc( | ||
| 83 | + family: f['family'], | ||
| 84 | + key: s.key, | ||
| 85 | + sub: sub, | ||
| 86 | + uri: uri, | ||
| 87 | + name: name, | ||
| 88 | + ); | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + for (final entry in <String, String>{ | ||
| 93 | + 'CupertinoIcons': | ||
| 94 | + 'https://github.com/flutter/packages/blob/master/third_party/packages/cupertino_icons/assets/CupertinoIcons.ttf', | ||
| 95 | + 'MaterialIcons': | ||
| 96 | + 'https://fonts.gstatic.com/s/materialicons/v98/flUhRq6tzZclQEJ-Vdg-IuiaDsNZ.ttf', | ||
| 97 | + 'NotoColorEmoji': | ||
| 98 | + 'https://github.com/googlefonts/noto-emoji/raw/main/fonts/NotoColorEmoji.ttf', | ||
| 99 | + }.entries) { | ||
| 100 | + yield FontDesc( | ||
| 101 | + key: entry.key, uri: Uri.parse(entry.value), name: entry.key); | ||
| 102 | + } | ||
| 103 | +} | ||
| 104 | + | ||
| 30 | void main(List<String> args) async { | 105 | void main(List<String> args) async { |
| 31 | final f = File('fonts.json'); | 106 | final f = File('fonts.json'); |
| 32 | final d = StringBuffer(); | 107 | final d = StringBuffer(); |
| @@ -84,62 +159,23 @@ void main(List<String> args) async { | @@ -84,62 +159,23 @@ void main(List<String> args) async { | ||
| 84 | output.writeln('import \'font.dart\';'); | 159 | output.writeln('import \'font.dart\';'); |
| 85 | output.writeln(''); | 160 | output.writeln(''); |
| 86 | output.writeln('/// Google Fonts'); | 161 | output.writeln('/// Google Fonts'); |
| 162 | + output.writeln('///'); | ||
| 163 | + output.writeln('/// Available fonts:'); | ||
| 164 | + for (final f in getFonts(m)) { | ||
| 165 | + output.writeln('/// - ${f.fontDartName} (${f.fontName})'); | ||
| 166 | + } | ||
| 87 | output.writeln('class PdfGoogleFonts extends DownloadbleFont {'); | 167 | output.writeln('class PdfGoogleFonts extends DownloadbleFont {'); |
| 88 | output.writeln(''); | 168 | output.writeln(''); |
| 89 | - output.writeln('/// Create a Google Font'); | ||
| 90 | output.writeln( | 169 | output.writeln( |
| 91 | 'const PdfGoogleFonts._(String url, String name) : super(url, name);'); | 170 | 'const PdfGoogleFonts._(String url, String name) : super(url, name);'); |
| 92 | 171 | ||
| 93 | - for (final f in m['items']) { | ||
| 94 | - final family = _uncapitalize(f['family'].replaceAll(' ', '')); | ||
| 95 | - | ||
| 96 | - for (final s in f['files'].entries) { | ||
| 97 | - var sub = _capitalize(s.key); | ||
| 98 | - | ||
| 99 | - sub = sub.replaceAll('100', 'Thin '); | ||
| 100 | - sub = sub.replaceAll('200', 'ExtraLight '); | ||
| 101 | - sub = sub.replaceAll('300', 'Light '); | ||
| 102 | - sub = sub.replaceAll('400', 'Regular '); | ||
| 103 | - sub = sub.replaceAll('500', 'Medium '); | ||
| 104 | - sub = sub.replaceAll('600', 'SemiBold '); | ||
| 105 | - sub = sub.replaceAll('700', 'Bold '); | ||
| 106 | - sub = sub.replaceAll('800', 'ExtraBold '); | ||
| 107 | - sub = sub.replaceAll('900', 'Black '); | ||
| 108 | - sub = sub.split(' ').map<String>((String e) => _capitalize(e)).join(''); | ||
| 109 | - | ||
| 110 | - final name = _capitalize(family) + '-' + sub; | ||
| 111 | - | ||
| 112 | - var uri = Uri.parse(s.value); | ||
| 113 | - if (uri.isScheme('http')) { | ||
| 114 | - uri = uri.replace(scheme: 'https'); | ||
| 115 | - } | ||
| 116 | - | ||
| 117 | - if (!uri.path.endsWith('.ttf')) { | ||
| 118 | - continue; | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | - output.writeln(''); | ||
| 122 | - output.writeln('/// ${f['family']} ${s.key}'); | ||
| 123 | - output.writeln('static Future<Font> $family$sub() {'); | ||
| 124 | - output.writeln('const font = PdfGoogleFonts._(\'$uri\', \'$name\',);'); | ||
| 125 | - output.writeln('return font.getFont();'); | ||
| 126 | - output.writeln('}'); | ||
| 127 | - } | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - for (final entry in <String, String>{ | ||
| 131 | - 'CupertinoIcons': | ||
| 132 | - 'https://github.com/flutter/packages/blob/master/third_party/packages/cupertino_icons/assets/CupertinoIcons.ttf', | ||
| 133 | - 'MaterialIcons': | ||
| 134 | - 'https://fonts.gstatic.com/s/materialicons/v98/flUhRq6tzZclQEJ-Vdg-IuiaDsNZ.ttf', | ||
| 135 | - 'NotoColorEmoji': | ||
| 136 | - 'https://github.com/googlefonts/noto-emoji/raw/main/fonts/NotoColorEmoji.ttf', | ||
| 137 | - }.entries) { | 172 | + for (final f in getFonts(m)) { |
| 138 | output.writeln(''); | 173 | output.writeln(''); |
| 139 | - output.writeln('/// ${entry.key}'); | ||
| 140 | - output.writeln('static Future<Font> ${_uncapitalize(entry.key)}() {'); | 174 | + output.writeln('/// @nodoc'); |
| 175 | + output.writeln('/// ${f.fontName}'); | ||
| 176 | + output.writeln('static Future<Font> ${f.fontDartName}() {'); | ||
| 141 | output.writeln( | 177 | output.writeln( |
| 142 | - 'const font = PdfGoogleFonts._(\'${entry.value}\', \'${entry.key}\',);'); | 178 | + 'const font = PdfGoogleFonts._(\'${f.uri}\', \'${f.name}\',);'); |
| 143 | output.writeln('return font.getFont();'); | 179 | output.writeln('return font.getFont();'); |
| 144 | output.writeln('}'); | 180 | output.writeln('}'); |
| 145 | } | 181 | } |
-
Please register or login to post a comment