Skip to content

Commit

Permalink
Merge pull request #453 from JoesCat/master
Browse files Browse the repository at this point in the history
Fix opening UFO fonts with bad openTypeOS2Type key
  • Loading branch information
vernnobile committed Mar 20, 2013
2 parents ad165ad + c47e8ee commit 95e0d4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
12 changes: 1 addition & 11 deletions fontforge/parsepfa.c
Expand Up @@ -876,18 +876,8 @@ return( ret );
}

static struct fontdict *PSMakeEmptyFont(void) {
struct fontdict *ret;

ret = gcalloc(1,sizeof(struct fontdict));
ret->fontinfo = gcalloc(1,sizeof(struct fontinfo));
ret->chars = gcalloc(1,sizeof(struct pschars));
ret->private = gcalloc(1,sizeof(struct private));
ret->private->subrs = gcalloc(1,sizeof(struct pschars));
ret->private->private = gcalloc(1,sizeof(struct psdict));
ret->private->leniv = 4;
struct fontdict *ret = MakeEmptyFont();
ret->charprocs = gcalloc(1,sizeof(struct charprocs));
ret->encoding_name = &custom;
ret->fontinfo->fstype = -1;
return( ret );
}

Expand Down
29 changes: 18 additions & 11 deletions fontforge/ufo.c
Expand Up @@ -576,7 +576,7 @@ return( false );
PListOutputString(plist,"openTypeOS2VendorID",vendor);
fc[0] = sf->pfminfo.os2_family_class>>8; fc[1] = sf->pfminfo.os2_family_class&0xff;
PListOutputIntArray(plist,"openTypeOS2FamilyClass",fc,2);
{
if ( sf->pfminfo.fstype!=-1 ) {
int fscnt,i;
char fstype[16];
for ( i=fscnt=0; i<16; ++i )
Expand Down Expand Up @@ -1116,7 +1116,7 @@ static SplineChar *_UFOLoadGlyph(xmlDocPtr doc,char *glifname) {
format = xmlGetProp(glyph,(xmlChar *) "format");
if ( xmlStrcmp(glyph->name,(const xmlChar *) "glyph")!=0 ||
(format!=NULL && xmlStrcmp(format,(xmlChar *) "1")!=0)) {
LogError(_("Expected glyph file with format==1\n"));
LogError(_("Expected glyph file with format==1"));
xmlFreeDoc(doc);
free(format);
return( NULL );
Expand Down Expand Up @@ -1377,7 +1377,7 @@ static SplineChar *UFOLoadGlyph(char *glifname) {

doc = xmlParseFile(glifname);
if ( doc==NULL ) {
LogError( _("Bad glif file %s\n" ), glifname);
LogError(_("Bad glif file %s"), glifname);
return( NULL );
}
return( _UFOLoadGlyph(doc,glifname));
Expand All @@ -1395,7 +1395,7 @@ return;
for ( r=sc->layers[ly_fore].refs; r!=NULL; r=r->next ) {
rsc = SFGetChar(sf,-1,(char *) (r->sc));
if ( rsc==NULL ) {
LogError( _("Failed to find glyph %s when fixing up references\n"), (char *) r->sc );
LogError(_("Failed to find glyph %s when fixing up references"), (char *) r->sc);
if ( prev==NULL )
sc->layers[ly_fore].refs = r->next;
else
Expand Down Expand Up @@ -1424,7 +1424,7 @@ static void UFOLoadGlyphs(SplineFont *sf,char *glyphdir) {
doc = xmlParseFile(glyphlist);
free(glyphlist);
if ( doc==NULL ) {
LogError( _("Bad contents.plist\n" ));
LogError(_("Bad contents.plist"));
return;
}
plist = xmlDocGetRootElement(doc);
Expand Down Expand Up @@ -1661,14 +1661,14 @@ SplineFont *SFReadUFO(char *basedir, int flags) {
int as = -1, ds= -1, em= -1;

if ( !libxml_init_base()) {
LogError( _("Can't find libxml2.\n") );
LogError(_("Can't find libxml2."));
return( NULL );
}

glyphdir = buildname(basedir,"glyphs");
glyphlist = buildname(glyphdir,"contents.plist");
if ( !GFileExists(glyphlist)) {
LogError(_("No glyphs directory or no contents file\n") );
LogError(_("No glyphs directory or no contents file"));
free(glyphlist);
return( NULL );
}
Expand Down Expand Up @@ -1774,9 +1774,16 @@ return( NULL );
if ( xmlStrcmp(keyname+11,(xmlChar *) "Panose")==0 ) {
UFOGetByteArray(sf->pfminfo.panose,sizeof(sf->pfminfo.panose),doc,value);
sf->pfminfo.panose_set = true;
} else if ( xmlStrcmp(keyname+11,(xmlChar *) "Type")==0 )
} else if ( xmlStrcmp(keyname+11,(xmlChar *) "Type")==0 ) {
sf->pfminfo.fstype = UFOGetBits(doc,value);
else if ( xmlStrcmp(keyname+11,(xmlChar *) "FamilyClass")==0 ) {
if ( sf->pfminfo.fstype<0 ) {
/* all bits are set, but this is wrong, OpenType spec says */
/* bits 0, 4-7 and 10-15 must be unset, go see */
/* http://www.microsoft.com/typography/otspec/os2.htm#fst */
LogError(_("Bad openTypeOS2type key: all bits are set. It will be ignored"));
sf->pfminfo.fstype = 0;
}
} else if ( xmlStrcmp(keyname+11,(xmlChar *) "FamilyClass")==0 ) {
char fc[2];
UFOGetByteArray(fc,sizeof(fc),doc,value);
sf->pfminfo.os2_family_class = (fc[0]<<8)|fc[1];
Expand Down Expand Up @@ -1913,7 +1920,7 @@ return( NULL );
ds = em-as;
}
if ( em==-1 ) {
LogError( _("This font does not specify unitsPerEm\n") );
LogError(_("This font does not specify unitsPerEm"));
xmlFreeDoc(doc);
setlocale(LC_NUMERIC,oldloc);
SplineFontFree(sf);
Expand Down Expand Up @@ -1993,7 +2000,7 @@ SplineSet *SplinePointListInterpretGlif(char *filename,char *memory, int memlen,
SplineSet *ss;

if ( !libxml_init_base()) {
LogError( _("Can't find libxml2.\n") );
LogError(_("Can't find libxml2."));
return( NULL );
}
if ( filename!=NULL )
Expand Down

0 comments on commit 95e0d4c

Please sign in to comment.