Skip to content

borj404/densort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

densort

Sorts characters by pixel density.

Characters have different "visual weight" when rendered. This program measures the exact pixel density of each character in a given font and outputs them sorted from darkest to lightest (or vice versa).

Requirements

pip install Pillow fonttools

Usage

# Table output (default: dense to sparse)
python3 densort.py -f "DejaVu Sans Mono" -i chars.txt

# C-style bitmap arrays (8x8 and 16x16)
python3 densort.py -f "Comic Sans MS" -i chars.txt -b

# Ascending order (sparse to dense)
python3 densort.py -f "Monaco" -i chars.txt -o asc

# Direct font path
python3 densort.py -f /path/to/font.ttf -i chars.txt

# Adjust font ratio for taller or wider characters (thai, arabic, etc)
python3 densort.py -f "Noto Sans Thai" -i chars.txt -b -r 0.8

Input

A text file containing characters to analyze, for example Paul Bourke's character ramp for grayscale:

$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^`'. 

Output

Table mode: Density values and Unicode codepoints for each character, and a ready-to-use density ramp string.

Bitmap mode: C-style arrays with 8x8 and 16x16 pixel representations of each character.

License

WTFPL

About

Sort characters by pixel density for any font

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages