Importing Kerning

hrant's picture

I have a hand-made kerning list consisting of pairs of characters, one pair per line (in WordPad). The characters are the actual Windows codes, not descriptives like "left square bracket", and the pairs are not separated by anything. I know FontLab can import AFM files, but I want to avoid converting my "raw" data to AFM before import. Help?

hhp

eomine's picture

> I want to avoid converting my "raw" data to AFM before import.

Is there a reason?

twardoch's picture

What do you mean by "raw Windows codes"? If you open your file in WordPad, can you see the rendered glyphs or some decimal values?

Are there only paired glyphs, or are there kerning values as well?

And then, if you choose File / Save As, which format do you choose? Text Document or Unicode Text Document?

Look at the K1.TXT file in the Kerning folder of your FontLab. Is this something you mean? If so, just put some name in the first line of the file and save it in this folder as K4.TXT (Text Document).

Adam

hrant's picture

Eduardo, there's too many pairs to do it by hand, especially since most of the characters are upper-ASCII, so they need to be "translated". I'm thinking of doing it all using Word macros though.

Adam:
- They're the actual characters, not codes or names.
- Since this is for a bitmap font, the kern values are almost all +125 or -125, and the list has been separated into +/- groups. Some very few pairs are double that, but those I can do by hand.
- Right now it's in WordPad RTF.
- I'll look at the K1.TXT file structure - thanks.

hhp

eomine's picture

> most of the characters are upper-ASCII, so they
> need to be "translated". I'm thinking of doing it
> all using Word macros though.

Or you can use the Find/Replace command, it'll take you less than 5 minutes! : )

John Hudson's picture

I'm thinking of doing it all using Word macros though.

This is what I have done in the past to convert from characters to glyph names. It doesn't take too long, and once you have the macros it is easy to repeat the process for other lists or sample strings.

hrant's picture

> K1.TXT

This looks like what I have, although I also see some names in K3.TXT (like "dotlessi"). The thing is, it looks like a "sample text" thing, since it doesn't have actual kerning values in there. But if I can assign the same kerning value (+/- 125) in FontLab to long lists of such value-less pairs en masse, then I'm set. Is there a way to do this?

> Word macros

In case I have to do this instead after all:
Where's the list of (Adobe?) character names again?

hhp

John Hudson's picture

The Adobe Glyph List is here. Note that this is version 2.0, which contains additional recognised names from multiple sources. Personally, I found the earlier version more useful for font development, as with few exceptions there was only one 'correct' name per Unicode character. General Adobe glyph naming rules are here.

The easiest way to get your kerning data into FontLab is probably to replace character pairs with spaced glyph name pairs in your list, append 'KPX ' before each one, paste them into a AFM and import them into FontLab. Note that the count of kern pairs at the beginning of that section of the AFM should equal or exceed the actual number, otherwise the list may be truncated during import.

hrant's picture

Thanks!

> append 'KPX ' before each one

As well as append the kerning value after each pair.

hhp

John Hudson's picture

As well as append the kerning value after each pair.

As the great man said: Well, duh!

hrant's picture

BTW, I've started writing that macro, and will make it available here when finished.
Although I fear you'll have to set your Security to "Low" to run it... :-)

hhp

hrant's picture

So the Word macro -a quick & dirty brute force affair- is here:
http://www.themicrofoundry.com/other/namesubber.rtf

All it does is convert non-alphabetic characters (except the space and non-breaking space) in the Windows:Western codepage to their Adobe names. So in my case I still had to do some manual processing:
1) Separate the pairs with a space. Which I actually did by hacking the macro: I put a space before each Adobe name, but then also had to find/replace all 52 alphabetic characters with space+character (which could be put in the macro as well though). This left me with a prefix space per line.
2) Put the "KPX" prefix per line (no space since I got a prefix space from #1). This I did by typing in a Tab at the head of each line* (Shoutcast's Goa channel helped) then doing a find/replace: Tab -> "KPX".
3) Put the kerning amounts (which were 99% either " +125" or " -125"). Using the same Tab trick. Tab is safe because nobody makes kerns with it... I assume!

* Note that leading Tabs are messed up by Word (it turns them into "ruler tabs"), so I used WordPad.

If I could get the macro to process linefeeds (which I couldn't) then I could get rid of manual processing entirely.

And after that you cannibalize any old AFM file (that has at least one kern defined) to get FontLab to read it in.

--

A question:
That Adobe name list has multiple names per codepoint for some characters. Like periodcentered/middot for 00B7 and overscore/macron for 00AF. Do you just choose any of the names?

hhp

John Hudson's picture

That Adobe name list has multiple names per codepoint for some characters. Like periodcentered/middot for 00B7 and overscore/macron for 00AF. Do you just choose any of the names?

This is a novelty of version 2.0 of the AGL. Previous versions had only Adobe's own glyph names, but version 2.0 includes names that have been used by other major developers, e.g. Apple, which Adobe software using AGL 2.0 will recognise. It is important to remember that the AGL does not primarily exist for the purpose of font developers, but for software developers who need to parse glyph names to obtain character codes.

So yes, you can choose any of the names in the AGL, but for maximum exchangeability with other font developers I recommend using Adobe's original names from the previous AGL versions. Here is one of the Tiro resource files which you and others might find useful: a FontLab .nam file that covers all the Basic Multilingual Place assignments for Unicode 4.0. Unzip and open the .nam in a text editor and read the lengthy comments at the top to understand what the file contains.


application/x-zip-compressedTiro AGL name mapping
tiro_Unicode4.0_BMP_withAFII.zip (175.4 k)



If you drop this .nam file in your FontLab /Mapping folder, you can use it with the Generate Unicode and Generate Names functions in FL. When the new Tiro website goes online, we plan to have a resource download section from which this and other useful FL files will be available, including a .nam that uses a much more extensive list of human-friendly production glyph names.

hrant's picture

Cool - thanks.

--

BTW, I wrote:
> you cannibalize any old AFM file

It turns out you need to make sure the source AFM file has a metrics entry for any character you're kerning: kern pairs for characters undefined in the "StartCharMetrics" section are ignored. The complication is that the names declared in AFM files output by FontLab don't always match the Adobe stuff, or maybe it's that they only [can] match one of the choices. Like if you declare a pair "L middot" (useful in Catalan) it won't show up because the metrics definition (assuming it was output from FontLab) uses "periodcentered" instead. And some stuff (like the superior numerals) are represented by Unicode numbers in the metrics section instead of names...

So it looks like my macro needs revision (to match FontLab).
Or I guess one could use an AFM file with names that match the ones in the macro.

hhp

John Hudson's picture

The easiest thing to do is open your own font in FontLab, save out an AFM with one dummy kerning pair, and then use that AFM as your kerning import source.

hrant's picture

Right, but the thing to watch out for is that the character names in the kerning pairs have to match the ones in the metrics section of the AFM file. That might seem obvious, but it gets complicated when you consider that the Adobe list shows multiple names per codepoint (like any kern using "middot" instead of "periodcentered" won't be recognized upon [re]import). So basically you can/should just use the names in the AFM file that FontLab outputs - you don't need the Adobe list (in this case).

--

I've found 7 wrong names and one typo in my macro - I'll provide an updated version soon.

hhp

hrant's picture

I'm dumb.
M

John Hudson's picture

...it gets complicated when you consider that the Adobe list shows multiple names per codepoint...

That's why previous versions of the AGL were better suited to new font development. If you refer to the .nam file I uploaded, that contains the Adobe's own names from earlier AGL.

hrant's picture

In case anybody's interested, I've updated the macro with a typo fix and 7 cases where FontLab wants character names a certain way. Same link.

hhp

twardoch's picture

John,

you're talking all the time about some "previous versions of the AGL", completely ignoring the fact that Adobe publish *two* AGLs. When was the last time you checked:
http://partners.adobe.com/asn/tech/type/unicodegn.jsp
?

Especially, the section 6 dedicated to glyph naming in new fonts?

Adam

hrant's picture

BTW, there's a bug in my macro: it confounds the four curly quotes with their straight versions - Im not sure why. But it might be a Word problem (as opposed to an algorithm problem), so it might be better to fix those by hand.

hhp

John Hudson's picture

Adam, thanks for pointing that out. I'd assumed that when Adobe published the new AGL it was a replacement, not an addition. I shouldn't be surprised: this is after all the same company that uses the name CoolType for two different technologies!

Marten Thavenius's picture

While checking out the different AGL's, I saw that the AGL "for new fonts" seems to be corrupt.

All the entries from "0077;w;LATIN SMALL LETTER W" to the end of the list are repeated:

http://partners.adobe.com/asn/tech/type/aglfn13.txt

/m

Thomas Phinney's picture

Marten,

I'm not seeing that at all. Perhaps it was a browser glitch?

Maybe somebody else can say if they're having the same problem, or not.

T

Marten Thavenius's picture

Hmm, I'm tired, but the last 20 lines at the bottom of the list looks pretty much the same as the 20 lines before those. That is, the range from w-z is repeated twice.

/m

hrant's picture

I'm seeing it too. And it's just a text file, so I don't think a browser could mess up like that. The good news is that it doesn't matter I guess, since duplicates are superfluous.

hhp

hrant's picture

> there's a bug in my macro

Fortunately the fix was easy: since the code proceeds sequentially, simply moving the two segments that process the straight single and double quotes to after the segments that process the curly stuff does the trick.

So one more update - same link:
http://www.themicrofoundry.com/other/namesubber.rtf

hhp

Syndicate content Syndicate content