fontforge 环境错误:无法加载图像文件

0 投票
1 回答
647 浏览
提问于 2025-04-18 11:53

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

$ 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


附注:在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

我也遇到同样的问题。

在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 );
}

撰写回答