You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The layout and drawing code of nanovg uses fonsTextIterInit and fonsTextIterNext to step through the glyphs. fonsTextIterInit needs to adjust the coordinates for the given origin and alignment (like NVG_ALIGN_CENTER). For that fonsTextIterInit needs to know the width of the text line, to adjust the origin, as the string is always drawn left to right.
fonsTextIterInit calls fonsTextBounds to calculate the width. fonsTextBounds is basically another simpler rover over the glyphs, that calculates the width. But it's calculation is unfortunately not compatible with that of nvgText or nvgTextGlyphPositions:
So that's where I think the differences in nvgTextBounds happen, as nvgTextBounds relies solely on fonsTextBounds. From a software engineering perspective though, the situation is unfortunate. The decision to use iter.x and iter.nextx is made in nanovg, so it's not transparent to fontstash. But the alignment values are defined and calculated in fontstash, which would need that information for accuracy.
I am currently of the opinion, that using the alignment implementation of fontstash is a mistake and alignment should be done in nanovg. But hacking fonsTextBounds to also use the whatever the values of iter.x and iter.nextx are, could work too...
The text was updated successfully, but these errors were encountered:
The layout and drawing code of nanovg uses
fonsTextIterInit
andfonsTextIterNext
to step through the glyphs.fonsTextIterInit
needs to adjust the coordinates for the given origin and alignment (likeNVG_ALIGN_CENTER
). For thatfonsTextIterInit
needs to know the width of the text line, to adjust the origin, as the string is always drawn left to right.fonsTextIterInit
callsfonsTextBounds
to calculate the width.fonsTextBounds
is basically another simpler rover over the glyphs, that calculates the width. But it's calculation is unfortunately not compatible with that ofnvgText
ornvgTextGlyphPositions
:fontstash
fonsTextBounds:
nanovg
nvgTextGlyphPositions uses
iter.x
anditer.nextx
:So that's where I think the differences in
nvgTextBounds
happen, asnvgTextBounds
relies solely onfonsTextBounds
. From a software engineering perspective though, the situation is unfortunate. The decision to useiter.x
anditer.nextx
is made in nanovg, so it's not transparent to fontstash. But the alignment values are defined and calculated in fontstash, which would need that information for accuracy.I am currently of the opinion, that using the alignment implementation of fontstash is a mistake and alignment should be done in nanovg. But hacking
fonsTextBounds
to also use the whatever the values ofiter.x
anditer.nextx
are, could work too...The text was updated successfully, but these errors were encountered: