You are not logged in.

#1 2020-05-04 18:28:01

bricem13
Member
Registered: 2011-02-02
Posts: 42

Automatic font listing and visualization

Hi guys

I am looking for selecting some fonts I could use under qcad (or any other cad software).

The first step I would like is to have all font listed and, ie under LIbreoffice document, an example of each font "abcdefghijklmnopqrstuvbwxyz 123456789 + name of the font" written in the font such that I could visualize.

the next step, that I found over the web would be: libreoffice ==> pdf ==> inkscape ==> dxf

I looked at programs like gnome-font-view or waterfall but nothing that can list all the fonts installed on the computer.


Any hint?

thank you in advance
Brice

Offline

#2 2020-05-04 18:45:22

seth
Member
Registered: 2012-09-03
Posts: 64,435

Offline

#3 2020-05-04 19:12:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,367
Website

Re: Automatic font listing and visualization

I was just working on a script using fc-list as well, but I was using the output to create a latex document which would print samples of all fonts on the system.  But I ran into so many corner cases that resulted in failure that I realized that either they weren't corners, or I was in a octacismyrihedron (80,000 sided shape).  So I gave up on it.

The imagemagic approach seems much better, but it doesn't seem to recognize *any* fonts on my system:

$ convert -background transparent -fill blue -font Terminus -pointsize 48 label:Test test.png
convert: unable to read font `Terminus' @ warning/annotate.c/RenderType/960.

I get the same error for countless other fonts and generic patterns including Serif and serif (as well as Candice in case it was some builtin imagemagick font).

EDIT: -family instead of -font appears to work, EDIT 2: nope, not reliably at all.  It failed on Terminus which fc-list provides.  More failing corners.  After testing 88 family names from fc-list, only 22 of them were accepted by imagemagic's 'convert', all the others failed.  I have not checked the images to see how many of those 22 actually appear to resemble the font versus some fallback - I just checked the images, many of them looked like a fallback font.  I confirmed with md5sums: there were only 7 unique images created.  So 7 out of 88 isn't good (well, probably 6 actual correct results and one fallback font).

Seth, do you have a way for this to actually do something useful?

Last edited by Trilby (2020-05-04 19:28:30)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2020-05-04 19:27:10

seth
Member
Registered: 2012-09-03
Posts: 64,435

Re: Automatic font listing and visualization

Doesn't seem to work for bitmap fonts (otb) and also pcf :-(
("Terminus TTF" works and using -family will resolve the font file, but fails on a different position in RenderFreetype")

Probably the same issue you were facing before.

Offline

#5 2020-05-04 19:40:01

bricem13
Member
Registered: 2011-02-02
Posts: 42

Re: Automatic font listing and visualization

wahooo guys, you pushed me wink but that's good

for i in $(convert -list font | grep Font | cut -d':' -f2); do convert -font $i -pointsize 72 label:123456789 $i.gif;done

with that in a folder I can get a gif for each font containing what I was mainly looking for: numbers

Now I still have to mod the script to get all in one file and add the font name in the label.

BR

Offline

#6 2020-05-04 19:47:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,367
Website

Re: Automatic font listing and visualization

convert -list font

*headdesk* yup, that's what we needed!  It seems imagemagick uses hyphens in place of spaces which is covers most of the previously failing cases.

Note that you can put newlines in the "label" which could include the font name, e.g.,:

convert -list font | sed -n 's/ *Font: //p' | while read font; do
        convert -background transparent -fill blue -font "$font" -pointsize 72 "label:$font\nABCDEFG\n123456789" "$font.png"
done

From there, another imagemagic command could tile all those individual images into one large one ... you'd have some choices on layout: do you want a large number of images all stacked vertically for scrolling, or do you want a more tiled / grid layout?

How would a web page preview work:

cat <<'EOF'
<!DOCTYPE html>
<html>
<head>
<style>
img { width: 15rem; hieght: auto; object-fit: contain; margin: 1rem; }
</style>
</head>
<body>
EOF

convert -list font | sed -n 's/ *Font: //p' | while read font; do
        convert -background transparent -fill blue -font "$font" -pointsize 72 "label:$font\nABCDEFG\n123456789" "$font.png"
        echo '<img src="'$font.png'">'
done

cat <<'EOF'
</body>
</html>
EOF

This generates the files and html (on stdout) that will present them all together.

Last edited by Trilby (2020-05-04 19:52:45)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2020-05-04 19:51:52

bricem13
Member
Registered: 2011-02-02
Posts: 42

Re: Automatic font listing and visualization

for i in $(convert -list font | grep Font | cut -d':' -f2); do convert -font $i -pointsize 72 label:123456789_abcdefghijklmnopqrstuvwxyz_"$i" $i.gif;done

coming closer...

Offline

#8 2020-05-04 19:54:12

bricem13
Member
Registered: 2011-02-02
Posts: 42

Re: Automatic font listing and visualization

@Trilby: I missed your post

vertical stack would be OK for scrolling!

Offline

#9 2020-05-04 20:57:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,367
Website

Re: Automatic font listing and visualization

How about this:

#!/bin/sh

tmp=$(mktemp -d fonts.XXXXXX)

printf '\033[32;1m=>\033[0;1m Processing fonts\033[0m\n'
convert -list font | sed -n 's/ *Font: //p' | while read font; do
	printf ' \033[1m-> \033[0m%s\n' "$font"
	convert -font "$font" -pointsize 72 "label:$font\n123456789\nabcdefghijklmnopqrstuvwxyz\n" "$tmp/$font.png"
done

printf '\033[32;1m=>\033[0;1m Creating single image\033[0m\n'
convert -append $tmp/*.png allfonts.png

printf '\033[32;1m=>\033[0;1m Cleaning temp files\033[0m\n'
rm -rf $tmp

EDIT: it creates a file "allfonts.png" in the current directory.

Last edited by Trilby (2020-05-04 20:57:49)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#10 2020-05-05 18:03:01

bricem13
Member
Registered: 2011-02-02
Posts: 42

Re: Automatic font listing and visualization

[brice@TuxBox:fonts]$ mkdir tmp
[brice@TuxBox:fonts]$ mv *.gif tmp/
[brice@TuxBox:fonts]$ convert -append tmp/*.gif allfonts.gif
Aborted (core dumped)
[brice@TuxBox:fonts]$ 

Offline

Board footer

Powered by FluxBB