diff --git a/build/cupertino_generated_icons.dart b/build/cupertino_generated_icons.dart index 8f7f43b..1330c72 100644 --- a/build/cupertino_generated_icons.dart +++ b/build/cupertino_generated_icons.dart @@ -2085,9 +2085,7 @@ /// This is the same icon as [create_solid] which is available in cupertino_icons 0.1.3. static const IconData square_pencil = IconData(0xf417, fontFamily: iconFont, fontPackage: iconFontPackage); /// square_pencil_fill — Cupertino icon named "square_pencil_fill". Available on cupertino_icons package 1.0.0+ only. - /// This is the same icon as [create] which is available in cupertino_icons 0.1.3. - /// This is the same icon as [create_solid] which is available in cupertino_icons 0.1.3. - static const IconData square_pencil_fill = IconData(0xf417, fontFamily: iconFont, fontPackage: iconFontPackage); + static const IconData square_pencil_fill = IconData(0xf418, fontFamily: iconFont, fontPackage: iconFontPackage); /// square_righthalf_fill — Cupertino icon named "square_righthalf_fill". Available on cupertino_icons package 1.0.0+ only. static const IconData square_righthalf_fill = IconData(0xf80e, fontFamily: iconFont, fontPackage: iconFontPackage); /// square_split_1x2 — Cupertino icon named "square_split_1x2". Available on cupertino_icons package 1.0.0+ only. diff --git a/build/existing_map.py b/build/existing_map.py index 79eb984..383608a 100644 --- a/build/existing_map.py +++ b/build/existing_map.py @@ -1,123 +1,130 @@ mapped_codepoints = { - "square_arrow_up": (0xf4ca, 0xf220), - "square_arrow_up_fill": (0xf4cb), - "book": (0xf3e7), - "book_fill": (0xf3e8), - "bookmark": (0xf3e9), - "bookmark_fill": (0xf3ea), - "info_circle": (0xf44c), - "arrowshape_turn_up_left": (0xf4c6), - "chat_bubble": (0xf3fb), - "person_crop_circle": (0xf419), - "plus_circle": (0xf48a), - "minus_circle": (0xf463), - "flag": (0xf42c), - "search": (0xf4a5), - "checkmark": (0xf3fd), - "checkmark_circle": (0xf3fe), - "checkmark_circle_fill": (0xf3ff), - "circle": (0xf401), - "circle_fill": (0xf400), - "chevron_left": (0xf3d2), - "chevron_right": (0xf3d3), - "chevron_back": (0xf3cf), - "chevron_forward": (0xf3d1), - "house": (0xf447), - "car": (0xf36f), - "cart": (0xf3f7), - "ellipsis": (0xf46a), - "phone": (0xf4b8), - "phone_fill": (0xf4b9), - "arrow_down": (0xf35d), - "arrow_up": (0xf366), - "battery_100": (0xf113, 0xf111, 0xf114), - "battery_0": (0xf112), - "battery_25": (0xf115), - "bluetooth": (0xf116), - "arrow_counterclockwise": (0xf21c), - "arrowshape_turn_up_left_2": (0xf21d), - "arrowshape_turn_up_left_2_fill": (0xf21e), - "shuffle": (0xf4a9, 0xf4a8, 0xf221), - "camera": (0xf3f5), - "camera_fill": (0xf3f6), - "videocam": (0xf4cc), - "videocam_fill": (0xf4cd), - "camera_rotate": (0xf49e), - "camera_rotate_fill": (0xf49f), - "rectangle_stack": (0xf3c9), - "rectangle_stack_fill": (0xf3ca), - "folder": (0xf434, 0xf38a), - "folder_fill": (0xf435), - "trash": (0xf4c4, 0xf37f), - "trash_fill": (0xf4c5), - "pencil": (0xf37e, 0xf2bf), - "square_pencil": (0xf417), - "square_pencil_fill": (0xf417), - "arrow_clockwise": (0xf49a, 0xf49d, 0xf3a8), - "arrow_clockwise_circle": (0xf49b), - "arrow_clockwise_circle_fill": (0xf49c), - "xmark": (0xf404, 0xf2d7), - "xmark_circle": (0xf405), - "xmark_circle_fill": (0xf36e, 0xf406), - "plus": (0xf489), - "plus_circle": (0xf48a), - "plus_circle_fill": (0xf48b), - "gear_alt": (0xf43c, 0xf2f7), - "gear_alt_fill": (0xf43d), - "gear": (0xf411, 0xf412), - "music_note": (0xf46b), - "music_note_2": (0xf46c), - "play": (0xf487), - "play_fill": (0xf488), - "pause": (0xf477), - "pause_fill": (0xf478), - "infinite": (0xf449, 0xf44a), - "speaker_1_fill": (0xf3b7), - "speaker_fill": (0xf3b8), - "speaker_slash_fill": (0xf3b9), - "speaker_3_fill": (0xf3ba), - "arrow_up_left_arrow_down_right": (0xf386), - "arrow_down_right_arrow_up_left": (0xf37d), - "mic_slash": (0xf45f), - "mic": (0xf460), - "mic_fill": (0xf461), - "clock": (0xf402, 0xf4be), - "clock_fill": (0xf403, 0xf4bf), - "lock": (0xf4c8), - "lock_fill": (0xf4c9), - "eye": (0xf424), - "eye_fill": (0xf425), - "person": (0xf47d), - "person_fill": (0xf47e), - "person_badge_plus": (0xf47f), - "person_badge_plus_fill": (0xf480), - "person_3": (0xf47b), - "person_3_fill": (0xf47c), - "envelope": (0xf422), - "envelope_fill": (0xf423), - "placemark": (0xf455), - "placemark_fill": (0xf456), - "tag": (0xf48c, 0xf48e), - "tag_fill": (0xf48d, 0xf48f), - "bus": (0xf36d), - "car_fill": (0xf36f), - "car_detailed": (0xf2c1), - "train_style_one": (0xf3af), - "train_style_two": (0xf3b4), - "paw": (0xf47a, 0xf479), - "gamecontroller": (0xf43a), - "gamecontroller_fill": (0xf43b), - "lab_flask": (0xf430), - "lab_flask_solid": (0xf431), - "heart": (0xf442), - "heart_fill": (0xf443), - "bell": (0xf3e1), - "bell_fill": (0xf3e2), - "news": (0xf471), - "news_solid": (0xf472), - "sun_max": (0xf4b6), - "sun_max_fill": (0xf4b7), -}, + "square_arrow_up": [0xf4ca, 0xf220], + "square_arrow_up_fill": [0xf4cb], + "book": [0xf3e7], + "book_fill": [0xf3e8], + "bookmark": [0xf3e9], + "bookmark_fill": [0xf3ea], + "info_circle": [0xf44c], + "arrowshape_turn_up_left": [0xf4c6], + "chat_bubble": [0xf3fb], + "person_crop_circle": [0xf419], + "plus_circle": [0xf48a], + "minus_circle": [0xf463], + "flag": [0xf42c], + "search": [0xf4a5], + "checkmark": [0xf3fd], + "checkmark_circle": [0xf3fe], + "checkmark_circle_fill": [0xf3ff], + "circle": [0xf401], + "circle_fill": [0xf400], + "chevron_left": [0xf3d2], + "chevron_right": [0xf3d3], + "chevron_back": [0xf3cf], + "chevron_forward": [0xf3d1], + "house": [0xf447], + "car": [0xf36f], + "cart": [0xf3f7], + "ellipsis": [0xf46a], + "phone": [0xf4b8], + "phone_fill": [0xf4b9], + "arrow_down": [0xf35d], + "arrow_up": [0xf366], + "battery_100": [0xf113, 0xf111, 0xf114], + "battery_0": [0xf112], + "battery_25": [0xf115], + "bluetooth": [0xf116], + "arrow_counterclockwise": [0xf21c], + "arrowshape_turn_up_left_2": [0xf21d], + "arrowshape_turn_up_left_2_fill": [0xf21e], + "shuffle": [0xf4a9, 0xf4a8, 0xf221], + "camera": [0xf3f5], + "camera_fill": [0xf3f6], + "videocam": [0xf4cc], + "videocam_fill": [0xf4cd], + "camera_rotate": [0xf49e], + "camera_rotate_fill": [0xf49f], + "rectangle_stack": [0xf3c9], + "rectangle_stack_fill": [0xf3ca], + "folder": [0xf434, 0xf38a], + "folder_fill": [0xf435], + "trash": [0xf4c4, 0xf37f], + "trash_fill": [0xf4c5], + "pencil": [0xf37e, 0xf2bf], + "square_pencil": [0xf417], + "square_pencil_fill": [0xf418], + "arrow_clockwise": [0xf49a, 0xf49d, 0xf3a8], + "arrow_clockwise_circle": [0xf49b], + "arrow_clockwise_circle_fill": [0xf49c], + "xmark": [0xf404, 0xf2d7], + "xmark_circle": [0xf405], + "xmark_circle_fill": [0xf36e, 0xf406], + "plus": [0xf489], + "plus_circle": [0xf48a], + "plus_circle_fill": [0xf48b], + "gear_alt": [0xf43c, 0xf2f7], + "gear_alt_fill": [0xf43d], + "gear": [0xf411, 0xf412], + "music_note": [0xf46b], + "music_note_2": [0xf46c], + "play": [0xf487], + "play_fill": [0xf488], + "pause": [0xf477], + "pause_fill": [0xf478], + "infinite": [0xf449, 0xf44a], + "speaker_1_fill": [0xf3b7], + "speaker_fill": [0xf3b8], + "speaker_slash_fill": [0xf3b9], + "speaker_3_fill": [0xf3ba], + "arrow_up_left_arrow_down_right": [0xf386], + "arrow_down_right_arrow_up_left": [0xf37d], + "mic_slash": [0xf45f], + "mic": [0xf460], + "mic_fill": [0xf461], + "clock": [0xf402, 0xf4be], + "clock_fill": [0xf403, 0xf4bf], + "lock": [0xf4c8], + "lock_fill": [0xf4c9], + "eye": [0xf424], + "eye_fill": [0xf425], + "person": [0xf47d], + "person_fill": [0xf47e], + "person_badge_plus": [0xf47f], + "person_badge_plus_fill": [0xf480], + "person_3": [0xf47b], + "person_3_fill": [0xf47c], + "envelope": [0xf422], + "envelope_fill": [0xf423], + "placemark": [0xf455], + "placemark_fill": [0xf456], + "tag": [0xf48c, 0xf48e], + "tag_fill": [0xf48d, 0xf48f], + "bus": [0xf36d], + "car_detailed": [0xf2c1], + "train_style_one": [0xf3af], + "train_style_two": [0xf3b4], + "paw": [0xf47a, 0xf479], + "gamecontroller": [0xf43a], + "gamecontroller_fill": [0xf43b], + "lab_flask": [0xf430], + "lab_flask_solid": [0xf431], + "heart": [0xf442], + "heart_fill": [0xf443], + "bell": [0xf3e1], + "bell_fill": [0xf3e2], + "news": [0xf471], + "news_solid": [0xf472], + "sun_max": [0xf4b6], + "sun_max_fill": [0xf4b7], +} + +# A list of glyphs that are bound to more than one dart names, +# for example, `CupertinoIcons.car_fill` refers to the same glyph +# as `CupertinoIcons.car`. The "main" name, and only the "main" name, +# must correspond to a svg file in the "src" directory. +aliases = { + "car": ["car_fill"], +} old_names = { "left_chevron": 0xf3d2, diff --git a/build/generate_font.py b/build/generate_font.py index a4e2c91..85c6113 100755 --- a/build/generate_font.py +++ b/build/generate_font.py @@ -12,57 +12,38 @@ import copy import collections -from existing_map import mapped_codepoints +from existing_map import mapped_codepoints, aliases SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) -BLANK_PATH = os.path.join(SCRIPT_PATH, 'blank.svg') INPUT_SVG_DIR = os.path.join(SCRIPT_PATH, '..', 'src') OUTPUT_FONT_DIR = os.path.join(SCRIPT_PATH, '..', 'fonts') MANIFEST_PATH = os.path.join(SCRIPT_PATH, 'manifest.json') AUTO_WIDTH = True -KERNING = 15 -def createGlyph(name, codepoint, file): +def getOrCreateLigatureComponentFor(char): + glyph = f.createChar(ord(char)) + glyph.width = 0 + return glyph.glyphname + +def createGlyph(name, codepoints, file): + assert len(codepoints) == len(set(codepoints)) + assert len(codepoints) != 0 + codepoint, *tail = codepoints glyph = f.createChar(codepoint, name) + assert not glyph.changed, ("Glyph %s is already assigned. Check for duplicated SVGs.") % glyph + if tail: + glyph.altuni = tail + + assert name not in build_data['icons'] + build_data['icons'][name] = codepoints + glyph.addPosSub('ligacomp', [getOrCreateLigatureComponentFor(c) for c in name]) + for alias in aliases.pop(name, []): + assert alias != name + assert alias + build_data['icons'][alias] = codepoints + glyph.addPosSub('ligacomp', [getOrCreateLigatureComponentFor(c) for c in alias]) - if not name in build_data['icons']: - build_data['icons'][name] = [codepoint] - else: - build_data['icons'][name].append(codepoint) glyph.importOutlines(file) - - # Add ligatures - ligature = []; - for c in name: - if (c == '_'): - c = "underscore" - if (c == '-'): - c = "hyphen" - if (c == ' '): - c = "space" - if (c == '1'): - c = "one" - if (c == '2'): - c = "two" - if (c == '3'): - c = "three" - if (c == '4'): - c = "four" - if (c == '5'): - c = "five" - if (c == '6'): - c = "six" - if (c == '7'): - c = "seven" - if (c == '8'): - c = "eight" - if (c == '9'): - c = "nine" - if (c == '0'): - c = "zero" - ligature.append(c) - glyph.addPosSub('ligatable1', ligature) - # set glyph size explicitly or automatically depending on autowidth if AUTO_WIDTH: glyph.left_side_bearing = glyph.right_side_bearing = 0 @@ -74,6 +55,7 @@ def createGlyph(name, codepoint, file): # There are legacy font glyphs from different svg sources. Leave them as is. else: glyph.width = 512 + return glyph unusable_names = { # Keywords in Dart we can't use as names. @@ -88,14 +70,8 @@ def createGlyph(name, codepoint, file): f.descent = 64 # Add lookup table -f.addLookup("ligatable","gsub_ligature",(),(("liga",(("latn",("dflt")),)),)) -f.addLookupSubtable("ligatable","ligatable1") - -# Import base characters -for char in "0123456789abcdefghijklmnopqrstuvwzxyz_- ": - glyph = f.createChar(ord(char)) - glyph.importOutlines(BLANK_PATH) - glyph.width = 0 +f.addLookup("ligatable","gsub_ligature",None,(("liga",(("latn",("dflt")),)),)) +f.addLookupSubtable("ligatable","ligacomp") manifest_file = open(MANIFEST_PATH, 'r') manifest_data = json.loads(manifest_file.read()) @@ -108,61 +84,57 @@ def createGlyph(name, codepoint, file): # Start at this codepoint since it's the last manually used codepoint from # cupertino_icons 0.1.3. -codepoint = 0xf4d4 +last_new_codepoint = 0xf4d3 for dirname, dirnames, filenames in os.walk(INPUT_SVG_DIR): for filename in sorted(filenames): name, ext = os.path.splitext(filename) filePath = os.path.join(dirname, filename) size = os.path.getsize(filePath) - if ext in ['.svg', '.eps']: + if ext not in ['.svg', '.eps']: + continue + # hack removal of tags + svgfile = open(filePath, 'r+') + tmpsvgfile = tempfile.NamedTemporaryFile(suffix=ext, delete=False, mode='w') + svgtext = svgfile.read() + svgfile.seek(0) - # hack removal of tags - svgfile = open(filePath, 'r+') - tmpsvgfile = tempfile.NamedTemporaryFile(suffix=ext, delete=False, mode='w') - svgtext = svgfile.read() - svgfile.seek(0) + # replace the tags with 'nothing' + svgtext = svgtext.replace('', '') + svgtext = svgtext.replace('', '') - # replace the tags with 'nothing' - svgtext = svgtext.replace('', '') - svgtext = svgtext.replace('', '') + tmpsvgfile.file.write(svgtext) - tmpsvgfile.file.write(svgtext) + svgfile.close() + tmpsvgfile.file.close() - svgfile.close() - tmpsvgfile.file.close() + filePath = tmpsvgfile.name + # end hack - filePath = tmpsvgfile.name - # end hack + if (name in unusable_names): + name = unusable_names[name] - if (name in unusable_names): - name = unusable_names[name] + mapped_value = mapped_codepoints.pop(name, None) + codepoints = [(last_new_codepoint:=last_new_codepoint + 1)] if mapped_value is None else mapped_value + glyph = createGlyph(name, codepoints, filePath); - if (name in mapped_codepoints[0]): - mapped_value = mapped_codepoints[0][name] - if isinstance(mapped_value, int): - createGlyph(name, mapped_codepoints[0][name], filePath) - else: - for repeated_codepoint in mapped_codepoints[0][name]: - createGlyph(name, repeated_codepoint, filePath) - mapped_codepoints[0].pop(name) - else: - createGlyph(name, codepoint, filePath) - codepoint += 1 + # if we created a temporary file, let's clean it up + os.unlink(tmpsvgfile.name) - # if we created a temporary file, let's clean it up - os.unlink(tmpsvgfile.name) - # resize glyphs if autowidth is enabled - if AUTO_WIDTH: - f.autoWidth(0, 0, 512) +# resize glyphs if autowidth is enabled +if AUTO_WIDTH: + f.autoWidth(0, 0, 512) - fontfile = '%s/CupertinoIcons' % (OUTPUT_FONT_DIR) +fontfile = '%s/CupertinoIcons' % (OUTPUT_FONT_DIR) f.fontname = font_name f.familyname = font_name f.fullname = font_name -f.generate(fontfile + '.ttf') +f.version = "1.08" +f.copyright = "" +# Generate the ttf without the glyphnames in the post table to reduce size +f.generate(fontfile + '.ttf', flags=('opentype','short-post')) scriptPath = os.path.dirname(os.path.realpath(__file__)) @@ -172,7 +144,10 @@ def createGlyph(name, codepoint, file): manifest_data['icons'] = collections.OrderedDict(sorted(build_data['icons'].items(), key=lambda glyph: glyph[0])) print("Save Manifest, Icons: %s" % ( len(manifest_data['icons']) )) -print(f"Unused mappings {mapped_codepoints}") +if mapped_codepoints: + print(f"Unused mappings {mapped_codepoints}") +if aliases: + print(f"Unused aliases {aliases}") f = open(MANIFEST_PATH, 'w') f.write( json.dumps(manifest_data, indent=2, separators=(',', ': ')) ) f.close() diff --git a/build/manifest.json b/build/manifest.json index 8d54a57..745a6a4 100755 --- a/build/manifest.json +++ b/build/manifest.json @@ -3113,7 +3113,7 @@ 62487 ], "square_pencil_fill": [ - 62487 + 62488 ], "square_righthalf_fill": [ 63502 diff --git a/fonts/CupertinoIcons.ttf b/fonts/CupertinoIcons.ttf index 0b13b50..d580ce7 100644 Binary files a/fonts/CupertinoIcons.ttf and b/fonts/CupertinoIcons.ttf differ diff --git a/src/sf/car_fill.svg b/src/sf/car_fill.svg deleted file mode 100644 index 521cf37..0000000 --- a/src/sf/car_fill.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file