All Projects → LingDong- → Chinese Hershey Font

LingDong- / Chinese Hershey Font

Licence: mit
Convert Chinese Characters to Single-Line Fonts using Computer Vision

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Chinese Hershey Font

ttf2hershey
Convert True Type Fonts (.ttf) to Hershey vector fonts
Stars: ✭ 29 (-58.57%)
Mutual labels:  font, convert, typography
Qiji Font
齊伋體 - typeface from Ming Dynasty woodblock printed books
Stars: ✭ 536 (+665.71%)
Mutual labels:  chinese, font, typography
Rrpl
Describing Chinese Characters with Recursive Radical Packing Language (RRPL)
Stars: ✭ 649 (+827.14%)
Mutual labels:  chinese, font, typography
huozi.js
A simple typography engine for CJK languages, especially designed for game rich-text. 用于游戏富文本的中日韩文字排印引擎。
Stars: ✭ 135 (+92.86%)
Mutual labels:  typography, chinese
baseline
New method for creating leading on the web
Stars: ✭ 31 (-55.71%)
Mutual labels:  font, typography
hzk-pixel-font
中文像素字体,12 和 16 像素。
Stars: ✭ 14 (-80%)
Mutual labels:  font, chinese
Osfcc
一个收集可用于中文字体排印的开源字体集合。
Stars: ✭ 314 (+348.57%)
Mutual labels:  chinese, typography
hkcs
香港民間字集 Hong Kong Character Set Project (HKCS)
Stars: ✭ 29 (-58.57%)
Mutual labels:  font, chinese
Otfcc
Optimized OpenType builder and inspector.
Stars: ✭ 348 (+397.14%)
Mutual labels:  font, typography
Juliamono
repository for JuliaMono, a monospaced font with reasonable Unicode support.
Stars: ✭ 625 (+792.86%)
Mutual labels:  font, typography
Commissioner
Commissioner is a variable and static sans typeface.
Stars: ✭ 147 (+110%)
Mutual labels:  font, typography
Google Type
Collaborative typography project using select passages from Aesop's Fables set to Google Fonts
Stars: ✭ 971 (+1287.14%)
Mutual labels:  font, typography
Epilogue
2 axes/Variable/18 styles/Sans
Stars: ✭ 104 (+48.57%)
Mutual labels:  font, typography
fontfacegen-webpack-plugin
A plugin for webpack that allows you to convert .ttf and .otf files into various other font formats such as .eot, .ttf, .svg, .woff and .woff2 using the existing NPM package fontfacegen.
Stars: ✭ 20 (-71.43%)
Mutual labels:  font, convert
typeface-minecraft
Minecraft typeface and colors
Stars: ✭ 20 (-71.43%)
Mutual labels:  font, typography
Web Typography Glossary
Webタイポグラフィの基礎知識と実践
Stars: ✭ 279 (+298.57%)
Mutual labels:  font, typography
ansi-to-svg
😹 convert ANSI Escaped CLI strings to SVGs
Stars: ✭ 18 (-74.29%)
Mutual labels:  font, convert
Bellota-Font
An ornamented Sans Serif font family
Stars: ✭ 21 (-70%)
Mutual labels:  font, typography
Prototypo
Create your own font in a few clicks
Stars: ✭ 388 (+454.29%)
Mutual labels:  font, typography
P5 Hershey Js
p5.js Hershey Vector Font Library
Stars: ✭ 23 (-67.14%)
Mutual labels:  font, typography

chinese-hershey-font

Convert Chinese Characters to Single-Line Fonts using Computer Vision

Single-line fonts such as the Hershey fonts are massively useful for making cool procedural graphics and for engraving. They're also arguably easier to learn for neural nets.

This tool automatically generates Chinese Single-Line fonts given a regular True Type Font file (ttf/ttc). It can output either the classic Hershey format, or a JSON file containing all the polylines.

The algorithm scans a raster rendering of a character at many different angles to find line segments that are most likely part of a stroke. It then estimates the strokes by connecting, merging, and cleaning up the line segments.

Dependencies

  • Python 2
  • PIL/Pillow (pip install pillow)

File Formats

The following are types of files this software can produce to encode single-line fonts.

Stroke Files

A JSON file with one object. The keys of the object are unicode indices of characters. Each key maps to an array of polylines. A polyline is an array of points. A point is a 2-element Array containing x and y coordinates. A coordinate is a float between 0.0 and 1.0, and (0,0) is the upper left-corner. For example:

{
  "U+4E00":[[[0.0, 0.55], [1.0, 0.55]]],
  "U+4E01":[[[0.02, 0.02], [0.99, 0.02]], [[0.51, 0.02], [0.53, 0.925], [0.31, 1.0]]]
}

The above encoding contains the first two Chinese characters in unicode, "一" and "丁".

Hershey Fonts

The Hershey fonts are a collection of vector fonts developed c. 1967 by Dr. Allen Vincent Hershey at the Naval Weapons Laboratory, originally designed to be rendered using vectors on early cathode ray tube displays. The fonts are publicly available and have few usage restrictions. Vector fonts are easily scaled and rotated in two or three dimensions; consequently the Hershey fonts have been widely used in computer graphics, computer-aided design programs, and more recently also in computer-aided manufacturing applications like laser engraving. (Wikipedia)

This link gives an overview on how to parse Hershey fonts. You can also find my own implementation at Lingdong-/p5-hershey-js.

Compared to stroke files, Hershey Fonts are many times more compact, but also has less accurate coordinates.

Usage

Pre-compiled Fonts

If you're only interested in utilizing pre-generated single-line fonts, you can grab them at the following places:

Note:

Heiti.hf.txt and Kaiti.hf.txt were originally based on proprietary macOS system fonts STHeiti and STKaiti. They're now replaced with open source alternatives.

Generating Stroke Files

If you would like to generate new single-line fonts from custom TTF/TTC files, first use the following command to generate a JSON-encoded stroke file.

python char2stroke.py build path/to/font.ttf

Optional arguments:

  --first [FIRST]
  --height [HEIGHT]
  --last [LAST]
  --ngradient [NGRADIENT]
  --output [OUTPUT]
  --strw [STRW]
  --width [WIDTH]
  • width and height determines the dimension of the raster images of characters to be scanned. The larger these numbers, the more detailed and the slower. Default is 100 for both.
  • strw is the approximate stroke width (in pixels, at given width and height). This is used when merging strokes. Default is 10.
  • first and last specifies the range of unicode characters to include. Default values are 0x4e00 and 0x9fef, which contains all the "CJK Ideograph" glyphs.
  • ngradient is the number of different gradients used to scan the image. At ngradient = 1, only strokes at 0°, 45° and 90° are scanned, while at 2, 3 and 4, slopes of atan(1/2), atan(1/3) and atan(1/4) are also included. Default is 2.
  • output: path to write the output file. When this is not specified, the program writes to stdout, and >(info) and |(info) can be used to redirect the output.

Quick Tests

Before generating large files, it is helpful to do some quick tests on small sets of characters, compare how different fonts turn out, and tweak parameters. The following command facilitate this process with side-by-side visualization of computer vision results.

python char2stroke.py test path/to/font1.ttf path/to/font2.ttf ...

Optional arguments:

  --corpus [CORPUS]
  --height [HEIGHT]
  --ngradient [NGRADIENT]
  --nsample [NSAMPLE]
  --strw [STRW]
  --width [WIDTH]
  • corpus: string to test on. Default is the text of Thousand Character Classic.
  • nsample: number of characters to be randomly picked from the corpus. Default is 8.
  • The other arguments are identical to those of build mode.

Generate Hershey Font from Stroke File

The following command generates a Hershey font from a stroke file produced in the previous step.

python tohershey.py path/to/input.json > path/to/output.hf.txt

Example

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].