首页 > 其他分享 >FreeType Glyph Conventions 翻译(2) ——Glyph Outlines 字符图形轮廓线

FreeType Glyph Conventions 翻译(2) ——Glyph Outlines 字符图形轮廓线

时间:2024-03-24 21:58:22浏览次数:30  
标签:EM FreeType point Conventions 像素 grid Glyph pixel size

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

目录

This section describes the way scalable representations of glyph images, called outlines, are used by FreeType as well as client applications.

像素,点,以及设备分辨率 Pixels, points, and device resolutions

Though it is a very common assumption when dealing with computer graphics programs, the physical dimensions of a given pixel (be it for screens or printers) are not squared.

虽然在处理计算机图像程序的时候,这是一个非常普遍的假设,但一个像素的物理大小(不论屏幕或者打印机)不一定是正方形的。

Often, the output device exhibits varying resolutions in both horizontal and vertical directions, and this must be taken care of when rendering text.
并且,不同输出设备在横向和纵向的分辨率不同,这些都需要在渲染文本的时候考虑到。

It is thus common to define a device's characteristics through two numbers expressed in dpi (dots per inch). For example, a printer with a resolution of 300×600 dpi has 300 pixels per inch in the horizontal direction, and 600 in the vertical one.
因此需要通过两个以dpi(dots per inch)每英寸点数为单位的值来表示设备的特性。举个例子,一台分辨率为300X600 dpi的打印机在横向有每英寸300个像素,在纵向上有600个像素每英寸。

The resolution of a typical computer monitor varies with its size (10″ and 25″ monitors don't have the same pixel sizes at 1024×768), and of course the graphics mode resolution.
计算机显示器的DPI会随着它的大小发生变化(10英寸和25英寸的显示器在1024×768时像素大小不同)。

As a consequence, the size of text is usually given in points, rather than device-specific pixels. Points are a physical unit, where 1 point equals 1/72 of an inch in digital typography.
结果就是,文本的大小经常以点为单位,而不是像素。点是一个物理单位,在电子排版中,1点等于1/72英寸。

As an example, most books using the Latin script are printed with a body text size somewhere between 10 and 14 points.
比如,大多数使用拉丁文的书籍的文本大小位于10点到14点之间。

It is thus possible to compute the size of text in pixels from the size in points with the following formula: pixel_size = point_size * resolution / 72
因此我们能够利用下面的公式,通过以点为单位的大小计算出以像素为单位的大小, pixel_size = point_size / 72 * resolution

这里point_size表示图片长宽有几个点, 由于一个点是 1/72英寸,可以得到以英寸为单位的长度,接着乘以 resolution (ppi, pixels per inch) 将其转化为像素,就得到以像素为单位的长度。

The resolution is expressed in dpi. Since horizontal and vertical resolutions may differ, a single point size usually defines a different text width and height in pixels.
这里分辨率(resolution)以dpi表示。因为横向和纵向的分辨率可能不同,一个点的大小可能对应不同的以像素为单位的长度和宽度。

Unlike what is often thought, the ‘size of text in pixels’ is not directly related to the real dimensions of characters when they are displayed or printed. The relationship between these two concepts is a bit more complex and depends on some design choices made by the font designer. This is described in more detail in the next sub-section (see the explanations on the EM square).
以像素为单位的文本大小和被人们看到的字体的大小并不直接相关。

矢量表示 Vectorial representation

The source format of outlines is a collection of closed paths called contours.
轮廓(outlines)的源格式是闭合路径的集合,被称为轮廓线(contours)。

Each contour delimits an outer or inner region of the glyph, and can be made of either line segments or Bézier arcs.
每个轮廓线分割了一个字符图形的内区域或者外区域,轮廓线可以是线段或者是贝塞尔曲线。

The arcs are defined through control points, and can be either second-order (these are conic Béziers) or third-order (cubic Béziers) polynomials, depending on the font format. Note that conic Béziers are usually called quadratic Béziers in the literature.
曲线通过控制点来定义,可以是二阶(圆锥)的,或者三阶多项式,取决于字体格式。注意圆锥贝塞尔曲线也被称作二次贝塞尔曲线。

Hence, FreeType associates each point of the outline with flags to indicate its type (normal or control point). As a consequence, scaling the points will scale the whole outline.
因此,FreeType会标记每个轮廓线的点来表示它的类型(普通的还是控制点)。缩放这些点就会缩放整个轮廓。

Each glyph's original outline points are located on a grid of indivisible units. The points are usually stored in a font file as 16-bit integer grid coordinates, with the grid's origin being at (0,0); they thus range from -32768 to 32767.
每个字符图形的原始轮廓线的点位于一个网格上。这些点通常会以16位整型坐标的形式被存储在字体文件中。网格的原点为(0,0)。坐标范围是(-32768, 32767)。

(Even though point coordinates can be floats in other formats such as Type 1, we will restrict our analysis to integer values for simplicity.)
虽然点坐标在其他格式中(Type 1)可以是浮点数,但我们为了简单考虑,只讨论整数数值。

The grid is always oriented like the traditional mathematical two-dimensional plane, i.e., the X axis goes from the left to the right, and the Y axis from bottom to top.
网格和传统数学二维平面一样,X轴从左向右,Y轴从底向上。

In creating the glyph outlines, a type designer uses an imaginary square called the EM square. Typically, the EM square can be thought of as a tablet on which the characters are drawn.
在创建字符图形轮廓线时,设计者需要使用一个想象中叫做EM 正方形的东西。我们可以将EM正方形看成是一个小板子,在这个板子上面我们画上字符图形。

The square's size, i.e., the number of grid units on its sides, is very important for two reasons:
这个EM正方形的大小非常重要(即边上网格单元的数量),有以下两点原因:

  • It is the reference size used to scale the outlines to a given text dimension. For example, a size of 12pt at 300×300 dpi corresponds to 12*300/72 = 50 pixels. This is the size the EM square would appear on the output device if it was rendered directly. In other words, scaling from grid units to pixels uses the formula:
    这是用于缩放轮廓线的参考大小。比如12pt(pt就是point)的大小在300X300dpi的屏幕上对应 12 / 72 * 300 = 50像素。这就是EM正方形会在屏幕上的大小,如果渲染正确的话。
    pixel_size = point_size * resolution / 72
    pixel_coord = grid_coord * pixel_size / EM_size
    Another acronym used for the pixel size is ppem (pixel per EM); this value can be fractional also. Note that fractional ppem values are not supported everywhere.
    另一个表示像素大小的缩写是ppem(pixel per EM)每一个EM正方形里有几个像素;这个值可能是分数。

  • The greater the EM size is, the larger resolution the designer can use when digitizing outlines. For example, in the extreme example of an EM size of 4 units, there are only 25 point positions available within the EM square which is clearly not enough. Typical TrueType fonts use an EM size of 2048 units; Type 1 or CFF PostScript fonts traditionally use an EM size of 1000 grid units (but point coordinates can be expressed as floating values).
    EM大小越大,...(没看懂,先跳过)

Note that glyphs can freely extend beyond the EM square if the font designer wants so. The EM square is thus just a convention in traditional typography.
注意字符图形可以没有限制地扩展到EM正方形之外,如果设计者需要的话。因此EM正方形就是传统打印的一个习俗。

As said before, pixel_size computed in the above formula does not directly relate to the size of characters on the screen. It simply is the size of the EM square if it was to be displayed. Each font designer is free to place its glyphs as it pleases him within the square. This explains why the letters of the following text have not the same height, even though they are displayed at the same point size with distinct fonts:
正如之前所说,pixel_size并不直接和字符的大小相关。它只表示EM正方形的大小。每个字体设计者可以自由地控制字符图形。这解释了相同point size的不同字体会有不同的高度。

Hinting and Bitmap rendering 启发和位图渲染

The outline as stored in a font file is called the ‘master’ outline, as its point coordinates are expressed in font units. Before it can be converted into a bitmap, it must be scaled to a given size and resolution.
存储在字体文件中的轮廓线被称为 “主要”轮廓线,因为他的点坐标以字体单位表示。在它被转化为位图之前,它必须被缩放到给定的大小和分辨率。

This is done with a very simple transformation, but especially at small sizes undesirable artifacts can appear, in particular stems of different width or height in letters like ‘E’ or ‘H’ can occur.
这通过一个非常简单的变换实现,但在非常小的尺寸的时候,不受欢迎的错位可能发生,尤其是字母E或H这些长度宽度不同的字母。

As a consequence, proper glyph rendering needs the scaled points to be aligned along the target device pixel grid, through an operation called grid-fitting (often called hinting).
因此,合适的字符图形渲染需要通过一个叫做网格对齐的方法(或者被叫做启发),将点对齐到目标设备像素网格。

One of its main purposes is to ensure that important widths and heights are respected throughout the whole font (for example, it is very often desirable that the ‘I’ and the ‘T’ glyphs have their central vertical line of the same pixel width), as well as to manage features like stems and overshoots, which can cause problems at small pixel sizes.
这样做的主要目的是保证重要的长高可以保留。

There are several ways to perform grid-fitting properly; most scalable formats associate some control data or programs with each glyph outline. Here is an overview:
有几种方式来实现网格对齐;大多数可缩放的格式有一些控制数据。

  • 显式网格对齐 explicit grid-fitting
    The TrueType format defines a stack-based virtual machine, for which programs (also called bytecode) can be written with the help of more than 200 operators, most of them related to geometrical operations. Each glyph is thus made of both an outline and a control program to perform the actual grid-fitting in the way defined by the font designer.
    TrueType格式定义了基于栈的虚拟机,程序可以借助200个操作符被写入其中,大多数操作符和几何操作有关。每个字符图形因此由一个轮廓线和知行网格对齐的控制程序组成。

  • 隐式网格对齐 implicit grid-fitting (also called hinting)
    The Type 1, CFF, and CFF2 formats take a much simpler approach: Each glyph is made of an outline as well as several pieces called hints which are used to describe some important features of the glyph, like the presence of stems, some width regularities, and the like. There aren't a lot of hint types, and it is up to the final renderer to interpret the hints in order to produce a fitted outline.
    Type1,CFF,和CFF2格式采用了更加简单的方式:每个字符由一个轮廓线和一些启发组成,这些启发用于描述字符图形的重要特性,像是balabala。当然启发也不会太多,取决于最终的渲染器如何解释这些启发。

  • 自动网格对齐
    Some formats include no control information with each glyph outline, apart from font metrics like the advance width and height. It is then up to the renderer to ‘guess’ the more interesting features of the outline in order to perform some decent grid-fitting.

grid-fitting scheme advantages disadvantages

explicit

Quality. Excellent results at small sizes are possible. This is very important for screen display.

Consistency. All renderers produce the same glyph bitmaps (at least in theory).

Speed. Interpreting bytecode can be slow if the glyph programs are complex.

Size. Glyph programs can be long.

Technical difficulty. It is extremely difficult to write good hinting programs. Very few tools available.

implicit

Size. Hints are usually much smaller than explicit glyph programs.

Speed. Grid-fitting is usually a fast process.

Quality. Often questionable at small sizes. Better with anti-aliasing though.

Inconsistency. Results can vary between different renderers, or even distinct versions of the same engine.

automatic

Size. No need for control information, resulting in smaller font files.

Speed. Depends on the grid-fitting algorithm. Usually faster than explicit grid-fitting.

Quality. Often questionable at small sizes. Better with anti-aliasing though.

Speed. Depends on the grid-fitting algorithm.

Inconsistency. Results can vary between different renderers, or even distinct versions of the same engine.

标签:EM,FreeType,point,Conventions,像素,grid,Glyph,pixel,size
From: https://www.cnblogs.com/dewxin/p/18092337

相关文章

  • 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="......
  • dotnet 读 WPF 源代码笔记 渲染层是如何将字符 GlyphRun 画出来的
    从业务代码构建出来GlyphRun对象,在WPF的渲染层里,如何利用GlyphRun提供的数据将字符在界面呈现出来。本文将和大家聊聊从WPF的渲染层获取到GlyphRun数据,到调用DirectX的各个渲染相关方法的过程,也就是WPF绘制文本字符的原理或者实现方法大家印象中的绘制一段文本是调......
  • dotnet 读 WPF 源代码笔记 GlyphRun 的 DeviceFontName 的功能是什么
    在WPF里面的GlyphRun里,有一个令人迷惑的DeviceFontName属性,似乎给这个属性传入什么值,结果都不会有变更。通过阅读源代码,可以了解到,这是一个没什么用途的属性。本文将告诉大家这个属性的细节逻辑在上一篇博客WPF简单聊聊如何使用DrawGlyphRun绘制文本里面就提到如何创......