Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libuninameslist Names2 support #3290

Merged
merged 6 commits into from May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -83,15 +83,15 @@ install:
wget 'https://github.com/zeromq/zeromq4-1/releases/download/v4.1.5/zeromq-4.1.5.tar.gz' -O - |tar -zxf -
wget 'https://github.com/zeromq/czmq/releases/download/v3.0.2/czmq-3.0.2.tar.gz' -O - |tar -zxf -
wget 'https://github.com/fontforge/libspiro/releases/download/0.5.20150702/libspiro-0.5.20150702.tar.gz' -O - | tar -zxf -
wget 'https://github.com/fontforge/libuninameslist/releases/download/20160701/libuninameslist-20160701.tar.gz' -O - | tar -zxf -
wget 'https://github.com/fontforge/libuninameslist/releases/download/20180408/libuninameslist-dist-20180408.tar.gz' -O - | tar -zxf -
wget 'https://bitbucket.org/sortsmill/libunicodenames/downloads/libunicodenames-1.1.0_beta1.tar.xz' -O - | tar -Jxf -
wget --tries 1 "http://download.savannah.gnu.org/releases/freetype/freetype-$FTVER.tar.gz" || \
wget "https://sourceforge.net/projects/freetype/files/freetype2/$SFFTVER/freetype-$FTVER.tar.gz"

pushd zeromq-4.1.5 && ./configure --prefix=$DEPSPREFIX && make && make install && popd
pushd czmq-3.0.2 && CFLAGS="-Wno-format-truncation" ./configure --prefix=$DEPSPREFIX && make && make install && popd
pushd libspiro-0.5.20150702 && ./configure --prefix=$DEPSPREFIX && make && make install && popd
pushd libuninameslist-20160701 && ./configure --prefix=$DEPSPREFIX && make && make install && popd
pushd libuninameslist-20180408 && ./configure --enable-pscript --prefix=$DEPSPREFIX && make && make install && popd
pushd libunicodenames-1.1.0_beta1 && ./configure --prefix=$DEPSPREFIX && make && make install && popd
tar -zxf freetype-$FTVER.tar.gz -C $DEPSPREFIX
popd
Expand Down
43 changes: 43 additions & 0 deletions doc/html/python.html
Expand Up @@ -344,6 +344,49 @@ <H2>Command line convenience</H2>
libuninameslist ver_0.3.20130501 or later, else it returns empty string "".
This can execute with no current font.</TD>
</TR>
<TR>
<TD><CODE>UnicodeNames2GetCntFromLib</CODE></TD>
<TD><CODE>()</CODE></TD>
Return the Total Count of all Names that were corrected with a new name.
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version.
If there is no libuninameslist ver 0.5 or later available, then return -1
</TR>
<TR>
<TD><CODE>UnicodeNames2GetNxtFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. With val==unicode value, this function
returns -1 if no Names2 exists, or the Nth table location for this
unicode value listed in libuninameslist that was corrected to a new name.
If there is no libuninameslist ver 0.5 or later, then return -1.
</TR>
<TR>
<TD><CODE>UnicodeNames2NxtUniFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Next Names2
listed in libuninameslist internal table that was corrected to a new name.
The internal table of Unicode values is of size UnicodeNames2GetCntFromLib().
If there is no libuninameslist ver 0.5 or later, then return -1.
</TR>
<TR>
<TD><CODE>UnicodeNames2FrmTabFromLib</CODE></TD>
<TD><CODE>(n)</CODE></TD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Next Names2
listed in libuninameslist internal table that was corrected to a new name.
The internal table of Unicode values is of size UnicodeNames2GetCntFromLib().
If there is no libuninameslist ver 0.5 or later, then return NULL.
<TR>
</TR>
<TD><CODE>UnicodeNames2FromLib</CODE></TD>
<TD><CODE>(val)</CODE></TD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Names2 or NULL
based on the unicode value given.
If there is no libuninameslist ver 0.5 or later, then return NULL.
</TR>
<TR>
<TD><CODE>IsFraction</CODE></TD>
<TD><CODE>(n)</CODE></TD>
Expand Down
38 changes: 38 additions & 0 deletions doc/html/scripting-alpha.html
Expand Up @@ -3449,6 +3449,44 @@ <H1 ALIGN=Center>
library is recent for your script. This function currently works only for
libuninameslist ver_0.3.20130501 or later, else it returns empty string "".
This can execute with no current font.
<DT>
<A NAME="UnicodeNames2GetCntFromLib">U</A>nicodeNames2GetCntFromLib()
<DD>
Return the Total Count of all Names that were corrected with a new name.
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version.
If there is no libuninameslist ver 0.5 or later available, then return -1
<DT>
<A NAME="UnicodeNames2GetNxtFromLib">U</A>nicodeNames2GetNxtFromLib(val)
<DD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. With val==unicode value, this function
returns -1 if no Names2 exists, or the Nth table location for this
unicode value listed in libuninameslist that was corrected to a new name.
If there is no libuninameslist ver 0.5 or later, then return -1.
<DT>
<A NAME="UnicodeNames2NxtUniFromLib">U</A>nicodeNames2NxtUniFromLib(val)
<DD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Next Unicode value
listed in libuninameslist internal table that was corrected to a new name.
The internal table of Unicode values is of size UnicodeNames2GetCntFromLib().
If there is no libuninameslist ver 0.5 or later, then return -1.
<DT>
<A NAME="UnicodeNames2FrmTabFromLib">U</A>nicodeNames2FrmTabFromLib(val)
<DD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Next Names2
listed in libuninameslist internal table that was corrected to a new name.
The internal table of Unicode values is of size UnicodeNames2GetCntFromLib().
If there is no libuninameslist ver 0.5 or later, then return NULL.
<DT>
<A NAME="UnicodeNames2FromLib">U</A>nicodeNames2FromLib(val)
<DD>
Errors and corrections happen, therefore names can be corrected in the
next Unicode Nameslist version. This function returns the Names2 or NULL
based on the unicode value given.
If there is no libuninameslist ver 0.5 or later, then return NULL.
<DT>
<A NAME="UnlinkReference" HREF="editmenu.html#Unlink">UnlinkReference</A>
<DD>
Expand Down
57 changes: 57 additions & 0 deletions fontforge/python.c
Expand Up @@ -856,6 +856,56 @@ static PyObject *PyFF_UnicodeNamesListVersion(PyObject *UNUSED(self), PyObject *
return( ret );
}

/* Names2 lookup commands to get info from attached libuninameslist >= v0.5. */
/* Cnt returns lookup table-size, Nxt returns next Unicode value from array, */
/* Nxt returns 'n' for table array[0..n..(Cnt-1)] pointer. Errors return -1. */
static PyObject *PyFF_UnicodeNames2GetCntFromLib(PyObject *UNUSED(self), PyObject *UNUSED(args)) {
return( Py_BuildValue("i", unicode_names2cnt()) );
}

static PyObject *PyFF_UnicodeNames2GetNxtFromLib(PyObject *UNUSED(self), PyObject *args) {
long val;

if ( !PyArg_ParseTuple(args,"|i",&val) )
return( NULL );
return( Py_BuildValue("i", unicode_names2getUtabLoc(val)) );
}

static PyObject *PyFF_UnicodeNames2NxtUniFromLib(PyObject *UNUSED(self), PyObject *args) {
long val;

if ( !PyArg_ParseTuple(args,"|i",&val) )
return( NULL );
return( Py_BuildValue("i", unicode_names2valFrmTab(val)) );
}

static PyObject *PyFF_UnicodeNames2FrmTabFromLib(PyObject *UNUSED(self), PyObject *args) {
long val;
char *temp;

if ( !PyArg_ParseTuple(args,"|i",&val) )
return( NULL );
if ( (temp=unicode_name2FrmTab(val))==NULL ) {
return Py_BuildValue("s", "");
}
PyObject *ret=Py_BuildValue("s",temp); free(temp);
return( ret );
}

static PyObject *PyFF_UnicodeNames2FromLib(PyObject *UNUSED(self), PyObject *args) {
long val;
char *temp;

if ( !PyArg_ParseTuple(args,"|i",&val) )
return( NULL );
if ( (temp=unicode_name2(val))==NULL ) {
return Py_BuildValue("s", "");
}
PyObject *ret=Py_BuildValue("s",temp); free(temp);
return( ret );
}


/* Ligature & Fraction information based on current Unicode (builtin) chart. */
/* Unicode chart seems to distinguish vulgar fractions from other fractions. */
/* These routines test value with internal table. Returns true/false values. */
Expand Down Expand Up @@ -17965,13 +18015,20 @@ PyMethodDef module_fontforge_methods[] = {
{ "preloadCidmap", PyFF_PreloadCidmap, METH_VARARGS, "Load a cidmap file" },
{ "unicodeFromName", PyFF_UnicodeFromName, METH_VARARGS, "Given a name, look it up in the namelists and find what unicode code point it maps to (returns -1 if not found)" },
{ "nameFromUnicode", PyFF_NameFromUnicode, METH_VARARGS, "Given a unicode code point and (optionally) a namelist, find the corresponding glyph name" },
/* --start of libuninameslist functions------------------------ */
{ "UnicodeNameFromLib", PyFF_UnicodeNameFromLib, METH_VARARGS, "Return the www.unicode.org name for a given unicode character value" },
{ "UnicodeAnnotationFromLib", PyFF_UnicodeAnnotationFromLib, METH_VARARGS, "Return the www.unicode.org annotation(s) for a given unicode character value" },
{ "UnicodeBlockCountFromLib", PyFF_UnicodeBlockCountFromLib, METH_NOARGS, "Return the www.unicode.org block count" },
{ "UnicodeBlockStartFromLib", PyFF_UnicodeBlockStartFromLib, METH_VARARGS, "Return the www.unicode.org block start, for example block[0]={0..127} -> 0" },
{ "UnicodeBlockEndFromLib", PyFF_UnicodeBlockEndFromLib, METH_VARARGS, "Return the www.unicode.org block end, for example block[1]={128..255} -> 255" },
{ "UnicodeBlockNameFromLib", PyFF_UnicodeBlockNameFromLib, METH_VARARGS, "Return the www.unicode.org block name, for example block[2]={256..383} -> Latin Extended-A" },
{ "UnicodeNamesListVersion", PyFF_UnicodeNamesListVersion, METH_NOARGS, "Return the www.unicode.org NamesList version for this library" },
{ "UnicodeNames2GetCntFromLib", PyFF_UnicodeNames2GetCntFromLib, METH_NOARGS, "Return the www.unicode.org NamesList total count of Names2 corrections for this library" },
{ "UnicodeNames2NxtUniFromLib", PyFF_UnicodeNames2NxtUniFromLib, METH_VARARGS, "Return the table location of the next www.unicode.org Names2 for this library" },
{ "UnicodeNames2GetNxtFromLib", PyFF_UnicodeNames2GetNxtFromLib, METH_VARARGS, "Return the table location of the next www.unicode.org Names2 for this library" },
{ "UnicodeNames2FrmTabFromLib", PyFF_UnicodeNames2FrmTabFromLib, METH_VARARGS, "Return the www.unicode.org NamesList Names2 from internal table[0<=N<UnicodeNames2GetCnt()] for this library" },
{ "UnicodeNames2FromLib", PyFF_UnicodeNames2FromLib, METH_VARARGS, "Return the www.unicode.org NamesList Names2 for this Unicode value if it exists for this library" },
/* --end of libuninameslist functions-------------------------- */
{ "IsFraction", PyFF_isfraction, METH_VARARGS, "Compare value with internal Vulgar_Fraction and Other_Fraction table. Return true/false" },
{ "IsLigature", PyFF_isligature, METH_VARARGS, "Compare value with internal Ligature table. Return true/false" },
{ "IsVulgarFraction", PyFF_isvulgarfraction, METH_VARARGS, "Compare value with internal Vulgar_Fraction table. Return true/false" },
Expand Down
90 changes: 90 additions & 0 deletions fontforge/scripting.c
Expand Up @@ -1168,6 +1168,9 @@ static void bNameFromUnicode(Context *c) {
c->return_val.u.sval = copy(StdGlyphName(buffer,c->a.vals[1].u.ival,uniinterp,for_new_glyphs));
}


/* --start of libuninameslist functions------------------------ */

static void bUnicodeBlockCountFromLib(Context *c) {
/* If the library is available, then return the number of name blocks */

Expand Down Expand Up @@ -1254,6 +1257,84 @@ static void bUnicodeNamesListVersion(Context *c) {
c->return_val.u.sval = temp;
}

/* ----start of libuninameslist Names2 functions--------------- */

static void bUnicodeNames2GetCntFromLib(Context *c) {
/* If the library is available, then Get the Names2 table Count */
c->return_val.type=v_int;
c->return_val.u.ival=unicode_names2cnt();
}

static void bUnicodeNames2GetNxtFromLib(Context *c) {
/* If the library is available, use unicode val to find Names2, */
/* if exists, return location in table, if not found return -1. */
const char *pt;
long ch;

c->return_val.type = v_int;
if ( c->a.vals[1].type==v_str ) {
pt = c->a.vals[1].u.sval;
ch = utf8_ildb(&pt);
c->return_val.u.ival = unicode_names2getUtabLoc(ch);
} else if ( c->a.vals[1].type==v_int || c->a.vals[1].type==v_unicode )
c->return_val.u.ival = unicode_names2getUtabLoc(c->a.vals[1].u.ival);
else
c->error = ce_badargtype;
}

static void bUnicodeNames2NxtUniFromLib(Context *c) {
/* If the library is available, return unicode val for table[n] */
const char *pt;
long ch;

c->return_val.type = v_int;
if ( c->a.vals[1].type==v_str ) {
pt = c->a.vals[1].u.sval;
ch = utf8_ildb(&pt);
c->return_val.u.ival = unicode_names2valFrmTab(ch);
} else if ( c->a.vals[1].type==v_int || c->a.vals[1].type==v_unicode )
c->return_val.u.ival = unicode_names2valFrmTab(c->a.vals[1].u.ival);
else
c->error = ce_badargtype;
}

static void bUnicodeNames2FrmTabFromLib(Context *c) {
/* If the library is available, return table[n]->Names2 string. */
const char *pt;
long ch;

c->return_val.type = v_str;
if ( c->a.vals[1].type==v_str ) {
pt = c->a.vals[1].u.sval;
ch = utf8_ildb(&pt);
c->return_val.u.sval = unicode_name2FrmTab(ch);
} else if ( c->a.vals[1].type==v_int || c->a.vals[1].type==v_unicode )
c->return_val.u.sval = unicode_name2FrmTab(c->a.vals[1].u.ival);
else
c->error = ce_badargtype;
}

static void bUnicodeNames2FromLib(Context *c) {
/* If the library is available, use unicode val to find Names2, */
/* if exists, return Names2, and if not exist then return NULL. */
const char *pt;
long ch;

c->return_val.type = v_str;
if ( c->a.vals[1].type==v_str ) {
pt = c->a.vals[1].u.sval;
ch = utf8_ildb(&pt);
c->return_val.u.sval = unicode_name2(ch);
} else if ( c->a.vals[1].type==v_int || c->a.vals[1].type==v_unicode )
c->return_val.u.sval = unicode_name2(c->a.vals[1].u.ival);
else
c->error = ce_badargtype;
}

/* ----end of libuninameslist Names2 functions----------------- */
/* --end of libuninameslist functions-------------------------- */


static void bChr(Context *c) {
char buf[2];
char *temp;
Expand Down Expand Up @@ -8695,13 +8776,22 @@ static struct builtins {
{ "SpiroVersion", bSpiroVersion, 1,1,0 },
{ "UnicodeFromName", bUnicodeFromName, 1,2,v_str },
{ "NameFromUnicode", bNameFromUnicode, 1,0,0 },
/* --start of libuninameslist functions------------------------ */
{ "UnicodeBlockCountFromLib", bUnicodeBlockCountFromLib, 1,1,0 },
{ "UnicodeBlockEndFromLib", bUnicodeBlockEndFromLib, 1,2,0 },
{ "UnicodeBlockNameFromLib", bUnicodeBlockNameFromLib, 1,2,0 },
{ "UnicodeBlockStartFromLib", bUnicodeBlockStartFromLib, 1,2,0 },
{ "UnicodeNameFromLib", bUnicodeNameFromLib, 1,2,0 },
{ "UnicodeAnnotationFromLib", bUnicodeAnnotationFromLib, 1,2,0 },
{ "UnicodeNamesListVersion", bUnicodeNamesListVersion, 1,1,0 },
/* ----start of libuninameslist Names2 functions--------------- */
{ "UnicodeNames2GetCntFromLib", bUnicodeNames2GetCntFromLib, 1,1,0 },
{ "UnicodeNames2GetNxtFromLib", bUnicodeNames2GetNxtFromLib, 1,2,0 },
{ "UnicodeNames2NxtUniFromLib", bUnicodeNames2NxtUniFromLib, 1,2,0 },
{ "UnicodeNames2FrmTabFromLib", bUnicodeNames2FrmTabFromLib, 1,2,0 },
{ "UnicodeNames2FromLib", bUnicodeNames2FromLib, 1,2,0 },
/* ----end of libuninameslist Names2 functions----------------- */
/* --end of libuninameslist functions-------------------------- */
{ "Chr", bChr, 1,0,0 },
{ "Ord", bOrd, 1,0,0 },
{ "Real", bReal, 1,2,0 },
Expand Down