我可以使用“旧式"广告素材吗? (非衬)数字在TCPDF中? [英] Can I use "old-style" (non-lining) numerals in TCPDF?

查看:93
本文介绍了我可以使用“旧式"广告素材吗? (非衬)数字在TCPDF中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unicode不能区分内衬数字(与大写字母具有相同的比例,并且在表格中很有用,但在运行文本中突出显示)和非内衬数字,后者看起来更像是小写字母,带有升序和降序,因为它们考虑到了彼此的变体.但是,许多字体都有两组数字,并提供了一种在它们之间进行选择的方法.在TCPDF中有什么方法可以实现这一目标?

Unicode does not distinguish between lining figures (which have the same proportions as capital letters, and are useful in tables, but stand out in running text) and non-lining figures, which look more like lowercase letters, with ascenders and descenders, as it considers them variants of each other. Many fonts, though, have both sets of digits, and provide a way to choose between them. Is there any way to achieve this in TCPDF?

理想情况下,我希望编号列表使用衬砌数字,正在运行的文本中的数字使用衬砌数字,而邮政编码(英国和爱尔兰邮政编码是字母数字)则要使用衬砌数字和小写大写字母.这可以在LaTeX中使用\oldstylenums{1234567890}来实现.

Ideally, I would like numbered lists to use lining figures, and numbers in running text to use non-lining, and postcodes (British and Irish postcodes are alphanumeric) to use non-lining figures and small block capital numbers. This could be achieved in LaTeX with \oldstylenums{1234567890}.

我可以找到的唯一类似问题是关于调整TCPDF中的字体指标以使未衬砌的图形显得衬砌.理想情况下,我希望在相同的字体和同一文档中同时使用这两者. TCPDF是否可以访问OpenType字符变体? (公平警告:我在这里有点深了.)

The only similar question I could find was about tweaking font metrics in TCPDF to make non-lining figures look lining. I would ideally want to use both, from the same font and within the same document. Does TCPDF give access to OpenType character variations? (Fair warning: I’m a little out of my depth here.)

推荐答案

不幸的是,据我所知,TCPDF不支持OpenType变体.例如,以freesans的字体声明文件为例,在字符宽度数组中甚至没有包含pnum变体字形.

Unfortunately, as far as I'm aware, TCPDF does not support OpenType variants. Looking at the font declaration file for freesans for example, the pnum variant glyphs are not even included in the character width array.

但是,您可以做的是使用字体伪造将变体字形复制到Unicode范围中,并在要使用它们的上下文中映射字符.例如,如果您不使用下标数字字形,那么它们是很好的候选者,因为搜索似乎仍然可以在我测试的多个PDF阅读器中找到它们.

However, what you can do is copy the variant glyphs into the Unicode range with font forge and map the characters in the contexts you want to use them. For instance, if you're not using the subscript numeral glyphs, they make good candidates as search appears to still find them in several of the PDF readers I tested.

为了让我可以进行测试,我运行了一个相似场景:使用Free Sans,但希望在某些地方使用比例字体和相同的字体文件.我使用FontForge打开了Free Sans字体,查看了字形信息,以了解哪些字形可用于零字形,然后使用它来查找pnum字形集,然后将其复制到下标图形上. (u2080-u2089)范围是任意的,因此,如果您使用这些字形,则可以使用例如私有使用范围,尽管它会破坏可搜索性,而无需采取任何额外步骤.

Just so I could have something to test, I ran a similar scenario: using Free Sans but wanting to use proportional figures in some places with the same font file. I opened the Free Sans font with FontForge, looked at the glyph info to see which variants were available for the zero glyph, used that to find the set of pnum glyphs, and then copied them over the subscript figures. (u2080 - u2089) The range is arbitrary, so if you're using these glyphs, there's the private use range for instance, though that destroys searchability without some extra steps.

然后在TCPDF中,只需对我想影响的字母数字字符串运行一个字符串替换.

Then in TCPDF, simply ran a string replace on the alphanumeric strings I wanted to affect.

$pdf->writeHTMLCell(0, 0, '', '', '<span style="font-family: freesansmod">H90173A8301X5</span>', 0, 1, 0, true, '', true);

//I feel like there's a shorter way to write this...
$special_numbers = str_replace(['0','1','2','3','4','5','6','7','8','9'],
    ["\u{2080}", "\u{2081}", "\u{2082}", "\u{2083}",
         "\u{2084}", "\u{2085}", "\u{2086}", "\u{2087}",
         "\u{2088}", "\u{2089}"], 'H90173A8301X5');

$pdf->writeHTMLCell(0, 0, '', '', '<span style="font-family: freesansmod">'.$special_numbers.'</span>', 0, 1, 0, true, '', true);

尽管复制粘贴有点怪异,但结果仍可搜索. [注意:那是关闭的,因为我想看看是否可以对字形位置进行调整.]

The result is still searchable, though copy-and-paste is a bit weird. [Note: The one is off because I wanted to see if I could make adjustments to glyph positioning.]

回到您的特定情况,如果您愿意放宽相同字体"的要求,则可以选择创建一个单独的派生字体,并使用变体字形覆盖标准数字,并在需要时切换为标准数字. .我没有搜索过,但是可能已有一些可以自动为您完成此操作的工具.内容将完全保留其语义,并且代码可能会更简洁一些,但要以有效地嵌入相同字体的两个副本为代价.

Back to your specific case, an alternative if you're willing to relax the "same font" requirement would be to create a separate derivative font with the variant glyphs overwriting the standard numerals and switching to it in the cases you want them. I haven't searched, but there may be pre-existing tools that can automatically do this for you. The content would fully retain its semantic meaning, and the code may be a bit cleaner, at the cost of embedding effectively two copies of the same font.

这篇关于我可以使用“旧式"广告素材吗? (非衬)数字在TCPDF中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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