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

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

问题描述

我想创建带有大量字形的字体.想想日文汉字,成千上万.因此,肯定会需要一些脚本/批处理.幸运的是,FontForge支持python脚本!不幸的是,我无法使其正常运行. [sadface]

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]

首先,感谢用户 Hoff 发布代码

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

更新:

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

这是霍夫的代码:

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

昨天经过五个小时的努力来构建FontForge(在Mac上是一个令人困惑的过程).我似乎已启动并正常运行.首先,我从.dmg安装了预构建版本,只是发现它缺少python支持.但是由于Hoff似乎没有遇到与我相同的错误,因此我没有排除构建问题.

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.

无论哪种方式,我都不了解涉及AGL的错误.什么是AGL? 我查了:"Adob​​e字形列表-标准字形命名约定".听起来像FontForge尝试将Unicode值映射到字形名称,但不能.

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.

那么,为什么AGL NameList有问题? 预先感谢您的帮助.

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

推荐答案

尝试重建Fonforge.因为代码应该工作.我对其进行了测试,并且运行正常.

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

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

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.

设置PYTHONPATH
当然,使用所需的所有标志运行brew install fontforge.
运行brew linkapps

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

以空字体开头,因此字体不是问题:

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

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

包括字形表(不必要) 下载: http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt ,然后:

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
...

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

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

char = font.createChar(65)

字形及其代码点:

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

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

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

无Unicode点的字形可以按名称在字体中引用.并且对于组成新字形的开放式功能部件或构建基块很有用.您可以这样创建它们:

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')

更新2

您应该命名 Adob​​e字形列表使用其AGL字形名称.其余字形应命名为uniXXXX,其中XXXX是Unicode索引.在开发过程中,您可以使用任何可读的名称.因此,请使用您自己的命名并在生成要运输的字体时替换它. 请参阅Typophile .

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天全站免登陆