字体呈现与字形信息 [英] Font Rendering with Glyph information

查看:253
本文介绍了字体呈现与字形信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我称之为GetCharABCWidthsFloatW获得宽度信息的字符。有了这个,我会得到leftside轴承,右侧的轴承和先进的宽度。

I call "GetCharABCWidthsFloatW" to get the width information for a character. With this I will get the leftside bearing, right side bearing and the advanced width.

有关定位每个字符,我将开始将开始在零xPlacement变量。我会先减去左侧轴承调整xPlacement变量。后字符被描画,我会再由字符的宽度推进它(我将说明的计算稍后)。然后,我会从目前的xPlacement添加右侧的轴承信息移动xPlacement变量。

For positioning each characters, I will start with a "xPlacement" variables that will begin at zero. I will first adjust the xPlacement variable by subtracting the "left side bearing". After the character is drawn, I will then advance it by the width of the character( I will show the calculation for this later). I will then move the xPlacement variable by adding the "right side bearing" information from the current "xPlacement".

这在我看来是所有的应该是code表示字符的位置,正确的?

This, in my opinion is all that should be code for character placement, correct?

这是重要的事情是纠正字符的宽度。宽度将通过采取advancedWidth,加上左侧轴承的正版本和右侧轴承的正版本被计算。我会,如果他们是消极的这个值转换为正,这样我就可以有字符的总宽度。

An important thing is to correct the width of the characters. The width will be calculated by taking the advancedWidth, plus the POSITIVE version of the left side bearing and the POSITIVE version of the right side bearing. I will convert this values to positive, if they are negative so I can have the total width of the character.

下面是一些伪code它是如何产生的。

Here is some pseudo code about how it is generated.

float xPlacement = 0.0f;
for(int i = 0; i < strlen(text); ++i)
{
 char charValue = text[i];
 GetCharWidthABC(.., .., charInfo);

 float posLeft = charInfo.leftSideBearing;
 if(charInfo.leftSideBearing < 0)
  posLeft = -charInfo.leftSideBearing;

 float posRight = charInfo.rightSideBearing;
 if(posRight < 0)
  posRight = -charInfo.rightSideBearing;

 float posWidth = posRight + posRight + charInfo.advancedWidth;

 float letterWidth = posWidth;

 xPlacement  -= charInfo.leftSideBearing;

 /* generated some vertex coordinates, using the xPlacement variable and letterWidth */

 xPlacement += letterWidth;
 xPlacement += charInfo.rightSideBearing
}

这是否看起来是这样做的正确方法?

Does this appear to be the correct way to do this?

推荐答案

由于C#中提到的问题的标签,也许你会发现在寻找一些非常强大的类,船舶与.NET框架的一些兴趣(开始版本3.0,实际上附带WPF核心组件)。它们是:

Since C# is mentioned in the question tags, maybe you'll find some interest in looking at some very powerful classes that ship with .NET Framework (starting with version 3.0, in fact shipped with WPF core assemblies). They are:

  • GlyphTypeFace :在指定物理字体面,对应于在磁盘上的字体文件。,有用解析一个.TTF文件,并​​从它建立字形。
  • GlyphRun :重新presents从单个字体的单面字形序列在一个单一的大小,并用一个单一的渲染风格,有许多有用的属性和方法(例如,你可以从它建立一个几何体)
  • GlyphRunDrawing :重新presents一个图形对象呈现一个GlyphRun。也许不感兴趣的你,因为它更依赖于WPF渲染/合成系统。
  • GlyphTypeFace: Specifies a physical font face that corresponds to a font file on the disk., useful to parse a .TTF file and build glyphs from it.
  • GlyphRun: Represents a sequence of glyphs from a single face of a single font at a single size, and with a single rendering style, with many usefull properties and methods (for example, you can build a Geometry from it)
  • GlyphRunDrawing: Represents a Drawing object that renders a GlyphRun. Maybe less interesting for you because it's more tied to WPF rendering/composition system.

这两个第一类是有些技术/设备的独立,除了从.NET框架本身。

The two first classes are somewhat technology/device independant, except from the .NET Framework itself.

这篇关于字体呈现与字形信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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