pettarin / glyphIgo

glyphIgo is a Swiss Army knife for dealing with fonts and EPUB eBooks
MIT License
75 stars 16 forks source link

Extracting range of chars from a font #9

Open mzealey opened 8 years ago

mzealey commented 8 years ago

Hi there, great project. I came across this when trying to extract a subset of chars from a font file like:

python glyphIgo.py subset -f ~/Downloads/dejavu-fonts-ttf-2.36/ttf/DejaVuSans.ttf -r 0x2600-0x2700 -o out.woff

Turns out with a bit of hacking it's very easy to do - perhaps you could include something like this in the code? (not sure if i got the parameter stuff right)

diff --git a/src/glyphIgo.py b/src/glyphIgo.py
index 2e87683..5f8f7e9 100755
--- a/src/glyphIgo.py
+++ b/src/glyphIgo.py
@@ -91,7 +91,7 @@ class CustomParser:
         COMMAND_LIST: [ ["blocks", "ebook", "font", "glyphs", "plain", "range"] ],
         COMMAND_LOOKUP: [ ["character"] ],
         COMMAND_OBFUSCATE: [ ["font"], ["id"] ],
-        COMMAND_SUBSET: [ ["ebook", "plain"], ["font"] ]
+        COMMAND_SUBSET: [ ["ebook", "plain", "range"], ["font"], ]
     } 

     DESCRIPTION = __description__
@@ -362,7 +362,7 @@ class CustomParser:

     OPTIONAL_PARAMETERS_CONFLICTS = [
         [ "blocks", "character", "ebook", "plain", "range" ],
-        [ "blocks", "character", "font", "glyphs", "range" ],
+        [ "blocks", "character", "font", "glyphs", ],
         [ "quiet", "verbose", "nohumanreadable" ],
         [ "adobe", "idpf" ],
         [ "compact", "full" ],
@@ -1286,6 +1286,9 @@ class GlyphIgo:
             if ("plain" in self.__args):
                 ebook_name = self.__args.plain
                 ebook_char_list = self.__get_plain_char_list()
+            if ("range" in self.__args):
+                ebook_name = self.__args.font
+                ebook_char_list = self.__get_range_char_list()
             font = fontforge.open(self.__args.font)
             font.selection.none()
             for c in ebook_char_list:
pettarin commented 8 years ago

Hi, thank you for your suggestion.

I believe you can do that by:

$ for ((i=0x2600; i<=0x2700; i++)); do printf '\u'`printf %04x $i`; done > your.set
$ python glyphIgo.py subset -f font.ttf -p your.set -o extracted.ttf

(See also: http://www.albertopettarin.it/blog/2014/09/16/subsetting-fonts-with-glyphigo.html )

However, I agree that a more straightforward way, e.g. by using -r as you suggested, would be better. Some time next month (August 2016) I will allocate time to rewrite glyphIgo, and I will address this issue. Hence, not doing anything right now, but leaving open to address it next month or so.