English 中文(简体)
确定用于撰写文字的字符的 Y 位置
原标题:Determining the y placement of a character for rendering text

我一直在研究我自己的位图字体转换器, 虽然我相信我可能有正确的字符间距, 但我不确定我如何确定字符的位置 。 例如, 如果字母a 的位置为 0 y, 那么会是什么? 我一直在使用 winapi 函数 < code> getCharABCWCAIDsFloatW 来决定字符之间的间距, 我能否用另一个函数来决定某种 y 偏移?

我在我的位图图像上做最合身的图案, 所以它们并不总是一样大小。

问题回答

每个字符本身都应在 y 方向中被正统的 APIs (TextOut , DrawText ,>等等) 文本抵消,所以您应该有一个常数的偏移。 我总是用 GetTextExtentPoint32 获得字符串“Ag” 的量度值, 以获得一般的量值。 此外, 您还可以尝试 < a href=" http://msdn. microsoft.com/ en- us/library/dd144941% 28v=vs. 85%29.aspx" rel=“ nofolt'GetTextMetrics 。

GetTextMetrics 是正确的答案。 但是, 混血儿可能想要说, 您需要用于 Y 坐标的字段是 tmAscent( 查看结构 ) 。

总高度为 tmH8 。 tmAscent 是 从顶部到基线的距离。 TmAscent 是 基线和字体底部之间的距离 。

因此,在多数情况下,如果您(x, y) 协调引用文本的左上角,您想要添加 tmAscent 。如果 y 坐标为底部,则减去 tmDraw (+ 或 - 也取决于您是否颠倒了视图端口,但您可以测试和查看您得到什么 。)

无论您写“a”、“*”或“j”,这些信息都是有效的。所有字符的基准都是相同的。

如果我理解正确的话 : 每种象形的位图最初都是相同的高度 。 然后您将每个象形周围的所有剩余空间剪裁, 为每个字符创建最小的位图 。

在此情况下, 答案很简单 。 当您创建了缩略位图时, 请记住您从左上( 或左下, 取决于您如何定位晶体) 上移多少像素。 当您绘制位图时, 您可以使用保存的值调整坐标 。

然而,如果您试图使用字体量度来确定每个位图的微调大小,您无法 。

<强> 一般字体信息:

您正在寻找的是如何将文本置于“ 基准线” 或“ 来源” (相同的概念) 的正常位置。 您可以根据您的坐标系统, 使用 ascent( 向量) 或 血统( 向量) 来做到这一点 。

http://www.freetype.org/freetytype2/docs/tutiment/step2.html

这提供了一套与打字有关的相当不错的范例图像。

< 加强> 一般位图字体信息:

现在,对于位图图像来说,确保它们排成齐全的最简单的方式是,在您的图示表单中,每个字符的位图表达式都具有相同的高度(无论根据实际字符宽度如何,宽度应该不同) 。如果你这样做,那么你就可以简单地根据共享的高度排列所有内容。

如果您在一个字符周围剪切多余的白空格, 您需要将剪切的值与光谱一起保存在某个结构中, 以便您能够确定偏移。 如果 API 是为您这样做的, 它们可能具有向上/ descender、 来源/ 基线或线形高度方法, 您可以根据字符获得全部尺寸, 以便您能够正确做到这一点 。

Api specific information
Edit: Based on other answers here are the relevant links for your API specific question:

GetTextMetrics:
http://msdn.microsoft.com/en-us/library/dd144941(v=vs.85).aspx

TEXTMETRIC struct:
http://msdn.microsoft.com/en-us/library/dd145132(v=vs.85).aspx

tmAscent 或 TMDD 可用于帮助抵消您的 y 坐标 。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签