# Accessing side-bearings in LuaTeX

This question has been solved, in XeTeX, by this code:

\def\kright#1{\leavevmode #1\kern-\XeTeXglyphbounds3 \the\XeTeXcharglyph#1 }
\def\kleft#1{\leavevmode \kern-\XeTeXglyphbounds1 \the\XeTeXcharglyph#1 #1}


which allows me to align text more precisely to the ink by accessing the side-bearing measurements (\XeTeXglyphbounds1 and 3).

This XeTeX dependency is currently the only thing stopping me from moving to LuaTeX (mainly for microtype). Is an equivalent function available in LuaTeX, or planned?

After reading a bit more on microtype, could the equivalent effect be achieved by an appropriately-tailored set of character protrusions? That way, my move to LuaTeX might be a lot simpler.

-

Yes and no. When you load the font via the built-in fontloader library (which is very low level), you can access all the information of the font file. This includes the bounding box, as far as I can see (look at the section 4.4.5.1.2 "Glyph items" in the LuaTeX reference manual).

But normally you load the fonts via the fontspec / luaotfload packages, which discard that information and only keep what is needed for TeX.

I doubt that inclusion of that information is planned in the luaotfload package, which is based on ConTeXt's font loader.

-
Thanks, Patrick. A couple of supplementaries: (1) it looks rather "overloaded" for what I want to do; (2) I'm definitely a fontspec person; and (3) it only has data for left side-bearings, and then "only if nonzero and not equal to bounding box", which leads me to equate the bounding box with the TeX character box, which is definitely what I don't want -- I need to get close to the actual ink. – Brent.Longborough Feb 23 '12 at 19:06
@Brent.Longborough The bounding box should be the real "tight" box. It is calculated from the actual outlines of the fonts if the font does not contain the bbox info. – dıʞsdoʇ Feb 23 '12 at 20:08
I'm sure the bounding box is kept, but you may be looking at the wrong place (too late now, I'll try to find a definite answer in the morning if there wasn’t one by then). – Khaled Hosny Feb 23 '12 at 21:40
@Brent.Longborough: the side bearings can be seen as the differences between glyphs bounding box and the box TeX sees. – Khaled Hosny Feb 23 '12 at 21:42
Sorry for not providing an answer as promised, but you can get the bounding box from fonts.identifiers[id].shared.otfdata.descriptions[gid].boundingbox where id is the font number and gid is glyph id. – Khaled Hosny Feb 26 '12 at 23:30