summaryrefslogtreecommitdiff
path: root/fontforge
diff options
context:
space:
mode:
authorpfaedit <pfaedit>2011-02-10 20:58:19 +0000
committerpfaedit <pfaedit>2011-02-10 20:58:19 +0000
commit8163e4b2a1c5111a0832f09ab69cfd8c4b17c03f (patch)
tree3af188dbbe817ede4ddf9e292dee0b3ecaaf19ea /fontforge
parentec0193eea87f1146885da2762744a6f6f1d9bac1 (diff)
My cidmap files have always been a one to one mapping of cid to unicode. But that's not what Adobe does. Many cids get mapped to several code points each. So I've revamped the format to support this. The new map files need the new code (obviously) so don't download one without the other.
Diffstat (limited to 'fontforge')
-rw-r--r--fontforge/encoding.c57
-rw-r--r--fontforge/encoding.h7
-rw-r--r--fontforge/parsettf.c1
-rw-r--r--fontforge/splinefont.c2
-rw-r--r--fontforge/splinefont.h1
-rw-r--r--fontforge/splineutil.c1
-rw-r--r--fontforge/stamp.c6
7 files changed, 61 insertions, 14 deletions
diff --git a/fontforge/encoding.c b/fontforge/encoding.c
index a71a6986..8a9685bf 100644
--- a/fontforge/encoding.c
+++ b/fontforge/encoding.c
@@ -770,9 +770,10 @@ int CID2NameUni(struct cidmap *map,int cid, char *buffer, int len) {
#if defined( _NO_SNPRINTF ) || defined( __VMS )
if ( map==NULL )
sprintf(buffer,"cid-%d", cid);
- else if ( cid<map->namemax && map->name[cid]!=NULL )
+ else if ( cid<map->namemax && map->name[cid]!=NULL ) {
strncpy(buffer,map->name[cid],len);
- else if ( cid==0 || (cid<map->namemax && map->unicode[cid]!=0 )) {
+ buffer[len-1] = '\0';
+ } else if ( cid==0 || (cid<map->namemax && map->unicode[cid]!=0 )) {
if ( map->unicode==NULL || map->namemax==0 )
enc = 0;
else
@@ -785,9 +786,10 @@ int CID2NameUni(struct cidmap *map,int cid, char *buffer, int len) {
#else
if ( map==NULL )
snprintf(buffer,len,"cid-%d", cid);
- else if ( cid<map->namemax && map->name[cid]!=NULL )
+ else if ( cid<map->namemax && map->name[cid]!=NULL ) {
strncpy(buffer,map->name[cid],len);
- else if ( cid==0 )
+ buffer[len-1] = '\0';
+ } else if ( cid==0 )
strcpy(buffer,".notdef");
else if ( cid<map->namemax && map->unicode[cid]!=0 ) {
if ( map->unicode==NULL || map->namemax==0 )
@@ -805,6 +807,7 @@ return( enc );
int NameUni2CID(struct cidmap *map,int uni, const char *name) {
int i;
+ struct cidaltuni *alts;
if ( map==NULL )
return( -1 );
@@ -812,6 +815,9 @@ return( -1 );
for ( i=0; i<map->namemax; ++i )
if ( map->unicode[i]==uni )
return( i );
+ for ( alts=map->alts; alts!=NULL; alts=alts->next )
+ if ( alts->uni==uni )
+return( alts->cid );
} else {
for ( i=0; i<map->namemax; ++i )
if ( map->name[i]!=NULL && strcmp(map->name[i],name)==0 )
@@ -820,6 +826,23 @@ return( i );
return( -1 );
}
+struct altuni *CIDSetAltUnis(struct cidmap *map,int cid) {
+ /* Some CIDs are mapped to several unicode code points, damn it */
+ struct altuni *sofar = NULL, *alt;
+ struct cidaltuni *alts;
+
+ for ( alts=map->alts; alts!=NULL; alts=alts->next ) {
+ if ( alts->cid==cid ) {
+ alt = chunkalloc(sizeof(struct altuni));
+ alt->next = sofar;
+ sofar = alt;
+ alt->unienc = alts->uni;
+ alt->vs = -1;
+ }
+ }
+return( sofar );
+}
+
int MaxCID(struct cidmap *map) {
return( map->cidmax );
}
@@ -910,6 +933,7 @@ static struct cidmap *MakeDummyMap(char *registry,char *ordering,int supplement)
ret->supplement = ret->maxsupple = supplement;
ret->cidmax = ret->namemax = 0;
ret->unicode = NULL; ret->name = NULL;
+ ret->alts = NULL;
ret->next = cidmaps;
cidmaps = ret;
return( ret );
@@ -920,7 +944,7 @@ struct cidmap *LoadMapFromFile(char *file,char *registry,char *ordering,
struct cidmap *ret = galloc(sizeof(struct cidmap));
char *pt = strrchr(file,'.');
FILE *f;
- int cid1, cid2, uni, cnt, i;
+ int cid1, cid2, uni, cnt, i, ch;
char name[100];
while ( pt>file && isdigit(pt[-1]))
@@ -930,19 +954,18 @@ struct cidmap *LoadMapFromFile(char *file,char *registry,char *ordering,
ret->maxsupple = supplement;
ret->registry = copy(registry);
ret->ordering = copy(ordering);
+ ret->alts = NULL;
+ ret->cidmax = ret->namemax = 0;
+ ret->unicode = NULL; ret->name = NULL;
ret->next = cidmaps;
cidmaps = ret;
f = fopen( file,"r" );
if ( f==NULL ) {
ff_post_error(_("Missing cidmap file"),_("Couldn't open cidmap file: %s"), file );
- ret->cidmax = ret->namemax = 0;
- ret->unicode = NULL; ret->name = NULL;
} else if ( fscanf( f, "%d %d", &ret->cidmax, &ret->namemax )!=2 ) {
ff_post_error(_("Bad cidmap file"),_("%s is not a cidmap file, please download\nhttp://fontforge.sourceforge.net/cidmaps.tgz"), file );
fprintf( stderr, _("%s is not a cidmap file, please download\nhttp://fontforge.sourceforge.net/cidmaps.tgz"), file );
- ret->cidmax = ret->namemax = 0;
- ret->unicode = NULL; ret->name = NULL;
} else {
ret->unicode = gcalloc(ret->namemax+1,sizeof(uint32));
ret->name = gcalloc(ret->namemax+1,sizeof(char *));
@@ -957,9 +980,21 @@ struct cidmap *LoadMapFromFile(char *file,char *registry,char *ordering,
for ( i=cid1; i<=cid2; ++i )
ret->unicode[i] = uni++;
} else if ( cnt==1 ) {
- if ( fscanf(f,"%x", (unsigned *) &uni )==1 )
+ if ( fscanf(f,"%x", (unsigned *) &uni )==1 ) {
ret->unicode[cid1] = uni;
- else if ( fscanf(f," /%s", name )==1 )
+ ch = getc(f);
+ while ( ch==',' ) {
+ if ( fscanf(f,"%x", (unsigned *) &uni )==1 ) {
+ struct cidaltuni *alt = chunkalloc(sizeof(struct cidaltuni));
+ alt->next = ret->alts;
+ ret->alts = alt;
+ alt->uni = uni;
+ alt->cid = cid1;
+ }
+ ch = getc(f);
+ }
+ ungetc(ch,f);
+ } else if ( fscanf(f," /%s", name )==1 )
ret->name[cid1] = copy(name);
}
}
diff --git a/fontforge/encoding.h b/fontforge/encoding.h
index c272c6d2..23cc93b8 100644
--- a/fontforge/encoding.h
+++ b/fontforge/encoding.h
@@ -1,6 +1,12 @@
#ifndef _ENCODING_H
#define _ENCODING_H
+struct cidaltuni {
+ struct cidaltuni *next;
+ int uni;
+ int cid;
+};
+
struct cidmap {
char *registry, *ordering;
int supplement, maxsupple;
@@ -8,6 +14,7 @@ struct cidmap {
int namemax; /* Max cid with useful info */
uint32 *unicode;
char **name;
+ struct cidaltuni *alts;
struct cidmap *next;
};
diff --git a/fontforge/parsettf.c b/fontforge/parsettf.c
index 878b9d63..bafd5716 100644
--- a/fontforge/parsettf.c
+++ b/fontforge/parsettf.c
@@ -3848,6 +3848,7 @@ static void cidfigure(struct ttfinfo *info, struct topdicts *dict,
subrs,gsubrs,buffer);
info->chars[i]->vwidth = sf->ascent+sf->descent;
info->chars[i]->unicodeenc = uni;
+ info->chars[i]->altuni = CIDSetAltUnis(map,cid);
sf->glyphs[cid] = info->chars[i];
sf->glyphs[cid]->parent = sf;
sf->glyphs[cid]->orig_pos = cid; /* Bug! should be i, but I assume sf->chars[orig_pos]->orig_pos==orig_pos */
diff --git a/fontforge/splinefont.c b/fontforge/splinefont.c
index 8cba2725..a19e34e3 100644
--- a/fontforge/splinefont.c
+++ b/fontforge/splinefont.c
@@ -193,6 +193,8 @@ return( sc );
sc->name = copy(dummy.name);
sc->width = dummy.width;
sc->orig_pos = 0xffff;
+ if ( sf->cidmaster!=NULL )
+ sc->altuni = CIDSetAltUnis(FindCidMap(sf->cidmaster->cidregistry,sf->cidmaster->ordering,sf->cidmaster->supplement,sf->cidmaster),enc);
/*SCLigDefault(sc);*/
SFAddGlyphAndEncode(sf,sc,map,enc);
}
diff --git a/fontforge/splinefont.h b/fontforge/splinefont.h
index 6e205a70..dee22045 100644
--- a/fontforge/splinefont.h
+++ b/fontforge/splinefont.h
@@ -2809,6 +2809,7 @@ extern int CIDFromName(char *name,SplineFont *cidmaster);
extern int CID2Uni(struct cidmap *map,int cid);
extern int CID2NameUni(struct cidmap *map,int cid, char *buffer, int len);
extern int NameUni2CID(struct cidmap *map,int uni, const char *name);
+extern struct altuni *CIDSetAltUnis(struct cidmap *map,int cid);
extern int MaxCID(struct cidmap *map);
extern struct cidmap *LoadMapFromFile(char *file,char *registry,char *ordering,
int supplement);
diff --git a/fontforge/splineutil.c b/fontforge/splineutil.c
index 682e0993..7cf0bb19 100644
--- a/fontforge/splineutil.c
+++ b/fontforge/splineutil.c
@@ -2898,6 +2898,7 @@ return( NULL );
chars[i]->vwidth = sf->subfonts[j]->ascent+sf->subfonts[j]->descent;
chars[i]->unicodeenc = uni;
chars[i]->orig_pos = i;
+ chars[i]->altuni = CIDSetAltUnis(map,i);
/* There better not be any references (seac's) because we have no */
/* encoding on which to base any fixups */
if ( chars[i]->layers[ly_fore].refs!=NULL )
diff --git a/fontforge/stamp.c b/fontforge/stamp.c
index 52312b45..4b0203b5 100644
--- a/fontforge/stamp.c
+++ b/fontforge/stamp.c
@@ -1,5 +1,5 @@
#include <time.h>
-const time_t source_modtime = 1295902918L;
-const char *source_modtime_str = "21:01 GMT 24-Jan-2011";
-const char *source_version_str = "20110124";
+const time_t source_modtime = 1297295727L;
+const char *source_modtime_str = "23:55 GMT 9-Feb-2011";
+const char *source_version_str = "20110209";