0

我正在尝试从单个 SVG 文件创建字体。这里的示例:

#!/usr/local/bin/fontforge
# file test.py

import fontforge;

font=fontforge.font();
glyph = font.createChar(65);
glyph.importOutlines("/home/user/guitar.svg");
# or glyph.importOutlines("~/guitar.svg");
# or glyph.importOutlines("./guitar.svg");
# or glyph.importOutlines("guitar.svg");

任何加载单个 SVG 文件的尝试都会导致相同的错误:

Traceback (most recent call last):
    File "test.py", line 8, in <module>
    glyph.importOutlines("/home/user/guitar.svg");

我哪里错了?


环境:

档案权

ls -la /home/user/guitar.svg -rwxrwxrwx 1 user user 3728 Jun 30 20:46 guitar.svg

操作系统

$ uname -a Linux servername 2.6.32-431.11.2.el6.i686 #1 SMP Tue Mar 25 17:17:46 UTC 2014 i686 i686 i386 GNU/Linux

$ cat /etc/centos-release CentOS release 6.5 (Final)

蟒蛇版本

$ python --version Python 2.7.7

字体版本

$ fontforge --version Copyright (c) 2000-2012 by George Williams. Executable based on sources from 14:57 GMT 31-Jul-2012-TtfDb. Library based on sources from 14:57 GMT 31-Jul-2012. fontforge 20120731 libfontforge 11524617


PS 同样的测试在 Ubuntu 12.04 上是可以的,但是 fontforge 是其他版本

$ fontforge --version Copyright (c) 2000-2011 by George Williams. Executable based on sources from 13:48 GMT 22-Feb-2011-ML. Library based on sources from 13:48 GMT 22-Feb-2011. fontforge 20110222 libfontforge 20110222-ML

4

1 回答 1

0

遇到同样的问题。

在 fontforge 源文件Python.c中,加载图像的代码是

    GImage *image = GImageRead(locfilename);
    int ly = ((PyFF_Glyph *) self)->layer;
    if ( image==NULL ) {
        PyErr_Format(PyExc_EnvironmentError, "Could not load image file %s", locfilename );
return(NULL);
    }

然后 SVG 的 switch 有一个错误,只需往里看,GImageReader.c然后尝试找到 SVG :)

GImage *GImageRead(char * filename) {
    char *pt;

    if ( filename==NULL )
return( NULL );

    pt = strrchr(filename,'.');
    if ( pt==NULL )
    pt = "";
    if ( strmatch(pt,".bmp")==0 )
return( GImageReadBmp(filename));
    else if ( strmatch(pt,".xbm")==0 )
return( GImageReadXbm(filename));
    else if ( strmatch(pt,".xpm")==0 )
return( GImageReadXpm(filename));
#ifndef _NO_LIBTIFF
    else if ( strmatch(pt,".tiff")==0 || strmatch(pt,".tif")==0 )
return( GImageReadTiff(filename));
#endif
#ifndef _NO_LIBJPEG
    else if ( strmatch(pt,".jpeg")==0 || strmatch(pt,".jpg")==0 )
return( GImageReadJpeg(filename));
#endif
#ifndef _NO_LIBPNG
    else if ( strmatch(pt,".png")==0 )
return( GImageReadPng(filename));
#endif
#ifndef _NO_LIBUNGIF
    else if ( strmatch(pt,".gif")==0 )
return( GImageReadGif(filename));
#endif
    else if ( strmatch(pt,".ras")==0 )
return( GImageReadRas(filename));       /* Sun raster */
    else if ( strmatch(pt,".rgb")==0 )
return( GImageReadRgb(filename));       /* SGI format */

return( NULL );
}
于 2014-07-16T13:34:43.463 回答