n 个字形的边界框,给定单独的 bboxes 和 Advances [英] bounding box of n glyphs, given individual bboxes and advances

查看:17
本文介绍了n 个字形的边界框,给定单独的 bboxes 和 Advances的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于特定原因,我正在实现自己的字体渲染,并且需要一种算法来通过使用单个字形的边界框以及相应的前进来计算文本的边界框.有关说明,请参阅此插图:

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 个字形中的每一个都给出了相对于原点(xmin、xmax、ymin、ymax)和前进(伪代码)的相对 bbox:

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];

没人咬我就自己回答.

推荐答案

对于一般情况,由于提示、字距调整和连字,您将无法仅使用字形边界框和提前宽度来准确测量字符串这将显着修改字形的大小及其间距,具体取决于它们在字符串中的位置以及所选的字体大小.

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.

这篇关于n 个字形的边界框,给定单独的 bboxes 和 Advances的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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