diff --git a/.gitignore b/.gitignore index 0d20b64..379e8d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *.pyc +*.egg-info +build +venv diff --git a/README.md b/README.md index 1225338..a3f05cc 100644 --- a/README.md +++ b/README.md @@ -2,32 +2,65 @@ # Tools for making OpenType-SVG fonts -Dependencies: +- `addsvg` + adds an SVG table to a font, using SVG files provided. The font's format can be either OpenType or TrueType. -- python 2.7 or higher -- [fontTools 3.0](https://github.com/fonttools/fonttools) +- `dumpsvg` + saves the contents of a font's SVG table as individual SVG files. The font's format can be either OpenType, TrueType, WOFF, or WOFF2. -## How to make OpenType-SVG fonts? +- `fonts2svg` + generates a set of SVG glyph files from one or more fonts and hex colors for each of them. The fonts' format can be either OpenType, TrueType, WOFF, or WOFF2. + + +### Dependencies + +- Python 3.6 or higher + +- [FontTools](https://github.com/fonttools/fonttools) 3.1.0 or higher + + +### Installation instructions + +- Make sure you have Python 3.6 (or higher) installed. + +- Clone this repository. + +- `cd` into the repository folder. + +- Setup a virtual environment: + + $ python3 -m venv venv + +- Activate the environment: + + $ source venv/bin/activate + +- Update `pip`: + + $ pip install -U pip + +- Install `opentypesvg`: + + $ pip install . + + +# How to make OpenType-SVG fonts? ### Step 1 #### Generate a set of SVG files from a series of fonts and color values. ![step1](imgs/step1.png "step 1") -```sh -$ python fonts2svg.py -c 99ccff,ff0066,cc0066 fonts/Zebrawood-Shadow.otf fonts/Zebrawood-Fill.otf fonts/Zebrawood-Dots.otf -``` + fonts2svg -c 99ccff,ff0066,cc0066 fonts/Zebrawood-Shadow.otf fonts/Zebrawood-Fill.otf fonts/Zebrawood-Dots.otf ### Step 2 #### Add a set of SVG files to an existing OpenType (or TrueType) font. ![step2](imgs/step2.png "step 2") -```sh -$ python addSVGtable.py -s fonts/SVGs fonts/Zebrawood.otf -``` + addsvg -s fonts/SVGs fonts/Zebrawood.otf -You can use **Step 2** without doing **Step 1**, but there are a few things you need to be aware of when using the `addSVGtable.py` script: +You can use **Step 2** without doing **Step 1**, but there are a few things you need to be aware of when using the `addsvg` tool: * After the SVG files are saved with the authoring application (e.g. Adobe Illustrator, CorelDRAW!, Inkscape) they should be put thru a process that optimizes and cleans up the SVG code; this will slim down the file size while keeping the resulting artwork the same. For this step you can use one of these tools: * [SVG Cleaner](https://github.com/RazrFalcon/svgcleaner-gui/releases) (GUI version) @@ -35,6 +68,6 @@ You can use **Step 2** without doing **Step 1**, but there are a few things you * [SVG Optimizer](https://github.com/svg/svgo) * [Scour](https://github.com/scour-project/scour) -* The script requires the SVG files to be named after the glyphs which they are meant to be associated with. For example, if the glyph in the font is named **ampersand**, the SVG file needs to be named `ampersand.svg`. +* The tool requires the SVG files to be named according to the glyphs which they are meant to be associated with. For example, if the glyph in the font is named **ampersand**, the SVG file needs to be named `ampersand.svg`. -* The script expects the color artwork to have been designed at the same size as the glyphs in the font, usually 1000 or 2048 UPM. This means 1 point (pt) in the authoring app equals 1 unit in font coordinates. +* The tool expects the color artwork to have been designed at the same size as the glyphs in the font, usually 1000 or 2048 UPM. This means 1 point (pt) in the authoring app equals 1 unit in font coordinates. diff --git a/addSVGtable.py b/lib/opentypesvg/addsvg.py similarity index 93% rename from addSVGtable.py rename to lib/opentypesvg/addsvg.py index d8c7be8..ee3df49 100755 --- a/addSVGtable.py +++ b/lib/opentypesvg/addsvg.py @@ -9,7 +9,7 @@ from __future__ import print_function -__version__ = '1.1.0' +__version__ = '1.1.1' import argparse import os @@ -17,13 +17,15 @@ import sys from shutil import copy2 -from util.shared_utils import (read_file, split_comma_sequence, - validate_font_paths, validate_folder_path) - -import util.check_fonttools # pylint: disable=unused-import - from fontTools import ttLib +from opentypesvg.utils import ( + read_file, + split_comma_sequence, + validate_folder_path, + validate_font_paths, +) + def getGlyphNameFromFileName(filePath): fontFileName = os.path.split(filePath)[1] @@ -81,7 +83,7 @@ def cleanupSVGdoc(svgItemData): return svgItemData -reCopyCounter = re.compile("#\d+$") +reCopyCounter = re.compile(r"#\d+$") def makeFontCopyPath(fontPath): @@ -281,15 +283,6 @@ def get_options(args): ) options = parser.parse_args(args) - if options.generate_woffs: - # Make sure that the brotli module is installed - try: - import brotli # pylint: disable=unused-variable - except ImportError as err: - print("ERROR: {} was found. The WOFF2 format requires it.".format( - err), file=sys.stderr) - sys.exit(1) - options.font_paths_list = validate_font_paths([options.input_path]) return options diff --git a/dumpSVGtable.py b/lib/opentypesvg/dumpsvg.py similarity index 93% rename from dumpSVGtable.py rename to lib/opentypesvg/dumpsvg.py index f95ae35..9d5d225 100755 --- a/dumpSVGtable.py +++ b/lib/opentypesvg/dumpsvg.py @@ -9,23 +9,26 @@ from __future__ import division, print_function -__version__ = '1.1.0' +__version__ = '1.1.1' import argparse import os import re import sys -from util.shared_utils import (write_file, final_message, - get_output_folder_path, - validate_font_paths, split_comma_sequence, - create_folder, create_nested_folder, - get_gnames_to_save_in_nested_folder) - -import util.check_fonttools # pylint: disable=unused-import - from fontTools import ttLib +from opentypesvg.utils import ( + create_folder, + create_nested_folder, + final_message, + get_gnames_to_save_in_nested_folder, + get_output_folder_path, + split_comma_sequence, + validate_font_paths, + write_file, +) + reViewBox = re.compile(r"viewBox=[\"|\']([\d, ])+?[\"|\']", re.DOTALL) diff --git a/fonts2svg.py b/lib/opentypesvg/fonts2svg.py similarity index 95% rename from fonts2svg.py rename to lib/opentypesvg/fonts2svg.py index b9a733a..78180b8 100755 --- a/fonts2svg.py +++ b/lib/opentypesvg/fonts2svg.py @@ -10,25 +10,28 @@ from __future__ import division, print_function -__version__ = '1.1.0' +__version__ = '1.1.1' import argparse import os import re import sys -from util.shared_utils import (write_file, final_message, - get_output_folder_path, - validate_font_paths, split_comma_sequence, - create_folder, create_nested_folder, - get_gnames_to_save_in_nested_folder) - -import util.check_fonttools # pylint: disable=unused-import - from fontTools import ttLib from fontTools.pens.basePen import BasePen from fontTools.pens.transformPen import TransformPen +from opentypesvg.utils import ( + create_folder, + create_nested_folder, + final_message, + get_gnames_to_save_in_nested_folder, + get_output_folder_path, + split_comma_sequence, + validate_font_paths, + write_file, +) + class SVGPen(BasePen): diff --git a/util/shared_utils.py b/lib/opentypesvg/utils.py similarity index 100% rename from util/shared_utils.py rename to lib/opentypesvg/utils.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b872bc7 --- /dev/null +++ b/setup.py @@ -0,0 +1,28 @@ +from setuptools import setup + +with open("README.md", "r") as fh: + long_description = fh.read() + +setup( + name="opentypesvg", + version="1.1.1", + author="Miguel Sousa", + author_email="msousa@adobe.com", + description="Tools for making OpenType-SVG fonts", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/adobe-type-tools/opentype-svg", + license="MIT", + platforms=["Any"], + package_dir={'': 'lib'}, + packages=['opentypesvg'], + python_requires='>=3.6', + install_requires=['fontTools[woff]>=3.1.0'], + entry_points={ + 'console_scripts': [ + "addsvg = opentypesvg.addsvg:main", + "dumpsvg = opentypesvg.dumpsvg:main", + "fonts2svg = opentypesvg.fonts2svg:main", + ] + }, +) diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/check_fonttools_test.py b/tests/check_fonttools_test.py deleted file mode 100644 index 2bee963..0000000 --- a/tests/check_fonttools_test.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2018 Adobe. All rights reserved. - -from __future__ import print_function, division, absolute_import - -import sys -import unittest - -from shared_utils_test import StringIO - -have_fonttools = False -try: - import fontTools # pylint: disable=unused-import - have_fonttools = True -except ImportError: - pass - - -class CheckFonttoolsTest(unittest.TestCase): - - def test_check_fonttools(self): - stream = sys.stderr = StringIO() - with self.assertRaises(SystemExit) as cm: - import util.check_fonttools # pylint: disable=unused-variable - - if not have_fonttools: - self.assertEqual( - stream.getvalue().strip(), - 'ERROR: FontTools Python module is not installed.\n' - 'Get the latest version at https://github.com/fonttools' - '/fonttools') - else: - self.assertEqual( - stream.getvalue().strip(), - 'ERROR: The FontTools module version must be 3.0 or ' - 'higher.\nYou have version 2.5 installed.\nGet the latest ' - 'version at https://github.com/fonttools/fonttools') - - self.assertEqual(cm.exception.code, 1) - - -if __name__ == "__main__": - sys.exit(unittest.main()) diff --git a/tests/run_tests.cmd b/tests/run_tests.cmd deleted file mode 100644 index 70f0b55..0000000 --- a/tests/run_tests.cmd +++ /dev/null @@ -1,6 +0,0 @@ - -set test_files=(shared_utils options) - -for %%n in %test_files% do ( - python tests\%%n_test.py -) diff --git a/tests/run_tests.sh b/tests/run_tests.sh deleted file mode 100644 index 2243f61..0000000 --- a/tests/run_tests.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -test_files="shared_utils options" - -for name in $test_files -do - coverage run -a --source=. "tests/"$name"_test".py -done diff --git a/util/__init__.py b/util/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/util/check_fonttools.py b/util/check_fonttools.py deleted file mode 100644 index a98be7a..0000000 --- a/util/check_fonttools.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2016 Adobe. All rights reserved. - -""" -Snippet to check if fontTools is installed and -is at least a certain version. -""" - -from __future__ import print_function - -import sys -from distutils.version import LooseVersion - - -FONTTOOLS_URL = 'https://github.com/fonttools/fonttools' -MIN_FT_VERSION = '3.0' - -try: - from fontTools import version as ftversion -except ImportError: - print("ERROR: FontTools Python module is not installed.\n" - "Get the latest version at {}".format(FONTTOOLS_URL), - file=sys.stderr) - sys.exit(1) - -if LooseVersion(ftversion) < LooseVersion(MIN_FT_VERSION): - print("ERROR: The FontTools module version must be {} or higher.\n" - "You have version {} installed.\n" - "Get the latest version at {}".format( - MIN_FT_VERSION, ftversion, FONTTOOLS_URL), - file=sys.stderr) - sys.exit(1)