Skip to content

Commit

Permalink
Merge pull request #29 from paullinnerud/main
Browse files Browse the repository at this point in the history
Python extension interface
  • Loading branch information
paullinnerud authored Jan 5, 2022
2 parents 286f706 + f9383ff commit bdb7c40
Show file tree
Hide file tree
Showing 42 changed files with 20,413 additions and 19,560 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/py_ext_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Python Extension

on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
tags: ["v*.*.*"]
pull_request:
branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

build:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install cibuildwheel
pip install cython
- name: Build Wheels
run: python -m cibuildwheel --output-dir wheelhouse

- name: Upload Wheels
uses: actions/upload-artifact@v2
with:
name: vttcompilepy-${{ matrix.os }}
path: ./wheelhouse/*.whl

- name: Build Source Distribution
run: python setup.py sdist

- name: Upload Source Distribution
uses: actions/upload-artifact@v2
with:
path: ./dist/*.zip

deploy:

needs: [build]
# only run if the commit is tagged...
if: startsWith(github.ref, 'refs/tags/v')
# ... and all build jobs completed successfully
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools cython wheel twine
- name: Download artifacts from build jobs
uses: actions/download-artifact@v2
with:
path: dist/

- uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}



32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ For details on the tool visit https://docs.microsoft.com/en-us/typography/tools/

Visual TrueType compiles binary from source formats included in the fonts that are instructed with Visual TrueType.

This repo contains source for VTTCompile which is a standalone tool can compile the high level VTT Talk source
to a lower level assembler source and then can assemble that source to cooresponding binaries. Since VTT can also
generate variation 'cvar' for variable fonts, VTTCompile can also compile the 'cvar' from source format. VTTCompile
also includes file management functions to prepare a font for production and to strip source formats for a final
'ship' font binary.
This repo contains the source for the compilers of Visual TrueType. The compilers can compile the high level VTT Talk source
to a lower level assembler source and then can assemble that source to corresponding binaries. Since VTT can also generate
variation 'cvar' data for variable fonts, the compilers can also produce 'cvar' data from a source format. File management
functions are included to prepare a font for production and to strip source formats for a final 'ship' font binary.

The interface for VTTCompile is similar to VTTShell which is included in Visual TrueType download package.
The source in this repo can be compiled and used in two different ways.

First is VTTCompile which is a standalone tool can VTTCompile that runs on the command line. The interface for VTTCompile is
similar to VTTShell which is included in Visual TrueType download package.

Second is VTTCompilePy which is Cython based Python extension that exports interfaces enabling a Python program to compile
and assemble TrueType data. This extension also provides a command line interface to the Python interface. VTTCompilePy is
available on PyPi, please visit https://pypi.org/project/vttcompilepy.

The source code in the repo is mostly a subset of the source code of Visual TrueType as needed to produce VTTCompile.
However not all of the source code included in the repo is necessary to produce VTTCompile but we optomized for including
However not all of the source code included in the repo is necessary to produce VTTCompile but we optimized for including
as complete source files as possible to make future maintenance easier.

For documentation of the Visual TrueType source formats visit https://docs.microsoft.com/en-us/typography/tools/vtt/tsi-tables.
Expand All @@ -32,6 +38,18 @@ Build as 32-bit on 64-bit systems with `cd src && make CXXFLAGS=-m32`.
You may need to do `cd src && make CXXFLAGS="-std=c++14"` to explicitly request
support for the 2014 ISO C++ standard.

In the "vttcompilepy" folder is the Cython source for the Python extension but the build is
done through the setup.py file in the main folder.

Setup a Python environment including dependencies in requirements-dev.txt.

To build the extension on local machine use "Python setup.py build".
To install the built extension into current Python environment use "Python setup.py install".
To create a distribution package for current system use "Python setup.py bdist_wheel".

The workflow Python Extension uses ciBuildWheel to build the extension across multiple platforms
and optionally upload result to PyPi.

The minimum compiler requirement is support for the 2014 ISO C++ standard plus amendments.

## Contributing
Expand Down
38 changes: 38 additions & 0 deletions pypi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Project

VTTCompilePy is a Python extension built using Cython. It provides streamlined bindings for
various compilers from Visual TrueType.

VTTCompilePy was developed to support a Python based font development environment. In addition to the Python interface,
a command line interface is also installed. Usage is available with "vttcompilepy --help".

### Example

```python
import sys
from pathlib import Path
import vttcompilepy as vtt

TESTDATA = Path(__file__).parent / "data"
IN_PATH = TESTDATA / "selawik-variable.ttf"
OUT_PATH = TESTDATA / "out.ttf"

print(bytes(IN_PATH))

print('VTTCompilePy Test Client')

compiler = vtt.Compiler(IN_PATH)

compiler.compile_all()

compiler.save_font(OUT_PATH, vtt.StripLevel.STRIP_NOTHING)

```

## Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = [
"setuptools",
"wheel",
"cython",
]
build-backend = "setuptools.build_meta"

[tool.cibuildwheel]
skip = ["*-manylinux_i686", "pp*"]

test-requires = ["pytest", "fonttools"]
test-command = "pytest {project}/tests"
8 changes: 8 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cython>=0.29.1

wheel>=0.31

pytest

fonttools

6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[sdist]
formats = zip

[metadata]
license_files =
LICENSE.txt
64 changes: 64 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
from io import open
import os
import sys
import platform
from setuptools import Extension, setup
from Cython.Build import cythonize

here = os.path.abspath(os.path.dirname(__file__))

# Get the long description from the pypi.md file
with open(os.path.join(here, 'pypi.md'), encoding='utf-8') as f:
long_description = f.read()

define_macros = [('UNICODE', 1), ('_UNICODE', 1)]
linetrace = False
if int(os.environ.get('CYTHON_LINETRACE', '0')):
linetrace = True
define_macros.append(('CYTHON_TRACE_NOGIL', '1'))

extra_compile_args = []

if platform.system() != 'Windows':
extra_compile_args.append('-std=c++14')

if platform.system() == 'Windows':
extra_compile_args.append('-sdl')

extension = Extension(
'vttcompilepy.vttcompilepy',
define_macros=define_macros,
include_dirs=[".","src"],
sources=['vttcompilepy/vttcompilepy.pyx','src/application.cpp','src/CvtManager.cpp','src/File.cpp','src/List.cpp', 'src/MathUtils.cpp', 'src/Memory.cpp','src/Platform.cpp','src/TextBuffer.cpp', 'src/TMTParser.cpp', 'src/TTAssembler.cpp', 'src/TTEngine.cpp', 'src/TTFont.cpp', 'src/TTGenerator.cpp', 'src/Variation.cpp', 'src/VariationInstance.cpp', 'src/VariationModels.cpp' ],
language='c++',
extra_compile_args=extra_compile_args,
)

setup(
name="vttcompilepy",
version= '0.0.1.2',
description="Python extension for Visual TrueType font compile. ",
long_description=long_description,
long_description_content_type='text/markdown',
author="Paul Linnerud",
author_email="[email protected]",
url="https://github.com/microsoft/VisualTrueType",
license="MIT",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
],
package_dir={"": "."},
packages=["vttcompilepy"],
zip_safe=False,
python_requires=">=3.7",
ext_modules = cythonize(
extension,
annotate=bool(int(os.environ.get('CYTHON_ANNOTATE', '0'))),
compiler_directives={"linetrace": linetrace},
),
entry_points={
'console_scripts': [ "vttcompilepy = vttcompilepy.__main__:main" ]
}
)
Loading

0 comments on commit bdb7c40

Please sign in to comment.