Skip to content
Browse files

Scripting access to nameslist datablocks(start, end, name)

  • Loading branch information...
1 parent f5cf22e commit 5d0a1da70d56d338051cb3a05357e49182338de9 @JoesCat JoesCat committed Apr 14, 2013
View
68 fontforge/python.c
@@ -882,14 +882,15 @@ static PyObject *PyFF_UnicodeAnnotationFromLib(PyObject *UNUSED(self), PyObject
/* This function may be used in conjunction with UnicodeNameFromLib(n) */
PyObject *ret;
char *temp;
+
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ temp=NULL;
+#else
long val;
if ( !PyArg_ParseTuple(args,"|i",&val) )
return( NULL );
-#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
- temp=NULL;
-#else
temp=unicode_annot(val);
#endif
if ( temp==NULL ) {
@@ -904,15 +905,71 @@ static PyObject *PyFF_UnicodeNameFromLib(PyObject *UNUSED(self), PyObject *args)
/* This function may be used in conjunction with UnicodeAnnotationFromLib(n) */
PyObject *ret;
char *temp;
+
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ temp=NULL;
+#else
long val;
if ( !PyArg_ParseTuple(args,"|i",&val) )
return( NULL );
+ temp=unicode_name(val);
+#endif
+ if ( temp==NULL ) {
+ temp=galloc(1*sizeof(char)); temp='\0';
+ }
+ ret=Py_BuildValue("s",temp); free(temp);
+ return( ret );
+}
+
+static PyObject *PyFF_UnicodeBlockStartFromLib(PyObject *UNUSED(self), PyObject *args) {
+/* If the library is available, then get the official start for this unicode block */
+/* Use this function with UnicodeBlockNameFromLib(n) & UnicodeBlockEndFromLib(n). */
+
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ return( Py_BuildValue("i", -1) );
+#else
+ long val;
+
+ if ( !PyArg_ParseTuple(args,"|i",&val) )
+ return( NULL );
+
+ return( Py_BuildValue("i", unicode_block_start(val)) );
+#endif
+}
+
+static PyObject *PyFF_UnicodeBlockEndFromLib(PyObject *UNUSED(self), PyObject *args) {
+/* If the library is available, then get the official end for this unicode block. */
+/* Use this function with UnicodeBlockStartFromLib(n), UnicodeBlockNameFromLib(n) */
+
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ return( Py_BuildValue("i", -1) );
+#else
+ long val;
+
+ if ( !PyArg_ParseTuple(args,"|i",&val) )
+ return( NULL );
+
+ return( Py_BuildValue("i", unicode_block_end(val)) );
+#endif
+}
+
+static PyObject *PyFF_UnicodeBlockNameFromLib(PyObject *UNUSED(self), PyObject *args) {
+/* If the library is available, then get the official name for this unicode block */
+/* Use this function with UnicodeBlockStartFromLib(n), UnicodeBlockEndFromLib(n). */
+ PyObject *ret;
+ char *temp;
+
#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
temp=NULL;
#else
- temp=unicode_name(val);
+ long val;
+
+ if ( !PyArg_ParseTuple(args,"|i",&val) )
+ return( NULL );
+
+ temp=unicode_block_name(val);
#endif
if ( temp==NULL ) {
temp=galloc(1*sizeof(char)); temp='\0';
@@ -18054,6 +18111,9 @@ static PyMethodDef module_fontforge_methods[] = {
{ "nameFromUnicode", PyFF_NameFromUnicode, METH_VARARGS, "Given a unicode code point and (optionally) a namelist, find the corresponding glyph name" },
{ "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" },
+ { "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" },
{ "version", PyFF_Version, METH_NOARGS, "Returns a string containing the current version of FontForge, as 20061116" },
{ "runInitScripts", PyFF_RunInitScripts, METH_NOARGS, "Run the system and user initialization scripts, if not already run" },
{ "scriptPath", PyFF_GetScriptPath, METH_NOARGS, "Returns a list of the directories searched for scripts"},
View
51 fontforge/scripting.c
@@ -1090,6 +1090,54 @@ static void bNameFromUnicode(Context *c) {
c->return_val.u.sval = copy(StdGlyphName(buffer,c->a.vals[1].u.ival,uniinterp,for_new_glyphs));
}
+static void bUnicodeBlockEndFromLib(Context *c) {
+/* If the library is available, then get the official Nth block end */
+ 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_int;
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ c->return_val.u.ival=-1;
+#else
+ c->return_val.u.ival=unicode_block_end(c->a.vals[1].u.ival);
+#endif
+}
+
+static void bUnicodeBlockNameFromLib(Context *c) {
+/* If the library is available, then get the official Nth block name */
+ 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_block_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 bUnicodeBlockStartFromLib(Context *c) {
+/* If the library is available, then get the official Nth block start */
+ 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_int;
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ c->return_val.u.ival=-1;
+#else
+ c->return_val.u.ival=unicode_block_start(c->a.vals[1].u.ival);
+#endif
+}
+
static void bUnicodeNameFromLib(Context *c) {
/* If the library is available, then get the official name for this unicode value */
char *temp;
@@ -8119,6 +8167,9 @@ static struct builtins { char *name; void (*func)(Context *); int nofontok; } bu
{ "GetEnv", bGetEnv, 1 },
{ "UnicodeFromName", bUnicodeFromName, 1 },
{ "NameFromUnicode", bNameFromUnicode, 1 },
+ { "UnicodeBlockEndFromLib", bUnicodeBlockEndFromLib, 1 },
+ { "UnicodeBlockNameFromLib", bUnicodeBlockNameFromLib, 1},
+ { "UnicodeBlockStartFromLib", bUnicodeBlockStartFromLib, 1 },
{ "UnicodeNameFromLib", bUnicodeNameFromLib, 1 },
{ "UnicodeAnnotationFromLib", bUnicodeAnnotationFromLib, 1 },
{ "Chr", bChr, 1 },
View
4 fontforge/splinefont.h
@@ -2769,6 +2769,10 @@ extern int SFFindOrder(SplineFont *sf);
extern void inituninameannot(void);
extern char *unicode_name(int32 unienc);
extern char *unicode_annot(int32 unienc);
+extern int32 unicode_block_start(int32 block_i);
+extern int32 unicode_block_end(int32 block_i);
+extern char *unicode_block_name(int32 block_i);
+
extern const char *UnicodeRange(int unienc);
extern SplineChar *SCBuildDummy(SplineChar *dummy,SplineFont *sf,EncMap *map,int i);
View
2 fontforge/startnoui.c
@@ -28,6 +28,7 @@
#ifndef _NO_LIBUNICODENAMES
#include <libunicodenames.h> /* need to open a database when we start */
extern uninm_names_db names_db; /* Unicode character names and annotations database */
+extern uninm_blocks_db blocks_db;
#endif
#include <gfile.h>
#include <ustring.h>
@@ -131,6 +132,7 @@ int fontforge_main( int argc, char **argv ) {
#ifndef _NO_LIBUNICODENAMES
uninm_names_db_close(names_db); /* close this database before exiting */
+ uninm_blocks_db_close(blocks_db);
#endif
lt_dlexit();
View
2 fontforge/startui.c
@@ -30,6 +30,7 @@
#ifndef _NO_LIBUNICODENAMES
#include <libunicodenames.h> /* need to open a database when we start */
extern uninm_names_db names_db; /* Unicode character names and annotations database */
+extern uninm_blocks_db blocks_db;
#endif
#include <gfile.h>
#include <gresource.h>
@@ -1249,6 +1250,7 @@ exit( 0 );
#ifndef _NO_LIBUNICODENAMES
uninm_names_db_close(names_db); /* close this database before exiting */
+ uninm_blocks_db_close(blocks_db);
#endif
lt_dlexit();
View
121 fontforge/unicodelibinfo.c
@@ -32,11 +32,18 @@
#ifndef _NO_LIBUNINAMESLIST
#include <uninameslist.h>
+#else
+struct unicode_block {
+ int start, end;
+ const char *name;
+};
#endif
const struct unicode_nameannot * const *const *_UnicodeNameAnnot = NULL; /* deprecated */
+const struct unicode_block *_UnicodeBlock = NULL;
#ifndef _NO_LIBUNICODENAMES
#include <libunicodenames.h>
uninm_names_db names_db; /* Unicode character names and annotations database */
+uninm_blocks_db blocks_db;
#endif
void inituninameannot(void) {
@@ -46,31 +53,37 @@ void inituninameannot(void) {
#if _NO_LIBUNINAMESLIST
_UnicodeNameAnnot = NULL; /* libuninameslist not available */
+ _UnicodeBlock = NULL;
#else
/* backward compatibility for other programs using libuninames */
_UnicodeNameAnnot = UnicodeNameAnnot;
+ _UnicodeBlock = UnicodeBlock;
#endif
#ifndef _NO_LIBUNICODENAMES
/* Open database file, read data for this 'local', then close. */
char *names_db_file;
+ char *blocks_db_file;
/* Load character names and annotations that come from the Unicode NamesList.txt */
/* This should not be done until after the locale has been set */
names_db_file = uninm_find_names_db(NULL);
names_db = (names_db_file == NULL) ? ((uninm_names_db) 0) : uninm_names_db_open(names_db_file);
free(names_db_file);
/* NOTE: you need to do uninm_names_db_close(names_db); when you exit program */
+
+ blocks_db_file = uninm_find_blocks_db(NULL);
+ blocks_db = (blocks_db_file == NULL) ? ((uninm_blocks_db) 0) : uninm_blocks_db_open(blocks_db_file);
+ free(blocks_db_file);
+ /* NOTE: you need to do uninm_blocks_db_close(blocks_db); when you exit program */
#endif
}
char *unicode_name(int32 unienc) {
/* Return the unicode name for the value given from a data library. */
/* If there's no data available for this code, or no library, return NULL */
/* User should free the return string when finished with this information */
- char *name_data;
- name_data=NULL;
#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
/* no nameslist library code available to use */
//fprintf(stderr,"no library\n");
@@ -80,6 +93,7 @@ char *unicode_name(int32 unienc) {
if ( unienc<0 || unienc>=0x110000 )
return( NULL );
+ char *name_data=NULL;
#ifndef _NO_LIBUNINAMESLIST
#ifndef _LIBUNINAMESLIST_FUN
/* old libuninameslist library code */
@@ -98,9 +112,9 @@ char *unicode_name(int32 unienc) {
name_data=copy(uninm_name(names_db,(unsigned int)(unienc)));
//fprintf(stderr,"libunicodes library ->%s<-\n",name_data\n");
#endif
-#endif
return( name_data );
+#endif
}
#ifndef _NO_LIBUNINAMESLIST
@@ -148,6 +162,21 @@ static char *unicode_nicer(const char *from) {
return( to );
}
+
+static int unicode_block_check(int block_i) {
+/* Older uninameslist database needs to be checked from start since we do */
+/* not know which is the last block. Currently this should be around 234. */
+ if ( _UnicodeBlock!=NULL ) {
+ int i;
+
+ for ( i=0; i<block_i; ++i )
+ if ( _UnicodeBlock[i].end>=0x10ffff )
+ break;
+ if ( i==block_i )
+ return( i );
+ }
+ return( -1 );
+}
#endif
char *unicode_annot(int32 unienc) {
@@ -160,14 +189,12 @@ char *unicode_annot(int32 unienc) {
//fprintf(stderr,"no library - annotation\n");
return( NULL );
#else
- char *annot_data;
-
- annot_data=NULL;
-
/* have nameslist library code available to use */
if ( unienc<0 || unienc>=0x110000 )
return( NULL );
+ char *annot_data=NULL;
+
#ifndef _NO_LIBUNINAMESLIST
#ifndef _LIBUNINAMESLIST_FUN
/* old libuninameslist library code */
@@ -190,3 +217,83 @@ char *unicode_annot(int32 unienc) {
return( annot_data );
#endif
}
+
+int32 unicode_block_start(int32 block_i) {
+/* Return the unicode value for the start of next unicode block. If no */
+/* library or data available, then return -1. */
+
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ /* no nameslist library available to use */
+ //fprintf(stderr,"no block library\n");
+ return( -1 );
+#else
+ int32 unistart;
+
+ unistart=-1;
+#ifndef _NO_LIBUNINAMESLIST
+ /* old libuninameslist library code */
+ if ( (unistart=unicode_block_check(block_i))>=0 )
+ unistart=_UnicodeBlock[unistart].start;
+ //fprintf(stderr,"use old code library, got values of %d %d\n",block_i,unistart);
+#else
+ /* libunicodesnames library code */
+ unistart=uninm_block_start(blocks_db,(unsigned int)(block_i));
+ //fprintf(stderr,"libunicodes library ->%s<-\n",name_data\n");
+#endif
+
+ return( unistart );
+#endif
+}
+
+int32 unicode_block_end(int32 block_i) {
+/* Return the unicode value for the end of this unicode block. If there */
+/* is no library or data available, then return -1 */
+
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ /* no nameslist library available to use */
+ //fprintf(stderr,"no block library\n");
+ return( -1 );
+#else
+ int32 uniend;
+
+ uniend=-1;
+#ifndef _NO_LIBUNINAMESLIST
+ /* old libuninameslist library code */
+ if ( (uniend=unicode_block_check(block_i))>=0 )
+ uniend=_UnicodeBlock[uniend].end;
+ //fprintf(stderr,"use old code library, got values of %d %d\n",block_i,uniend);
+#else
+ /* libunicodesnames library code */
+ uniend=uninm_block_end(blocks_db,(unsigned int)(block_i));
+ //fprintf(stderr,"libunicodes library ->%s<-\n",name_data\n");
+#endif
+
+ return( uniend );
+#endif
+}
+
+char *unicode_block_name(int32 block_i) {
+/* Return the unicode name for this unicode block. If there is no library */
+/* then return NULL */
+
+#if _NO_LIBUNINAMESLIST && _NO_LIBUNICODENAMES
+ /* no nameslist library code available to use */
+ //fprintf(stderr,"no library\n");
+ return( NULL );
+#else
+ char *name_data=NULL;
+#ifndef _NO_LIBUNINAMESLIST
+ int i;
+ /* old libuninameslist library code */
+ if ( (i=unicode_block_check(block_i))>=0 )
+ name_data=copy(_UnicodeBlock[i].name);
+ //fprintf(stderr,"use old code library, got values of %d %d %s\n",i,block_i,name_data);
+#else
+ /* libunicodesnames library code */
+ name_data=copy(uninm_block_name(blocks_db,(unsigned int)(block_i)));
+ //fprintf(stderr,"libunicodes library ->%s<-\n",name_data\n");
+#endif
+
+ return( name_data );
+#endif
+}
View
24 htdocs/python.html
@@ -280,6 +280,30 @@ <H1 ALIGN=Center>
then return empty string "". It can execute with no current font.</TD>
</TR>
<TR>
+ <TD><CODE>UnicodeBlockEndFromLib</CODE></TD>
+ <TD><CODE>(n)</CODE></TD>
+ <TD>Returns the Unicode Block end value as described by www.unicode.org.
+ Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
+ If there is no value, or no library available, then return -1.
+ This can execute with no current font.</TD>
+ </TR>
+ <TR>
+ <TD><CODE>UnicodeBlockNameFromLib</CODE></TD>
+ <TD><CODE>(n)</CODE></TD>
+ <TD>Returns the Unicode Block Name as described by www.unicode.org.
+ Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
+ If there is no value, or no library available, then return empty string "".
+ This can execute with no current font.</TD>
+ </TR>
+ <TR>
+ <TD><CODE>UnicodeBlockStartFromLib</CODE></TD>
+ <TD><CODE>(n)</CODE></TD>
+ <TD>Returns the Unicode Block start value as described by www.unicode.org.
+ Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
+ If there is no value, or no library available, then return -1.
+ This can execute with no current font.</TD>
+ </TR>
+ <TR>
<TD><CODE>unicodeFromName</CODE></TD>
<TD><CODE>(glyphname)</CODE></TD>
<TD>Looks up glyph name in its dictionary and if it is associated with a
View
21 htdocs/scripting-alpha.html
@@ -3182,6 +3182,27 @@ <H1 ALIGN=Center>
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="UnicodeBlockEndFromLib">U</A>nicodeBlockEndFromLib(val)
+ <DD>
+ Returns the Unicode Block end value as described by www.unicode.org.
+ Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
+ If there is no value, or no library available, then return -1.
+ This can execute with no current font.
+ <DT>
+ <A NAME="UnicodeBlockNameFromLib">U</A>nicodeBlockNameFromLib(val)
+ <DD>
+ Returns the Unicode Block Name as described by www.unicode.org.
+ Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
+ If there is no value, or no library available, then return empty string "".
+ This can execute with no current font.
+ <DT>
+ <A NAME="UnicodeBlockStartFromLib">U</A>nicodeBlockStartFromLib(val)
+ <DD>
+ Returns the Unicode Block start value as described by www.unicode.org.
+ Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
+ If there is no value, or no library available, then return -1.
+ This 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

0 comments on commit 5d0a1da

Please sign in to comment.
Something went wrong with that request. Please try again.