边框ñ字形的,某一个人bboxes及垫款 [英] bounding box of n glyphs, given individual bboxes and advances

查看:148
本文介绍了边框ñ字形的,某一个人bboxes及垫款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关具体原因,我实现我自己的字体渲染,和算法使用单个字形的边界框计算文本的边框,配以相应的进步,是必要的。为了清楚看到这个例子

For specific reasons, I'm implementing my own font rendering, and an algorithm to compute the bounding box of a text by using bounding boxes of single glyphs, together with the respective advance, is needed. For clarification see this illustration:

有关每一这些的 N 的字形是给定的相对的相对BBOX到原点(XMIN,XMAX,YMIN,YMAX),和先行(伪$ C $三):

For every of these N glyphs is given the relative bbox relative to the origin (xmin, xmax, ymin, ymax), and the advance (pseudocode):

int xmin[N], xmax[N], ymin[N], ymax[N], adv[N];

我给自己的答案,如果没有人咬伤。

I will give the answer myself if noone bites.

推荐答案

有关,一般情况下,你将不能够准确地测量只使用字形边框和超前宽度因暗示,字距和连字符的字符串这将显著修改字形的大小和它们的取决于它们的字符串中的位置,以及选择的字体大小间距

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.

的幼稚方式是通过遍历字形和添加超前宽度和XMIN才是正确的,在某些特定的大小的字体和要如果在所有可能不被用于计算串长度

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.

让字体规格最简单的方法是使用一个既定的字体渲染引擎直接获取文本的长度(如API公开的),或者呈现文本到表面,并找到在最小/最大像素X / Y方向。

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.

这篇关于边框ñ字形的,某一个人bboxes及垫款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆