在 imagettftext() 之前映射字符?
我正在建立一个带有字体预览的免费字体网站。 imagettftext() 生成的许多字体字符都带有方框,因为它们没有映射。
我查看 dafont.com 这样的网站,它们的所有字体预览都正确。我非常怀疑他们是否会检查每种字体并确保使用正确的字符。
所以我的问题是,是否有 PHP 脚本或函数可以执行此操作:
1)打开 ttf 文件并根据字符串查找映射字符。例如:我想将名称“foobar”作为文本传递给 imagettftext(),但如果字体 foobar 只映射大写字符,我必须将 FOOBAR 传递给 imagettftext()。
2) 如果返回的字符串中的任何字符未映射到字体中,则找到下一个映射的字符并将其替换为该字符。
基本上,我试图避免所有未映射的字体框出现在我的网站上。
谢谢大家!
I'm building a free font website with font previews. Many of the font characters generated by imagettftext() are coming up with square boxes because they are not mapped.
I look at a site like dafont.com, and all of their fonts preview correctly. I highly doubt they are going though each font and making sure the right characters are being used.
So the question I have is, is there a PHP script or function that can do this:
1) open a ttf file and find mapped characters based on a string. EX: I want to pass the name 'foobar' to imagettftext() as the text, but if the font foobar only maps uppercase characters, I would have to pass FOOBAR to imagettftext().
2) if any character in the returned string is not mapped in the font, find the next mapped character and replace it with that.
Basically, I'm trying to avoid all unmapped font boxes from appearing on my site.
Thanks everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经使用 dafont.com 中的几种字体进行了测试。使用
imagettftext
,未映射的字符通常显示为空白(无)。例如,我尝试通过输入˰
来访问字体边界之外的字符。然而,即使在 dafont.com 上,也有一些字体包含这些方块; 例如此花卉装饰字体或此 4yeo Sport 字体。我的猜测是这些基本字符是强制性的,因此被替换为空框。
我个人对 dingbats 和文本字体的建议是:
Dingbats:显示 dingbats 字体的静态文本。这就是 dafont.com 所做的,无论您如何更改示例文本,字体示例将保持不变,因此除非您单击查看映射详细信息,否则您永远不会看到这些框。
文本字体:如果您确定该字体包含标准英文字母,请为每个文本打印“The Quick Brown Fox Jumps over the Lazy Dog”字体。它将让用户了解字母表中每个字母的设计。
I have tested with several fonts from dafont.com. Unmapped characters usually show up as blank (nothing) using
imagettftext
. I tried to access characters outside the bounds of a font by entering˰
for example. However, even on dafont.com, there are some fonts that have those squares in them; for example this Flower Ornaments font or this 4yeo Sport font.My guess is that those basic characters are mandatory and thus are replaced with an empty box.
My personal suggestions for dingbats and text fonts are:
Dingbats: Display a static text for dingbats fonts. This is what dafont.com does, no matter how much you change the sample text, the font sample will remain the same and thus you will never see those boxes unless you click to see the mapping details.
Text fonts: If you are certain that the font has standard English alphabet in it, print out "The quick brown fox jumps over the lazy dog" for every text font. It will give the user an idea of the design of every letter in the alphabet.