So is that even a thing? I felt like it would make sense when I was testing my font using the famous Pablo Impallari's template:
The solution is pretty straightforward, but requires us to keep the list of all glyphs in the font within a class (here any
):
<b>feature </b>kern {<br> <b>lookup </b>kerning1 {<br> <b>ignore pos</b> <i>@any</i> [ f f.swsh j p y ]';<br> <b>pos </b>f' <60 0 60 0> ;<br> <b>pos </b>f.swsh' <510 0 510 0> ;<br> <b>pos </b>j' <235 0 235 0>;<br> <b>pos </b>p' <20 0 20 0>;<br> <b>pos </b>y' <25 0 25 0>;<br> } kerning1;<br> <b>lookup </b>kerning2 {<br> <b>ignore pos </b>[ f f.swsh ]' <i>@any</i>;<br> <b>pos </b>f' <0 0 60 0> ;<br> <b>pos </b>f.swsh' <0 0 190 0> ;<br> } kerning2;<br>} <b>kern</b>;
This will increase the left sidebearing at the beginning of the glyph run and the right sidebearing at the end.

Is this approach at all practical or useful, have you ever implemented this or something similar? Is there an easy way to do this in any of the apps/tools you use? Now that I come to think of it, you could just write a script checking the sidebearings in all glyphs and applying appropriate kerning.
One way of thinking is that resolving such issues is responsibility of the layout engine or the typesetter. But obviously most people are not even aware this could be an issue:
Fixing a bug like above wouldn't be really obvious, I think at least some (if not most) design environments just take the advance width of the text as equivalent of the bounding box.
From my experiments, MS Word uses advance width to center text. So text with applied kerning of this kind would be centered more precisely, if that is what you'd want. (Besides, I often find myself centering text in InDesign manually because the unique shapes of sidebearings (even positive) make for an illusion of misalignment... but that's another pair of shoes).
Comments
I used a similar mechanism for line-initial/terminal swashes and ornaments in the Gabriola font, but am wary about recommending it for any critical functionality such as spacing.
span
s are not necessarily treated as separate runs, for instance, positioning marks and even substitutions work on Windows in Firefox (though not Edge or Opera): Codepen.