如何获取使用“文本数字”的字体的升序或降序高度 [英] How to get the ascending or descending height of a font that uses 'Text figures'

查看:132
本文介绍了如何获取使用“文本数字”的字体的升序或降序高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建的PDF文档中遇到文字图片(查看维基百科)的问题使用 itextsharp

I'm having a problem with Text figures (see Wikipedia) in a PDF document created with itextsharp.

基线与数字最低点之间的距离(例如 9 )与字体的正常下降高度不同。

The distances between the baseline and the lowest point of a number (e.g. 9) is NOT the same as the normal descender height of a font.

使用以下代码我可以计算下降器的高度字体:

With the following code i can calculate the height of the descender of a font:

var fontSize = 60;
var fontPath = @"CorpusGothic-Condensed.otf";
var font = BaseFont.CreateFont(fontPath, BaseFont.CP1252, BaseFont.EMBEDDED);
var descentHeight = font.GetFontDescriptor(BaseFont.DESCENT, fontSize)

我现在的问题:

是否可以使用维基百科页面上显示的文字图形获得字体数字的下降或上升高度?

My question now:
Is it possible to get the descender- or ascender-heights of the numbers in a font with text-figures as shown on the Wikipedia page?

推荐答案

字体包含上升器和下降器的一般值。这是您在自己的代码示例中获得的值。

A font contains a general value of the ascender and the descender. This is the value that you are getting in your own code sample.

但是,每个字形也有自己的尺寸。字母h的字形具有比字母g的字形更高的上升字符和更低的下划线。

However, every glyph also has its own dimensions. The glyph for letter h has a higher ascender and a lower descender than the glyph for the letter g.

仅在四小时前,我回答了问题如何计算元素的高度?(使您的问题重复)。

Only four hours ago, I answered the question How to calculate the height of an element? (making your question a duplicate).

这就是我写的:

如果 bf BaseFont 实例,然后你可以使用:

If bf is a BaseFont instance, then you can use:

float ascent = bf.getAscentPoint("Some String", 12);
float descent = bf.getDescentPoint("Some String", 12);

当我们使用字体大小时,这将返回高于基线的高度和高于基线的高度您可能知道,字体大小表示平均高度。这不是实际的高度。这只是我们合作的一个数字。

This will return the height above the baseline and the height below the baseline, when we use a font size of 12. As you probably know, the font size is an indication of the average height. It's not the actual height. It's just a number we work with.

总高度将是:

float height = ascent - descent;

请注意,提供字符串(在您的情况下为例如9)是不够的。你还需要传递一个字体大小(在我的情况下为12pt)以获得ascender和descender的值。

Note that providing a String (in your case for instance "9") isn't sufficient. You also need to pass a font size (in my case 12pt) to get the value of the ascender and descender in points.

备注:如果你正在使用iTextSharp,请在我提到的方法中用获取替换 get

Remark: if you're using iTextSharp, replace get with Get in the methods I mentioned.

这篇关于如何获取使用“文本数字”的字体的升序或降序高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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