Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pack all available glyphs in font? #86

Open
jakerdy opened this issue Mar 11, 2023 · 2 comments
Open

How to pack all available glyphs in font? #86

jakerdy opened this issue Mar 11, 2023 · 2 comments
Labels

Comments

@jakerdy
Copy link

jakerdy commented Mar 11, 2023

Hi, it will be great if there is a way to extract all glyphs defined in font.
Using original msdf-atlas-gen you could specify charset via ranges, like

[0x00, 0xFFFF]

An you get all glyphs from this range (if they are present) packed.
But it seems there is no way to do in using msdf-bmfont.

@soimy soimy added the Feature label Mar 11, 2023
@soimy
Copy link
Owner

soimy commented Mar 11, 2023

Range is currently not possible via charset option, sorry. You have to find a way to generate all the character string by yourself.

@jakerdy
Copy link
Author

jakerdy commented Mar 12, 2023

Okay.

After googling some time, i find here one cool and automatic way to do this.
Works on linux (which is not perfect but vm is enuogh), and maybe somewhere else, where you have utility fc-query.

You should create bash script (lets call it fdump.sh):

#!/bin/bash -

Usage() { echo "$0 FontFile"; exit 1; }
SayError() { local error=$1; shift; echo "$0: $@"; exit "$error"; }

[ "$#" -ne 1 ] && Usage

width=70
fontfile="$1"

[ -f "$fontfile" ] || SayError 4 'File not found'

list=$(fc-query --format='%{charset}\n' "$fontfile")

for    range in $list
do     IFS=- read start end <<<"$range"
       if    [ "$end" ]
       then
             start=$((16#$start))
         end=$((16#$end))
         for((i=start;i<=end;i++)); do
         printf -v char '\\U%x' "$i"
         printf '%b' "$char"
         done
       else
         printf '%b' "\\U$start"
       fi
done | grep -oP '.{'"$width"'}'

Don't forget to make in executable: chmod +x fdump.sh

And run in on your font:

./fdump.sh MyFont.ttf > MyFont_charset.txt

As a result you will get file with all defined glyphs in your font:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants