-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
94 changed files
with
726 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The icons contained in the `Items.ttf` font may not be extracted, used, or distributed by any third party (See [here](../icons/README.md) for more information) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import sys | ||
import os | ||
import glob | ||
|
||
try: | ||
import fontforge | ||
except : | ||
sys.stderr.write("fontforge package not found in the python path\n") | ||
sys.exit(1) | ||
|
||
FIRST_FONT_CHARACTER_INDEX = 0x100 | ||
|
||
class NoSourceSvgDirectoriesException(Exception): | ||
pass | ||
|
||
class FontforgeFont(): | ||
|
||
def __init__(self, kerning=15): | ||
#initialize the font | ||
self.font = fontforge.font() | ||
# starts in the character code for ! | ||
self.font_character_index = FIRST_FONT_CHARACTER_INDEX | ||
|
||
#other fontforge options: | ||
self.kerning = kerning | ||
|
||
def add_character(self, svg_file): | ||
c = self.font.createChar(self.font_character_index) | ||
#import the svg file | ||
c.importOutlines(svg_file.path) | ||
#set the margins to the vectorial image | ||
c.left_side_bearing = self.kerning | ||
c.right_side_bearing = self.kerning | ||
|
||
#update the SvgFile instance with the character index assigned for it | ||
svg_file.set_character_index(self.font_character_index) | ||
|
||
self.font_character_index += 1 | ||
|
||
|
||
def save_to_file(self, path): | ||
self.font.generate(path) | ||
|
||
class SvgFile(): | ||
def __init__(self, path, use_dirname_as_prefix=False): | ||
self.path = path | ||
|
||
#initalize the name | ||
self.name = os.path.basename(path).split('.')[0] | ||
if (use_dirname_as_prefix): | ||
prefix = os.path.basename(os.path.dirname(path)) | ||
self.name = "%s-%s" % (prefix, self.name) | ||
|
||
self.character_index = None | ||
self.character = None | ||
|
||
def set_character_index(self, character_index): | ||
self.character_index = character_index | ||
self.character = chr(character_index) | ||
|
||
class SvgToFontGenerator(): | ||
|
||
def __init__(self, source_directories, target_ttf_file): | ||
self.use_svg_dirname_as_prefix = (len(source_directories) > 1) | ||
self.source_directories = self.validate_source_directories( | ||
source_directories) | ||
self.target_ttf_file = target_ttf_file | ||
|
||
self.source_svg_files = self.collect_svg_files() | ||
|
||
def validate_source_directories(self, source_directories): | ||
ret_directories = list() | ||
for directory in source_directories: | ||
directory = os.path.realpath(directory) | ||
if os.path.exists(directory): | ||
ret_directories.append(directory) | ||
else: | ||
sys.stderr("path \"%s\" for source svg files does not exist." % \ | ||
directory) | ||
if len(ret_directories) == 0: | ||
raise NoSourceSvgDirectoriesException("No valid paths for source \ | ||
svg files provided") | ||
return ret_directories | ||
|
||
|
||
def collect_svg_files(self): | ||
file_paths = list() | ||
for directory in self.source_directories: | ||
file_paths += [os.path.join(directory, filename) | ||
for filename in list(glob.glob1(directory, "*.svg"))] | ||
|
||
svg_files = [SvgFile(file_path, self.use_svg_dirname_as_prefix) | ||
for file_path in file_paths] | ||
|
||
svg_files.sort(key=lambda a: a.name.lower()) | ||
return svg_files | ||
|
||
def generate(self): | ||
|
||
#start by processing the file | ||
font = FontforgeFont() | ||
for svg_file in self.source_svg_files: | ||
font.add_character(svg_file); | ||
font.save_to_file(self.target_ttf_file) | ||
|
||
if __name__ == "__main__": | ||
fontGenerator = SvgToFontGenerator(['./icons/icons8', './icons'], './fonts/Items.ttf') | ||
fontGenerator.generate() | ||
names = [svg.name.lower().replace("-", "_").replace("icons8_","") for svg in fontGenerator.source_svg_files] | ||
with open('./lib/item_icons.dart', 'w') as f: | ||
f.write(""" | ||
/* generated code, do not edit */ | ||
// ignore_for_file: constant_identifier_names | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:kitchenowl/models/item.dart'; | ||
class ItemIcons { | ||
ItemIcons._(); | ||
static const _kFontFam = 'Items'; | ||
static const String? _kFontPkg = null; | ||
static IconData? get(Item item) { | ||
return map[item.icon]; | ||
} | ||
static const Map<String, IconData> map = {\n""") | ||
|
||
for name in names: | ||
f.write(f""" "{name}": {name},\n""") | ||
|
||
f.write(""" };\n\n""") | ||
|
||
for i, name in enumerate(names): | ||
f.write(f""" static const IconData {name} = IconData({i+FIRST_FONT_CHARACTER_INDEX}, fontFamily: _kFontFam, fontPackage: _kFontPkg);\n""") | ||
|
||
f.write("""}\n""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Icons8 | ||
|
||
The icons in the `/icons/icons8` folder cannot be extracted, used, or distributed by any third party. See [copyright](./icons8/COPYRIGHT) for more information. | ||
|
||
Specials thanks to https://icons8.com/ who are the sole copyright holder. | ||
|
||
# Contributing | ||
|
||
If you are a designer and want to add item icons please add the new icon SVG files next to this README file and create a PR. Make sure you are the copyright holder when adding icons. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://intercom.help/icons8-7fb7577e8170/en/articles/5534926-universal-multimedia-license-agreement-for-icons8 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.