Skip to main content

[JAVA2D] Fonts from AFM Files

4 replies [Last post]
Anonymous

I have at best a limited understanding of font technology, but...
Given an AFM file, is there a way to construct a corresponding
java.awt.Font?

Thanks,
Aaron

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Phil Race

Aaron Mulder wrote:
> Okay, so far so good. Can you take an existing font in the system
> and adjust it based on the AFM metrics? For instance, if my AFM file is
> for "Times" and my system has some close but perhaps not exact match,
> could I just massage the existing font so the metrics match?

Not addressing the specifics of AFM's but rather trying to keep
within the bounds of the 2D APIs I have a suggestion

You could create 2 GlyphVectors's: one from the font that you want
for the glyphs, one for the font that you want the metrics.

you then assign the positions of the latter to the former and
then draw it.

The details of this are left as an exercise for the reader but
one caution is that this doesn't do full text layout.
ie directly creating a glyphvector doesn't get you corectly
re-ordered and glyph substituted arabic, but should work
just fine for Latin scripts.

>
> Also, Font.createFont says that it only supports TrueType fonts,
> but you mention that Java supports Type 1 too -- how would I load a Type 1
> font?

JDK reads Type1 fonts from the same locations as other fonts.
Eg drop it into jre/lib/fonts or \windows\fonts

1.5 however does now support Type1 with createFont.

http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html#createFont

>
> And heck, if you'll bear with me for one more, what's the
> difference between TTF and TTC or PFA and PFB?

TTC is a "collection" of TTF fonts.

PF = Postscript Font "A" = ascii."B=" binary

its just the way the font is stored

Go check out adobe's website

-phil.
>
> Thanks,
> Aaron
>
> On Fri, 28 May 2004, Igor Nekrestyanov wrote:
>
>>Hello Aaron,
>>
>>Afm stands for Adobe Font Metrics. The afm file is a text file
>>that lists the postscript metrics of each character in the font in a
>>readable manner.
>>
>>Because afm file per se does not contain enough information to
>>render glyphs there is no way to create java.awt.Font from afm file.
>>
>>At the moment java supports TrueType fonts (ttf/ttc files) or Type1 fonts
>>(pfa/pfb files) only.
>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Igor Nekrestyanov

Hello Aaron,

Afm stands for Adobe Font Metrics. The afm file is a text file
that lists the postscript metrics of each character in the font in a
readable manner.

Because afm file per se does not contain enough information to
render glyphs there is no way to create java.awt.Font from afm file.

At the moment java supports TrueType fonts (ttf/ttc files) or Type1 fonts
(pfa/pfb files) only.

-igor

On Fri, 28 May 2004, Aaron Mulder wrote:

> I have at best a limited understanding of font technology, but...
> Given an AFM file, is there a way to construct a corresponding
> java.awt.Font?
>
> Thanks,
> Aaron
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Aaron Mulder

Okay, so far so good. Can you take an existing font in the system
and adjust it based on the AFM metrics? For instance, if my AFM file is
for "Times" and my system has some close but perhaps not exact match,
could I just massage the existing font so the metrics match?

Also, Font.createFont says that it only supports TrueType fonts,
but you mention that Java supports Type 1 too -- how would I load a Type 1
font?

And heck, if you'll bear with me for one more, what's the
difference between TTF and TTC or PFA and PFB?

Thanks,
Aaron

On Fri, 28 May 2004, Igor Nekrestyanov wrote:
> Hello Aaron,
>
> Afm stands for Adobe Font Metrics. The afm file is a text file
> that lists the postscript metrics of each character in the font in a
> readable manner.
>
> Because afm file per se does not contain enough information to
> render glyphs there is no way to create java.awt.Font from afm file.
>
> At the moment java supports TrueType fonts (ttf/ttc files) or Type1 fonts
> (pfa/pfb files) only.

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Igor Nekrestyanov

On Fri, 28 May 2004, Aaron Mulder wrote:

> Okay, so far so good. Can you take an existing font in the system
> and adjust it based on the AFM metrics? For instance, if my AFM file is
> for "Times" and my system has some close but perhaps not exact match,
> could I just massage the existing font so the metrics match?

No, at the moment java has no support for AFM files.

> Also, Font.createFont says that it only supports TrueType fonts,
> but you mention that Java supports Type 1 too -- how would I load a Type 1
> font?

JDK1.5 adds support for Type 1 fonts in Font.createFont.
(Have a look at beta release at java.sun.com)

In previous versions of jdk public API provides only possibility to
request installed type 1 font by family name.

> And heck, if you'll bear with me for one more, what's the
> difference between TTF and TTC or PFA and PFB?

TTC - is collection of TrueType fonts

PFA and PFB are just different representations of Type 1 fonts.
(Ascii and binary. Ascii is platform independent one.)

-igor

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".