在PHP中列出可用的字体 [英] Listing available fonts in PHP

查看:172
本文介绍了在PHP中列出可用的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询类似nix的系统上可用的字体,理想情况下使用PHP 5.2或5.3,但似乎没有多少库可以以独立于系统的方式进行操作。 php-font-lib 只是扫描目录( code demo ),但我希望有一个更优雅的方式来做到这一点。 (在任何情况下,扫描一个文件夹只是任务的一部分,字体文件仍然需要打开来检索名称和其他元数据)。

背景:我正在渲染使用Inkscape的Web服务器上的PDF,并且想要确定什么字体可用于呈现文本元素。我正在开发OS 10.6.8并在Linux上部署。



编辑:我找到了 Pango的PHP wrapper ,这是一个经常和Cairo一起使用的高级字体渲染器。这两个都用在Inkscape中。包装是相当新的,所以我不确定是否可以产生一个字体列表 - 但它看起来很有趣:)

解决方案

嘿!我做了一个小时左右的搜索,找不到任何满意的东西;然后像巴士一样,找到了几个答案。下面是另一种方法,从ImageMagick的 convert -list font 命令(显然是从 convert -list type 在v6.3.5之前重命名-7 [])。我想我更喜欢 fc-list ,因为输出看起来像可以被解析为YAML。



从Linux开始:

 路径:/usr/lib/ImageMagick-6.5.7/config/type-ghostscript.xml 
字体:AvantGarde-Book
系列:AvantGarde
风格:普通
拉伸:正常
重量:400
字形:/ usr / share / fonts / type1 / gsfonts /a010013l.pfb
字体:AvantGarde-BookOblique
系列:AvantGarde
风格:倾斜
拉伸:正常
重量:400
字形:/ usr / share / fonts / type1 / gsfonts / a010033l.pfb
...

Mac:

 路径:/opt/local/etc/ImageMagick/type-ghostscript.xml 
字体:AvantGarde-预订
系列:AvantGarde
风格:普通
拉伸:正常
重量:400
字形:/ opt / local / share / fonts / urw-fonts / a010013l。 pfb
字体:AvantGarde-BookOblique
系列:AvantGarde
风格:倾斜
拉伸:正常
重量:400
字形:/ opt / local / share / fonts /urw-fonts/a010033l.pfb
...
路径:系统字体
字体:.Aqua-Kana-Bold
系列:.Aqua Kana
风格:正常
拉伸:正常
重量:600
字形:/System/Library/Fonts/AquaKana.ttc
字体:.Aqua-Kana-Regular
系列:。 Aqua Kana
style:Normal
stretch:Normal
weight:300
glyphs:/System/Library/Fonts/AquaKana.ttc


I'd like to query what fonts are available on a *nix-like system, ideally using PHP 5.2 or 5.3, but there doesn't seem to be many libraries available to do it in a system-independent way. php-font-lib just scans a directory (code, demo) but I'd hope there is a more elegant way to do it. (In any case, scanning a folder is only part of the task; font files still need to be opened to retrieve name and other metadata).

Background: I am rendering PDFs on a webserver using Inkscape, and would like to determine what fonts are available to render text elements. I'm developing on OS 10.6.8 and deploying on Linux.

Edit: I've found a PHP wrapper for Pango, which is an advanced font renderer often used with Cairo; both of these are used in Inkscape. The wrapper is quite new, so I am not yet sure whether it can produce a font listing - but it does look interesting :).

解决方案

Heh! I do an hour or so of searching, and find nothing satisfying; then like buses, several answers are found at once. Here's another method, from ImageMagick's convert -list font command (apparently renamed from convert -list type prior to v6.3.5-7 [source]). I think I prefer this over fc-list, as the output looks like it could be parsed as YAML.

From Linux:

Path: /usr/lib/ImageMagick-6.5.7/config/type-ghostscript.xml
    Font: AvantGarde-Book
        family: AvantGarde
        style: Normal
        stretch: Normal
        weight: 400
        glyphs: /usr/share/fonts/type1/gsfonts/a010013l.pfb
    Font: AvantGarde-BookOblique
        family: AvantGarde
        style: Oblique
        stretch: Normal
        weight: 400
        glyphs: /usr/share/fonts/type1/gsfonts/a010033l.pfb
...

And from the Mac:

Path: /opt/local/etc/ImageMagick/type-ghostscript.xml
    Font: AvantGarde-Book
        family: AvantGarde
        style: Normal
        stretch: Normal
        weight: 400
        glyphs: /opt/local/share/fonts/urw-fonts/a010013l.pfb
    Font: AvantGarde-BookOblique
        family: AvantGarde
        style: Oblique
        stretch: Normal
        weight: 400
        glyphs: /opt/local/share/fonts/urw-fonts/a010033l.pfb
...
Path: System Fonts
    Font: .Aqua-Kana-Bold
        family: .Aqua Kana
        style: Normal
        stretch: Normal
        weight: 600
        glyphs: /System/Library/Fonts/AquaKana.ttc
    Font: .Aqua-Kana-Regular
        family: .Aqua Kana
        style: Normal
        stretch: Normal
        weight: 300
        glyphs: /System/Library/Fonts/AquaKana.ttc

这篇关于在PHP中列出可用的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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