Need help to batch create pfm files via pf2afm

Avi Greenbury lists at avi.co
Fri Jul 29 21:18:49 UTC 2011


NoOp wrote:

> I've a large amount of licensed postscript fonts that I'd like to use
> in OpenOffice/LO. I have both the .pfb and .pfm files in the same
> folder and can generate the .afm file via:
> 
> $ pf2afm <fontfilename>
> 
> Unfortunately that will get old real fast with 400 font files. How
> would I go about using pf2afm to batch convert all 400 in one go?
> 
> Note: Abiword only needs the .pfb, but OOo/LO require the .afm.
> 
> 

It's not clear quite which you'd like, but if it's for every file in
the directory, then in a bash prompt in the directory in question:

for file in *; do pf2afm $file; done

Which is a one-line form of this:

for file in *; do
	pf2afm $file
done

Which causes bash to expand the asterisk to match every file name, and
iterate through them, passing each in turn (as the variable '$file') to
pf2afm. 

The general syntax is

for [variable name] in [list]; do
	something
done

And the newlines can be replaced with semi-colons. The [variable name]
is the definition of it - that's where you decide what you can refer to
the current list element with during the loop, and the 'list' can be
anything that produces a space- or newline-separated list.

So you could go restrict it to file of a particular extension:

for file in *.pfb

Or replace the asterisk with a way of getting just the part of the
filename before the extension if that's actually what you like:

for file in $(ls | awk -F. '{print $1}'); do

Where you run ls and pipe it through to awk, which splits each line on
periods (the argument to -F) and then prints the first element. You'd
then need to reappend whichever extension you need in the loop:

for file in $(ls | awk -F. '{print $1}'); do
	pf2afm $file.pfm
done

I don't know the first thing about fonts, so I'm not sure which is
what you'd like :)

-- 
Avi




More information about the ubuntu-users mailing list