bounding box of n glyphs, given individual bboxes and advances

左心房为你撑大大i 提交于 2019-12-06 05:21:42

For the general case you won't be able to accurately measure a string using just the glyph bounding box and the advance width due to hinting, kerning, and ligatures which will significantly modify the sizes of glyphs and their spacing depending on their position in the string as well as the chosen font size.

The naive way to calculate the string length by iterating the glyphs and adding the advance width and xMin will only be correct for certain fonts at certain sizes and shouldn't be used if at all possible.

The easiest way to get font metrics is to use an established font rendering engine to either directly get the length of the text (if the API exposes that) or render the text to a surface and find the min/max pixel in the X/Y directions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!