首页 > 其他分享 >FreeType Glyph Conventions 翻译(3) ——Glyph Metrics 字符图形参数

FreeType Glyph Conventions 翻译(3) ——Glyph Metrics 字符图形参数

时间:2024-03-27 16:49:10浏览次数:23  
标签:FreeType 字形 Conventions width bbox 步进 Glyph glyph

原文地址 https://freetype.org/freetype2/docs/glyphs/glyphs-3.html

目录

基线,笔位置以及布局 Baseline, pens and layouts

The baseline is an imaginary line that is used to ‘guide’ glyphs when rendering text. It can be horizontal (e.g., Latin, Cyrillic, Arabic) or vertical (e.g., Chinese, Japanese, Mongolian). Moreover, to render text, a virtual point, located on the baseline, called the pen position or origin, is used to locate glyphs.
基线是渲染文本时用于“引导”字符图形的想象中的线。基线可以是水平的(拉丁文,阿拉伯文)也可以是垂直的(中文,日文)。为了渲染文本,一个位于基线的虚拟的点,被用于定位字符图形,这个点被称为笔位置或者原点。

Each layout uses a different convention for glyph placement:
每个布局使用了不同的传统来放置图形:

  • With horizontal layout, glyphs simply ‘rest’ on the baseline. Text is rendered by incrementing the pen position, either to the right or to the left.
    如果是水平布局,那么字符图形就“躺”在基线上。文本通过递增笔位置来渲染。
    The distance between two successive pen positions is glyph-specific and is called the advance width. Note that its value is always positive, even for right-to-left oriented scripts like Arabic. This introduces some differences in the way text is rendered. The pen position is always placed on the baseline.
    两个连续笔位置的距离是和字符图形自身有关的,并且被称作步进宽度。注意这个值永远是正数,即使是从右到左书写的脚本。步进宽度引入了渲染方式的一些区别。笔位置总是位于基线上。

  • With a vertical layout, glyphs are centered around the baseline:
    对于垂直布局,字符图形位于基线中间。

排版参数和包围盒 Typographic metrics and bounding boxes

Various face metrics are defined for all glyphs in a given font.
在一个字体中,所有的字符图形都有多个字体参数。

  • Ascent 升部
    The distance from the baseline to the highest or upper grid coordinate used to place an outline point. It is a positive value, due to the grid's orientation with the Y axis upwards.
    基线到最高网格坐标的距离,用于放置一个轮廓线的点。由于网格的朝向是Y轴向上的,所以这是一个正数。

  • Descent 降部
    The distance from the baseline to the lowest grid coordinate used to place an outline point. In FreeType, this is a negative value, due to the grid's orientation. Note that in some font formats this is a positive value.
    基线到最低网格坐标的距离,用于放置一个轮廓线的点。在FreeType中,由于网格的朝向,这是一个负数。注意在某些字体格式中,这是正数。

  • Linegap 行间距
    The distance that must be placed between two lines of text. The baseline-to-baseline distance should be computed as linespace = ascent - descent + linegap if you use the typographic values.
    两行文本中间的距离。基线到基线的距离应该这样计算 linespace = ascent - descent + linegap

还有一些更简单的参数:

  • Bounding box 包围盒
    This is an imaginary box that encloses all glyphs from the font, usually as tightly as possible. It is represented by four parameters, namely xMin, yMin, xMax, and yMax, that can be computed for any outline. Their values can be in font units if measured in the original outline, or in integer (or fractional) pixel units when measured on scaled outlines.
    这是一个假想的框,通常尽可能紧密地包围字体中的所有字形。它由四个参数表示,即xMin、yMin、xMax和yMax。如果在原始轮廓中测量,则它们的值可以是字体单位,如果在缩放轮廓中测量时,则可以以整数(或分数)像素为单位。

    A common shorthand for the bounding box is ‘bbox’.
    包围盒的常用缩写是“bbox”。

  • Internal leading 内间距
    This concept comes directly from the world of traditional typography. It represents the amount of space within the leading which is reserved for glyph features that lay outside of the EM square (like accentuation). It usually can be computed as internal leading = ascent - descent - EM_size
    这个概念直接来自传统印刷术。它表示为字符图形在EM正方形之外预留的空间(如重音)。它可以通过这个公式获得internal leading = ascent - descent - EM_size

  • External leading 外间距
    This is another name for the line gap.
    就是linegap行间距。

定位和步进 Bearings and Advances

Each glyph also has distances called bearings and advances. The actual values depend on the layout, as the same glyph can be used to render text either horizontally or vertically:
每个字形还有两个参数:定位,步进。因为相同的字形可以用于水平或垂直呈现文本,它们实际的值取决于布局:

  • Left side bearing 左侧定位
    The horizontal distance from the current pen position to the glyph's left bbox edge. It is positive for horizontal layouts, and in most cases negative for vertical ones.
    当前笔位置(原点)到字形包围盒左侧的水平距离。它对水平布局是正的,在大多数情况下对垂直布局是负的。

    In the FreeType API, this is also called bearingX. Another shorthand is ‘lsb’.
    在FreeType API中,这也称为bearingX。另一个简写是lsb(left side bearing)。

  • Top side bearing 上侧定位
    The vertical distance from the baseline to the top of the glyph's bbox. It is usually positive for horizontal layouts, and negative for vertical ones.
    从基线到字形包围盒顶部的垂直距离。它通常对水平布局是正的,对垂直布局是负的。

    In the FreeType API, this is also called bearingY.
    在FreeType API中,这也称为bearingY

  • Advance width 步进宽度
    The horizontal distance to increment (for left-to-right writing) or decrement (for right-to-left writing) the pen position after a glyph has been rendered when processing text. It is always positive for horizontal layouts, and zero for vertical ones.
    在一个字形被渲染后,笔位置发生的水平距离的变化,变化可能是增加(对于从左到右的书写)或减少(对于从右到左的书写)。对于水平布局,它总是正的,对于垂直布局,它是零。

    In the FreeType API, this is also called advanceX.
    在FreeType API中,这也称为advanceX

  • Advance height 步进高度
    The vertical distance to decrement (for top-to-bottom writing) or increment (for bottom-to-top writing, which is extremely rare) the pen position after a glyph has been rendered. It is always zero for horizontal layouts, and positive for vertical layouts.
    字形渲染后,笔位置的垂直距离的变化,变化可能是减少(对于从上到下的书写)或增加(对于从下到上的书写,这是极为罕见的)。对于水平布局,它始终为零,对于垂直布局,它总是为正。

    In the FreeType API, this is also called advanceY.
    在FreeType API中,这也称为advanceY

  • Glyph width 字形宽度
    The glyph's horizontal extent. For unscaled font coordinates, it is glyph width = bbox.xMax - bbox.xMin
    字形的水平宽度。对于未缩放的字体坐标,它是glyph width = bbox.xMax - bbox.xMin

    For scaled glyphs, its computation requests specific care, described in the grid-fitting chapter below.
    对于缩放的字形,其计算需要特别小心,具体情况在下文有详细描述。

  • Glyph height 字形高度
    The glyph's vertical extent. For unscaled font coordinates, it isglyph height = bbox.yMax - bbox.yMin
    字形的水平高度。对于未缩放的字体坐标,它是glyph height = bbox.yMax - bbox.yMin

  • Right side bearing 右侧定位
    Only used for horizontal layouts to describe the distance from the bbox's right edge to the advance width. In most cases it is a non-negative number:right side bearing = advance_width - left_side_bearing - (xMax-xMin)
    只存在于水平布局,用于描述包围盒右侧到步进宽度的距离。绝大多数情况,这是一个非负数:right side bearing = advance_width - left_side_bearing - (xMax-xMin)

    A common shorthand for this value is ‘rsb’.
    一个常见的缩写是rsb(right side bearing)

Here is a picture giving all the details for horizontal metrics:
水平布局 参数的图解:

垂直布局 参数的图解:

网格对齐 The effects of grid-fitting

Because hinting aligns the glyph's control points to the pixel grid, this process slightly modifies the dimensions of character images in ways that differ from simple scaling.
因为启发(hinting)将字形的控制点与像素网格对齐,所以这个过程会略微修改字符图像的尺寸, 这点和简单的缩放会有所不同。

For example, the image of the lowercase ‘m’ letter sometimes fits a square in the master grid. However, to make it readable at small pixel sizes, hinting tends to enlarge its scaled outline horizontally in order to keep its three legs distinctly visible, resulting in a wider character bitmap.
例如,小写字母“m”的图像有时在主网格中是正方形。然而,为了使其在小像素大小下可读,启发倾向于将轮廓线横向放大,以保持其三条腿清晰可见,从而生成更宽的字符位图。

The glyph metrics are also influenced by the grid-fitting process:
字形参数也会受到网格对齐的影响:

  • The image's width and height are altered. Even if this is only by one pixel, it can make a big difference at small pixel sizes.
    图像的宽度和高度会发生更改。即使只改变了一个像素,在小像素的情况下也会产生很大的差异

  • The image's bounding box is modified, thus modifying the bearings.
    图像包围盒会发生改变,从而定位(bearings)会发生改变。

  • The advances must be updated. For example, the advance width must be incremented if the hinted bitmap is larger than the scaled one, to reflect the augmented glyph width.
    步进会被更新。例如,如果启发生成的点阵图大于放大的点阵图,则必须增加步进宽度,以反映增强的字形宽度。

This has some implications:
这产生一些影响:

  • Because of hinting, simply scaling the font ascent or descent might not give correct results. A possible solution is to keep the ceiling of the scaled ascent, and floor of the scaled descent.

  • There is no easy way to get the hinted glyph and advance widths of a range of glyphs, as hinting works differently on each outline. The only solution is to hint each glyph separately and record the returned values (for example in a cache). Some formats, like TrueType, even include a table of pre-computed values for a small set of common character pixel sizes.
    没有简单的方法可以获得一系列字形的启发字形和步进宽度,因为启发在每个轮廓上的作用不同。唯一的解决方案是分别启发每个字形并记录返回的值(例如在缓存中)。某些格式,如TrueType,甚至包括一小组常见字符像素大小的预先计算值表。

  • Hinting depends on the final character width and height in pixels, which means that it is highly resolution-dependent. This property makes correct WYSIWYG(what you see is what you get) layouts difficult to implement.
    启发取决于以像素为单位的最终字符宽度和高度,这意味着它高度依赖于分辨率的。此属性使 所见即所得 布局难以实现。

Performing 2D transformations on glyph outlines is very easy with FreeType. However, when using translation on hinted outlines, one should always take care of exclusively using integer pixel distances (which means that the parameters to the FT_Outline_Translate API function should all be multiples of 64, as the point coordinates are in 26.6 fixed-point format). Otherwise, the translation will simply ruin the hinter's work, resulting in very low quality bitmaps!
使用FreeType对字形轮廓线进行二维转换非常容易。然而,当在启发后的轮廓线上使用变换时,应始终注意仅使用整数像素距离(这意味着FT_Outline_Translate API函数的参数都应为64的倍数,因为点坐标为26.6定点格式)。否则,变换只会破坏启发器的工作,导致位图质量非常低!

Note, however, that the restriction to integer pixel distances mentioned in the previous paragraph has become weaker; today, it is quite common to do no hinting along the horizontal axis, only adjusting the glyphs vertically. Typical examples are Microsoft's ClearType implementation, FreeType's new CFF engine (contributed by Adobe), or the ‘light’ auto-hinting mode. For such modes you get best rendering results if you do sub-pixel glyph positioning.
然而,请注意,上一段中提到的对整数像素距离的限制已经变得较弱;今天,水平轴不启发,只垂直调整字形是很常见的。典型的例子是微软的ClearType实现、FreeType的新CFF引擎(由Adobe提供)或“轻”自动提示模式。对于这种模式,如果进行亚像素图示符定位,则可以获得最佳渲染结果。

文本宽度和包围盒 Text widths and bounding box

As seen before, the ‘origin’ of a given glyph corresponds to the position of the pen on the baseline. It is not necessarily located on one of the glyph's bounding box corners, unlike many typical bitmapped font formats. In some cases, the origin can be out of the bounding box, in others, it can be within it, depending on the shape of the given glyph.
如前所述,给定字形的“原点”对应于笔在基线上的位置。与许多典型的点阵字体格式不同,它不一定位于字形的包围盒边角之一。在某些情况下,原点可以在包围盒外,在其他情况下,它可以在边界盒内,这取决于给定字形的形状。

Likewise, the glyph's ‘advance width’ is the increment to apply to the pen position during layout, and is not related to the glyph's ‘width’, which really is the glyph's bounding box width.
同样,字形的“步进宽度”是字形布局期间应用于笔位置的增量,与字形的“宽度”无关,后者实际上是字形的包围盒宽度。

The same conventions apply to strings of text, with the following consequences.
同样的约定也适用于文本字符串,结果如下。

  • The bounding box of a given string of text doesn't necessarily contain the text cursor, nor is the latter located on one of its corners.
    给定文本字符串的包围盒不一定包含文本光标,文本光标也不位于其一个角上。

  • The string's advance width isn't related to its bounding box dimensions. Especially if it contains leading and trailing spaces or tabs.
    字符串的步进宽度与其包围盒尺寸无关。特别是如果它包含前导和尾随空格或制表符。

  • Finally, additional processing like kerning creates strings of text whose dimensions are not directly related to the simple juxtaposition of individual glyph metrics. For example, the advance width of ‘VA’ isn't the sum of the advances of ‘V’ and ‘A’ taken separately.
    最后,像字间距这样的额外处理会导致文本的参数不仅仅是文本内各个字符图形参数的总和。例如,“VA”的步进宽度不是“V”和“A”分别的步进宽度的总和。

标签:FreeType,字形,Conventions,width,bbox,步进,Glyph,glyph
From: https://www.cnblogs.com/dewxin/p/18093252

相关文章

  • FreeType编译与使用
    FreeType是一款免费用于渲染字体的开源库。在使用该类库时,最好先过一遍官方文档,其中FreeTypeGlyphConventions部分的文章必读。编译我们可以进入下载界面,点击任意一个地址下载源码。这里笔者使用的是2.13.2版本,解压后会获得一个freetype-2.13.2文件夹。进入目录freetype-2.......
  • FreeType Glyph Conventions 翻译(2) ——Glyph Outlines 字符图形轮廓线
    原文地址https://freetype.org/freetype2/docs/glyphs/glyphs-2.html目录像素,点,以及设备分辨率Pixels,points,anddeviceresolutions矢量表示VectorialrepresentationHintingandBitmaprendering启发和位图渲染Thissectiondescribesthewayscalablerepresentatio......
  • freetype
    freetype依赖于libpng,libpng又依赖于zlib。所以先编译安装zlib,再编译安装libpng,最后编译安装freetype。问题一:zlib安装时需要使用交叉编译器跟着正点原子的应用开发手册安装zlib,直接参照手册上执行./configure,make,makeinstall后安装编译libpng时会报错,说找不到zli......
  • freetype 显示一行字符
    #include<stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<fcntl.h>#include<sys/io.h>#include<sys/types.h>#include<sys/stat.h>#include<sys/mman.h>#include<lin......
  • SQL Server 2005 数据库对象命名规范 Database Naming Conventions(Guidelines)
    使用SQLServer2005命名数据库对象时可以参照微软的示例数据库AdventureWorks。其次可以参照以下内容:DatabaseNamingConventionsVersion1.1LastRevisedMay13,2004byJasonMaussThemaingoalofadoptinganamingconventionfordatabaseobjectsissothatyouand......
  • Configuration failed to find one of freetype2 libpng libtiff-4 libjpeg.
     001、问题,安装devtools中遇到如下报错:Configurationfailedtofindoneoffreetype2libpnglibtiff-4libjpeg. 002、解决方法:[root@pc1~]#yuminstallfreetype-devellibpng-devellibtiff-devellibjpeg-devel##根据提示安装  。 ......
  • 初学Bokeh:修改图形符号(glyphs)的属性【10】跬步
    初学Bokeh:修改图形符号(glyphs)的属性【10】跬步如果在创建对象之后希望更改其属性,可以通过直接定义并覆盖对象的属性的方法进行修改。以上面【9】跬步的绘图例程为例。过参数设置fill_color="red"将圆的填充色定义为红色。若希望将圆的填充颜色从红色改为蓝色,首先需要调用circle(......
  • 初学Bokeh:图形(figure)与图形符号(glyphs)的概念 【8】跬步
    初学Bokeh:图形(figure)与图形符号(glyphs)的概念【8】跬步Bokeh的绘图有主要有2个概念,一个是图形(figure),另一个是图形符号(glyphs)。一般在绘图过程中,我们先建立一个图形,然后在该图形中添加图形符号。glyphs可以根据所需的用途呈现多种形状:圆形(circles),线条(lines),补丁(p......
  • 解决警告UserWarning: Glyph 38388 (\N{CJK UNIFIED IDEOGRAPH-95F4}) missing from
    这个警告是由于在绘图时使用了当前字体不支持的字符,通常出现在使用非英文字符(比如中文、日文等)时。为了解决这个问题,你可以尝试以下几种方法:方法一:选择支持中文的字体在绘图之前,指定一个支持中文的字体。例如,可以使用matplotlib.rcParams来指定字体,示例如下:importmatplotlib.pyplo......
  • Bootstrap教程(一)Glyphicons字体图标使用
    一.已下载bootstrap3.Xhttps://v3.bootcss.com/getting-started/#download也可以CDN引用<!--最新版本的Bootstrap核心CSS文件--><linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"integrity="......