Reverse-engineering anchors

Grzegorz Rolek's picture

I have a font with all the diacritical Latin flattened, that is, precomposed and decomposed with no trace of anchors whatsoever. I would want to reverse-engineer placement of anchors if there indeed were any or other effectively same preplanning. Now, doing this somewhat intuitively and matching it all by trial and error is obviously insane. Do you guys know any step-by-step algorithm that would make such a task a finite one or at least determine there was no approximate anchoring in the first place?

hrant's picture

I imagine the best way would be to write a Python script that
would take measurements and figure out the original numbers.

hhp

Bendy's picture

I don't think there'd be a way to figure out where the original anchors were, because anchors positions are arbitrary in relation to the glyphs as long as they match up between the base glyph and the mark.

If you're planning to create more composite glyphs you wouldn't necessarily need to have details of the original anchors though. I'm not sure what your aim is.

Grzegorz Rolek's picture

Well, I just want to play with it as a font of only Unicode-based diacritical combining. It’s not for any historical record, so it doesn’t matter if my anchors would reflect the original ones as long as diacritics placement would be the same. Ironically, this arbitrariness in character to diacritic anchor matching is exactly what I was afraid of and what is the trickiest part of the task. Anyway, some utility that would somehow heuristically figure out such anchoring or even its approximation would be quite useful, I think, at least for modernizing old fonts. I’ll give it some more thought.

hrant's picture

Ben, I guess I didn't mean "original" (which does indeed seem
impossible) I meant an "extraction" that would reproduce the
same results (which is entirely possible, although it requires
programming). Speaking of which: no heuristics necessary,
it would "just" be an algorithm.

hhp

Michel Boyer's picture

Let us assume that like in the Adobe example @TOP_MARKS of Mark-to-Base attachment positioning, we have the base letters a, e, o, u and the diacritics acute, grave, dieresis, umlaut. Then it is true that to get the glyph for aacute all you need to do is to match the basis anchor for the a and the anchor for the acute, and you can decide arbitrarily to put either anchor wherever you want. For instance you can put the base anchor for a at (0,0). However, when you have done that arbitrary choice, all the other anchor positions are fixed; indeed, there is then only one position for the anchors of acute, grave, dieresis, umlaut that will give the right looking glyph for aacute, agrave, adieresis, aumlaut when matching with the anchor for the a at (0,0), and then there is also only one possible position for the base anchor on e, o and u that will match any of the anchors on the diacritics. The choice is thus unique up to a translation of all anchor pairs (you can add the same number to all x values, and the same other number to all y values of the anchor positions).

In terms of programming, you can initialize one of the anchors to whatever pair you want, and then run some algorithm. Now, I don't know what tools are available, I will just try to illustrate with one tool I use, namely FontForge. Here is a small script that takes as input a fontfile and a list of glyphnames and outputs their foreground; I called it dmpfrgrnd.

#!/usr/bin/env python

import sys, fontforge
fnt=fontforge.open(sys.argv[1],1)
for gl in sys.argv[2:]:
  print gl, fnt[gl].foreground

If I call
dmpfrgrnd MyriadPro-Regular.otf dotlessi iacute acute
I get the following output (with one point per line however)

dotlessi <Layer(cubic)
 <Contour (161,0) on (73,0) on (73,484) on (161,484) on >
>
iacute <Layer(cubic)
 <Contour (155,693) on (252,693) on (130,550) on (67,550) on >
 <Contour (161,0) on (73,0) on (73,484) on (161,484) on >
>
acute <Layer(cubic)
 <Contour (189,693) on (286,693) on (164,550) on (101,550) on >
>

Here it is easy to see that the iacute is obtained by "pasting" the acute on top of the dotlessi and moving it (-34,0). As a consequence if the anchor for the dotelessi is at say (10,0) then the anchor for the acute needs to be at (44,0). The problem in this particular example is matching the countours. For some fonts, the contours for the diacritics are listed first, some other fonts last. Once you have matched the contours, it is easy to get the displacement.

I don't know how far one can go with that. During my vacations, I generated an AAT font using anchors. Once I was done, I happily moved some diacritics to where they seemed to look better. I don't see why professionals (I am not one) would not do the same.

Michel Boyer's picture

Once you have matched the contours, it is easy to get the displacement.

I should have said "Once you have matched the contours, you have the displacement". Indeed, matching the contours means finding (dx,dy) such that the contours corresponding to the diacritic in the precomposed glyph are obtained by adding (dx,dy) to all pairs in the contours of the glyph for the diacritic: (dx,dy) is the displacement.

Grzegorz Rolek's picture

Everything you’ve said is of course right, Michel. Thanks for making it so explicit, this indeed clarified my thoughts a bit. I even ran quickly all those calculations by hand sketching out the deltas in a matrix for both vowels and diacritics and… well, there was no consistency for any given anchor pair I tried. Must have been no anchors and no luck for me.

Syndicate content Syndicate content