Skip to content

Commit

Permalink
finished reviewing argparse usage on the new scripts
Browse files Browse the repository at this point in the history
(the ones that came from fontbakery). And also updated dependencies on setup.py
(issue googlefonts#3)
  • Loading branch information
felipesanches committed Nov 2, 2017
1 parent b1e7187 commit 99b3da4
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 108 deletions.
51 changes: 18 additions & 33 deletions bin/gftools-check-bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import argparse
from argparse import RawTextHelpFormatter
import csv
import sys
from fontTools.ttLib import TTFont
import tabulate

description = """
gftools check-bbox
~~~~~~~~~~~~~~~~~~~~~~~~
"""
A Python script for printing bounding boxes to stdout.
Users can either check a collection of fonts bounding boxes (--family) or
the bounding box for each glyph in the collection of fonts (--glyphs).
Extremes coordinates for each category can be returned with the argument
--extremes.
e.g:
Check bounding boxes of fonts in collection:
gftools check-bbox --family [fonts]
Check bounding boxes of glyphs in fonts collection:
gftools check-bbox --glyphs [fonts]
Find the extreme coordinates for the bounding boxes in the fonts collection:
gftools check-bbox --family --extremes [fonts]
"""
parser = argparse.ArgumentParser(description=description,
formatter_class=RawTextHelpFormatter)
from argparse import (ArgumentParser,
RawTextHelpFormatter)
import csv
import sys
from fontTools.ttLib import TTFont
import tabulate
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('fonts',
nargs="+",
help="Fonts in OpenType (TTF/OTF) format")
parser.add_argument('--csv', default=False, action='store_true')
parser.add_argument('--extremes', default=False, action='store_true')
nargs='+',
help='Fonts in OpenType (TTF/OTF) format')
parser.add_argument('--csv', default=False, action='store_true',
help='Output data in comma-separated-values format')
parser.add_argument('--extremes', default=False, action='store_true',
help='Print extremes coordinates for each category')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--glyphs', default=False, action="store_true")
group.add_argument('--glyphs', default=False, action='store_true',
help=('Return the bounds for glyphs'
' in a collection of fonts'))
group.add_argument('--family', default=False, action="store_true",
help='Return the bounds for a family of fonts')

Expand Down
22 changes: 8 additions & 14 deletions bin/gftools-check-vtt-compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
#
# See AUTHORS.txt for the list of Authors and LICENSE.txt for the License.
#
import argparse
"""
Check a hinted font will successfully transfer
vtt instructions to an unhinted font.
"""
from argparse import (ArgumentParser,
RawTextHelpFormatter)
from fontTools.ttLib import TTFont
import logging

description = """
check-vtt-compatibility
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Check a hinted font will successfully transfer vtt instructions to an
unhinted font
$ gftools check-vtt-compatibility hinted.ttf unhinted.ttf
"""


def font_glyphs(font):
'''return a dict of glyphs objects for font
Expand Down Expand Up @@ -64,9 +59,8 @@ def compare_glyph_count(font1, name1, name2):
logging.info('%s %s glyphs match' % (name1, name2))


parser = argparse.ArgumentParser(
description=description,
formatter_class=argparse.RawTextHelpFormatter)
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('hinted', help='Hinted font')
parser.add_argument('unhinted', help='Unhinted font')
parser.add_argument('--count', action="store_true", default=True,
Expand Down
6 changes: 4 additions & 2 deletions bin/gftools-family-html-snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
import json
import requests
import sys
from argparse import ArgumentParser
from argparse import (ArgumentParser,
RawTextHelpFormatter)

GF_API = "https://www.googleapis.com/webfonts/v1/webfonts?key={}"

Expand Down Expand Up @@ -177,7 +178,8 @@ def gen_body_text(styles, sample_text):


def main():
parser = ArgumentParser(description=__doc__)
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('key',
help='Key from Google Fonts Developer API')
parser.add_argument('family',
Expand Down
21 changes: 6 additions & 15 deletions bin/gftools-fix-fstype.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import argparse
from argparse import RawTextHelpFormatter
from fontTools.ttLib import TTFont

description = """
gftools fix-fstype
~~~~~~~~~~~~~~~~~~~~~~~~
"""
Update a collection of fonts fsType value to Installable Embedding.
Google Fonts requires Installable Embedding (0):
https://github.com/googlefonts/gf-docs/blob/master/ProjectChecklist.md#fstype
Microsoft OpenType specification:
https://www.microsoft.com/typography/otspec/os2.htm#fst
e.g:
gftools fix-fstype [fonts]
"""

parser = argparse.ArgumentParser(description=description,
formatter_class=RawTextHelpFormatter)
from argparse import (ArgumentParser,
RawTextHelpFormatter)
from fontTools.ttLib import TTFont
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('fonts',
nargs="+",
help="Fonts in OpenType (TTF/OTF) format")
Expand Down
13 changes: 8 additions & 5 deletions bin/gftools-fix-nonhinting.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@
# $ gftools fix-nonhinting FontIn.ttf FontOut.ttf

# Import our system library and fontTools ttLib
import argparse
"""
Fixes TTF GASP table so that its program
contains the minimal recommended instructions.
"""
from argparse import (ArgumentParser,
RawTextHelpFormatter)
import os
from fontTools import ttLib
from fontTools.ttLib.tables import ttProgram

description = 'Fixes TTF GASP table so that its program ' \
'contains the minimal recommended instructions'
parser = argparse.ArgumentParser(description=description)
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('fontfile_in',
nargs=1,
help="Font in OpenType (TTF/OTF) format")
Expand Down
27 changes: 11 additions & 16 deletions bin/gftools-nametable-from-filename.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,19 @@
# limitations under the License.
#
# See AUTHORS.txt for the list of Authors and LICENSE.txt for the License.
"""
Replace a collection of fonts nametable's with new tables based on
the Google Fonts naming spec from just the filename.
The fsSelection, fsType and macStyle also get updated
to reflect the new names.
"""
import re
import ntpath
import argparse
from argparse import RawTextHelpFormatter
from argparse import (ArgumentParser,
RawTextHelpFormatter)
from fontTools.ttLib import TTFont, newTable


description = """
gftools nametable-from-filename
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Replace a collection of fonts nametable's with new tables based on the Google
Fonts naming spec from just the filename.
The fsSelection, fsType and macStyle also get updated to reflect the new
names.
"""

WIN_SAFE_STYLES = [
'Regular',
'Bold',
Expand Down Expand Up @@ -267,8 +262,8 @@ def nametable_from_filename(filepath):
return new_table


parser = argparse.ArgumentParser(description=description,
formatter_class=RawTextHelpFormatter)
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('fonts', nargs="+")


Expand Down
18 changes: 6 additions & 12 deletions bin/gftools-update-nameids.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from fontTools.ttLib import TTFont
import argparse
from argparse import RawTextHelpFormatter

description = """
gftools update-nameids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
Update specific nameIDs in a collection of fonts with new strings.
Examples:
Expand All @@ -33,7 +26,9 @@
if you need to change the name or style of a collection of font families,
use gftools nametable-from-filename instead.
"""

from fontTools.ttLib import TTFont
from argparse import (ArgumentParser,
RawTextHelpFormatter)

NAME_IDS = {
0: 'copyright',
Expand Down Expand Up @@ -63,9 +58,8 @@ def update_field(arg, args, fields, nametable):
swap_name(fields, nametable, text)



parser = argparse.ArgumentParser(description=description,
formatter_class=RawTextHelpFormatter)
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('fonts', nargs="+")
parser.add_argument('-c', '--copyright', type=str,
help='Update copyright string')
Expand Down
17 changes: 6 additions & 11 deletions bin/gftools-update-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import argparse
from argparse import RawTextHelpFormatter
from fontTools.ttLib import TTFont

description = """
gftools update-version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
Update a collection of fonts version number to a new version number.
e.g:
gftools update-version [fonts] 2.300 2.301
"""
from argparse import (ArgumentParser,
RawTextHelpFormatter)
from fontTools.ttLib import TTFont

parser = argparse.ArgumentParser(description=description,
formatter_class=RawTextHelpFormatter)
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('fonts',
nargs="+",
help="Fonts in OpenType (TTF/OTF) format")
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def gftools_scripts():
# see: https://github.com/fontforge/fontforge/issues/2048
'FontTools',
'Flask',
'glyphsLib',
'pillow',
'protobuf',
'requests',
Expand Down

0 comments on commit 99b3da4

Please sign in to comment.