Discussion:
small command line app to dump font name from ttf/otf file?
David C. Rankin
2014-02-07 23:14:58 UTC
Permalink
Guys,

I am working with fonts and need a small app to get the 'font name' from a
font file (ttf/otf). Something that would work like:

$ someapp --opt=name somefontfile.ttf
RealFontFile_name

Is there a small command line app that will read a font file and dump the name
of the font? I've looked at texlive-bin: 'ttfdump -t name font.ttf' and others
that dump the various 'tables' within the ttf or otf file, but there is no rhyme
or reason to which subtable/etc... the name is in.

If not an app, then is there a font library that provides a function that does
this that could be included in a quick app.c to do it?

Thanks for any info. I've never messed with the nuts and bolts of font files
before, so I don't speak font fluently :)
--
David C. Rankin, J.D.,P.E.
--
To unsubscribe, e-mail: opensuse+***@opensuse.org
To contact the owner, e-mail: opensuse+***@opensuse.org
Martin Helm
2014-02-07 23:36:29 UTC
Permalink
Maybe there is already a command line tool which I do not know, but it
is easy to make your own.
Download the short python code from
http://www.starrhorne.com/2012/01/18/how-to-extract-font-names-from-ttf-files-using-python-and-our-old-friend-the-command-line.html
and install the package fonttools with yast/zypper.
I tested that it extracts the name from ttf as well as otf.
--
To unsubscribe, e-mail: opensuse+***@opensuse.org
To contact the owner, e-mail: opensuse+***@opensuse.org
Malcolm
2014-02-07 23:45:01 UTC
Permalink
Post by Martin Helm
Maybe there is already a command line tool which I do not know, but it
is easy to make your own.
Download the short python code from
http://www.starrhorne.com/2012/01/18/how-to-extract-font-names-from-ttf-files-using-python-and-our-old-friend-the-command-line.html
and install the package fonttools with yast/zypper.
I tested that it extracts the name from ttf as well as otf.
Hi
There is always fc-cat?

fc-cat |cut -f1 -d"="
--
Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
openSUSE 13.1 (Bottle) (x86_64) GNOME 3.10.2 Kernel 3.11.10-7-desktop
up 9:47, 4 users, load average: 0.38, 0.23, 0.17
CPU Intel® ***@1.9GHz | GPU Intel® Sandybridge Mobile
--
To unsubscribe, e-mail: opensuse+***@opensuse.org
To contact the owner, e-mail: opensuse+***@opensuse.org
Martin Helm
2014-02-07 23:53:09 UTC
Permalink
Post by Malcolm
Post by Martin Helm
Maybe there is already a command line tool which I do not know, but it
is easy to make your own.
Download the short python code from
http://www.starrhorne.com/2012/01/18/how-to-extract-font-names-from-ttf-files-using-python-and-our-old-friend-the-command-line.html
and install the package fonttools with yast/zypper.
I tested that it extracts the name from ttf as well as otf.
Hi
There is always fc-cat?
fc-cat |cut -f1 -d"="
Isn't that different in that fc-cat reads the cache and not from the
otf/ttf file?
--
To unsubscribe, e-mail: opensuse+***@opensuse.org
To contact the owner, e-mail: opensuse+***@opensuse.org
David C. Rankin
2014-02-08 01:06:04 UTC
Permalink
Post by Martin Helm
Post by Malcolm
Post by Martin Helm
Maybe there is already a command line tool which I do not know, but it
is easy to make your own.
Download the short python code from
http://www.starrhorne.com/2012/01/18/how-to-extract-font-names-from-ttf-files-using-python-and-our-old-friend-the-command-line.html
and install the package fonttools with yast/zypper.
I tested that it extracts the name from ttf as well as otf.
Hi
There is always fc-cat?
fc-cat |cut -f1 -d"="
Isn't that different in that fc-cat reads the cache and not from the
otf/ttf file?
Martin, Malcolm,

Thank you both! I've also stumbled across a piece of fontforge that I think I
can cannibalize to do what I need. Check out showttf.c (builds fine with gcc -o
someexe showfft.c) in:

https://github.com/fontforge/fontforge/tree/master/contrib/fonttools

I will have to cut it down quite a bit. It dumps about 140k of data, but it
does have the following in:

struct ttfinfo {
<snip>
char *familyname; /* nameid=1 */
char *fullname; /* nameid=4 */
char *version; /* nameid=5 */
char *fontname; /* postscript font name, nameid=6 */
<snip>
}

Now all I have to do is cut away about 99% of the remaining source :)
--
David C. Rankin, J.D.,P.E.
--
To unsubscribe, e-mail: opensuse+***@opensuse.org
To contact the owner, e-mail: opensuse+***@opensuse.org
Simon
2014-02-08 02:14:11 UTC
Permalink
Post by David C. Rankin
Guys,
I am working with fonts and need a small app to get the 'font name' from a
$ someapp --opt=name somefontfile.ttf
RealFontFile_name
Is there a small command line app that will read a font file and dump the name
of the font? I've looked at texlive-bin: 'ttfdump -t name font.ttf' and others
that dump the various 'tables' within the ttf or otf file, but there is no rhyme
or reason to which subtable/etc... the name is in.
If not an app, then is there a font library that provides a function that does
this that could be included in a quick app.c to do it?
Thanks for any info. I've never messed with the nuts and bolts of font files
before, so I don't speak font fluently :)
It is quite easy to do with QFontInfo in Qt as for a specific app i am
unsure.

Simon
--
To unsubscribe, e-mail: opensuse+***@opensuse.org
To contact the owner, e-mail: opensuse+***@opensuse.org
David Haller
2014-02-08 00:38:40 UTC
Permalink
Hello,
Post by David C. Rankin
I am working with fonts and need a small app to get the 'font name' from a
==== fontname ====
#!/bin/bash
ttfinfo() {
ttf2pt1 -pft -Gf -Ouost "$1" - 2>/dev/null | \
awk '/\/FullName/ {
print gensub("/FullName.*\\(([^)]*)\\).*def", "\\1", 1, $0);
}'
}

for f; do
case "$f" in
*.[oOtT][tT][fF]) printf "%s: %s\n" "$f" "$(ttfinfo "$f")";;
esac
done
====

$ cd /usr/share/fonts/truetype
/usr/share/fonts/truetype $ fontname trebucbd.ttf cmunst.otf LnLibertine_aBL.otf
trebucbd.ttf: Trebuchet MS Bold
cmunst.otf: CMU Typewriter Text Oblique
LinLibertine_aBL.otf: Linux Libertine Slanted O Bold

ttf2pt1 available as a package of the same name. I do not know how
that works with PS-type OTFs (don't know if I have some of those), but
using the freetype backend ('-p ft') as done should work.

HTH,
-dnh
--
"Any technology, no matter how simple, is magic to those who do not
understand it." -- Florence Ambrose in Freefall
--
To unsubscribe, e-mail: opensuse+***@opensuse.org
To contact the owner, e-mail: opensuse+***@opensuse.org
David C. Rankin
2014-02-08 09:17:14 UTC
Permalink
Post by David Haller
Hello,
Post by David C. Rankin
I am working with fonts and need a small app to get the 'font name' from a
==== fontname ====
#!/bin/bash
ttfinfo() {
ttf2pt1 -pft -Gf -Ouost "$1" - 2>/dev/null | \
awk '/\/FullName/ {
print gensub("/FullName.*\\(([^)]*)\\).*def", "\\1", 1, $0);
}'
}
for f; do
case "$f" in
*.[oOtT][tT][fF]) printf "%s: %s\n" "$f" "$(ttfinfo "$f")";;
esac
done
====
$ cd /usr/share/fonts/truetype
/usr/share/fonts/truetype $ fontname trebucbd.ttf cmunst.otf LnLibertine_aBL.otf
trebucbd.ttf: Trebuchet MS Bold
cmunst.otf: CMU Typewriter Text Oblique
LinLibertine_aBL.otf: Linux Libertine Slanted O Bold
ttf2pt1 available as a package of the same name. I do not know how
that works with PS-type OTFs (don't know if I have some of those), but
using the freetype backend ('-p ft') as done should work.
HTH,
-dnh
It most certainly does... and it is a heck of a lot shorter than the patch
applied to fontforge (showttf.c), but the mod worked :-)

$ ./showttf -n consola.ttf
Consolas

It just took about 3 hours longer.... :(

But with a little more tweaking, it will work on ttc files as well:

$ ./showttf -n cambria.ttc
This is a TrueType Font Collection file (version=20000), with 2 fonts

=============================> TTC font 0
Cambria

=============================> TTC font 1
Cambria Math
--
David C. Rankin, J.D.,P.E.
David C. Rankin
2014-02-08 16:48:13 UTC
Permalink
Post by David C. Rankin
It most certainly does... and it is a heck of a lot shorter than the patch
applied to fontforge (showttf.c), but the mod worked :-)
Opps,

Bleary eyed backwards patch.. Here is a corrected version.
--
David C. Rankin, J.D.,P.E.
David Haller
2014-02-10 01:02:07 UTC
Permalink
Hello,
Post by David C. Rankin
Post by David Haller
Post by David C. Rankin
I am working with fonts and need a small app to get the 'font name' from a
==== fontname ====
[..]

I pimped that script a bit:

==== fontname ====
#!/bin/bash
ttfinfo() {
ttf2pt1 -pft -Gf -Ouost "$1" - 2>/dev/null | tr '\r' '\n' | \
awk '/\/FullName/ {
print gensub(".*/FullName.*\\(([^)]*)\\)([[:space:]]readonly)?[[:space:]]+def[[:space:]]*.*", "\\1", 1, $0);
}'
}

type1info() {
tr '\r' '\n' < "$1" | awk '/\/FullName/ {
print gensub(".*/FullName.*\\(([^)]*)\\)([[:space:]]readonly)?[[:space:]]+def[[:space:]]*.*", "\\1", 1, $0);
}'
}

bdfinfo() {
awk '
/^FACE_NAME/{
$1="";
gsub("\"","");
sub("^[[:space:]]","");
if($1) { face="[" $0 "]"; };
}
/^FONT[[:space:]]/{
split($2, name, "-");
for(i=2; i < 7; i++) {
printf("%s ", name[i]);
}
for(i=14; i <= length(name); i++) {
enc=enc "-" name[i];
}
sub("^-", "", enc);
sub("-$", "", enc);
}
END {
printf("%s %s\n", enc, face);
}' "$1"
}

for f; do
case "$f" in
*.[bB][dD][fF]) printf "%s: %s\n" "$f" "$(bdfinfo "$f")";;
*.[oOtT][tT][fF]) printf "%s: %s\n" "$f" "$(ttfinfo "$f")";;
*.[pP][fF][aAbB]) printf "%s: %s\n" "$f" "$(type1info "$f")";;
esac
done
====

/usr/share/fonts (0)$ fontname Type1/c0611bt_.pfb Type1/courb.pfa \
truetype/arialbi.ttf truetype/trebucbd.ttf truetype/trebucit.ttf \
bdf/thai24.bdf bdf/jiskan24.bdf
Type1/c0611bt_.pfb: Courier 10 Pitch Bold Italic
Type1/courb.pfa: Courier Bold
truetype/arialbi.ttf: Arial Bold Italic
truetype/trebucbd.ttf: Trebuchet MS Bold
truetype/trebucit.ttf: Trebuchet MS Italic
bdf/thai24.bdf: Misc Fixed Medium R Normal TIS620.2529-1 [Thai typewriter (24dots)]
bdf/jiskan24.bdf: JIS Fixed Medium R Normal JISX0208.1983-0

Support for pcf is a bit more difficult ... What else?
.pk: simple
.[res]gf: should simple, might not be
.mf: tricky (all but an id (shared amongst the family) is parameters,
easiest (only?) way would probably be to just run mf and parse the
resulting .gf ;)
Post by David C. Rankin
Post by David Haller
ttf2pt1 available as a package of the same name. I do not know how
that works with PS-type OTFs (don't know if I have some of those), but
using the freetype backend ('-p ft') as done should work.
It most certainly does... and it is a heck of a lot shorter than the patch
applied to fontforge (showttf.c), but the mod worked :-)
*g*
Post by David C. Rankin
$ ./showttf -n consola.ttf
Consolas
$ showttf Type1/c0611bt_.pfb truetype/trebucbd.ttf
This looks like a postscript (pfb) file, and not a truetype font.
Post by David C. Rankin
It just took about 3 hours longer.... :(
You made that patch in 3:05hrs? Nice work ;)
Post by David C. Rankin
$ ./showttf -n cambria.ttc
This is a TrueType Font Collection file (version=20000), with 2 fonts
=============================> TTC font 0
Cambria
=============================> TTC font 1
Cambria Math
Nice.

[reversed patch]

Looks ok, but the logic seems somewhat reversed too. And if you initialize

static int name_check = false

you should check for 'name_check == false' or better, just for
'name_check', i.e.:

+ if (!name_check)
printf( " Offset to font %d header: %d\n", i, info->ttcoffsets[i]);

or

+ if (name_check == false)
printf( " Offset to font %d header: %d\n", i, info->ttcoffsets[i]);

in the second chunk of your patch. Maybe 'just_name_check' would be a
more appropriate name for that variable too.

-dnh, why does that random sig remind me of systemd?
--
Software isn't released; it escapes into the wild under
cover of darkness and before anyone realises it's become
tenaciously established in the greater world, a bit like
Kudzu or Mink. -- Tanuki
--
To unsubscribe, e-mail: opensuse+***@opensuse.org
To contact the owner, e-mail: opensuse+***@opensuse.org
Loading...