Skip to content

Commit

Permalink
Added --exclude switch while subsetting
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Pettarin committed Jun 7, 2015
1 parent cd227a2 commit 56a1ad1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2012-2014 Alberto Pettarin ([email protected])
Copyright (c) 2012-2015 Alberto Pettarin ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 20 additions & 0 deletions OUTPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,26 @@ $ ./glyphIgo.py subset -f font.otf -e ebook.epub -o minimized.otf



## Subset `font.ttf` into `minimized.ttf` by removing the glyphs that appear in `list.txt`

```
$ ./glyphIgo.py subset -f font.ttf -p list.txt -o minimized.ttf --exclude
[INFO] Subsetting font 'font.ttf' with ebook 'list.txt' into new font 'minimized.ttf', not containing the following glyphs:
'0' 48 0x30 DIGIT ZERO
'1' 49 0x31 DIGIT ONE
'2' 50 0x32 DIGIT TWO
'3' 51 0x33 DIGIT THREE
'4' 52 0x34 DIGIT FOUR
'5' 53 0x35 DIGIT FIVE
'6' 54 0x36 DIGIT SIX
'7' 55 0x37 DIGIT SEVEN
'8' 56 0x38 DIGIT EIGHT
'9' 57 0x39 DIGIT NINE
```



## Convert `font.ttf` (TTF) into `new.font.otf` (OTF)

```
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

**glyphIgo** is a Swiss Army knife for dealing with fonts and EPUB eBooks

* Version: 3.0.2
* Date: 2014-10-19
* Version: 3.0.3
* Date: 2015-06-07
* Developer: [Alberto Pettarin](http://www.albertopettarin.it/) ([contact](http://www.albertopettarin.it/contact.html))
* License: the MIT License (MIT), see LICENSE.md

Expand Down Expand Up @@ -65,6 +65,8 @@ optional arguments:
--compact compact lookup output (Unicode character, name, and
codepoint only)
--exact use exact Unicode lookup (default)
--exclude exclude the characters in EBOOK or PLAIN from the
output
--full full lookup output (default)
--heuristic use heuristic Unicode lookup
--idpf use IDPF obfuscation algorithm (default)
Expand Down Expand Up @@ -150,6 +152,9 @@ exit codes:
21. Subset font.ttf into min.font.otf by copying only the glyphs appearing in ebook.epub
$ ./glyphIgo.py subset -f font.ttf -e ebook.epub -o min.font.otf
22. Subset font.ttf into rem.font.ttf by removing the glyphs appearing in list.txt
$ glyphIgo.py subset -f font.ttf -p list.txt -o rem.font.ttf --exclude
```

Please see [OUTPUT.md](OUTPUT.md) for usage examples with their actual output.
Expand Down
33 changes: 23 additions & 10 deletions src/glyphIgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

__license__ = 'MIT'
__author__ = 'Alberto Pettarin ([email protected])'
__copyright__ = '2012-2014 Alberto Pettarin ([email protected])'
__version__ = 'v3.0.2'
__date__ = '2014-10-19'
__copyright__ = '2012-2015 Alberto Pettarin ([email protected])'
__version__ = 'v3.0.3'
__date__ = '2015-06-07'
__description__ = 'glyphIgo is a Swiss Army knife for dealing with fonts and EPUB eBooks'


### BEGIN changelog ###
#
# 3.0.3 2015-06-07 Added option to remove the char set while subsetting a font
# 3.0.2 2014-10-19 Support for bash/zsh autocompletion via argcomplete
# 3.0.1 2014-10-08 Better hex/dec char lookup, added range option to list command
# 3.0.0 2014-07-31 Heavy code refactoring, switched to argparse, changed CLI names
Expand Down Expand Up @@ -180,6 +181,10 @@ class CustomParser:
"msg": "Subset font.ttf into min.font.otf by copying only the glyphs appearing in ebook.epub",
"cmd": ["subset -f font.ttf -e ebook.epub -o min.font.otf"]
},
{
"msg": "Subset font.ttf into rem.font.ttf by removing the glyphs appearing in list.txt",
"cmd": ["subset -f font.ttf -p list.txt -o rem.font.ttf --exclude"]
},
{
"msg": "",
"cmd": [""]
Expand Down Expand Up @@ -323,6 +328,12 @@ class CustomParser:
"help": "use exact Unicode lookup (default)",
"action": "store_true"
},
{
"short": None,
"long": "--exclude",
"help": "exclude the characters in EBOOK or PLAIN from the output",
"action": "store_true"
},
{
"short": None,
"long": "--full",
Expand Down Expand Up @@ -1139,8 +1150,6 @@ def __create_epub(self, char_list):
generator.createEPUB(dec_codepoint_list, epub_title, epub_file_name)
self.__print_info("Created EPUB file '%s'." % (epub_file_name))



def __do_check(self):
font_char_list = []
ebook_char_list = []
Expand Down Expand Up @@ -1283,14 +1292,18 @@ def __do_subset(self):
if (c[0] in font_char_list):
font.selection.select(("more", "unicode"), ord(c[0]))
found_char_list.append(c[0])
font.selection.invert()
if (not ("exclude" in self.__args)):
font.selection.invert()
font.clear()
output_font_file = self.__get_name_output_file(self.__args.font, prefix="subset_")
font.generate(output_font_file)
except Exception as e:
self.__print_error(str(e))
return CustomParser.EXIT_CODE_COMMAND_FAILED
self.__print_info("Subsetting font '%s' with ebook '%s' into new font '%s', containing the following glyphs:" % (font_name, ebook_name, output_font_file))
if ("exclude" in self.__args):
self.__print_info("Subsetting font '%s' with ebook '%s' into new font '%s', not containing the following glyphs:" % (font_name, ebook_name, output_font_file))
else:
self.__print_info("Subsetting font '%s' with ebook '%s' into new font '%s', containing the following glyphs:" % (font_name, ebook_name, output_font_file))
self.__print_char_list(found_char_list)
return CustomParser.EXIT_CODE_OK

Expand Down Expand Up @@ -1326,7 +1339,7 @@ def execute(self):
def main():
# read command line parameters
args = CustomParser().get_arguments()

# run glyphIgo
returnCode = GlyphIgo(args).execute()

Expand All @@ -1335,8 +1348,8 @@ def main():

if (__name__ == '__main__'):
# force UTF-8 encoding
reload(sys)
sys.setdefaultencoding("utf-8")
#reload(sys)
#sys.setdefaultencoding("utf-8")
main()


Expand Down

0 comments on commit 56a1ad1

Please sign in to comment.