Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #505 from JoesCat/UnicodeLib_NativeScripting

Unicode lib native scripting
  • Loading branch information...
commit 6898821538eecb95d738a82811524ef879ee7094 2 parents 23d9169 + 85ca014
@mskala mskala authored
Showing with 79 additions and 26 deletions.
  1. +67 −26 fontforge/scripting.c
  2. +12 −0 htdocs/scripting-alpha.html
View
93 fontforge/scripting.c
@@ -77,7 +77,7 @@ struct keywords { enum token_type tok; char *name; } keywords[] = {
};
static const char *toknames[] = {
- "name", "string", "number", "unicode id", "real number",
+ "name", "string", "number", "unicode id", "real number",
"lparen", "rparen", "comma", "end of ff_statement",
"lbracket", "rbracket",
"minus", "plus", "logical not", "bitwise not", "colon",
@@ -333,7 +333,7 @@ void ScriptErrorF( Context *c, const char *format, ... ) {
va_start(ap,format);
vsnprintf(errbuf,sizeof(errbuf),format,ap);
va_end(ap);
-
+
if ( verbose>0 )
fflush(stdout);
if (c->interactive)
@@ -1065,7 +1065,7 @@ static void bNameFromUnicode(Context *c) {
char buffer[400];
int uniinterp;
NameList *for_new_glyphs;
-
+
if ( c->a.argc!=2 && c->a.argc!=3 )
ScriptError( c, "Wrong number of arguments" );
else if ( c->a.vals[1].type!=v_int && c->a.vals[1].type!=v_unicode )
@@ -1085,11 +1085,50 @@ static void bNameFromUnicode(Context *c) {
uniinterp = c->curfv->sf->uni_interp;
for_new_glyphs = c->curfv->sf->for_new_glyphs;
}
-
+
c->return_val.type = v_str;
c->return_val.u.sval = copy(StdGlyphName(buffer,c->a.vals[1].u.ival,uniinterp,for_new_glyphs));
}
+static void bUnicodeNameFromLib(Context *c) {
+/* If the library is available, then get the official name for this unicode value */
+ char *temp;
+
+ if ( c->a.argc!=2 )
+ ScriptError( c, "Wrong number of arguments" );
+ else if ( c->a.vals[1].type!=v_int && c->a.vals[1].type!=v_unicode )
+ ScriptError( c, "Bad type for argument" );
+ c->return_val.type = v_str;
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ temp = NULL;
+#else
+ temp = unicode_name(c->a.vals[1].u.ival);
+#endif
+ if ( temp==NULL ) {
+ temp = galloc(1*sizeof(char)); temp = '\0';
+ }
+ c->return_val.u.sval = temp;
+}
+
+static void bUnicodeAnnotationFromLib(Context *c) {
+ char *temp;
+
+ if ( c->a.argc!=2 )
+ ScriptError( c, "Wrong number of arguments" );
+ else if ( c->a.vals[1].type!=v_int && c->a.vals[1].type!=v_unicode )
+ ScriptError( c, "Bad type for argument" );
+ c->return_val.type = v_str;
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ temp = NULL;
+#else
+ temp = unicode_annot(c->a.vals[1].u.ival);
+#endif
+ if ( temp==NULL ) {
+ temp = galloc(1*sizeof(char)); temp = '\0';
+ }
+ c->return_val.u.sval = temp;
+}
+
static void bChr(Context *c) {
char buf[2];
char *temp;
@@ -1790,12 +1829,12 @@ static void bSave(Context *c) {
ScriptError(c,"The second argument to Save() must be a number of revisions to keep (integer)");
localRevisionsToRetain = c->a.vals[2].u.ival;
}
-
+
if ( c->a.argc>=2 )
{
if ( c->a.vals[1].type!=v_str )
ScriptError(c,"If an argument is given to Save it must be a filename");
-
+
t = script2utf8_copy(c->a.vals[1].u.sval);
locfilename = utf82def_copy(t);
#ifdef VMS
@@ -1813,7 +1852,7 @@ static void bSave(Context *c) {
localRevisionsToRetain );
if ( !rc )
ScriptError(c,"Save failed" );
-
+
/* Hmmm. We don't set the filename, nor the save_to_dir bit */
free(t); free(locfilename);
}
@@ -2349,7 +2388,7 @@ static void bPrintSetup(Context *c) {
}
if ( c->a.vals[1].u.ival<0 || c->a.vals[1].u.ival>5 )
ScriptError( c, "First argument out of range [0,5]");
-
+
printtype = c->a.vals[1].u.ival;
if ( c->a.argc>=3 && printtype==4 )
printcommand = copy(c->a.vals[2].u.sval);
@@ -2375,7 +2414,7 @@ static void bPrintFont(Context *c) {
}
if ( c->a.argc>=3 ) {
if ( c->a.vals[2].type==v_int ) {
- if ( c->a.vals[2].u.ival>0 ) {
+ if ( c->a.vals[2].u.ival>0 ) {
pointsizes = gcalloc(2,sizeof(int32));
pointsizes[0] = c->a.vals[2].u.ival;
}
@@ -3101,7 +3140,7 @@ static void bRemoveDetachedGlyphs(Context *c) {
for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( sf->glyphs[gid]!=NULL )
sf->glyphs[gid]->ticked = false;
-
+
for ( i=0; i<map->enccount; ++i ) if ( (gid=map->map[i])!=-1 )
sf->glyphs[gid]->ticked = true;
@@ -3318,7 +3357,7 @@ static void bSetGasp(Context *c) {
base = 0;
} else if ( (c->a.argc&1)==0 )
ScriptError( c, "Wrong number of arguments");
- else {
+ else {
arr = &c->a;
base = 1;
}
@@ -3840,7 +3879,7 @@ static void bGetFontBoundingBox(Context *c) {
c->return_val.u.aval->vals[2].u.fval = b.maxx;
c->return_val.u.aval->vals[3].u.fval = b.maxy;
}
-
+
static void bSetUniqueID(Context *c) {
if ( c->a.argc!=2 )
@@ -3867,7 +3906,7 @@ static void bGetTeXParam(Context *c) {
else
c->return_val.u.ival = sf->texdata.params[c->a.vals[1].u.ival];
}
-
+
static void bSetTeXParams(Context *c) {
int i;
@@ -4137,7 +4176,7 @@ return( true );
}
return( false );
}
-
+
static void FVApplySubstitution(FontViewBase *fv,uint32 script, uint32 lang, uint32 feat_tag) {
SplineFont *sf = fv->sf, *sf_sl=sf;
SplineChar *sc, *replacement, *sc2;
@@ -5631,7 +5670,7 @@ static void bClearTable(Context *c) {
static void bAddDHint( Context *c ) {
int i, any, gid;
BasePoint left, right, unit;
- real args[6];
+ real args[6];
double len, width;
FontViewBase *fv = c->curfv;
SplineFont *sf = fv->sf;
@@ -5978,7 +6017,7 @@ static void bAutoKern(Context *c) {
sub = SFFindLookupSubtable(c->curfv->sf,c->a.vals[3].u.sval);
if ( sub==NULL )
ScriptErrorString(c,"Unknown lookup subtable",c->a.vals[3].u.sval);
-
+
if ( !AutoKernScript(c->curfv,c->a.vals[1].u.ival,c->a.vals[2].u.ival,
sub,c->a.argc==5?c->a.vals[4].u.sval:NULL) )
ScriptError(c,"No characters selected.");
@@ -6315,7 +6354,7 @@ static void bCIDChangeSubFont(Context *c) {
static void bCIDSetFontNames(Context *c) {
SplineFont *sf = c->curfv->sf;
-
+
if ( sf->cidmaster==NULL )
ScriptErrorString( c, "Not a cid-keyed font", sf->fontname );
_SetFontNames(c,sf->cidmaster);
@@ -6323,26 +6362,26 @@ static void bCIDSetFontNames(Context *c) {
static void bCIDFlatten(Context *c) {
SplineFont *sf = c->curfv->sf;
-
+
if ( sf->cidmaster==NULL )
ScriptErrorString( c, "Not a cid-keyed font", sf->fontname );
else if ( c->a.argc!=1 )
ScriptError( c, "Wrong number of arguments");
-
+
SFFlatten(sf->cidmaster);
}
static void bCIDFlattenByCMap(Context *c) {
SplineFont *sf = c->curfv->sf;
char *t; char *locfilename;
-
+
if ( sf->cidmaster==NULL )
ScriptErrorString( c, "Not a cid-keyed font", sf->fontname );
else if ( c->a.argc!=2 )
ScriptError( c, "Wrong number of arguments");
else if ( c->a.vals[1].type!=v_str )
ScriptError( c, "Argument must be a filename");
-
+
t = script2utf8_copy(c->a.vals[1].u.sval);
locfilename = utf82def_copy(t);
if ( !SFFlattenByCMap(sf,locfilename))
@@ -6962,7 +7001,7 @@ static void bSetFeatureList(Context *c) {
if ( c->a.argc!=3 )
ScriptError( c, "Wrong number of arguments");
- else if ( c->a.vals[1].type!=v_str ||
+ else if ( c->a.vals[1].type!=v_str ||
(c->a.vals[2].type!=v_arr && c->a.vals[2].type!=v_arrfree))
ScriptError( c, "Bad type for argument");
@@ -7447,7 +7486,7 @@ static void FigureProfile(Context *c,SplineChar *sc,int pos,int xextrema) {
val[l] = val[i];
val[i] = temp;
}
-
+
c->return_val.type = v_arrfree;
c->return_val.u.aval = galloc(sizeof(Array));
c->return_val.u.aval->argc = j;
@@ -7650,7 +7689,7 @@ static void bGetAnchorPoints(Context *c) {
sc = GetOneSelChar(c);
- for ( ap=sc->anchor, cnt=0; ap!=NULL; ap=ap->next, ++cnt )
+ for ( ap=sc->anchor, cnt=0; ap!=NULL; ap=ap->next, ++cnt )
;
ret = galloc(sizeof(Array));
ret->argc = cnt;
@@ -8080,6 +8119,8 @@ static struct builtins { char *name; void (*func)(Context *); int nofontok; } bu
{ "GetEnv", bGetEnv, 1 },
{ "UnicodeFromName", bUnicodeFromName, 1 },
{ "NameFromUnicode", bNameFromUnicode, 1 },
+ { "UnicodeNameFromLib", bUnicodeNameFromLib, 1 },
+ { "UnicodeAnnotationFromLib", bUnicodeAnnotationFromLib, 1 },
{ "Chr", bChr, 1 },
{ "Ord", bOrd, 1 },
{ "Real", bReal, 1 },
@@ -9006,7 +9047,7 @@ static void handlename(Context *c,Val *val) {
else sf = FontViewFirst()->sf;
} else {
if ( c->curfv==NULL ) ScriptError(c,"No current font");
- if ( strcmp(name,"$curfont")==0 )
+ if ( strcmp(name,"$curfont")==0 )
sf = c->curfv->sf;
else {
if ( c->curfv->next==NULL ) sf = NULL;
@@ -9510,7 +9551,7 @@ static void comp(Context *c,Val *val) {
if ( val->u.fval>other.u.fval ) cmp = 1;
else if ( val->u.fval<other.u.fval ) cmp = -1;
else cmp = 0;
- } else
+ } else
ScriptError( c, "Invalid type in integer expression" );
val->type = v_int;
if ( tok==tt_eq ) val->u.ival = (cmp==0);
View
12 htdocs/scripting-alpha.html
@@ -3176,6 +3176,12 @@ <H1 ALIGN=Center>
Converts the argument to a unicode code point (a special type used in several
commands). It can execute with no current font.
<DT>
+ <A NAME="UnicodeAnnotationFromLib">U</A>nicodeAnnotationFromLib(val)
+ <DD>
+ Returns the Unicode Annotations for this value as described by www.unicode.org.
+ If there is no unicode annotation for this value, or no library available,
+ then return empty string "". It can execute with no current font.
+ <DT>
<A NAME="UnicodeFromName">U</A>nicodeFromName(name)
<DD>
Looks the string "name" up in FontForge's database of commonly used glyph
@@ -3183,6 +3189,12 @@ <H1 ALIGN=Center>
found. This does <EM>not</EM> check the current font (if any). It can execute
with no current font.
<DT>
+ <A NAME="UnicodeNameFromLib">U</A>nicodeNameFromLib(val)
+ <DD>
+ Returns the Unicode Name for this value as described by www.unicode.org.
+ If there is no unicode name for this value, or no library available,
+ then return empty string "". It can execute with no current font.
+ <DT>
<A NAME="UnlinkReference" HREF="editmenu.html#Unlink">UnlinkReference</A>
<DD>
Unlinks all references within all selected glyphs
Please sign in to comment.
Something went wrong with that request. Please try again.