How FreeType's rasterizer work
by David Turner
Revised 2007-Feb-01
This file is an attempt to explain the internals of the FreeType
rasterizer. The rasterizer is of quite general purpose and could
easily be integrated into other programs.
I. Introduction
II. Rendering Technology
1. Requirements
2. Profiles and Spans
a. Sweeping the Shape
b. Decomposing Outlines into Profiles
c. The Render Pool
d. Computing Profiles Extents
e. Computing Profiles Coordinates
f. Sweeping and Sorting the Spans
I. Introduction
===============
A rasterizer is a library in charge of converting a vectorial
representation of a shape into a bitmap. The FreeType rasterizer
has been originally developed to render the glyphs found in
TrueType files, made up of segments and second-order Béziers.
Meanwhile it has been extended to render third-order Bézier curves
also. This document is an explanation of its design and
implementation.
While these explanations start from the basics, a knowledge of
common rasterization techniques is assumed.
II. Rendering Technology
========================
1. Requirements
---------------
We assume that all scaling, rotating, hinting, etc., has been
already done. The glyph is thus described by a list of points in
the device space.
- All point coordinates are in the 26.6 fixed float format. The
used orientation is:
^ y
| reference orientation
|
*----> x
0
`26.6' means that 26 bits are used for the integer part of a
value and 6 bits are used for the fractional part.
Consequently, the `distance' between two neighbouring pixels is
64 `units' (1 unit = 1/64th of a pixel).
Note that, for the rasterizer, pixel centers are located at
integer coordinates. The TrueType bytecode interpreter,
however, assumes that the lower left edge of a pixel (which is
taken to be a square with a length of 1 unit) has integer
coordinates.
^ y ^ y
| |
| (1,1) | (0.5,0.5)
+-----------+ +-----+-----+
| | | | |
| | | | |
| | | o-----+-----> x
| | | (0,0) |
| | | |
o-----------+-----> x +-----------+
(0,0) (-0.5,-0.5)
TrueType bytecode interpreter FreeType rasterizer
A pixel line in the target bitmap is called a `scanline'.
- A glyph is usually made of several contours, also called
`outlines'. A contour is simply a closed curve that delimits an
outer or inner region of the glyph. It is described by a series
of successive points of the points table.
Each point of the glyph has an associated flag that indicates
whether it is `on' or `off' the curve. Two successive `on'
points indicate a line segment joining the two points.
One `off' point amidst two `on' points indicates a second-degree
(conic) Bézier parametric arc, defined by these three points
(the `off' point being the control point, and the `on' ones the
start and end points). Similarly, a third-degree (cubic) Bézier
curve is described by four points (two `off' control points
between two `on' points).
Finally, for second-order curves only, two successive `off'
points forces the rasterizer to create, during rendering, an
`on' point amidst them, at their exact middle. This greatly
facilitates the definition of successive Bézier arcs.
The parametric form of a second-order Bézier curve is:
P(t) = (1-t)^2*P1 + 2*t*(1-t)*P2 + t^2*P3
(P1 and P3 are the end points, P2 the control point.)
The parametric form of a third-order Bézier curve is:
P(t) = (1-t)^3*P1 + 3*t*(1-t)^2*P2 + 3*t^2*(1-t)*P3 + t^3*P4
(P1 and P4 are the end points, P2 and P3 the control points.)
For both formulae, t is a real number in the range [0..1].
Note that the rasterizer does not use these formulae directly.
They exhibit, however, one very useful property of Bézier arcs:
Each point of the curve is a weighted average of the control
points.
As all weights are positive and always sum up to 1, whatever the
value of t, each arc point lies within the triangle (polygon)
defined by the arc's three (four) control points.
In the following, only second-order curves are discussed since
rasterization of third-order curves is completely identical.
Here some samples for second-order curves.
* # on curve
* off curve
__---__
#-__ _-- -_
--__ _- -
--__ # \
--__ #
-#
Two `on' points
Two `on' points and one `off' point
between them
*
# __ Two `on' points with two `off'
\ - - points between them. The point
\ / \ marked `0' is the middle of the
- 0 \ `off' points, and is a `virtual
-_ _- # on' point where the curve passes.
-- It does not appear in the point
* list.
2. Profiles and Spans
---------------------
The following is a basic explanation of the _kind_ of computations
made by the rasterizer to build a bitmap from a vector
representation. Note that the actual implementation is slightly
different, due to performance tuning and other factors.
However, the following ideas remain in the same category, and are
more convenient to understand.
a. Sweeping the Shape
The best way to fill a shape is to decompose it into a number of
simple horizontal segments, then turn them on in the target
bitmap. These segments are called `spans'.
__---__
_-- -_
_- -
- \
/ \
/ \
| \
__---__ Example: filling a shape
_----------_ with spans.
_--------------
----------------\
/-----------------\ This is typically done from the top
/ \ to the bottom of the shape, in a
| | \ movement called a `sweep'.
V
__---__
_----------_
_--------------
----------------\
/-----------------\
/-------------------\
|---------------------\
In order to draw a span, the rasterizer must compute its
coordinates, which are simply the x coordinates of the shape's
contours, taken on the y scanlines.
/---/ |---| Note that there are usually
/---/ |---| several spans per scanline.
| /---/ |---|
| /---/_______|---| When rendering this shape to the
V /----------------| current scanline y, we must
/-----------------| compute the x values of the
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
完美编译podofo0.9.7开源PDF读写库,附带podofo所需的编译好的freetype、libjpeg、libpng、libtiff、lua(部分例子需要)、openssl(文档加密需要)、zlib(压缩文档)、cppunit(部分例子用到)、crypto(头文件在openssl中),如果不需要用到文档加密可以去掉相关宏PODOFO_HAVE_OPENSSL,有两个用例需要用到linux相关库,没做编译是禁用状态,启用了PODOFO_HAVE_OPENSSL宏后需要添加两个dll文件到程序目录并且要连接相关lib库。因为该开源库涉及到的开源库太多,为避免开发程序时过多的连接这些静态库,所以将其编译成了lib库。建议有一定基础编程人员下载,目前VS工程下载即可打开编译成功。
资源详情
资源评论
资源推荐
收起资源包目录
VS2005版本编译podofo0.9.7开源PDF读写lib库 (1382个子文件)
ChangeLog.20 89KB
ChangeLog.21 321KB
ChangeLog.22 97KB
configure.ac 13KB
INSTALL.ANY 5KB
PDFread.aps 33KB
ttinterp.c 250KB
jidctint.c 182KB
pngrtran.c 170KB
jfdctint.c 159KB
tif_dirread.c 137KB
pngrutil.c 123KB
ftraster.c 106KB
ftobjs.c 105KB
tif_fax3sm.c 102KB
png.c 94KB
pngwutil.c 93KB
tif_dirwrite.c 86KB
deflate.c 77KB
cffgload.c 76KB
tif_ojpeg.c 75KB
tif_getimage.c 72KB
ttcmap.c 71KB
bdflib.c 69KB
t1load.c 67KB
aflatin2.c 66KB
tif_jpeg.c 66KB
aflatin.c 63KB
ttgload.c 62KB
pshalgo.c 60KB
transupp.c 57KB
pngtest.c 57KB
ttgxvar.c 55KB
gxvcommn.c 54KB
ftgrays.c 54KB
inflate.c 54KB
ttsbit.c 52KB
pngwrite.c 51KB
ftstroke.c 50KB
jdhuff.c 49KB
jquant2.c 49KB
jchuff.c 49KB
tif_dirinfo.c 47KB
psobjs.c 46KB
jdmarker.c 46KB
tif_dir.c 45KB
t1decode.c 45KB
ttload.c 44KB
cffload.c 44KB
tif_fax3.c 44KB
trees.c 43KB
ftmac.c 42KB
tif_luv.c 42KB
afcjk.c 42KB
jmemmgr.c 41KB
tif_pixarlog.c 40KB
pngread.c 39KB
pngset.c 38KB
pngpread.c 37KB
sfobjs.c 35KB
t42parse.c 34KB
ttobjs.c 33KB
pcfread.c 33KB
tif_read.c 32KB
ftmac.c 32KB
winfnt.c 32KB
example.c 32KB
jcmaster.c 31KB
jquant1.c 31KB
pshrec.c 31KB
pngget.c 31KB
tif_lzw.c 31KB
afhints.c 30KB
otvgpos.c 29KB
jcarith.c 28KB
gxvkern.c 27KB
ftoutln.c 27KB
otvcommn.c 27KB
jdcoefct.c 26KB
jdinput.c 25KB
ttsbit0.c 25KB
pfrload.c 25KB
ftbbox.c 25KB
cffobjs.c 25KB
ftdbgmem.c 24KB
jdarith.c 24KB
tif_write.c 24KB
pngtrans.c 23KB
ftrfork.c 23KB
jcparam.c 22KB
infback.c 22KB
bdfdrivr.c 22KB
afmparse.c 22KB
pfrgload.c 22KB
ftcbasic.c 22KB
cjpeg.c 22KB
pshglob.c 21KB
pngerror.c 21KB
tif_print.c 21KB
jdmainct.c 21KB
共 1382 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
泰迪超
- 粉丝: 4
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 《CKA/CKAD应试指南/从docker到kubernetes 完全攻略》学习笔记 第1章docker基础(1.1-1.4)
- 基于python实现的水下压缩空气储能互补系统建模仿真与经济效益分析+源代码+论文
- 华中科技大学-自然语言处理实验,Bi-LSTM+CRF的中文分词框架,并且利用基于深度学习的方法进行中文命名实体识别++源码报告
- 基于动态罚函数的铁路车流分配与径路优化模型python源码
- 鱼群算法求解组环问题python源码+文档说明
- 基于决策优化的多波束测深测线规划模型MATLAB代码
- 课程设计-基于python实现的多目标优化算法求解带时间窗的车辆路径规划问题+源代码+文档说明+界面截图+pptx
- 基于通信信号与通信系统的MATLAB仿真源码-课程设计
- 嵌入式-信号机制(概念,发送,定时,捕捉,SIGCHLD 信号实现回收子进程)
- c语言管理系统大一大二笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0