我想查询类似*nix的系统上可用的字体,理想情况下使用PHP 5.2或5.3,但似乎没有很多库可用于以独立于系统的方式进行.php-font-lib只扫描一个目录(代码,演示),但我希望有更优雅的方法来实现它.(无论如何,扫描文件夹只是任务的一部分;仍然需要打开字体文件来检索名称和其他元数据).
背景:我正在使用Inkscape在Web服务器上呈现PDF,并希望确定可用于呈现文本元素的字体.我正在开发OS 10.6.8并在Linux上进行部署.
编辑:我找到了Pango 的PHP包装器,它是一个经常与Cairo一起使用的高级字体渲染器; 这些都在Inkscape中使用.包装器是新的,所以我还不确定它是否可以生成字体列表 - 但它确实看起来很有趣:).
我刚刚发现了一个跨平台的命令fc-list.适用于OS X 10.6.8和我的Ubuntu VPS,可以很容易地被PHP调用.在我的Linux机器上,我得到了这种格式的列表:
Nimbus Sans L:style=Regular Italic
URW Palladio L:style=Roman
Century Schoolbook L:style=Bold Italic
Nimbus Sans L:style=Bold
URW Chancery L:style=Medium Italic
Nimbus Roman No9 L:style=Regular
Century Schoolbook L:style=Bold
Century Schoolbook L:style=Italic
Nimbus Sans L:style=Regular
URW Palladio L:style=Italic
Nimbus Sans L:style=Bold Condensed
URW Gothic L:style=Demi
Nimbus Roman No9 L:style=Medium Italic
Nimbus Mono L:style=Bold Oblique
Dingbats:style=Regular
...continues...
Run Code Online (Sandbox Code Playgroud)
在Mac上它看起来像这样:
URW Gothic L:style=Book Oblique
Fixed:style=ja
URW Palladio L:style=Bold Italic
Heiti SC,??\-?,??\-?,Heiti\-??,??\-?:style=Light,??,Mager,Fein,Ohut,Fin,Leggero,???,???,Licht,Tynn,Leve,???????,??,Fina
Arial Narrow:style=Bold Italic,Negreta cursiva,tu?né kurzíva,fed kursiv,Fett Kursiv,?????? ??????,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér d?lt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,?????????? ??????,Tu?ná kurzíva,Fet Kursiv,Kal?n ?talik,Krepko poševno,Lodi etzana
Fixed:style=Regular
Helvetica:style=Bold Oblique
Arial:style=Bold,Negreta,tu?né,fed,Fett,??????,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,??????????,Fet,Kal?n,Krepko,??m,Lodia
KufiStandardGK:style=Regular,???,Ordinær,Normal,Normaali,Regolare,?????,???,Regulier,???????,???
Courier:style=Regular,???,Ordinær,Normal,Normaali,Regolare,?????,???,Regulier,???????,???
New Century Schoolbook:style=Italic
Menlo:style=Bold
Luxi Sans:style=Bold Oblique
...
Run Code Online (Sandbox Code Playgroud)
嘿!我做了一个小时左右的搜索,发现没什么令人满意的; 然后就像公共汽车一样,可以找到几个答案.这是另一种方法,来自ImageMagick的convert -list font命令(显然是从convert -list typev6.3.5-7 [ source ] 之前重命名).我认为我更喜欢这个fc-list,因为输出看起来可以解析为YAML.
来自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
...
Run Code Online (Sandbox Code Playgroud)
从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
Run Code Online (Sandbox Code Playgroud)
这也会产生结果,尽管它只是Font:根据convert输出的行得到字体名称:
<?php
$imagick = new Imagick();
$fonts = $imagick->queryFonts();
foreach($fonts as $font)
{
echo $font;
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9236 次 |
| 最近记录: |