Skip to content

Commit

Permalink
Package the scripts. Improve documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelsousa committed May 2, 2020
1 parent fa2de4e commit 4410a5a
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 134 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.pyc
*.egg-info
build
venv
59 changes: 46 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,72 @@

# 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)
* [SVG Cleaner](https://github.com/RazrFalcon/svgcleaner) (command line version)
* [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.
25 changes: 9 additions & 16 deletions addSVGtable.py → lib/opentypesvg/addsvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@

from __future__ import print_function

__version__ = '1.1.0'
__version__ = '1.1.1'

import argparse
import os
import re
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]
Expand Down Expand Up @@ -81,7 +83,7 @@ def cleanupSVGdoc(svgItemData):
return svgItemData


reCopyCounter = re.compile("#\d+$")
reCopyCounter = re.compile(r"#\d+$")


def makeFontCopyPath(fontPath):
Expand Down Expand Up @@ -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

Expand Down
21 changes: 12 additions & 9 deletions dumpSVGtable.py → lib/opentypesvg/dumpsvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 12 additions & 9 deletions fonts2svg.py → lib/opentypesvg/fonts2svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
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",
]
},
)
Empty file removed tests/__init__.py
Empty file.
42 changes: 0 additions & 42 deletions tests/check_fonttools_test.py

This file was deleted.

6 changes: 0 additions & 6 deletions tests/run_tests.cmd

This file was deleted.

8 changes: 0 additions & 8 deletions tests/run_tests.sh

This file was deleted.

Empty file removed util/__init__.py
Empty file.
31 changes: 0 additions & 31 deletions util/check_fonttools.py

This file was deleted.

0 comments on commit 4410a5a

Please sign in to comment.