fontforge EnvironmentError:无法加载图像文件

时间:2014-07-02 15:38:52

标签: python svg webfonts centos6 fontforge

我正在尝试从单个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

OS

$ 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版

$ python --version Python 2.7.7

Fontforge版本

$ 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


P.S。在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

1 个答案:

答案 0 :(得分: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切换中出现了一个错误,只需查看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 );
}