将一系列 .svg 文件作为字形导入 FontForge 并输出字体文件 [英] Import a sequence of .svg files into FontForge as glyphs and output a font file

查看:60
本文介绍了将一系列 .svg 文件作为字形导入 FontForge 并输出字体文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个包含大量字形的字体.想想数以千计的日本汉字.所以肯定需要一些脚本/批处理.幸运的是 FontForge 支持 python 脚本!不幸的是,我一直无法让它工作.[悲伤]

首先,感谢用户 Hoff 发布代码 这里 回答了我的大部分问题.但是在运行他的脚本时,我遇到了一些问题,这些问题引发了更多问题:

未能找到 NameList: AGL For New Fonts警告:字体不包含字形

更新:

  • 字体不包含字形"错误显然是 FontForge 中的一个错误,当字体包含一个或更少字形时会出现该错误.添加第二个字形B"解决了这个问题.
  • 我发现无论是保存 .ttf .sfd .otf 等,都可以使用相同的语法
  • NameList 失败实际上并不会阻止写入字体文件.我很高兴发现这一点,但仍然不明白如何提供它想要的 NameList.

这是霍夫的代码:

import fontforgefont = fontforge.open('blank.sfd')glyph = font.createMappedChar('A')glyph.importOutlines('sourceimg.svg')font.generate('testfont.ttf')

昨天在构建 FontForge(Mac 上的一个令人困惑的过程)方面苦苦挣扎了五个小时之后.我似乎已经启动并正常运行.我最初从 .dmg 安装了一个预构建的版本,却发现它缺乏 python 支持.但由于 Hoff 似乎没有遇到与我相同的错误,因此我不排除构建问题.

无论如何,我不明白涉及 AGL 的错误.什么是 AGL?我查了一下:Adobe 字形列表 - 标准字形命名约定".听起来 FontForge 试图将 Unicode 值映射到字形名称,但不能.

那么,为什么 AGL NameList 会出现问题?在此先感谢您的帮助.

解决方案

尝试重建您的 Fonforge.因为代码应该可以工作.我测试了它,它运行良好.

我使用 Homebrew 成功安装了带有 Python 扩展的 Fontforge.这是信息:

<块引用>

allcaps$ brew info fontforgefontforge: 稳定 20120731, HEADhttp://fontforge.org//usr/local/Cellar/fontforge/20120731(377 个文件,16M)*从源代码构建:--with-x来自:https://github.com/Homebrew/homebrew/commits/master/Library/Formula/fontforge.rb==>依赖关系必需:gettext ✘,fontconfig ✔推荐:jpeg ✔、libtiff ✔可选:cairo ✔、pango ✘、libspiro ✘、czmq ✘==>选项--with-开罗在开罗的支持下构建--with-czmq使用 czmq 支持构建--with-gif使用 GIF 支持构建--with-libspiro使用 libspiro 支持构建--with-pango使用 pango 支持构建--with-x使用 X11 支持构建,包括 FontForge.app--没有-jpeg在不支持 jpeg 的情况下构建--没有-libpng在不支持 libpng 的情况下构建--没有-libtiff在没有 libtiff 支持的情况下构建--没有-蟒蛇无需python支持即可构建- 头安装 HEAD 版本==>注意事项如果您需要 Python 来查找已安装的站点包,请设置 PYTHONPATH:导出 PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH.app 包已安装.运行 `brew linkapps` 将这些符号链接到/Applications.

设置PYTHONPATH
运行 brew install fontforge 当然带有你需要的所有标志.
运行 brew linkapps

更新

从一个空字体开始,这样字体就不是问题:

import fontforgefont = fontforge.font() # 创建一个新字体

包含字形列表(应该不是必需的)下载:http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt 然后:

import fontforgefontforge.loadNamelist('glyphlist.txt') # 加载一个名字列表...

按代码点创建字形.createChar(uni[,name]) 'A' 是 65 所以

char = font.createChar(65)

字形及其代码点:

<预><代码>>>>for c in u'ABC贤治':print ord(c).>>>65、66、67、32、36066、27835.

Unicode 联盟定义了 Unicode 标准.CJK 统一表意文字"存在于基本多语言平面 (BMP)"中.

可以在字体中按名称引用没有 Unicode 点的字形.并且对于开放类型特征或构建块来组成新字形很有用.您可以像这样创建它们:

font.createChar(-1, 'some_name')

更新 2

您应该命名出现在 Adobe 字形列表 按他们的 AGL 字形名称.其余的字形应命名为 uniXXXX,其中 XXXX 是 Unicode 索引.在开发过程中,您可以使用任何人类可读的名称.因此,在生成用于交付的字体时,请使用您自己的命名并替换它.参见 Typophile.

I want to create a font with a large volume of glyphs. Think Japanese kanji, in the thousands. So there will definitely be some scripting / batch processing required. Luckily FontForge supports python scripting! Unluckily I haven't been able to get it working. [sadface]

Firstly, thanks to the user Hoff for posting code here that answered a big part of my question. But upon running his script I encounter problems which raise more questions:

Failed to find NameList: AGL For New Fonts
Warning: Font contained no glyphs

Updates:

  • The "font contained no glyphs" error is apparently a bug in FontForge that occurs when the font contains one or less glyph. Adding a second glyph 'B' resolved this.
  • I found the same syntax can be used whether saving .ttf .sfd .otf etc.
  • The NameList failure actually doesn't prevent the font file from being written. I was happy to discover this, but still don't understand how to provide the NameList it wants.

Here is Hoff's code:

import fontforge
font = fontforge.open('blank.sfd')
glyph = font.createMappedChar('A')
glyph.importOutlines('sourceimg.svg')
font.generate('testfont.ttf')

After five hours of struggling yesterday with building FontForge (a confusing process on a Mac). I appear to have it up and running properly. I had at first installed a pre-built version from a .dmg only to find it lacked python support. But since Hoff seemed not to encounter the same error I did, I'm not ruling out a build issue.

Either way, I don't understand the error involving AGL. What is AGL? I looked it up: "Adobe Glyph List - a standard glyph naming convention". Sounds like FontForge tried to map Unicode values to glyph names and couldn't.

So, why the AGL NameList problem? Thanks in advance for any help.

解决方案

Try to rebuild your Fonforge. Because the code should work. I tested it and it runs fine.

I successfully installed Fontforge with Python extension with Homebrew. This is the info:

allcaps$ brew info fontforge
fontforge: stable 20120731, HEAD
http://fontforge.org/
/usr/local/Cellar/fontforge/20120731 (377 files, 16M) *
  Built from source with: --with-x
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/fontforge.rb
==> Dependencies
Required: gettext ✘, fontconfig ✔
Recommended: jpeg ✔, libtiff ✔
Optional: cairo ✔, pango ✘, libspiro ✘, czmq ✘
==> Options
--with-cairo
  Build with cairo support
--with-czmq
  Build with czmq support
--with-gif
  Build with GIF support
--with-libspiro
  Build with libspiro support
--with-pango
  Build with pango support
--with-x
  Build with X11 support, including FontForge.app
--without-jpeg
  Build without jpeg support
--without-libpng
  Build without libpng support
--without-libtiff
  Build without libtiff support
--without-python
  Build without python support
--HEAD
  install HEAD version
==> Caveats
Set PYTHONPATH if you need Python to find the installed site-packages:
  export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

.app bundles were installed.
Run `brew linkapps` to symlink these to /Applications.

Set PYTHONPATH
Run brew install fontforge of course with all flags you need.
Run brew linkapps

UPDATE

Start with a empty font so the font isn't the problem:

import fontforge
font = fontforge.font() # create a new font

To include a glyphlist (shouldn't be necessary) Download: http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt and then:

import fontforge
fontforge.loadNamelist('glyphlist.txt') # load a name list
...

Create the glyph by code point. createChar(uni[,name]) 'A' is 65 so

char = font.createChar(65)

Glyphs and their code points:

>>> for c in u'ABC 賢治':  print ord(c). 
>>> 65, 66, 67, 32, 36066, 27835. 

The Unicode Consortium defines the Unicode standard. The 'CJK Unified Ideographs' live in 'Basic Multilingual Plane (BMP)'.

Glyphs without a unicode point can be referenced within a font by name. And are useful for open type features or building blocks to compose new glyphs. You can create them like this:

font.createChar(-1, 'some_name')

UPDATE 2

You should name all glyphs that occur in the Adobe Glyph List by their AGL glyph name. The rest of the glyphs should be named uniXXXX where XXXX is the Unicode index. During development you can use any human readable name. So use your own naming and replace it when you generate the font for shipping. See Typophile.

这篇关于将一系列 .svg 文件作为字形导入 FontForge 并输出字体文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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