Paul Pedriana a écrit :
I'm trying to understand how kerning is done in RTL text and can't
find any documentation (on the Internet nor in Freetype) that
addresses this.
Questions:
- Do kerning pairs in RTL refer to two sequential glyphs in logical
order or visual order?
At least for TrueType and Type 1 fonts, it only refers to visual order.
Nelson just wrote
something about TeX which apparently follows the opposite convention,
but I can guarantee
you that it is not followed by other industry-standard formats.
- If there is a string with the logical order is CAT and a visual
order of TAC,
do kerning adjustment pairings apply for CA (logical order) or
for AC (visual order)?
you'll need to apply the kernings for (T,A) then (A,C)
- Given that the RTL layout alrogithm
(http://freetype.sourceforge.net/freetype2/docs/glyphs/glyphs-5.html)
specifies that advance width of C (from our CAT above) is applied
before the positioning
and drawing of C, how and when and in what way is a kerning
adjustment applied?
if you write text left-to-right, independent of its logical order, you're
going to do the following:
prev = -1;
xpos = 0;
for ( n=0; n < num_visual_glyphs; n++ )
{
gindex = visual_glyphs[n].index;
if ( prev > 0 )
xpos += kerning( prev, gindex );
drawGlyph( gindex, xpos );
xpos += visual_glyphs[n].advance;
prev = gindex;
}
when writing right-to-left text, you can do the following, which results
in the same glyph positions, justified to the right:
prev = -1;
xpos = width;
for ( n=num_visual_glyphs-1; n >= 0; n-- )
{
gindex = visual_glyphs[n].index;
xpos -= visual_glyphs[n].advance;
if ( prev > 0 )
xpos -= kerning( gindex, prev );
drawGlyph( gindex, xpos );
prev = gindex;
}
to better understand why, here's an example with two glyphs,
named 'L' (for left) and 'R' (for right):
left-to-right text:
L.x = 0
R.x = L.advance + kerning(L,R)
xpos.final = L.advance + R.advance + kerning(L,R)
xpos.final - xpos.start = L.advance + R.advance + kerning(L,R)
right-to-left text:
R.x = width - R.advance
L.x = width - R.advance - L.advance - kerning(L,R)
xpos.final = L.x
xpos.final - xpos.start = -(L.advance + R.advance + kerning(L,R))
L.x - xpos.final = 0
R.x - xpos.final = L.advance + kerning(L,R)
Hope this helps,
- David