Skip to main content

Utility for OpenType chws/vchw features

Project description

Continuous Test + Deploy PyPI Dependencies

chws_tool

This tool adds the OpenType chws, vchw, halt, and vhal features to OpenType/TrueType fonts when any of these features are missing. Please see east-asian-spacing for details of these features.

This tool uses the east-asian-spacing package as its core engine, and has following advantages:

To add new fonts to the supported font list, please see the Adding Fonts section below.

Install

pip install chws-tool

If you want to clone and install in the editable mode with the development packages:

git clone https://github.com/googlefonts/chws_tool.git
cd chws_tool
pip install -e '.[dev]'

Command Line Usage

The following example adds the features to input.otf and saves it to the build directory. If the argument is a directory, the tool expands it to all fonts in the directory recursively.

add-chws input.otf

Use the -o option to change the output directory, or the --help option for the full list of options.

add-chws input_dir -o output_dir

API

The following example creates a font with the features in the "build" directory if the features are applicable:

import chws_tool

def main():
    output_path = chws_tool.add_chws("fonts/input.otf", "build")
    if output_path:
        print(f"Success! saved to {output_path}")
    else:
        print("Skipped")

If you prefer to overwrite existing fonts, you can omit the output directory.

import chws_tool

def main():
    chws_tool.add_chws("fonts/input.otf")

If your program uses asyncio:

import asyncio
import chws_tool

async def main_async():
    output_path = await chws_tool.add_chws_async("fonts/input.otf", "build")
    if output_path:
        print(f"Success! saved to {output_path}")
    else:
        print("Skipped")

asyncio.run(main_async())

Adding Fonts

This package has a built-in list of supported fonts in its config.

Fonts not in the known list are still processed with the default configuration, but this package shows a warning message.

When adding new fonts to the known font list, the following process is recommended:

  1. Find the font names. Running the add-chws with --print-name option can print them.
  2. Add them to the config.
  3. (Optional) Build the font and run the Visual Test. This step is optional because this package automatically avoids glyph collisions by computing glyph outlines.
  4. (Optional) Tweak the config if needed.

Visual Test

The primary purpose of this process is to find too tight spacings or glyph collisions caused by the kernings.

This tool has heuristic rules to determine the applicability of the spacings using the glyph metrics, but assumes that full-width punctuation glyphs have enough internal spacings according to linguistic conventions as in UAX#50 or in CLREQ. Unfortunately, not all fonts follow the conventions.

To run the visual test:

  1. Add the test font to the font list in the top <script> block of tests/test.html.
  2. Open it in your browser.
  3. Check "Fullwidth", "Upright", and "Hide same size" check boxes.

Here is the check list and tips:

  • Find where glyphs are too tight or collide when the feature is on but look fine without the feature.
    • Quotation marks can collide most often, especially in vertical flow but sometimes in horizontal flow too.
    • "Open+Open" and "Close+Close" are more likely to collide than other pairs.
    • Select glyphs to check how much inks overflow the glyph metrics.
  • Test both horizontal and vertical flows by flipping the "Vertical" checkbox.

Other controls in the test are not mandatory, but they may be useful in following cases.

  • Uncheck "Hide same size" to see cases where kernings are not applied by the built-in rules. They are usually fine. In most cases, they are because the glyphs are missing, they are not full-width, or the pair should not apply for the script of the font. The test file contaisn code poitns for all East Asian scripts, but not all code points should apply spacings for all script.
  • The "Language" list does not matter in most cases, except when the font supports multiple locales, such as Noto CJK.
  • The "Fullwidth" feature can change glyphs, but in most cases, if glyphs look ok with the feature on, they should be ok with the feature off.
  • The "Upright" feature is only valid in the vertical flow. You can just check it on, for the same reason as the "Fullwidth" feature.
  • The "Characters" input fields can change the test cases. You don't have to change them unless you have specific needs.

Releasing

See https://googlefonts.github.io/python#make-a-release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chws_tool-1.4.1.tar.gz (122.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chws_tool-1.4.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file chws_tool-1.4.1.tar.gz.

File metadata

  • Download URL: chws_tool-1.4.1.tar.gz
  • Upload date:
  • Size: 122.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for chws_tool-1.4.1.tar.gz
Algorithm Hash digest
SHA256 7dd12e3c42dabc848b89a6c815baf22d711207018dafd91529072f790c8a2eb5
MD5 688133d2d023617fc63ea5bad2b814dc
BLAKE2b-256 d072a06b3840022ff706d7741be4d971582ea5f3c780d39119ab78a507b5728c

See more details on using hashes here.

File details

Details for the file chws_tool-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: chws_tool-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for chws_tool-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52ae4f5ee143e4da547cd73dc4dfa04df06b4c78e018f932bc7aac6324728fb4
MD5 09859cab41eddcd652db2a8115136f7b
BLAKE2b-256 db397166175ca3fc52777609e79c47034542e7c9f1d220d331893383c5d92ef6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page