文档库 最新最全的文档下载
当前位置:文档库 › TrueType字库文件在CGM图形系统中的读取流程_下_

TrueType字库文件在CGM图形系统中的读取流程_下_

绿色质量观察T rueT ype字库文件在CGM图形系统中的读取流程(下)

TrueType Transplanting Files in CGM Graphics System.The Reading Process(Ⅱ)

吴宪斌1,贾雨1,余杰2(1.成都理工大学核技术及自动化工程学

院,四川成都610059;2.中石油华川庆钻探工程有限公司地球物

理勘探公司技术发展中心,四川成都610213)

Wu Xian-bin1,Jia Yu1,Yu Jie2(1.chengdu university of technology nuclear technology

and automation engineering institute,Sichuan Chengdu610059;2.petrochina huanchuan

celebrates the drilling engineering Co.,LTD.geophysical exploration company technology

development center,Sichuan Chengdu610213)

摘要:CGM是一种通用的计算机图形文件格式,在各行各业中应用广泛,尤其是在石油勘探上的应用尤为重要。

TrueType字库是一种以二进制编码的数据格式文件,常用于CGM图形处理系统中增加图形的文字标注功能,采

用TrueType字库文件设计的文字处理具有很多优势,为此该文将对TrueType字库在CGM图形处理系统中的实

现流程进行较详尽的研究。

关键词:CGM;TrueType字库;unicode码

中图分类号:TP316文献标识码:A文章编号:1003-0107(2011)05-0041-04

Abstract:CGM is a universal computer graphics file format,is widely used in all walks of life,especially in the application of oil exploration

is especially important in dictionaries,TrueType is a binary coded data format file,often used for CGM graphics processing system in-

crease graphic characters by mark function,TrueType transplanting file design word processing has many advantages,therefore this pa-

per will be to TrueType transplanting from CGM graphics processing system to achieve the process for teaching detailed study.

Key w ords:CGM;TrueType fonts;Unicode yards

CLC number:TP316Document code:A Article ID:1003-0107(2011)05-0041-04

5解析glyf表

glyf直接给出了汉字的关键点坐标及其控制信息。glyf字体表中对应每个汉字的开头结构如表9所示。

表9各汉字开头结构

glyf可以采用两种不同的存储方式:simple glyph和com-posite glyph。当前两个字节表示的整数大于等于0时说明该表是simple glyph,否则是composite glyph。对于汉字而言,几个标准常用库都主要采用simple方式,所以我们重点研究simple 方式。其格式如表10所示。表10simple方式格式表

Type Name Description

SHORT numberOfContours If the number of contours is greater than or equal to zero,this is a single glyph;if negative,this is a

composite glyph.

FWord xMin Minimum x for coordinate data. FWord yMin Minimum y for coordinate data. FWord xMax Maximum x for coordinate data. FWord yMax Maximum y for coordinate data.

Type Name Description

USHORT endPtsOfContours[n]

Array of last points of each

contour;n is the number of

contours.

USHORT instructionLength

Total number of bytes for in-

structions.

BYTE instructions[n]

Array of instructions for each

glyph;n is the number of in-

structions.

BYTE flags[n]

Array of flags for each coor-

dinate in outline;n is the

number of flags.

BYTE or SHORT xCoordinates[]

First coordinates relative to

(0,0);others are relative to

previous point.

BYTE or SHORT yCoordinates[]

First coordinates relative to

(0,0);others are relative to

previous point.

测评与应用

ssessment and Application A

需要注意的是,对于不同的flags值,相应的存储方式有所差别。另外,为了节省存储空间,采用相对坐标存储方式,即在上一个坐标的基础上进行坐标加减的计算。

flag字节各bit的含义如表11所示。

据此,根据flag将坐标状况分为16类,如表12所示。

相应地,可以得到对横纵坐标取值时各flag应归入哪一类,如表13所示。

Flags Bit Description

On Curve0If set,the point is on the curve;otherwise,it is off the curve. x-Short Vector1If set,the corresponding x-coordinate is1byte long,not2. y-Short Vector2If set,the corresponding y-coordinate is1byte long,not2.

Repeat3If set,the next byte specifies the number of additional times this set of flags is to be repeated.In this way,the number of flags listed can be smaller than the number of points in a character.

This x is same (Positive x-Short Vector)4

This flag has two meanings,depending on how the x-Short Vector flag is set.If x-Short Vector is set,this bit describes the sign of the value,with1equalling positive and0neg-ative.If the x-Short Vector bit is not set and this bit is set,then the current x-coordinate is the same as the previous x-coordinate.If the x-Short Vector bit is not set and this bit is also not set,the current x-coordinate is a signed16-bit delta vector.

This y is same (Positive y-Short Vector)5

This flag has two meanings,depending on how the y-Short Vector flag is set.If y-Short Vector is set,this bit describes the sign of the value,with1equalling positive and0neg-ative.If the y-Short Vector bit is not set and this bit is set,then the current y-coordinate is the same as the previous y-coordinate.If the y-Short Vector bit is not set and this bit is also not set,the current y-coordinate is a signed16-bit delta vector.

Reserved6This bit is reserved.Set it to zero.

Reserved7This bit is reserved.Set it to zero.

表11flag字节各bit含义表

表1216类坐标状况表

组别坐标字节数是否重复坐标含义点类型12否16位有符号整数参考点22否16位有符号整数关键点31否8位无符号数,取负值参考点41否8位无符号数,取负值关键点52是16位有符号整数参考点62是16位有符号整数关键点71是8位无符号数,取负值参考点81是8位无符号数,取负值关键点92否与前一点坐标相等参考点102否与前一点坐标相等关键点111否8位无符号数,取正值参考点121否8位无符号数,取正值关键点132是与前一点坐标相等参考点142是与前一点坐标相等关键点151是8位无符号数,取正值参考点161是8位无符号数,取正值关键点

绿色质量观察

下转56页

在第三步得到的值的基础上获取汉字坐标信息的流程:(1)将第一步得到的glyph 表起始位置和第三步得到的汉字起始位置和终止位置偏移量分别相加,得到汉字的起始位置和终止位置。

(2)跳到汉字的起始位置,读取两个字节,得到number Of Contours(笔画数)。

(3)向后跳10个字节,即到了end Pts Of Contours 数组的开始,该数组存储各笔画中的点数,将其依次读出并存储。与此同时,由于每有一个点便有一个flag ,因此要对flag 进行计数

(但是当flag 中设置了repeat 时,flag 数可能少于点数,这点程序中似乎并未考虑,不知道会不会因此出错)。

(4)接下来读取instruction Length 值,因为instruction 不是我们需要的内容,因此向后跳instruction Length 个字节以跳过instructions[n]。目前,库里使用的字体instruction Length 值均为0,因而不包含instructions[n]字段(根据程序猜的,因为注释的部分原本有根据读出的长度进行跳转的语句)。

(5)接下来就到了flag[n]字段,将其读出并保存。

表13flag 应归入的类

组别取x 值时取y 值时100,04,20,2400,02,10,12201,05,21,2501,03,11,13302,06,22,2604,06,14,16403,07,23,2705,07,15,17508,0C ,28,2C 08,0A ,18,1A 609,0D ,29,2D 09,0B ,19,1B 70A ,0E ,2A ,2E 0C ,0E ,1C ,1E 80B ,0F ,2B ,2F 0D ,0F ,1D ,1F 910,14,30,3420,22,30,321011,15,31,3521,23,31,331112,16,32,3624,26,34,361213,17,33,3725,27,35,371318,1C ,38,3C 28,2A ,38,3A 1419,1D ,39,3D 29,2B ,39,3B 151A ,1E ,3A ,3E 2C ,2E ,3C ,3E 16

1B ,

1F ,3B ,3F 2D ,2F ,3D ,3F

第一点

最后点Now Next 线k 变化

11当前0L(No,Ne)

01与后面斜体部分重复,不写

10当前0B(No,k,k,Ne)0

当前(0+k)/2B(No,k,k,Ne)1

1当前K+1L(No,Ne)101当前K+2B(No,k+1,k+1,Ne)k++1

0当前(k+1+k+2)/2B(No,k+1,k+1,Ne)k++010当前(0+k+1)/2

B(No,k+1,k+1,Ne)k++11

0当前0B(No,k+1,k+1,Ne)k++

010(0+n)/21B(No,0,0,Ne)(k=0)00

(0+n)/2

(0+1)/2

B(No,0,0,Ne)(k=0)

011n 1B(No,0,0,Ne)(k=0)0

1

n

(0+1)/2

B(No,0,0,Ne)(k=0)

01当前K+1B(No,k,k,Ne)0

当前

(k+1+k+2)/2

B(No,k,k,Ne)

表14绘图命令解析表

上接43

(6)接着将flag[n]字段之后到汉字截止位置的数据全部读出并保存。(以上操作均在init 函数中)

(7)接下来根据flag 值和数据得到各点的坐标,要注意的是得到的点可能是关键点(在笔画上),也可能是控制点,需要记录该信息。(count 函数)

(8)其后关于利用坐标和控制点信息绘图见draw 函数,其中bezeier 曲线的构造和填充方式见原文档(主要是两个控制点连线的中点是关键点,以及bezeier 曲线的构造为关键点1-控制点-同一控制点-关键点2,还有就是当字体填充方式为第二种时,需要进行优先级的判断)。

draw 函数中各种情况的绘图命令解析(红色表示当前点,记为k ,

Now 和Next 中k 表示k 点坐标,(0+k)/2表示0点和k 点的中点坐标,n 表示最后一点坐标),如表14所示。

下面针对表14中的一些内容作解释:

(1)之所以经常用到取中点,是根据两个控制点连线的中点是关键点这一结论得来的。

(2)之所以只有在当前点为起始点且值为0时,才需要重设Now 值,是因为每次画线之后让Now 等于Next ,因而除去笔画的开始,Now 始终代表着关键点的坐标。而当起始点为1时,其本身就是关键点,由于在笔画开始时会让Now 等于起始点坐标,因而不用重设其值。

(3)之所以要将终止部分和起始部分进行连线,是为了保

证笔画的封闭性。

(4)之所以第二种情况和斜体部分重复,而第四种情况却不与斜体部分上面的两种情况重复,是因为第四种情况会用到n 之前的关键点。

(5)之所以只有其中四种情况会使k 额外加1(由于每次循环后k+1,相当于直接跳过下一个点),是因为只有这四种情况下下一个点直接作为曲线的参考点,因而可以直接跳到下一条线的开始。

6总结

TrueType 字体在Windows 平台下的应用很多,TrueType 字体的重要性已越来越受到人们的关注,但是涉及到具体的操作层面上中文资料还是很少。本论文较详尽地论述了TrueType 字库文件在CGM 图形处理系统中的读取流程,为进一步研究TrueType 提供了基础。(完)

参考文献:

[1]STANDARDS FOR CG,ISO8623:1992;ANSI;FIPS[Z].https://www.wendangku.net/doc/354103739.html,/div897/ctg/graphics/cgm_std.htm.

[2]CGM [Z].https://www.wendangku.net/doc/354103739.html,/CGM _Central/index.php.[3]https://www.wendangku.net/doc/354103739.html,/wiki/TrueType.[4]QT4帮助文档[Z].

目查询到的2007年9月———2010年9月连续三个学期学生对"信号与系统"课程评教情况可以看出,教学改革是比较成功的。与硬件实验有机地结合起来将会取得更好的效果。

5结束语

通过近年来对"信号与系统"课程的教学改革与尝试证明,在教学过程中采用上述教学方法和教学理念,动态地改革和完善教学手段,可以有效地提高教学效果,激发学生的学习兴趣,培养学生独立获取知识的能力。由于"信号与系统"理论涉及面广,该学科领域的理论与实践研究发展迅速,分析方法不断更新,技术应用范围日益扩展。因此,如何在教学过程中更好地发挥学生的学习主动性,培养学生独立获取知识的能力,提高本课程的教学效果,有待进一步的研究和实践。

参考文献:

[1]Oppenhem Alan V.信号与系统[M ].刘树棠,译.西安:西安交通大学出版社,1985.

[2]Simon Haykin,Barry Van Veen.Signals and Systems(Second Edi-tion)[M ].Publishing House of Electronics Industry,2004.[3]吴大正.信号与线性系统分析(第四版)[M ].北京:高等工业出版社,2005.

[4]梁虹.信号与系统分析及M ATLAB 实现[M ].北京:电子工业出版社,2005.

基金项目:河南工业大学2010年教学改革项目

绿色质量与管理

reen Quality &Management

G

相关文档