Oops, forgot the attachment.

On Sun, Dec 13, 2009 at 02:29:26PM +0200, Khaled Hosny wrote:
> On Sun, Dec 13, 2009 at 12:37:00PM +0100, Hans Hagen wrote:
> > Khaled Hosny wrote:
> > >On Sun, Dec 13, 2009 at 11:52:29AM +0100, Hans Hagen wrote:
> > >>Khaled Hosny wrote:
> > >>>Is there a way to retrieve internal font id from its csname, either using
> > >>>lua or some tex hackary?
> > >>{\somefont \directlua{tex.write(font.current())}
> > >
> > >Yup, I know about font.current(), but this means I've to activate the
> > >font first which is not some thing I can do (I need this for fontspec;
> > >I want to access the font table of a certain defined font that I only
> > >know it csname).
> > 
> > 
> > i remember that when a while ago taco and i discussed this that
> > there were some good reasons for not yet having access to all this
> > specific info i.e. i can imagine that tex.somefontcs returns the
> > number but quite some of those accessors have to wait till the whole
> > global/local issue of the code is resolved.
> > 
> > also, we're not close to 0.50 so it's unlikely that new accessors
> > will show up before that stable version is out
> 
> Any way, I tried to implement a font.id() last night, but didn't get it
> to work. I get it to work finally (patch attached, in case anyone
> interested), just to discover tex.fontidentifier() (what an odd place, I
> was only looking under font library!) that can be used to implement the
> function I want:
> 
> function font_id(str)
>     for i=font.max(),0,-1 do
>         if tex.fontidentifier(i) == str then
>             return i
>         end
>     end
>     return -1
> end
> 
> 
> Regards,
>  Khaled
> 
> -- 
>  Khaled Hosny
>  Arabic localiser and member of Arabeyes.org team
>  Free font developer

-- 
 Khaled Hosny
 Arabic localiser and member of Arabeyes.org team
 Free font developer
From 27f4f5022d335040c0a7d74265f10cc39996c191 Mon Sep 17 00:00:00 2001
From: Khaled Hosny <[email protected]>
Date: Sun, 13 Dec 2009 12:43:51 +0200
Subject: [PATCH] Implement font.id()

---
 manual/luatexref-t.tex                     |    9 ++++++++-
 source/texk/web2c/luatexdir/lua/lfontlib.c |   25 +++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/manual/luatexref-t.tex b/manual/luatexref-t.tex
index 7b411cd..4c7b025 100644
--- a/manual/luatexref-t.tex
+++ b/manual/luatexref-t.tex
@@ -4571,7 +4571,7 @@ raised. The table is a font structure, as explained in
 \subsection{Projected next font id}
 
 \startfunctioncall
-number i = font.nextid();
+<number> i = font.nextid();
 \stopfunctioncall
 
 This returns the font id number that would be returned by a
@@ -4579,7 +4579,14 @@ This returns the font id number that would be returned by a
 flow. This is useful for virtual fonts that need to reference
 themselves.
 
+\subsection{Font id (0.47)}
 
+\startfunctioncall
+<number> i = font.id(<string> csname);
+\stopfunctioncall
+
+This returns the font id associated with \type{csname} string, or $-1$
+if \type{csname} is not defined, new in 0.47.
 
 \subsection{Currently active font}
 
diff --git a/source/texk/web2c/luatexdir/lua/lfontlib.c b/source/texk/web2c/luatexdir/lua/lfontlib.c
index fc5d783..67f4f6c 100644
--- a/source/texk/web2c/luatexdir/lua/lfontlib.c
+++ b/source/texk/web2c/luatexdir/lua/lfontlib.c
@@ -256,6 +256,30 @@ static int getfont(lua_State * L)
 }
 
 
+static int getfontid(lua_State * L)
+{
+    char *s;
+    size_t ff;
+    int cur_cs;
+    integer f;
+    if (lua_type(L, 1) == LUA_TSTRING) {
+        s = (char *) lua_tolstring(L, 1, &ff);
+        cur_cs = string_lookup(s, ff);
+        if (cur_cs == undefined_control_sequence || cur_cs == undefined_cs_cmd) {
+            lua_pushstring(L, "not a valid font csname");
+	    f = -1;
+        } else {
+            f = equiv(cur_cs);
+        }
+        lua_pushnumber(L, f);
+    } else {
+        lua_pushstring(L, "expected font csname as first argument");
+        lua_error(L);
+    }
+    return 1;
+}
+
+
 static const struct luaL_reg fontlib[] = {
     {"read_tfm", font_read_tfm},
     {"read_vf", font_read_vf},
@@ -266,6 +290,7 @@ static const struct luaL_reg fontlib[] = {
     {"setfont", setfont},
     {"define", deffont},
     {"nextid", nextfontid},
+    {"id", getfontid},
     {"frozen", frozenfont},
     {NULL, NULL}                /* sentinel */
 };
-- 
1.6.3.3

Attachment: signature.asc
Description: Digital signature

_______________________________________________
dev-luatex mailing list
[email protected]
http://www.ntg.nl/mailman/listinfo/dev-luatex

Reply via email to