~ubuntu-branches/ubuntu/saucy/luatex/saucy

« back to all changes in this revision

Viewing changes to source/texk/web2c/luatexdir/luafontloader/src/luafflib.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2009-12-25 09:47:05 UTC
  • mfrom: (1.1.9 upstream) (4.2.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091225094705-y33rpflo8t4u9nag
Tags: 0.50.0-1
* new upstream release
* disable fix-hurd-ftbfs patch, included upstream
* disable upstram-fixes, included upstream
* disable ubuntu_libpoppler-0.11, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* luafflib.c
 
2
   
 
3
   Copyright 2007-2009 Taco Hoekwater <taco@luatex.org>
 
4
 
 
5
   This file is part of LuaTeX.
 
6
 
 
7
   LuaTeX is free software; you can redistribute it and/or modify it under
 
8
   the terms of the GNU General Public License as published by the Free
 
9
   Software Foundation; either version 2 of the License, or (at your
 
10
   option) any later version.
 
11
 
 
12
   LuaTeX is distributed in the hope that it will be useful, but WITHOUT
 
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
14
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
15
   License for more details.
 
16
 
 
17
   You should have received a copy of the GNU General Public License along
 
18
   with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
 
19
 
1
20
/**
2
 
*  $Id $
3
21
*  @desc Support interface for fontforge 20070607
4
22
*  @version  1.0
5
23
*  @author Taco Hoekwater
13
31
#include "pfaedit.h"
14
32
#include "ustring.h"
15
33
 
 
34
static const char __svn_version[] =
 
35
    "$Id: luafflib.c 3187 2009-11-22 22:29:05Z oneiros $ "
 
36
    "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.50.0/source/texk/web2c/luatexdir/luafontloader/src/luafflib.c $";
 
37
 
16
38
extern char **gww_errors;
17
39
extern int gww_error_count;
18
 
extern void gwwv_errors_free (void);
 
40
extern void gwwv_errors_free(void);
19
41
extern struct ui_interface luaui_interface;
20
42
 
21
 
extern int readbinfile(FILE *f, unsigned char **b, int *s);
 
43
extern int readbinfile(FILE * f, unsigned char **b, int *s);
22
44
 
23
45
#define FONT_METATABLE "fontloader.splinefont"
24
46
 
25
47
#define LUA_OTF_VERSION "0.3"
26
48
 
27
 
static char *possub_type_enum[] = { 
28
 
  "null", "position", "pair",  "substitution", 
29
 
  "alternate", "multiple", "ligature", "lcaret",  
30
 
  "kerning", "vkerning", "anchors", "contextpos", 
31
 
  "contextsub", "chainpos", "chainsub","reversesub", 
32
 
  "max", "kernback", "vkernback", NULL };
 
49
static char *possub_type_enum[] = {
 
50
    "null", "position", "pair", "substitution",
 
51
    "alternate", "multiple", "ligature", "lcaret",
 
52
    "kerning", "vkerning", "anchors", "contextpos",
 
53
    "contextsub", "chainpos", "chainsub", "reversesub",
 
54
    "max", "kernback", "vkernback", NULL
 
55
};
33
56
 
34
57
#define LAST_POSSUB_TYPE_ENUM 18
35
58
 
36
59
#define eight_nulls() NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
37
60
 
38
 
static char *asm_type_enum[] = { 
39
 
  "indic", "context", "lig", NULL, "simple", "insert", NULL, NULL,
40
 
  eight_nulls(),
41
 
  NULL, "kern" };
42
 
 
43
 
static char *otf_lookup_type_enum[] = { 
44
 
  "gsub_start", "gsub_single", "gsub_multiple", "gsub_alternate", 
45
 
  "gsub_ligature", "gsub_context",  "gsub_contextchain", NULL, 
46
 
  "gsub_reversecontextchain", NULL, NULL, NULL,  NULL, NULL, NULL, NULL, /*0x00F */
47
 
  eight_nulls(),eight_nulls(),
48
 
  eight_nulls(),eight_nulls(),
49
 
  eight_nulls(),eight_nulls(),
50
 
  eight_nulls(),eight_nulls(),
51
 
  eight_nulls(),eight_nulls(),
52
 
  eight_nulls(),eight_nulls(),
53
 
  eight_nulls(),eight_nulls(),
54
 
  eight_nulls(),eight_nulls(),
55
 
  eight_nulls(),eight_nulls(),
56
 
  eight_nulls(),eight_nulls(),
57
 
  eight_nulls(),eight_nulls(),
58
 
  eight_nulls(),eight_nulls(),
59
 
  eight_nulls(),eight_nulls(),
60
 
  eight_nulls(),eight_nulls(),
61
 
  eight_nulls(), NULL, NULL, NULL, NULL,  NULL, "morx_indic", "morx_context", "morx_insert", /* 0x0FF*/
62
 
  "gpos_start", "gpos_single", "gpos_pair", "gpos_cursive", 
63
 
  "gpos_mark2base", "gpos_mark2ligature", "gpos_mark2mark",  "gpos_context", 
64
 
  "gpos_contextchain", NULL, NULL, NULL,  NULL, NULL, NULL, NULL, /* 0x10F */
65
 
  eight_nulls(),eight_nulls(),
66
 
  eight_nulls(),eight_nulls(),
67
 
  eight_nulls(),eight_nulls(),
68
 
  eight_nulls(),eight_nulls(),
69
 
  eight_nulls(),eight_nulls(),
70
 
  eight_nulls(),eight_nulls(),
71
 
  eight_nulls(),eight_nulls(),
72
 
  eight_nulls(),eight_nulls(),
73
 
  eight_nulls(),eight_nulls(),
74
 
  eight_nulls(),eight_nulls(),
75
 
  eight_nulls(),eight_nulls(),
76
 
  eight_nulls(),eight_nulls(),
77
 
  eight_nulls(),eight_nulls(),
78
 
  eight_nulls(),eight_nulls(),
79
 
  eight_nulls(), NULL, NULL, NULL, NULL,  NULL, NULL, NULL, "kern_statemachine", /* 0x1FF*/
80
 
};
81
 
 
82
 
 
83
 
static char *anchor_type_enum[] = { 
84
 
   "mark", "basechar", "baselig", "basemark", "centry", "cexit", "max", NULL };
 
61
static char *asm_type_enum[] = {
 
62
    "indic", "context", "lig", NULL, "simple", "insert", NULL, NULL,
 
63
    eight_nulls(),
 
64
    NULL, "kern"
 
65
};
 
66
 
 
67
static char *otf_lookup_type_enum[] = {
 
68
    "gsub_start", "gsub_single", "gsub_multiple", "gsub_alternate",
 
69
    "gsub_ligature", "gsub_context", "gsub_contextchain", NULL,
 
70
    "gsub_reversecontextchain", NULL, NULL, NULL, NULL, NULL, NULL, NULL,       /*0x00F */
 
71
    eight_nulls(), eight_nulls(),
 
72
    eight_nulls(), eight_nulls(),
 
73
    eight_nulls(), eight_nulls(),
 
74
    eight_nulls(), eight_nulls(),
 
75
    eight_nulls(), eight_nulls(),
 
76
    eight_nulls(), eight_nulls(),
 
77
    eight_nulls(), eight_nulls(),
 
78
    eight_nulls(), eight_nulls(),
 
79
    eight_nulls(), eight_nulls(),
 
80
    eight_nulls(), eight_nulls(),
 
81
    eight_nulls(), eight_nulls(),
 
82
    eight_nulls(), eight_nulls(),
 
83
    eight_nulls(), eight_nulls(),
 
84
    eight_nulls(), eight_nulls(),
 
85
    eight_nulls(), NULL, NULL, NULL, NULL, NULL, "morx_indic", "morx_context", "morx_insert",   /* 0x0FF */
 
86
    "gpos_start", "gpos_single", "gpos_pair", "gpos_cursive",
 
87
    "gpos_mark2base", "gpos_mark2ligature", "gpos_mark2mark", "gpos_context",
 
88
    "gpos_contextchain", NULL, NULL, NULL, NULL, NULL, NULL, NULL,      /* 0x10F */
 
89
    eight_nulls(), eight_nulls(),
 
90
    eight_nulls(), eight_nulls(),
 
91
    eight_nulls(), eight_nulls(),
 
92
    eight_nulls(), eight_nulls(),
 
93
    eight_nulls(), eight_nulls(),
 
94
    eight_nulls(), eight_nulls(),
 
95
    eight_nulls(), eight_nulls(),
 
96
    eight_nulls(), eight_nulls(),
 
97
    eight_nulls(), eight_nulls(),
 
98
    eight_nulls(), eight_nulls(),
 
99
    eight_nulls(), eight_nulls(),
 
100
    eight_nulls(), eight_nulls(),
 
101
    eight_nulls(), eight_nulls(),
 
102
    eight_nulls(), eight_nulls(),
 
103
    eight_nulls(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, "kern_statemachine",       /* 0x1FF */
 
104
};
 
105
 
 
106
 
 
107
static char *anchor_type_enum[] = {
 
108
    "mark", "basechar", "baselig", "basemark", "centry", "cexit", "max", NULL
 
109
};
85
110
 
86
111
#define MAX_ANCHOR_TYPE 7
87
112
 
88
 
static char *anchorclass_type_enum[] = { 
89
 
  "mark", "mkmk", "curs", "mklg", NULL };
90
 
 
91
 
static char *glyph_class_enum[] = { 
92
 
  "automatic", "none" ,"base", "ligature","mark", "component", NULL };
93
 
 
94
 
static char *ttfnames_enum[ttf_namemax] = { 
 
113
static char *anchorclass_type_enum[] = {
 
114
    "mark", "mkmk", "curs", "mklg", NULL
 
115
};
 
116
 
 
117
static char *glyph_class_enum[] = {
 
118
    "automatic", "none", "base", "ligature", "mark", "component", NULL
 
119
};
 
120
 
 
121
static char *ttfnames_enum[ttf_namemax] = {
95
122
    "copyright", "family", "subfamily", "uniqueid",
96
123
    "fullname", "version", "postscriptname", "trademark",
97
124
    "manufacturer", "designer", "descriptor", "venderurl",
98
125
    "designerurl", "license", "licenseurl", "idontknow",
99
126
    "preffamilyname", "prefmodifiers", "compatfull", "sampletext",
100
 
    "cidfindfontname", "wwsfamily", "wwssubfamily" };
101
 
 
102
 
static char *fpossub_format_enum [] = { 
103
 
   "glyphs", "class","coverage","reversecoverage" , NULL};
104
 
 
105
 
static char *tex_type_enum[4] = { "unset", "text", "math", "mathext"};
 
127
    "cidfindfontname", "wwsfamily", "wwssubfamily"
 
128
};
 
129
 
 
130
static char *fpossub_format_enum[] = {
 
131
    "glyphs", "class", "coverage", "reversecoverage", NULL
 
132
};
 
133
 
 
134
static char *tex_type_enum[4] = { "unset", "text", "math", "mathext" };
106
135
 
107
136
/* has an offset of 1, ui_none = 0. */
108
137
static char *uni_interp_enum[9] = {
109
 
  "unset", "none", "adobe", "greek", "japanese",
110
 
  "trad_chinese", "simp_chinese", "korean", "ams" };
111
 
        
 
138
    "unset", "none", "adobe", "greek", "japanese",
 
139
    "trad_chinese", "simp_chinese", "korean", "ams"
 
140
};
 
141
 
112
142
#define check_isfont(L,b) (SplineFont **)luaL_checkudata(L,b,FONT_METATABLE)
113
143
 
114
 
void handle_generic_pst (lua_State *L, struct generic_pst *pst);  /* forward */
115
 
void handle_generic_fpst (lua_State *L, struct generic_fpst *fpst);  /* forward */
116
 
void handle_generic_asm (lua_State *L, struct generic_asm *sm) ;
117
 
void handle_kernclass (lua_State *L, struct kernclass *kerns);
118
 
void handle_anchorclass (lua_State *L, struct anchorclass *anchor);
119
 
void handle_splinefont(lua_State *L, struct splinefont *sf) ;
120
 
 
121
 
 
122
 
void
123
 
lua_ff_pushfont(lua_State *L, SplineFont *sf) {
124
 
  SplineFont **a;
125
 
  if (sf==NULL) {
126
 
    lua_pushnil(L);
127
 
  } else {
128
 
        a = lua_newuserdata(L,sizeof(SplineFont *));
129
 
        *a = sf;
130
 
    luaL_getmetatable(L,FONT_METATABLE);
131
 
    lua_setmetatable(L,-2);
132
 
  }
133
 
  return;
134
 
}
135
 
 
136
 
 
137
 
static int 
138
 
ff_open (lua_State *L) {
139
 
  SplineFont *sf;
140
 
  const char *fontname;
141
 
  FILE *l;
142
 
  char s[511];
143
 
  size_t len;
144
 
  int args,i ;
145
 
  int openflags = 1;
146
 
  fontname = luaL_checkstring(L,1);
147
 
  /* test fontname for existance */
148
 
  if ((l = fopen(fontname,"r"))) {
149
 
        fclose(l); 
150
 
  } else {
151
 
        lua_pushfstring(L,"font loading failed for %s (read error)\n", fontname);
152
 
        lua_error(L);
153
 
  }
154
 
  args = lua_gettop(L);
155
 
  if (args>=2 && lua_isstring(L,2)) {
156
 
    if (*(fontname+strlen(fontname))!=')') {
157
 
      /* possibly fails for embedded parens in the font name */
158
 
      snprintf(s,511,"%s(%s)", fontname, lua_tolstring(L,2,&len));
159
 
      if (len==0) {
160
 
        snprintf(s,511,"%s", fontname);
161
 
      }
162
 
    }
163
 
  } else {
164
 
        snprintf(s,511,"%s", fontname);
165
 
  }
166
 
  if (strlen(s)>0) {
167
 
    gww_error_count=0;
168
 
        sf = ReadSplineFont((char *)s,openflags);
169
 
        if (sf==NULL) {
170
 
          lua_pushfstring(L,"font loading failed for %s\n", s);
171
 
          if (gww_error_count>0) {
172
 
                for (i=0;i<gww_error_count;i++) {
173
 
                  lua_pushstring(L,gww_errors[i]);
174
 
          lua_concat(L,2);
175
 
                }
176
 
                gwwv_errors_free();
177
 
      }
178
 
          lua_error(L);
179
 
        } else {
180
 
          FVAppend(_FontViewCreate(sf));
181
 
          lua_ff_pushfont(L,sf);
182
 
          if (gww_error_count>0) {
183
 
                lua_newtable(L);
184
 
                for (i=0;i<gww_error_count;i++) {
185
 
                  lua_pushstring(L,gww_errors[i]);
186
 
                  lua_rawseti(L,-2,(i+1));
187
 
                }
188
 
                gwwv_errors_free();
189
 
          } else {
190
 
                lua_pushnil(L);
191
 
          }
192
 
        }
193
 
  } else {
194
 
        lua_pushfstring(L,"font loading failed: empty string given\n", fontname);
195
 
        lua_error(L);
196
 
  }
197
 
  return 2;
198
 
}
199
 
 
200
 
 
201
 
static int 
202
 
ff_close (lua_State *L) {
203
 
  SplineFont **sf;
204
 
  /*fputs("ff_close called",stderr);*/
205
 
  sf = check_isfont(L,1);
206
 
  if (*sf!=NULL) {
207
 
    SplineFontFree(*sf);
208
 
    *sf = NULL;
209
 
  }
210
 
  return 0;
211
 
}
212
 
 
213
 
static int 
214
 
ff_apply_featurefile (lua_State *L) {
215
 
  SplineFont **sf;
216
 
  char *fname;
217
 
  sf = check_isfont(L,1);
218
 
  fname = (char *)luaL_checkstring(L,2);
219
 
  SFApplyFeatureFilename(*sf,fname);
220
 
  return 0;
221
 
}
222
 
 
223
 
static int 
224
 
ff_apply_afmfile (lua_State *L) {
225
 
  SplineFont **sf;
226
 
  char *fname;
227
 
  sf = check_isfont(L,1);
228
 
  fname = (char *)luaL_checkstring(L,2);
229
 
  CheckAfmOfPostscript(*sf,fname,(*sf)->map);
230
 
 
231
 
  return 0;
232
 
}
233
 
 
234
 
 
235
 
 
236
 
static void 
237
 
dump_intfield (lua_State *L, char *name, long int field) {
238
 
  lua_checkstack(L,2);
239
 
  lua_pushstring(L,name);
240
 
  lua_pushnumber(L,field);
241
 
  lua_rawset(L,-3);
242
 
}
243
 
 
244
 
static void 
245
 
dump_realfield (lua_State *L, char *name, real field) {
246
 
  lua_checkstack(L,2);
247
 
  lua_pushstring(L,name);
248
 
  lua_pushnumber(L,field);
249
 
  lua_rawset(L,-3);
 
144
void handle_generic_pst(lua_State * L, struct generic_pst *pst);        /* forward */
 
145
void handle_generic_fpst(lua_State * L, struct generic_fpst *fpst);     /* forward */
 
146
void handle_generic_asm(lua_State * L, struct generic_asm *sm);
 
147
void handle_kernclass(lua_State * L, struct kernclass *kerns);
 
148
void handle_anchorclass(lua_State * L, struct anchorclass *anchor);
 
149
void handle_splinefont(lua_State * L, struct splinefont *sf);
 
150
 
 
151
 
 
152
void lua_ff_pushfont(lua_State * L, SplineFont * sf)
 
153
{
 
154
    SplineFont **a;
 
155
    if (sf == NULL) {
 
156
        lua_pushnil(L);
 
157
    } else {
 
158
        a = lua_newuserdata(L, sizeof(SplineFont *));
 
159
        *a = sf;
 
160
        luaL_getmetatable(L, FONT_METATABLE);
 
161
        lua_setmetatable(L, -2);
 
162
    }
 
163
    return;
 
164
}
 
165
 
 
166
 
 
167
static int ff_open(lua_State * L)
 
168
{
 
169
    SplineFont *sf;
 
170
    const char *fontname;
 
171
    FILE *l;
 
172
    char s[511];
 
173
    size_t len;
 
174
    int args, i;
 
175
    int openflags = 1;
 
176
    fontname = luaL_checkstring(L, 1);
 
177
    /* test fontname for existance */
 
178
    if ((l = fopen(fontname, "r"))) {
 
179
        fclose(l);
 
180
    } else {
 
181
        lua_pushnil(L);
 
182
        lua_pushfstring(L, "font loading failed for %s (read error)\n",
 
183
                        fontname);
 
184
        return 2;
 
185
    }
 
186
    args = lua_gettop(L);
 
187
    if (args >= 2 && lua_isstring(L, 2)) {
 
188
        if (*(fontname + strlen(fontname)) != ')') {
 
189
            /* possibly fails for embedded parens in the font name */
 
190
            snprintf(s, 511, "%s(%s)", fontname, lua_tolstring(L, 2, &len));
 
191
            if (len == 0) {
 
192
                snprintf(s, 511, "%s", fontname);
 
193
            }
 
194
        }
 
195
    } else {
 
196
        snprintf(s, 511, "%s", fontname);
 
197
    }
 
198
    if (strlen(s) > 0) {
 
199
        gww_error_count = 0;
 
200
        sf = ReadSplineFont((char *) s, openflags);
 
201
        if (sf == NULL) {
 
202
            lua_pushnil(L);
 
203
            lua_pushfstring(L, "font loading failed for %s\n", s);
 
204
            if (gww_error_count > 0) {
 
205
                for (i = 0; i < gww_error_count; i++) {
 
206
                    lua_pushstring(L, gww_errors[i]);
 
207
                    lua_concat(L, 2);
 
208
                }
 
209
                gwwv_errors_free();
 
210
            }
 
211
        } else {
 
212
            FVAppend(_FontViewCreate(sf));
 
213
            lua_ff_pushfont(L, sf);
 
214
            if (gww_error_count > 0) {
 
215
                lua_newtable(L);
 
216
                for (i = 0; i < gww_error_count; i++) {
 
217
                    lua_pushstring(L, gww_errors[i]);
 
218
                    lua_rawseti(L, -2, (i + 1));
 
219
                }
 
220
                gwwv_errors_free();
 
221
            } else {
 
222
                lua_pushnil(L);
 
223
            }
 
224
        }
 
225
    } else {
 
226
        lua_pushnil(L);
 
227
        lua_pushfstring(L, "font loading failed: empty string given\n",
 
228
                        fontname);
 
229
    }
 
230
    return 2;
 
231
}
 
232
 
 
233
 
 
234
static int ff_close(lua_State * L)
 
235
{
 
236
    SplineFont **sf;
 
237
    /*fputs("ff_close called",stderr); */
 
238
    sf = check_isfont(L, 1);
 
239
    if (*sf != NULL) {
 
240
        SplineFontFree(*sf);
 
241
        *sf = NULL;
 
242
    }
 
243
    return 0;
 
244
}
 
245
 
 
246
static int ff_apply_featurefile(lua_State * L)
 
247
{
 
248
    SplineFont **sf;
 
249
    char *fname;
 
250
    sf = check_isfont(L, 1);
 
251
    fname = (char *) luaL_checkstring(L, 2);
 
252
    SFApplyFeatureFilename(*sf, fname);
 
253
    return 0;
 
254
}
 
255
 
 
256
static int ff_apply_afmfile(lua_State * L)
 
257
{
 
258
    SplineFont **sf;
 
259
    char *fname;
 
260
    sf = check_isfont(L, 1);
 
261
    fname = (char *) luaL_checkstring(L, 2);
 
262
    CheckAfmOfPostscript(*sf, fname, (*sf)->map);
 
263
 
 
264
    return 0;
 
265
}
 
266
 
 
267
 
 
268
 
 
269
static void dump_intfield(lua_State * L, char *name, long int field)
 
270
{
 
271
    lua_checkstack(L, 2);
 
272
    lua_pushstring(L, name);
 
273
    lua_pushnumber(L, field);
 
274
    lua_rawset(L, -3);
 
275
}
 
276
 
 
277
static void dump_realfield(lua_State * L, char *name, real field)
 
278
{
 
279
    lua_checkstack(L, 2);
 
280
    lua_pushstring(L, name);
 
281
    lua_pushnumber(L, field);
 
282
    lua_rawset(L, -3);
250
283
}
251
284
 
252
285
 
253
286
#define dump_cond_intfield(a,b,c) if ((c)!=0) { dump_intfield ((a),(b),(c)); }
254
287
 
255
288
 
256
 
static void 
257
 
dump_stringfield (lua_State *L, char *name, char *field) {
258
 
  lua_checkstack(L,2);
259
 
  lua_pushstring(L,name);
260
 
  lua_pushstring(L,field);
261
 
  lua_rawset(L,-3);
262
 
}
263
 
 
264
 
static void 
265
 
dump_char_ref (lua_State *L, struct splinechar *spchar) {
266
 
  lua_checkstack(L,2);
267
 
  lua_pushstring(L,"char");
268
 
  lua_pushstring(L,spchar->name);
269
 
  lua_rawset(L,-3);
270
 
}
271
 
 
272
 
 
273
 
static void 
274
 
dump_lstringfield (lua_State *L, char *name, char *field, int len) {
275
 
  lua_checkstack(L,2);
276
 
  lua_pushstring(L,name);
277
 
  lua_pushlstring(L,field,len);
278
 
  lua_rawset(L,-3);
279
 
}
280
 
 
281
 
static void 
282
 
dump_enumfield (lua_State *L, char *name, int fid, char **fields) {
283
 
  lua_checkstack(L,2);
284
 
  lua_pushstring(L,name);
285
 
  lua_pushstring(L,fields[fid]);
286
 
  lua_rawset(L,-3);
287
 
}
288
 
 
289
 
static void 
290
 
dump_floatfield (lua_State *L, char *name, double field) {
291
 
  lua_checkstack(L,2);
292
 
  lua_pushstring(L,name);
293
 
  lua_pushnumber(L,field);
294
 
  lua_rawset(L,-3);
295
 
}
296
 
 
297
 
static char tag_string [5] = {0};
298
 
 
299
 
static char *make_tag_string (unsigned int field) {
300
 
  tag_string[0] = (field&0xFF000000) >> 24;
301
 
  tag_string[1] = (field&0x00FF0000) >> 16;
302
 
  tag_string[2] = (field&0x0000FF00) >> 8;
303
 
  tag_string[3] = (field&0x000000FF);
304
 
  return (char *)tag_string;
305
 
}
306
 
 
307
 
static char featbuf[32] = {0};
308
 
 
309
 
static char *make_mactag_string (unsigned int field) {
310
 
  sprintf( featbuf, "<%d,%d>", field>>16, field&0xffff );
311
 
  return (char *)featbuf;
312
 
}
313
 
 
314
 
 
315
 
static void 
316
 
dump_tag (lua_State *L, char *name, unsigned int field) {
317
 
  lua_checkstack(L,2);
318
 
  lua_pushstring(L,name);
319
 
  lua_pushlstring(L,make_tag_string(field),4);
320
 
  lua_rawset(L,-3);
321
 
}
322
 
 
323
 
static void 
324
 
dump_mactag (lua_State *L, char *name, unsigned int field) {
325
 
  lua_checkstack(L,2);
326
 
  lua_pushstring(L,name);
327
 
  lua_pushstring(L,make_mactag_string(field));
328
 
  lua_rawset(L,-3);
329
 
}
330
 
 
331
 
void
332
 
dump_subtable_name (lua_State *L, char *name, struct lookup_subtable *s) {
333
 
  /* this is likely a backref */ 
334
 
  if (s==NULL)
335
 
    return;
336
 
  lua_checkstack(L,2);
337
 
  if (s->next == NULL) {
338
 
    dump_stringfield(L,name,s->subtable_name);
339
 
  } else {
340
 
    /* can this really happen ? */
341
 
    int i = 0;
342
 
    lua_newtable(L);
343
 
    while (s!=NULL) {
344
 
      lua_pushstring(L, s->subtable_name);
345
 
      lua_rawseti(L, -2, ++i);
346
 
      s = s->next;
 
289
static void dump_stringfield(lua_State * L, char *name, char *field)
 
290
{
 
291
    lua_checkstack(L, 2);
 
292
    lua_pushstring(L, name);
 
293
    lua_pushstring(L, field);
 
294
    lua_rawset(L, -3);
 
295
}
 
296
 
 
297
static void dump_char_ref(lua_State * L, struct splinechar *spchar)
 
298
{
 
299
    lua_checkstack(L, 2);
 
300
    lua_pushstring(L, "char");
 
301
    lua_pushstring(L, spchar->name);
 
302
    lua_rawset(L, -3);
 
303
}
 
304
 
 
305
 
 
306
static void dump_lstringfield(lua_State * L, char *name, char *field, int len)
 
307
{
 
308
    lua_checkstack(L, 2);
 
309
    lua_pushstring(L, name);
 
310
    lua_pushlstring(L, field, len);
 
311
    lua_rawset(L, -3);
 
312
}
 
313
 
 
314
static void dump_enumfield(lua_State * L, char *name, int fid, char **fields)
 
315
{
 
316
    lua_checkstack(L, 2);
 
317
    lua_pushstring(L, name);
 
318
    lua_pushstring(L, fields[fid]);
 
319
    lua_rawset(L, -3);
 
320
}
 
321
 
 
322
static void dump_floatfield(lua_State * L, char *name, double field)
 
323
{
 
324
    lua_checkstack(L, 2);
 
325
    lua_pushstring(L, name);
 
326
    lua_pushnumber(L, field);
 
327
    lua_rawset(L, -3);
 
328
}
 
329
 
 
330
static char tag_string[5] = { 0 };
 
331
 
 
332
static char *make_tag_string(unsigned int field)
 
333
{
 
334
    tag_string[0] = (field & 0xFF000000) >> 24;
 
335
    tag_string[1] = (field & 0x00FF0000) >> 16;
 
336
    tag_string[2] = (field & 0x0000FF00) >> 8;
 
337
    tag_string[3] = (field & 0x000000FF);
 
338
    return (char *) tag_string;
 
339
}
 
340
 
 
341
static char featbuf[32] = { 0 };
 
342
 
 
343
static char *make_mactag_string(unsigned int field)
 
344
{
 
345
    sprintf(featbuf, "<%d,%d>", field >> 16, field & 0xffff);
 
346
    return (char *) featbuf;
 
347
}
 
348
 
 
349
 
 
350
static void dump_tag(lua_State * L, char *name, unsigned int field)
 
351
{
 
352
    lua_checkstack(L, 2);
 
353
    lua_pushstring(L, name);
 
354
    lua_pushlstring(L, make_tag_string(field), 4);
 
355
    lua_rawset(L, -3);
 
356
}
 
357
 
 
358
static void dump_mactag(lua_State * L, char *name, unsigned int field)
 
359
{
 
360
    lua_checkstack(L, 2);
 
361
    lua_pushstring(L, name);
 
362
    lua_pushstring(L, make_mactag_string(field));
 
363
    lua_rawset(L, -3);
 
364
}
 
365
 
 
366
void dump_subtable_name(lua_State * L, char *name, struct lookup_subtable *s)
 
367
{
 
368
    /* this is likely a backref */
 
369
    if (s == NULL)
 
370
        return;
 
371
    lua_checkstack(L, 2);
 
372
    if (s->next == NULL) {
 
373
        dump_stringfield(L, name, s->subtable_name);
 
374
    } else {
 
375
        /* can this really happen ? */
 
376
        int i = 0;
 
377
        lua_newtable(L);
 
378
        while (s != NULL) {
 
379
            lua_pushstring(L, s->subtable_name);
 
380
            lua_rawseti(L, -2, ++i);
 
381
            s = s->next;
 
382
        }
 
383
        lua_setfield(L, -2, name);
347
384
    }
348
 
    lua_setfield(L, -2, name);
349
 
  }
350
385
}
351
386
 
352
387
 
363
398
      next = next->next;                                                \
364
399
    } }
365
400
 
366
 
void
367
 
do_handle_scriptlanglist (lua_State *L, struct scriptlanglist *sl) {
368
 
  int k;
369
 
  dump_tag(L,"script",          sl->script);
370
 
 
371
 
  lua_checkstack(L,3);
372
 
  lua_newtable(L);
373
 
  for (k=0;k<MAX_LANG;k++) {
374
 
    if (sl->langs[k] != 0) {
375
 
      lua_pushnumber(L,(k+1));
376
 
      lua_pushstring(L,make_tag_string(sl->langs[k]));
377
 
      lua_rawset(L,-3);
378
 
    }
379
 
  }
380
 
 
381
 
  if (sl->lang_cnt>=MAX_LANG) {
382
 
    for (k=MAX_LANG;k<sl->lang_cnt;k++) {
383
 
      lua_pushnumber(L,(k+1));
384
 
      lua_pushstring(L,make_tag_string(sl->morelangs[k-MAX_LANG]));
385
 
      lua_rawset(L,-3);
386
 
    }
387
 
  }
388
 
  lua_setfield(L,-2,"langs");
389
 
390
 
 
391
 
void
392
 
handle_scriptlanglist (lua_State *L, struct scriptlanglist *sll) {
393
 
  struct scriptlanglist *next;
394
 
  NESTED_TABLE(do_handle_scriptlanglist,sll,4);
395
 
}
396
 
 
397
 
void
398
 
do_handle_featurescriptlanglist (lua_State *L, struct featurescriptlanglist *features) {
399
 
  if (features->ismac) {
400
 
        dump_mactag (L,"tag",features->featuretag);
401
 
  } else {
402
 
        dump_tag (L,"tag",features->featuretag);
403
 
  }
404
 
  lua_newtable(L);
405
 
  handle_scriptlanglist(L, features->scripts);
406
 
  lua_setfield(L,-2,"scripts");
407
 
  dump_cond_intfield (L,"ismac",features->ismac);
408
 
409
 
 
410
 
void
411
 
handle_featurescriptlanglist (lua_State *L, struct featurescriptlanglist *features) {
412
 
  struct featurescriptlanglist *next;
413
 
  NESTED_TABLE(do_handle_featurescriptlanglist,features,3);
414
 
}
415
 
 
416
 
void 
417
 
do_handle_lookup_subtable (lua_State *L, struct lookup_subtable *subtable) {
418
 
 
419
 
  dump_stringfield(L,"name",                 subtable->subtable_name); 
420
 
  dump_stringfield(L,"suffix",               subtable->suffix); 
421
 
 
422
 
  /* struct otlookup *lookup; */ /* this is the parent */
423
 
 
424
 
  /* dump_intfield   (L,"unused",               subtable->unused); */
425
 
  /* The next one is true if there is no fpst, false otherwise */
426
 
  /*
427
 
     dump_intfield      (L,"per_glyph_pst_or_kern",subtable->per_glyph_pst_or_kern); 
428
 
  */
429
 
  dump_cond_intfield (L,"anchor_classes",       subtable->anchor_classes); 
430
 
  dump_cond_intfield (L,"vertical_kerning",     subtable->vertical_kerning); 
431
 
 
432
 
  if (subtable->kc != NULL) {
433
 
    lua_newtable(L);
434
 
    handle_kernclass(L, subtable->kc);
435
 
    lua_setfield(L,-2, "kernclass");
436
 
  }
437
 
 
 
401
#define NESTED_TABLE_SF(a,b,c,d) {                                      \
 
402
    int k = 1;                                                          \
 
403
    next = b;                                                                                                                   \
 
404
    while (next != NULL) {                                              \
 
405
      lua_checkstack(L,2);                                                                                              \
 
406
      lua_pushnumber(L,k); k++;                                         \
 
407
      lua_createtable(L,0,d);                                           \
 
408
      a(L, next, c);                                                    \
 
409
      lua_rawset(L,-3);                                                 \
 
410
      next = next->next;                                                \
 
411
    } }
 
412
 
 
413
 
 
414
void do_handle_scriptlanglist(lua_State * L, struct scriptlanglist *sl)
 
415
{
 
416
    int k;
 
417
    dump_tag(L, "script", sl->script);
 
418
 
 
419
    lua_checkstack(L, 3);
 
420
    lua_newtable(L);
 
421
    for (k = 0; k < MAX_LANG; k++) {
 
422
        if (sl->langs[k] != 0) {
 
423
            lua_pushnumber(L, (k + 1));
 
424
            lua_pushstring(L, make_tag_string(sl->langs[k]));
 
425
            lua_rawset(L, -3);
 
426
        }
 
427
    }
 
428
 
 
429
    if (sl->lang_cnt >= MAX_LANG) {
 
430
        for (k = MAX_LANG; k < sl->lang_cnt; k++) {
 
431
            lua_pushnumber(L, (k + 1));
 
432
            lua_pushstring(L, make_tag_string(sl->morelangs[k - MAX_LANG]));
 
433
            lua_rawset(L, -3);
 
434
        }
 
435
    }
 
436
    lua_setfield(L, -2, "langs");
 
437
}
 
438
 
 
439
void handle_scriptlanglist(lua_State * L, struct scriptlanglist *sll)
 
440
{
 
441
    struct scriptlanglist *next;
 
442
    NESTED_TABLE(do_handle_scriptlanglist, sll, 4);
 
443
}
 
444
 
 
445
void
 
446
do_handle_featurescriptlanglist(lua_State * L,
 
447
                                struct featurescriptlanglist *features)
 
448
{
 
449
    if (features->ismac) {
 
450
        dump_mactag(L, "tag", features->featuretag);
 
451
    } else {
 
452
        dump_tag(L, "tag", features->featuretag);
 
453
    }
 
454
    lua_newtable(L);
 
455
    handle_scriptlanglist(L, features->scripts);
 
456
    lua_setfield(L, -2, "scripts");
 
457
    dump_cond_intfield(L, "ismac", features->ismac);
 
458
}
 
459
 
 
460
void
 
461
handle_featurescriptlanglist(lua_State * L,
 
462
                             struct featurescriptlanglist *features)
 
463
{
 
464
    struct featurescriptlanglist *next;
 
465
    NESTED_TABLE(do_handle_featurescriptlanglist, features, 3);
 
466
}
 
467
 
 
468
void do_handle_lookup_subtable(lua_State * L, struct lookup_subtable *subtable)
 
469
{
 
470
 
 
471
    dump_stringfield(L, "name", subtable->subtable_name);
 
472
    dump_stringfield(L, "suffix", subtable->suffix);
 
473
 
 
474
    /* struct otlookup *lookup; *//* this is the parent */
 
475
 
 
476
    /* dump_intfield   (L,"unused",               subtable->unused); */
 
477
    /* The next one is true if there is no fpst, false otherwise */
 
478
    /*
 
479
       dump_intfield      (L,"per_glyph_pst_or_kern",subtable->per_glyph_pst_or_kern); 
 
480
     */
 
481
    dump_cond_intfield(L, "anchor_classes", subtable->anchor_classes);
 
482
    dump_cond_intfield(L, "vertical_kerning", subtable->vertical_kerning);
 
483
 
 
484
    if (subtable->kc != NULL) {
 
485
        lua_newtable(L);
 
486
        handle_kernclass(L, subtable->kc);
 
487
        lua_setfield(L, -2, "kernclass");
 
488
    }
438
489
#if 0
439
 
  if (subtable->fpst != NULL) {
440
 
    /* lua_newtable(L); */
441
 
    handle_generic_fpst(L, subtable->fpst);
442
 
    /* lua_setfield(L,-2, "fpst"); */
443
 
  }
 
490
    if (subtable->fpst != NULL) {
 
491
        /* lua_newtable(L); */
 
492
        handle_generic_fpst(L, subtable->fpst);
 
493
        /* lua_setfield(L,-2, "fpst"); */
 
494
    }
444
495
#endif
445
496
 
446
 
  if (subtable->sm != NULL) {
447
 
    lua_newtable(L);
448
 
    handle_generic_asm(L, subtable->sm);
449
 
    lua_setfield(L,-2, "sm");
450
 
  }
451
 
  /* int subtable_offset; */ /* used by OTF file generation */
452
 
  /* int32 *extra_subtables; */ /* used by OTF file generation */
453
 
}
454
 
 
455
 
void
456
 
handle_lookup_subtable (lua_State *L, struct lookup_subtable *subtable) {
457
 
  struct lookup_subtable *next;
458
 
  NESTED_TABLE(do_handle_lookup_subtable,subtable,2); 
459
 
}
460
 
 
461
 
void 
462
 
do_handle_lookup (lua_State *L, struct otlookup *lookup ) {
463
 
 
464
 
  dump_enumfield     (L,"type",             lookup->lookup_type, otf_lookup_type_enum); 
465
 
 
466
 
  lua_newtable(L);
467
 
  if (lookup->lookup_flags & pst_r2l) {
468
 
    lua_pushstring(L,"r2l");  lua_pushboolean(L,1);   lua_rawset(L,-3);
469
 
  }
470
 
  if (lookup->lookup_flags & pst_ignorebaseglyphs) {
471
 
    lua_pushstring(L,"ignorebaseglyphs");  lua_pushboolean(L,1);   lua_rawset(L,-3);
472
 
  }
473
 
  if (lookup->lookup_flags & pst_ignoreligatures) {
474
 
    lua_pushstring(L,"ignoreligatures");  lua_pushboolean(L,1);   lua_rawset(L,-3);
475
 
  }
476
 
  if (lookup->lookup_flags & pst_ignorecombiningmarks) {
477
 
    lua_pushstring(L,"ignorecombiningmarks");  lua_pushboolean(L,1);   lua_rawset(L,-3);
478
 
  }
479
 
  lua_setfield(L,-2,"flags");
480
 
 
481
 
 
482
 
  dump_stringfield   (L,"name",             lookup->lookup_name); 
483
 
 
484
 
  if (lookup->features != NULL) {
485
 
    lua_newtable(L);
486
 
    handle_featurescriptlanglist(L,lookup->features); 
487
 
    lua_setfield(L,-2,"features");
488
 
  }
489
 
 
490
 
  if (lookup->subtables != NULL) {
491
 
    lua_newtable(L);
492
 
    handle_lookup_subtable(L,lookup->subtables);
493
 
    lua_setfield(L,-2,"subtables");
494
 
  }
495
 
 
496
 
  /* dump_intfield   (L,"unused",           lookup->unused);  */
497
 
  /* dump_intfield   (L,"empty",            lookup->empty); */
498
 
  /* dump_intfield   (L,"store_in_afm",     lookup->store_in_afm); */
499
 
  /* dump_intfield   (L,"needs_extension",  lookup->needs_extension); */
500
 
  /* dump_intfield   (L,"temporary_kern",   lookup->temporary_kern); */
501
 
  /* dump_intfield   (L,"def_lang_checked", lookup->def_lang_checked); */
502
 
  /* dump_intfield   (L,"def_lang_found",   lookup->def_lang_found); */
503
 
  /* dump_intfield   (L,"ticked",           lookup->ticked); */
504
 
  /* dump_intfield   (L,"subcnt",           lookup->subcnt); */
505
 
  /* dump_intfield   (L,"lookup_index",     lookup->lookup_index); */ /* identical to array index */
506
 
  /* dump_intfield   (L,"lookup_offset",    lookup->lookup_offset); */
507
 
  /* dump_intfield   (L,"lookup_length",    lookup->lookup_length); */
508
 
  /* dump_stringfield(L,"tempname",         lookup->tempname); */
509
 
 
510
 
}
511
 
 
512
 
void
513
 
handle_lookup (lua_State *L, struct otlookup *lookup ) {
514
 
  struct otlookup *next;
515
 
  NESTED_TABLE(do_handle_lookup,lookup,18); /* 18 is a guess */
516
 
}
517
 
 
518
 
void
519
 
do_handle_kernpair (lua_State *L, struct kernpair *kp) {
520
 
 
521
 
  if (kp->sc != NULL)
522
 
    dump_char_ref(L, kp->sc); 
523
 
  dump_intfield(L,"off",          kp->off);
524
 
  /*  uint16 kcid;   */ /* temporary value */
525
 
  dump_subtable_name(L, "lookup", kp->subtable);
526
 
}
527
 
 
528
 
void
529
 
handle_kernpair (lua_State *L, struct kernpair *kp) {
530
 
  struct kernpair *next;
531
 
  NESTED_TABLE(do_handle_kernpair,kp,4);
532
 
}
533
 
 
534
 
void
535
 
handle_splinecharlist (lua_State *L, struct splinecharlist *scl) {
536
 
 
537
 
  struct splinecharlist *next = scl;
538
 
  int k = 1;
539
 
  lua_checkstack(L,10);
540
 
  while( next != NULL) {
541
 
    if (next->sc != NULL) {
542
 
      lua_pushnumber(L,k); k++;
543
 
      lua_pushstring(L,next->sc->name);
544
 
      lua_rawset(L,-3);
545
 
    }
546
 
    next = next->next;
547
 
  }
 
497
    if (subtable->sm != NULL) {
 
498
        lua_newtable(L);
 
499
        handle_generic_asm(L, subtable->sm);
 
500
        lua_setfield(L, -2, "sm");
 
501
    }
 
502
    /* int subtable_offset; *//* used by OTF file generation */
 
503
    /* int32 *extra_subtables; *//* used by OTF file generation */
 
504
}
 
505
 
 
506
void handle_lookup_subtable(lua_State * L, struct lookup_subtable *subtable)
 
507
{
 
508
    struct lookup_subtable *next;
 
509
    NESTED_TABLE(do_handle_lookup_subtable, subtable, 2);
 
510
}
 
511
 
 
512
void do_handle_lookup(lua_State * L, struct otlookup *lookup, SplineFont * sf)
 
513
{
 
514
    int mc;
 
515
 
 
516
    dump_enumfield(L, "type", lookup->lookup_type, otf_lookup_type_enum);
 
517
 
 
518
    lua_newtable(L);
 
519
    if (lookup->lookup_flags & pst_r2l) {
 
520
        lua_pushstring(L, "r2l");
 
521
        lua_pushboolean(L, 1);
 
522
        lua_rawset(L, -3);
 
523
    }
 
524
    if (lookup->lookup_flags & pst_ignorebaseglyphs) {
 
525
        lua_pushstring(L, "ignorebaseglyphs");
 
526
        lua_pushboolean(L, 1);
 
527
        lua_rawset(L, -3);
 
528
    }
 
529
    if (lookup->lookup_flags & pst_ignoreligatures) {
 
530
        lua_pushstring(L, "ignoreligatures");
 
531
        lua_pushboolean(L, 1);
 
532
        lua_rawset(L, -3);
 
533
    }
 
534
    if (lookup->lookup_flags & pst_ignorecombiningmarks) {
 
535
        lua_pushstring(L, "ignorecombiningmarks");
 
536
        lua_pushboolean(L, 1);
 
537
        lua_rawset(L, -3);
 
538
    }
 
539
    mc = (lookup->lookup_flags >> 8);
 
540
    if (mc > 0 && mc < sf->mark_class_cnt && sf->mark_class_names[mc] != NULL) {
 
541
        lua_pushstring(L, "mark_class");
 
542
        lua_pushstring(L, sf->mark_class_names[mc]);
 
543
        lua_rawset(L, -3);
 
544
    }
 
545
    lua_setfield(L, -2, "flags");
 
546
 
 
547
 
 
548
 
 
549
    dump_stringfield(L, "name", lookup->lookup_name);
 
550
 
 
551
    if (lookup->features != NULL) {
 
552
        lua_newtable(L);
 
553
        handle_featurescriptlanglist(L, lookup->features);
 
554
        lua_setfield(L, -2, "features");
 
555
    }
 
556
 
 
557
    if (lookup->subtables != NULL) {
 
558
        lua_newtable(L);
 
559
        handle_lookup_subtable(L, lookup->subtables);
 
560
        lua_setfield(L, -2, "subtables");
 
561
    }
 
562
 
 
563
    /* dump_intfield   (L,"unused",           lookup->unused);  */
 
564
    /* dump_intfield   (L,"empty",            lookup->empty); */
 
565
    /* dump_intfield   (L,"store_in_afm",     lookup->store_in_afm); */
 
566
    /* dump_intfield   (L,"needs_extension",  lookup->needs_extension); */
 
567
    /* dump_intfield   (L,"temporary_kern",   lookup->temporary_kern); */
 
568
    /* dump_intfield   (L,"def_lang_checked", lookup->def_lang_checked); */
 
569
    /* dump_intfield   (L,"def_lang_found",   lookup->def_lang_found); */
 
570
    /* dump_intfield   (L,"ticked",           lookup->ticked); */
 
571
    /* dump_intfield   (L,"subcnt",           lookup->subcnt); */
 
572
    /* dump_intfield   (L,"lookup_index",     lookup->lookup_index); *//* identical to array index */
 
573
    /* dump_intfield   (L,"lookup_offset",    lookup->lookup_offset); */
 
574
    /* dump_intfield   (L,"lookup_length",    lookup->lookup_length); */
 
575
    /* dump_stringfield(L,"tempname",         lookup->tempname); */
 
576
 
 
577
}
 
578
 
 
579
void handle_lookup(lua_State * L, struct otlookup *lookup, SplineFont * sf)
 
580
{
 
581
    struct otlookup *next;
 
582
    NESTED_TABLE_SF(do_handle_lookup, lookup, sf, 18);  /* 18 is a guess */
 
583
}
 
584
 
 
585
void do_handle_kernpair(lua_State * L, struct kernpair *kp)
 
586
{
 
587
 
 
588
    if (kp->sc != NULL)
 
589
        dump_char_ref(L, kp->sc);
 
590
    dump_intfield(L, "off", kp->off);
 
591
    /*  uint16 kcid;   *//* temporary value */
 
592
    dump_subtable_name(L, "lookup", kp->subtable);
 
593
}
 
594
 
 
595
void handle_kernpair(lua_State * L, struct kernpair *kp)
 
596
{
 
597
    struct kernpair *next;
 
598
    NESTED_TABLE(do_handle_kernpair, kp, 4);
 
599
}
 
600
 
 
601
void handle_splinecharlist(lua_State * L, struct splinecharlist *scl)
 
602
{
 
603
 
 
604
    struct splinecharlist *next = scl;
 
605
    int k = 1;
 
606
    lua_checkstack(L, 10);
 
607
    while (next != NULL) {
 
608
        if (next->sc != NULL) {
 
609
            lua_pushnumber(L, k);
 
610
            k++;
 
611
            lua_pushstring(L, next->sc->name);
 
612
            lua_rawset(L, -3);
 
613
        }
 
614
        next = next->next;
 
615
    }
548
616
}
549
617
 
550
618
 
556
624
/*  variant shape. The specifics depend on the selector and script */
557
625
/*  fid is currently unused, but may, someday, be used to do ttcs */
558
626
/* NOTE: GlyphInfo displays vs==-1 as vs==0, and fixes things up */
559
 
void
560
 
handle_altuni (lua_State *L, struct altuni *au) {
561
 
  struct altuni *next = au;
562
 
  int k = 1;
563
 
  lua_checkstack(L,3);
564
 
  while( next != NULL) {
565
 
    lua_newtable(L);
566
 
    dump_intfield(L, "unicode", next->unienc);
567
 
    if (next->vs != -1)
568
 
      dump_intfield(L, "variant", next->vs);
569
 
    /* dump_intfield(L, "fid", next->fid); */
570
 
    lua_rawseti(L, -2, k++);
571
 
    next = next->next;
572
 
  }
 
627
void handle_altuni(lua_State * L, struct altuni *au)
 
628
{
 
629
    struct altuni *next = au;
 
630
    int k = 1;
 
631
    lua_checkstack(L, 3);
 
632
    while (next != NULL) {
 
633
        lua_newtable(L);
 
634
        dump_intfield(L, "unicode", next->unienc);
 
635
        if (next->vs != -1)
 
636
            dump_intfield(L, "variant", next->vs);
 
637
        /* dump_intfield(L, "fid", next->fid); */
 
638
        lua_rawseti(L, -2, k++);
 
639
        next = next->next;
 
640
    }
573
641
}
574
642
 
575
643
 
576
644
 
577
645
#define interesting_vr(a) (((a)->xoff!=0) || ((a)->yoff!=0) || ((a)->h_adv_off!=0) || ((a)->v_adv_off!=0))
578
646
 
579
 
void handle_vr (lua_State *L, struct vr *pos) {
580
 
 
581
 
  dump_cond_intfield(L,"x", pos->xoff); 
582
 
  dump_cond_intfield(L,"y", pos->yoff); 
583
 
  dump_cond_intfield(L,"h", pos->h_adv_off); 
584
 
  dump_cond_intfield(L,"v", pos->v_adv_off);
585
 
 
586
 
}
587
 
 
588
 
void
589
 
do_handle_generic_pst (lua_State *L, struct generic_pst *pst) {
590
 
  int k;
591
 
  if (pst->type>LAST_POSSUB_TYPE_ENUM) {
592
 
    dump_tag(L,"type",  pst->type); 
593
 
  } else {
594
 
    dump_enumfield(L,"type",             pst->type, possub_type_enum); 
595
 
  }
596
 
  /*  unsigned int ticked: 1;*/
597
 
  /*  unsigned int temporary: 1;*/ /* Used in afm ligature closure */
598
 
  /*  struct lookup_subtable *subtable; */ /* handled by caller */
599
 
 
600
 
  lua_checkstack(L,4);
601
 
  lua_pushstring(L,"specification");
602
 
  lua_createtable(L,0,4);
603
 
  if (pst->type == pst_position) {
604
 
    handle_vr (L, &pst->u.pos);
605
 
  } else if (pst->type == pst_pair) {
606
 
    dump_stringfield(L,"paired",pst->u.pair.paired);
607
 
    if (pst->u.pair.vr != NULL) {
608
 
      lua_pushstring(L,"offsets");
609
 
      lua_createtable(L,2,0);
610
 
      if (interesting_vr(pst->u.pair.vr)) {
611
 
        lua_createtable(L,0,4);
612
 
        handle_vr (L, pst->u.pair.vr);
613
 
        lua_rawseti(L,-2,1);
614
 
      }
615
 
      if (interesting_vr(pst->u.pair.vr+1)) {
616
 
        lua_createtable(L,0,4);
617
 
        handle_vr (L, pst->u.pair.vr+1);
618
 
        lua_rawseti(L,-2,2);
619
 
      }
620
 
      lua_rawset(L,-3);
621
 
    }
622
 
  } else if (pst->type == pst_substitution) {
623
 
    dump_stringfield(L,"variant",pst->u.subs.variant);
624
 
  } else if (pst->type == pst_alternate) {
625
 
    dump_stringfield(L,"components",pst->u.mult.components);
626
 
  } else if (pst->type == pst_multiple) {
627
 
    dump_stringfield(L,"components",pst->u.alt.components);
628
 
  } else if (pst->type == pst_ligature) {
629
 
    dump_stringfield(L,"components",pst->u.lig.components);
630
 
    if (pst->u.lig.lig != NULL) {
631
 
      dump_char_ref(L,pst->u.lig.lig);
632
 
    }
633
 
  } else if (pst->type == pst_lcaret) {
634
 
    for (k=0;k<pst->u.lcaret.cnt;k++) {
635
 
      lua_pushnumber(L,(k+1));
636
 
      lua_pushnumber(L,pst->u.lcaret.carets[k]);
637
 
      lua_rawset(L,-3);
638
 
    }
639
 
  }
640
 
  lua_rawset(L,-3);
641
 
}
642
 
 
643
 
 
644
 
void
645
 
handle_generic_pst (lua_State *L, struct generic_pst *pst) {
646
 
  struct generic_pst *next;
647
 
  int k;
648
 
  int l = 1;
649
 
  next = pst; 
650
 
  /* most likely everything arrives in proper order. But to prevent
651
 
   * surprises, better do this is the proper way
652
 
   */
653
 
  while (next != NULL) {       
654
 
        if (next->subtable !=NULL && 
655
 
                next->subtable->subtable_name !=NULL) {
656
 
          lua_checkstack(L,3); /* just in case */
657
 
          lua_getfield(L,-1,next->subtable->subtable_name);
658
 
          if (!lua_istable(L,-1)) {
659
 
                lua_pop(L,1);
660
 
                lua_newtable(L);
661
 
                lua_setfield(L,-2,next->subtable->subtable_name);
662
 
                lua_getfield(L,-1,next->subtable->subtable_name);
663
 
          }
664
 
          k = lua_objlen(L,-1) + 1; 
665
 
          lua_pushnumber(L,k);
666
 
          lua_createtable(L,0,4);    
667
 
          do_handle_generic_pst(L, next);                
668
 
          lua_rawset(L,-3);          
669
 
          next = next->next;         
670
 
          lua_pop(L,1); /* pop the subtable */
671
 
        } else {
672
 
          /* Found a pst without subtable, or without subtable name */
673
 
          lua_pushnumber(L,l); l++;
674
 
          lua_createtable(L,0,4);    
675
 
          do_handle_generic_pst(L, next);                
676
 
          lua_rawset(L,-3);          
677
 
          next = next->next;         
678
 
        }
679
 
  }
680
 
}
681
 
 
682
 
void
683
 
do_handle_liglist (lua_State *L, struct liglist *ligofme) {
684
 
  lua_checkstack(L,2);
685
 
  if(ligofme->lig != NULL) {
686
 
    lua_createtable(L,0,6);
687
 
    handle_generic_pst (L,ligofme->lig);
688
 
    lua_setfield(L,-2,"lig");    
689
 
  }
690
 
  dump_char_ref(L,ligofme->first);
691
 
  if (ligofme->components != NULL) {
692
 
    lua_newtable(L);
693
 
    handle_splinecharlist (L,ligofme->components);
694
 
    lua_setfield(L,-2,"components");    
695
 
  }
696
 
  dump_intfield(L,"ccnt",ligofme->ccnt); 
697
 
}
698
 
 
699
 
void
700
 
handle_liglist (lua_State *L, struct liglist *ligofme) {
701
 
  struct liglist *next;
702
 
  NESTED_TABLE(do_handle_liglist,ligofme,3);
703
 
}
704
 
 
705
 
void
706
 
do_handle_anchorpoint (lua_State *L, struct anchorpoint *anchor) {
707
 
 
708
 
  if (anchor->anchor==NULL) {
709
 
    return;
710
 
  }
711
 
  if (anchor->type>=0 && anchor->type <= MAX_ANCHOR_TYPE ) {
712
 
    lua_pushstring(L,anchor_type_enum[anchor->type]);
713
 
  } else {
714
 
    lua_pushstring(L,"Anchorpoint has an unknown type!");
715
 
    lua_error(L);
716
 
  }
717
 
  /* unsigned int selected: 1; */
718
 
  /* unsigned int ticked: 1; */
719
 
 
720
 
  lua_rawget(L,-2);
721
 
  if (!lua_istable(L,-1)) {
722
 
    /* create the table first */
723
 
    lua_pop(L,1);
724
 
    lua_pushstring(L,anchor_type_enum[anchor->type]);
725
 
    lua_pushvalue(L,-1);
726
 
    lua_newtable(L);
727
 
    lua_rawset(L,-4);
728
 
    lua_rawget(L,-2);
729
 
  }
730
 
  /* now the 'type' table is top of stack */
731
 
  if (anchor->type==at_baselig) {
732
 
    lua_pushstring(L,anchor->anchor->name);
733
 
    lua_rawget(L,-2);
734
 
    if (!lua_istable(L,-1)) {
735
 
      /* create the table first */
736
 
      lua_pop(L,1);
737
 
      lua_pushstring(L,anchor->anchor->name);
738
 
      lua_pushvalue(L,-1);
739
 
      lua_newtable(L);
740
 
      lua_rawset(L,-4);
741
 
      lua_rawget(L,-2);
742
 
    }
743
 
    lua_newtable(L);
744
 
    dump_intfield(L,"x",      anchor->me.x);
745
 
    dump_intfield(L,"y",      anchor->me.y);
746
 
    if (anchor->has_ttf_pt)
747
 
      dump_intfield(L,"ttf_pt_index",  anchor->ttf_pt_index);
748
 
    dump_intfield(L,"lig_index",     anchor->lig_index); 
749
 
    lua_rawseti(L,-2,(anchor->lig_index+1));  
750
 
    lua_pop(L,1);  
751
 
  } else {
752
 
    lua_pushstring(L,anchor->anchor->name);
753
 
    lua_newtable(L);
754
 
    dump_intfield(L,"x",      anchor->me.x);
755
 
    dump_intfield(L,"y",      anchor->me.y);
756
 
    if (anchor->has_ttf_pt)
757
 
      dump_intfield(L,"ttf_pt_index",  anchor->ttf_pt_index);
758
 
    dump_intfield(L,"lig_index",     anchor->lig_index);     
759
 
    lua_rawset(L,-3);  
760
 
  }
761
 
  lua_pop(L,1);
762
 
}
763
 
 
764
 
void
765
 
handle_anchorpoint (lua_State *L, struct anchorpoint *anchor) {
766
 
  struct anchorpoint *next;
767
 
  next = anchor;
768
 
  while (next != NULL) {
769
 
    do_handle_anchorpoint(L, next);
770
 
    next = next->next;
771
 
  } 
772
 
}
773
 
 
774
 
void
775
 
handle_glyphvariants (lua_State *L, struct glyphvariants *vars) {
776
 
  int i ;
777
 
  dump_stringfield(L, "variants", vars->variants);
778
 
  dump_intfield   (L, "italic_correction", vars->italic_correction);
779
 
  lua_newtable(L);
780
 
  for (i=0; i< vars->part_cnt; i++) {
781
 
    lua_newtable(L);
782
 
    dump_stringfield(L, "component", vars->parts[i].component);
783
 
    dump_intfield(L, "extender", vars->parts[i].is_extender);
784
 
    dump_intfield(L, "start", vars->parts[i].startConnectorLength);
785
 
    dump_intfield(L, "end", vars->parts[i].endConnectorLength);
786
 
    dump_intfield(L, "advance", vars->parts[i].fullAdvance);
787
 
    lua_rawseti(L,-2,(i+1));
788
 
  }
789
 
  lua_setfield(L, -2, "parts");
790
 
}
791
 
 
792
 
void handle_mathkernvertex (lua_State *L, struct mathkernvertex *mkv) {
793
 
  int i;
794
 
  for (i=0; i<mkv->cnt;i++) {
795
 
    lua_newtable(L);
796
 
    dump_intfield(L, "height", mkv->mkd[i].height );
797
 
    dump_intfield(L, "kern",   mkv->mkd[i].kern );
798
 
    lua_rawseti(L,-2, (i+1));
799
 
  }
800
 
}
801
 
 
802
 
void handle_mathkern (lua_State *L, struct mathkern *mk) {
803
 
  lua_newtable(L);
804
 
  handle_mathkernvertex(L, &(mk->top_right));
805
 
  lua_setfield(L, -2, "top_right");
806
 
  lua_newtable(L);
807
 
  handle_mathkernvertex(L, &(mk->top_left));
808
 
  lua_setfield(L, -2, "top_left");
809
 
  lua_newtable(L);
810
 
  handle_mathkernvertex(L, &(mk->bottom_right));
811
 
  lua_setfield(L, -2, "bottom_right");
812
 
  lua_newtable(L);
813
 
  handle_mathkernvertex(L, &(mk->bottom_left));
814
 
  lua_setfield(L, -2, "bottom_left");
815
 
}
816
 
 
817
 
 
818
 
 
819
 
void 
820
 
handle_splinechar (lua_State *L,struct splinechar *glyph, int hasvmetrics) {
821
 
  DBounds bb;
822
 
  if (glyph->xmax==0 && glyph->ymax==0 && glyph->xmin==0 && glyph->ymin==0) {
823
 
    SplineCharFindBounds(glyph,&bb);
824
 
    glyph->xmin = bb.minx;
825
 
    glyph->ymin = bb.miny;
826
 
    glyph->xmax = bb.maxx;
827
 
    glyph->ymax = bb.maxy;
828
 
  }
829
 
  dump_stringfield(L,"name",        glyph->name);
830
 
  dump_intfield(L,"unicode",     glyph->unicodeenc);
831
 
  lua_createtable(L,4,0);
832
 
  lua_pushnumber(L,1);  lua_pushnumber(L,glyph->xmin); lua_rawset(L,-3);
833
 
  lua_pushnumber(L,2);  lua_pushnumber(L,glyph->ymin); lua_rawset(L,-3);
834
 
  lua_pushnumber(L,3);  lua_pushnumber(L,glyph->xmax); lua_rawset(L,-3);
835
 
  lua_pushnumber(L,4);  lua_pushnumber(L,glyph->ymax); lua_rawset(L,-3);
836
 
  lua_setfield(L,-2,"boundingbox");
837
 
  /*dump_intfield(L,"orig_pos",       glyph->orig_pos);*/
838
 
  if (hasvmetrics)
839
 
    dump_intfield(L,"vwidth",         glyph->vwidth);
840
 
  dump_intfield(L,"width",          glyph->width);
841
 
 
842
 
  if (glyph->lsidebearing != glyph->xmin) {
843
 
    dump_cond_intfield(L,"lsidebearing",   glyph->lsidebearing); 
844
 
  }
845
 
  /* dump_intfield(L,"ttf_glyph",   glyph->ttf_glyph);  */
846
 
  
847
 
  /* Layer layers[2];   */      /* TH Not used */
848
 
  /*  int layer_cnt;    */      /* TH Not used */
849
 
  /*  StemInfo *hstem;  */      /* TH Not used */
850
 
  /*  StemInfo *vstem;  */      /* TH Not used */
851
 
  /*  DStemInfo *dstem; */      /* TH Not used */
852
 
 
853
 
  /* MinimumDistance *md; */    /* TH Not used */
854
 
  /* struct charviewbase *views; */ /* TH Not used */
855
 
  /* struct charinfo *charinfo;  */ /* TH ? (charinfo.c) */
856
 
  /* struct splinefont *parent;  */  /* TH Not used */
857
 
 
858
 
  if (glyph->glyph_class>0) {
859
 
    dump_enumfield(L,"class",              glyph->glyph_class, glyph_class_enum);  
860
 
  }
861
 
  /* TH: internal fontforge stuff
862
 
     dump_intfield(L,"changed",                  glyph->changed); 
863
 
     dump_intfield(L,"changedsincelasthinted",   glyph->changedsincelasthinted); 
864
 
     dump_intfield(L,"manualhints",              glyph->manualhints); 
865
 
     dump_intfield(L,"ticked",                   glyph->ticked);
866
 
     dump_intfield(L,"changed_since_autosave",   glyph->changed_since_autosave); 
867
 
     dump_intfield(L,"widthset",                 glyph->widthset); 
868
 
     dump_intfield(L,"vconflicts",               glyph->vconflicts); 
869
 
     dump_intfield(L,"hconflicts",               glyph->hconflicts); 
870
 
     dump_intfield(L,"searcherdummy",            glyph->searcherdummy); 
871
 
     dump_intfield(L,"changed_since_search",     glyph->changed_since_search); 
872
 
     dump_intfield(L,"wasopen",                  glyph->wasopen); 
873
 
     dump_intfield(L,"namechanged",              glyph->namechanged); 
874
 
     dump_intfield(L,"blended",                  glyph->blended); 
875
 
     dump_intfield(L,"ticked2",                  glyph->ticked2);
876
 
     dump_intfield(L,"unused_so_far",            glyph->unused_so_far); 
877
 
     dump_intfield(L,"numberpointsbackards",     glyph->numberpointsbackards);  
878
 
     dump_intfield(L,"instructions_out_of_date", glyph->instructions_out_of_date);  
879
 
     dump_intfield(L,"complained_about_ptnums",  glyph->complained_about_ptnums);
880
 
    unsigned int vs_open: 1;
881
 
    unsigned int unlink_rm_ovrlp_save_undo: 1;
882
 
    unsigned int inspiro: 1;
883
 
    unsigned int lig_caret_cnt_fixed: 1;
884
 
 
885
 
 
886
 
  uint8 *ttf_instrs;
887
 
  int16 ttf_instrs_len;
888
 
  int16 countermask_cnt;
889
 
  HintMask *countermasks;
890
 
  */
891
 
 
892
 
 if (glyph->kerns != NULL) {
893
 
   lua_newtable(L);
894
 
   handle_kernpair(L,glyph->kerns);
895
 
   lua_setfield(L,-2,"kerns");
896
 
 }
897
 
 if (glyph->vkerns != NULL) {
898
 
   lua_newtable(L);
899
 
   handle_kernpair(L,glyph->vkerns);
900
 
   lua_setfield(L,-2,"vkerns");
901
 
 }
902
 
 
903
 
 if (glyph->dependents != NULL) {
904
 
   lua_newtable(L);
905
 
   handle_splinecharlist(L,glyph->dependents);
906
 
   lua_setfield(L,-2,"dependents");
907
 
   
908
 
 }
909
 
 if (glyph->possub != NULL) {
910
 
   lua_newtable(L);
911
 
   handle_generic_pst(L,glyph->possub);
912
 
   lua_setfield(L,-2,"lookups");
913
 
 }
914
 
 
915
 
 if (glyph->ligofme != NULL) {
916
 
   lua_newtable(L);
917
 
   handle_liglist(L,glyph->ligofme);
918
 
   lua_setfield(L,-2,"ligatures");
919
 
 }
920
 
 
921
 
 if (glyph->comment != NULL)
922
 
   dump_stringfield(L,"comment",              glyph->comment);
923
 
 
924
 
 /* Color color;  */  /* dont care */
925
 
 
926
 
 if (glyph->anchor != NULL) {
927
 
   lua_newtable(L);
928
 
   handle_anchorpoint(L,glyph->anchor);
929
 
   lua_setfield(L,-2,"anchors");
930
 
 }
931
 
 
932
 
 if (glyph->altuni != NULL) {
933
 
   lua_newtable(L);
934
 
   handle_altuni(L, glyph->altuni);
935
 
   lua_setfield(L,-2,"altuni");   
936
 
 }
937
 
 
938
 
  if (glyph->tex_height != TEX_UNDEF)
939
 
    dump_intfield(L,"tex_height",              glyph->tex_height);  
940
 
  if (glyph->tex_depth != TEX_UNDEF)
941
 
    dump_intfield(L,"tex_depth",               glyph->tex_depth);  
942
 
  
943
 
  dump_cond_intfield(L, "is_extended_shape", glyph->is_extended_shape);
944
 
  if (glyph->italic_correction != TEX_UNDEF)
945
 
     dump_intfield(L, "italic_correction", glyph->italic_correction);
946
 
  if (glyph->top_accent_horiz != TEX_UNDEF)
947
 
     dump_intfield(L, "top_accent",  glyph->top_accent_horiz);
948
 
 
949
 
  if (glyph->vert_variants != NULL) {
950
 
    lua_newtable(L);
951
 
    handle_glyphvariants(L, glyph->vert_variants);
952
 
    lua_setfield(L,-2,"vert_variants");
953
 
  }
954
 
  if (glyph->horiz_variants != NULL) {
955
 
    lua_newtable(L);
956
 
    handle_glyphvariants(L, glyph->horiz_variants);
957
 
    lua_setfield(L,-2,"horiz_variants");
958
 
  }
959
 
  if (glyph->mathkern != NULL) {
960
 
    lua_newtable(L);
961
 
    handle_mathkern(L, glyph->mathkern);
962
 
    lua_setfield(L,-2,"mathkern");
963
 
  }
964
 
}
965
 
 
966
 
char *panose_values_0[] = { "Any", "No Fit", "Text and Display", "Script", "Decorative", "Pictorial" };
967
 
 
968
 
char *panose_values_1[] = { "Any", "No Fit", "Cove", "Obtuse Cove", "Square Cove", "Obtuse Square Cove",
969
 
                            "Square", "Thin", "Bone", "Exaggerated", "Triangle", "Normal Sans",
970
 
                            "Obtuse Sans", "Perp Sans", "Flared", "Rounded" } ;
971
 
 
972
 
char *panose_values_2[] = { "Any", "No Fit", "Very Light", "Light", "Thin", "Book",
973
 
                            "Medium", "Demi", "Bold", "Heavy", "Black", "Nord" } ;
974
 
 
975
 
char *panose_values_3[] = { "Any", "No Fit", "Old Style", "Modern", "Even Width",
976
 
                            "Expanded", "Condensed", "Very Expanded", "Very Condensed", "Monospaced" };
977
 
 
978
 
char *panose_values_4[] = { "Any", "No Fit", "None", "Very Low", "Low", "Medium Low",
979
 
                            "Medium", "Medium High", "High", "Very High" };
980
 
 
981
 
char *panose_values_5[] = { "Any", "No Fit", "Gradual/Diagonal", "Gradual/Transitional","Gradual/Vertical", 
982
 
                            "Gradual/Horizontal", "Rapid/Vertical",  "Rapid/Horizontal",  "Instant/Vertical" };
983
 
 
984
 
char *panose_values_6[] = {"Any","No Fit","Straight Arms/Horizontal","Straight Arms/Wedge","Straight Arms/Vertical",
985
 
                           "Straight Arms/Single Serif","Straight Arms/Double Serif","Non-Straight Arms/Horizontal",
986
 
                           "Non-Straight Arms/Wedge","Non-Straight Arms/Vertical","Non-Straight Arms/Single Serif",
987
 
                           "Non-Straight Arms/Double Serif" };
988
 
 
989
 
char *panose_values_7[] = { "Any", "No Fit","Normal/Contact","Normal/Weighted","Normal/Boxed","Normal/Flattened",
990
 
                            "Normal/Rounded","Normal/Off Center","Normal/Square","Oblique/Contact","Oblique/Weighted",
991
 
                            "Oblique/Boxed","Oblique/Flattened","Oblique/Rounded","Oblique/Off Center","Oblique/Square" };
992
 
 
993
 
char *panose_values_8[] = { "Any","No Fit","Standard/Trimmed","Standard/Pointed","Standard/Serifed","High/Trimmed",
994
 
                            "High/Pointed","High/Serifed","Constant/Trimmed","Constant/Pointed","Constant/Serifed",
995
 
                            "Low/Trimmed","Low/Pointed","Low/Serifed"};
996
 
 
997
 
char *panose_values_9[] = { "Any","No Fit", "Constant/Small",  "Constant/Standard",
998
 
                            "Constant/Large", "Ducking/Small", "Ducking/Standard", "Ducking/Large" };
999
 
 
1000
 
 
1001
 
void 
1002
 
handle_pfminfo (lua_State *L, struct pfminfo pfm) {
1003
 
 
1004
 
  dump_intfield (L, "pfmset",            pfm.pfmset);
1005
 
  dump_intfield (L, "winascent_add",     pfm.winascent_add);
1006
 
  dump_intfield (L, "windescent_add",    pfm.windescent_add);
1007
 
  dump_intfield (L, "hheadascent_add",   pfm.hheadascent_add);
1008
 
  dump_intfield (L, "hheaddescent_add",  pfm.hheaddescent_add);
1009
 
  dump_intfield (L, "typoascent_add",    pfm.typoascent_add);
1010
 
  dump_intfield (L, "typodescent_add",   pfm.typodescent_add);
1011
 
  dump_intfield (L, "subsuper_set",      pfm.subsuper_set);
1012
 
  dump_intfield (L, "panose_set",        pfm.panose_set);
1013
 
  dump_intfield (L, "hheadset",          pfm.hheadset);
1014
 
  dump_intfield (L, "vheadset",          pfm.vheadset);
1015
 
  dump_intfield (L, "pfmfamily",         pfm.pfmfamily);
1016
 
  dump_intfield (L, "weight",            pfm.weight);
1017
 
  dump_intfield (L, "width",             pfm.width);
1018
 
  dump_intfield (L, "avgwidth",          pfm.avgwidth);
1019
 
  dump_intfield (L, "firstchar",         pfm.firstchar);
1020
 
  dump_intfield (L, "lastchar",          pfm.lastchar);
1021
 
  lua_createtable(L,0,10);
1022
 
  dump_enumfield(L,"familytype",      pfm.panose[0], panose_values_0);
1023
 
  dump_enumfield(L,"serifstyle",      pfm.panose[1], panose_values_1);
1024
 
  dump_enumfield(L,"weight",          pfm.panose[2], panose_values_2);
1025
 
  dump_enumfield(L,"proportion",      pfm.panose[3], panose_values_3);
1026
 
  dump_enumfield(L,"contrast",        pfm.panose[4], panose_values_4);
1027
 
  dump_enumfield(L,"strokevariation", pfm.panose[5], panose_values_5);
1028
 
  dump_enumfield(L,"armstyle",        pfm.panose[6], panose_values_6);
1029
 
  dump_enumfield(L,"letterform",      pfm.panose[7], panose_values_7);
1030
 
  dump_enumfield(L,"midline",         pfm.panose[8], panose_values_8);
1031
 
  dump_enumfield(L,"xheight",         pfm.panose[9], panose_values_9);
1032
 
  lua_setfield  (L,-2,"panose");
1033
 
 
1034
 
  dump_intfield (L, "fstype",            pfm.fstype);
1035
 
  dump_intfield (L, "linegap",           pfm.linegap);
1036
 
  dump_intfield (L, "vlinegap",          pfm.vlinegap);
1037
 
  dump_intfield (L, "hhead_ascent",      pfm.hhead_ascent);
1038
 
  dump_intfield (L, "hhead_descent",     pfm.hhead_descent);
1039
 
  dump_intfield (L, "hhead_descent",     pfm.hhead_descent);
1040
 
  dump_intfield (L, "os2_typoascent",     pfm.os2_typoascent  );
1041
 
  dump_intfield (L, "os2_typodescent",    pfm.os2_typodescent );
1042
 
  dump_intfield (L, "os2_typolinegap",    pfm.os2_typolinegap );
1043
 
  dump_intfield (L, "os2_winascent",      pfm.os2_winascent       );
1044
 
  dump_intfield (L, "os2_windescent",     pfm.os2_windescent  );
1045
 
  dump_intfield (L, "os2_subxsize",       pfm.os2_subxsize        );
1046
 
  dump_intfield (L, "os2_subysize",       pfm.os2_subysize        );
1047
 
  dump_intfield (L, "os2_subxoff",        pfm.os2_subxoff         );
1048
 
  dump_intfield (L, "os2_subyoff",        pfm.os2_subyoff         );
1049
 
  dump_intfield (L, "os2_supxsize",       pfm.os2_supxsize        );
1050
 
  dump_intfield (L, "os2_supysize",       pfm.os2_supysize        );
1051
 
  dump_intfield (L, "os2_supxoff",        pfm.os2_supxoff         );
1052
 
  dump_intfield (L, "os2_supyoff",        pfm.os2_supyoff         );
1053
 
  dump_intfield (L, "os2_strikeysize",    pfm.os2_strikeysize );
1054
 
  dump_intfield (L, "os2_strikeypos",     pfm.os2_strikeypos  );
1055
 
  dump_lstringfield (L, "os2_vendor",    pfm.os2_vendor, 4);
1056
 
  dump_intfield (L, "os2_family_class",   pfm.os2_family_class);
1057
 
  dump_intfield (L, "os2_xheight",        pfm.os2_xheight);
1058
 
  dump_intfield (L, "os2_capheight",      pfm.os2_capheight);
1059
 
  dump_intfield (L, "os2_defaultchar",    pfm.os2_defaultchar);
1060
 
  dump_intfield (L, "os2_breakchar",      pfm.os2_breakchar);
1061
 
  if (pfm.hascodepages) {
1062
 
    lua_newtable(L);
1063
 
    lua_pushnumber(L, pfm.codepages[0]);  lua_rawseti(L,-2,1);
1064
 
    lua_pushnumber(L, pfm.codepages[1]);  lua_rawseti(L,-2,2);
1065
 
    lua_setfield(L,-2,"codepages");
1066
 
  }
1067
 
  if (pfm.hasunicoderanges) {
1068
 
    lua_newtable(L);
1069
 
    lua_pushnumber(L, pfm.unicoderanges[0]); lua_rawseti(L,-2,1);
1070
 
    lua_pushnumber(L, pfm.unicoderanges[1]); lua_rawseti(L,-2,2);
1071
 
    lua_pushnumber(L, pfm.unicoderanges[2]); lua_rawseti(L,-2,3);
1072
 
    lua_pushnumber(L, pfm.unicoderanges[3]); lua_rawseti(L,-2,4);
1073
 
    lua_setfield(L,-2,"unicoderanges");
1074
 
  }
1075
 
}
1076
 
 
1077
 
 
1078
 
void 
1079
 
do_handle_enc (lua_State *L, struct enc *enc) { 
1080
 
  int i;
1081
 
  
1082
 
  dump_stringfield(L,"enc_name", enc->enc_name);
1083
 
  dump_intfield  (L,"char_cnt", enc->char_cnt);
1084
 
 
1085
 
  lua_checkstack(L,4);
1086
 
  if (enc->char_cnt && enc->unicode != NULL) {
1087
 
        lua_createtable(L,enc->char_cnt,1);
1088
 
        for (i=0;i<enc->char_cnt;i++) {
1089
 
          lua_pushnumber(L,i);
1090
 
          lua_pushnumber(L,enc->unicode[i]);
1091
 
          lua_rawset(L,-3);
1092
 
        }
1093
 
        lua_setfield(L,-2,"unicode");
1094
 
  }
1095
 
 
1096
 
  if (enc->char_cnt && enc->psnames != NULL) {
1097
 
        lua_createtable(L,enc->char_cnt,1);
1098
 
        for (i=0;i<enc->char_cnt;i++) {
1099
 
          lua_pushnumber(L,i);
1100
 
          lua_pushstring(L,enc->psnames[i]);
1101
 
          lua_rawset(L,-3);
1102
 
        }
1103
 
        lua_setfield(L,-2,"psnames");
1104
 
  }
1105
 
  dump_intfield  (L,"builtin",            enc->builtin         );
1106
 
  dump_intfield  (L,"hidden",             enc->hidden         );
1107
 
  dump_intfield  (L,"only_1byte",         enc->only_1byte     );
1108
 
  dump_intfield  (L,"has_1byte",          enc->has_1byte      );
1109
 
  dump_intfield  (L,"has_2byte",          enc->has_2byte      );
1110
 
  dump_cond_intfield  (L,"is_unicodebmp",      enc->is_unicodebmp  );
1111
 
  dump_cond_intfield  (L,"is_unicodefull",     enc->is_unicodefull );
1112
 
  dump_cond_intfield  (L,"is_custom",          enc->is_custom      );
1113
 
  dump_cond_intfield  (L,"is_original",        enc->is_original    );  
1114
 
  dump_cond_intfield  (L,"is_compact",         enc->is_compact     );
1115
 
  dump_cond_intfield  (L,"is_japanese",        enc->is_japanese    );  
1116
 
  dump_cond_intfield  (L,"is_korean",          enc->is_korean      );
1117
 
  dump_cond_intfield  (L,"is_tradchinese",     enc->is_tradchinese );
1118
 
  dump_cond_intfield  (L,"is_simplechinese",   enc->is_simplechinese);
1119
 
 
1120
 
  if (enc->iso_2022_escape_len > 0) {
1121
 
        dump_lstringfield (L,"iso_2022_escape", enc->iso_2022_escape, enc->iso_2022_escape_len);
1122
 
  }
1123
 
  dump_intfield (L,"low_page", enc->low_page);
1124
 
  dump_intfield(L,"high_page", enc->high_page);
1125
 
 
1126
 
  dump_stringfield(L,"iconv_name", enc->iconv_name);
1127
 
 
1128
 
  dump_intfield  (L,"char_max", enc->char_max);
1129
 
}
1130
 
      
1131
 
void 
1132
 
handle_enc (lua_State *L, struct enc *enc) {
1133
 
  struct enc *next;
1134
 
  NESTED_TABLE(do_handle_enc,enc,24);
1135
 
}
1136
 
 
1137
 
void 
1138
 
handle_encmap (lua_State *L, struct encmap *map, int notdef_loc) {
1139
 
  int i;
1140
 
  dump_intfield(L,"enccount", map->enccount) ;
1141
 
  dump_intfield(L,"encmax",   map->encmax) ;
1142
 
  dump_intfield(L,"backmax",  map->backmax) ;
1143
 
  /*dump_intfield(L,"ticked",   map->ticked) ;*/
1144
 
  if (map->remap != NULL) {
1145
 
    lua_newtable(L);
1146
 
    dump_intfield(L,"firstenc", map->remap->firstenc) ;
1147
 
    dump_intfield(L,"lastenc",  map->remap->lastenc) ;
1148
 
    dump_intfield(L,"infont",   map->remap->infont) ;
1149
 
    lua_setfield(L,-2,"remap");
1150
 
  }
1151
 
  lua_checkstack(L,4);
1152
 
  if (map->encmax > 0 && map->map != NULL) {
1153
 
    lua_createtable(L,map->encmax,1);
1154
 
    for (i=0;i<map->encmax;i++) {
1155
 
      if (map->map[i]!=-1) {
1156
 
        int l = map->map[i];
1157
 
        lua_pushnumber(L,i);
1158
 
        if (l<notdef_loc)
1159
 
          lua_pushnumber(L,(l+1));
1160
 
        else
1161
 
          lua_pushnumber(L,l);
1162
 
                lua_rawset(L,-3);
1163
 
      }
1164
 
    }
1165
 
    lua_setfield(L,-2,"map");
1166
 
  }
1167
 
 
1168
 
  if (map->backmax > 0 && map->backmap != NULL) {
1169
 
    lua_newtable(L);
1170
 
    for (i=0;i<map->backmax;i++) {
1171
 
      if (map->backmap[i]!=-1) { /* TODO: check this, because valgrind sometimes says
1172
 
                                    "Conditional jump or move depends on uninitialised value(s)"
1173
 
                                    needs a test file.
1174
 
                                 */ 
1175
 
        if (i<notdef_loc)
1176
 
          lua_pushnumber(L,(i+1));
1177
 
        else
1178
 
          lua_pushnumber(L,i);
1179
 
                lua_pushnumber(L,map->backmap[i]);
1180
 
                lua_rawset(L,-3);
1181
 
      }
1182
 
    }
1183
 
    lua_setfield(L,-2,"backmap");
1184
 
  }
1185
 
 
1186
 
  if (map->enc != NULL) {
1187
 
    lua_newtable(L);
1188
 
    handle_enc(L,map->enc);
1189
 
    lua_setfield(L,-2,"enc");
1190
 
  }
1191
 
}
1192
 
 
1193
 
static void
1194
 
handle_psdict (lua_State *L, struct psdict *private) {
1195
 
  int k;
1196
 
  if (private->keys != NULL && private->values != NULL) {
1197
 
        for (k=0;k<private->next;k++) {
1198
 
          lua_pushstring(L,private->keys[k]);
1199
 
          lua_pushstring(L,private->values[k]);
1200
 
          lua_rawset(L,-3);
1201
 
        }
1202
 
  }
1203
 
}
1204
 
 
1205
 
void 
1206
 
do_handle_ttflangname (lua_State *L, struct ttflangname *names) {
1207
 
  int k;
1208
 
  dump_stringfield(L,"lang", (char *)MSLangString(names->lang)) ;
1209
 
  lua_checkstack(L,4);
1210
 
  lua_createtable(L,0,ttf_namemax);
1211
 
  for (k=0;k<ttf_namemax;k++) {
1212
 
        lua_pushstring(L,ttfnames_enum[k]);
1213
 
        lua_pushstring(L,names->names[k]);
1214
 
        lua_rawset(L,-3);
1215
 
  }
1216
 
  lua_setfield(L, -2 , "names");
1217
 
}
1218
 
 
1219
 
 
1220
 
void 
1221
 
handle_ttflangname (lua_State *L, struct ttflangname *names) {
1222
 
  struct ttflangname *next;
1223
 
  NESTED_TABLE(do_handle_ttflangname,names,2);
1224
 
}
1225
 
 
1226
 
 
1227
 
void
1228
 
do_handle_anchorclass (lua_State *L, struct anchorclass *anchor) {
1229
 
 
1230
 
  dump_stringfield(L,"name",           anchor->name);
1231
 
  dump_subtable_name (L, "lookup", anchor->subtable);
1232
 
  dump_enumfield(L,"type",              anchor->type, anchorclass_type_enum);
1233
 
  /*   uint8 has_base; */
1234
 
  /*  uint8 processed, has_mark, matches, ac_num; */
1235
 
  /*  uint8 ticked; */
1236
 
}
1237
 
 
1238
 
void
1239
 
handle_anchorclass (lua_State *L, struct anchorclass *anchor) {
1240
 
  struct anchorclass *next;
1241
 
  NESTED_TABLE(do_handle_anchorclass,anchor,10);
1242
 
}
1243
 
 
1244
 
void
1245
 
do_handle_ttf_table  (lua_State *L, struct ttf_table *ttf_tab) {
1246
 
 
1247
 
  dump_tag(L,"tag",               ttf_tab->tag);
1248
 
  dump_intfield(L,"len",          ttf_tab->len);
1249
 
  dump_intfield(L,"maxlen",       ttf_tab->maxlen);
1250
 
  dump_lstringfield(L,"data", (char *)ttf_tab->data, ttf_tab->len);
1251
 
}
1252
 
 
1253
 
void
1254
 
handle_ttf_table  (lua_State *L, struct ttf_table *ttf_tab) {
1255
 
  struct ttf_table *next;
1256
 
  NESTED_TABLE(do_handle_ttf_table,ttf_tab,4);
1257
 
}
1258
 
 
1259
 
void
1260
 
do_handle_kernclass (lua_State *L, struct kernclass *kerns) {
1261
 
  int k;
1262
 
  
1263
 
  /*
1264
 
   * dump_intfield(L,"first_cnt",       kerns->first_cnt);
1265
 
   * dump_intfield(L,"second_cnt",      kerns->second_cnt);
1266
 
   */
1267
 
  lua_checkstack(L,4);
1268
 
  lua_createtable(L,kerns->first_cnt,1);
1269
 
  for (k=0;k<kerns->first_cnt;k++) {
1270
 
    lua_pushnumber(L,(k+1));
1271
 
    lua_pushstring(L,kerns->firsts[k]);
1272
 
    lua_rawset(L,-3);
1273
 
  }
1274
 
  lua_setfield(L,-2,"firsts");
1275
 
 
1276
 
  lua_createtable(L,kerns->second_cnt,1);
1277
 
  for (k=0;k<kerns->second_cnt;k++) {
1278
 
    lua_pushnumber(L,(k+1));
1279
 
        lua_pushstring(L,kerns->seconds[k]);
1280
 
        lua_rawset(L,-3);
1281
 
  }
1282
 
  lua_setfield(L,-2,"seconds");
1283
 
 
1284
 
  dump_subtable_name(L, "lookup", kerns->subtable);
1285
 
  /*dump_intfield(L,"kcid", kerns->kcid); *//* probably not needed */
1286
 
 
1287
 
  lua_createtable(L,kerns->second_cnt*kerns->first_cnt,1);
1288
 
  for (k=0;k<(kerns->second_cnt*kerns->first_cnt);k++) {
1289
 
    if (kerns->offsets[k]!=0) {
1290
 
      lua_pushnumber(L,(k+1));
1291
 
      lua_pushnumber(L,kerns->offsets[k]);
1292
 
      lua_rawset(L,-3);
1293
 
    }
1294
 
  }
1295
 
  lua_setfield(L,-2,"offsets");
1296
 
 
1297
 
}
1298
 
 
1299
 
void
1300
 
handle_kernclass (lua_State *L, struct kernclass *kerns) {
1301
 
  struct kernclass *next;
1302
 
  NESTED_TABLE(do_handle_kernclass,kerns,8);
 
647
void handle_vr(lua_State * L, struct vr *pos)
 
648
{
 
649
 
 
650
    dump_cond_intfield(L, "x", pos->xoff);
 
651
    dump_cond_intfield(L, "y", pos->yoff);
 
652
    dump_cond_intfield(L, "h", pos->h_adv_off);
 
653
    dump_cond_intfield(L, "v", pos->v_adv_off);
 
654
 
 
655
}
 
656
 
 
657
void do_handle_generic_pst(lua_State * L, struct generic_pst *pst)
 
658
{
 
659
    int k;
 
660
    if (pst->type > LAST_POSSUB_TYPE_ENUM) {
 
661
        dump_tag(L, "type", pst->type);
 
662
    } else {
 
663
        dump_enumfield(L, "type", pst->type, possub_type_enum);
 
664
    }
 
665
    /*  unsigned int ticked: 1; */
 
666
    /*  unsigned int temporary: 1; *//* Used in afm ligature closure */
 
667
    /*  struct lookup_subtable *subtable; *//* handled by caller */
 
668
 
 
669
    lua_checkstack(L, 4);
 
670
    lua_pushstring(L, "specification");
 
671
    lua_createtable(L, 0, 4);
 
672
    if (pst->type == pst_position) {
 
673
        handle_vr(L, &pst->u.pos);
 
674
    } else if (pst->type == pst_pair) {
 
675
        dump_stringfield(L, "paired", pst->u.pair.paired);
 
676
        if (pst->u.pair.vr != NULL) {
 
677
            lua_pushstring(L, "offsets");
 
678
            lua_createtable(L, 2, 0);
 
679
            if (interesting_vr(pst->u.pair.vr)) {
 
680
                lua_createtable(L, 0, 4);
 
681
                handle_vr(L, pst->u.pair.vr);
 
682
                lua_rawseti(L, -2, 1);
 
683
            }
 
684
            if (interesting_vr(pst->u.pair.vr + 1)) {
 
685
                lua_createtable(L, 0, 4);
 
686
                handle_vr(L, pst->u.pair.vr + 1);
 
687
                lua_rawseti(L, -2, 2);
 
688
            }
 
689
            lua_rawset(L, -3);
 
690
        }
 
691
    } else if (pst->type == pst_substitution) {
 
692
        dump_stringfield(L, "variant", pst->u.subs.variant);
 
693
    } else if (pst->type == pst_alternate) {
 
694
        dump_stringfield(L, "components", pst->u.mult.components);
 
695
    } else if (pst->type == pst_multiple) {
 
696
        dump_stringfield(L, "components", pst->u.alt.components);
 
697
    } else if (pst->type == pst_ligature) {
 
698
        dump_stringfield(L, "components", pst->u.lig.components);
 
699
        if (pst->u.lig.lig != NULL) {
 
700
            dump_char_ref(L, pst->u.lig.lig);
 
701
        }
 
702
    } else if (pst->type == pst_lcaret) {
 
703
        for (k = 0; k < pst->u.lcaret.cnt; k++) {
 
704
            lua_pushnumber(L, (k + 1));
 
705
            lua_pushnumber(L, pst->u.lcaret.carets[k]);
 
706
            lua_rawset(L, -3);
 
707
        }
 
708
    }
 
709
    lua_rawset(L, -3);
 
710
}
 
711
 
 
712
 
 
713
void handle_generic_pst(lua_State * L, struct generic_pst *pst)
 
714
{
 
715
    struct generic_pst *next;
 
716
    int k;
 
717
    int l = 1;
 
718
    next = pst;
 
719
    /* most likely everything arrives in proper order. But to prevent
 
720
     * surprises, better do this is the proper way
 
721
     */
 
722
    while (next != NULL) {
 
723
        if (next->subtable != NULL && next->subtable->subtable_name != NULL) {
 
724
            lua_checkstack(L, 3);       /* just in case */
 
725
            lua_getfield(L, -1, next->subtable->subtable_name);
 
726
            if (!lua_istable(L, -1)) {
 
727
                lua_pop(L, 1);
 
728
                lua_newtable(L);
 
729
                lua_setfield(L, -2, next->subtable->subtable_name);
 
730
                lua_getfield(L, -1, next->subtable->subtable_name);
 
731
            }
 
732
            k = lua_objlen(L, -1) + 1;
 
733
            lua_pushnumber(L, k);
 
734
            lua_createtable(L, 0, 4);
 
735
            do_handle_generic_pst(L, next);
 
736
            lua_rawset(L, -3);
 
737
            next = next->next;
 
738
            lua_pop(L, 1);      /* pop the subtable */
 
739
        } else {
 
740
            /* Found a pst without subtable, or without subtable name */
 
741
            lua_pushnumber(L, l);
 
742
            l++;
 
743
            lua_createtable(L, 0, 4);
 
744
            do_handle_generic_pst(L, next);
 
745
            lua_rawset(L, -3);
 
746
            next = next->next;
 
747
        }
 
748
    }
 
749
}
 
750
 
 
751
void do_handle_liglist(lua_State * L, struct liglist *ligofme)
 
752
{
 
753
    lua_checkstack(L, 2);
 
754
    if (ligofme->lig != NULL) {
 
755
        lua_createtable(L, 0, 6);
 
756
        handle_generic_pst(L, ligofme->lig);
 
757
        lua_setfield(L, -2, "lig");
 
758
    }
 
759
    dump_char_ref(L, ligofme->first);
 
760
    if (ligofme->components != NULL) {
 
761
        lua_newtable(L);
 
762
        handle_splinecharlist(L, ligofme->components);
 
763
        lua_setfield(L, -2, "components");
 
764
    }
 
765
    dump_intfield(L, "ccnt", ligofme->ccnt);
 
766
}
 
767
 
 
768
void handle_liglist(lua_State * L, struct liglist *ligofme)
 
769
{
 
770
    struct liglist *next;
 
771
    NESTED_TABLE(do_handle_liglist, ligofme, 3);
 
772
}
 
773
 
 
774
void do_handle_anchorpoint(lua_State * L, struct anchorpoint *anchor)
 
775
{
 
776
 
 
777
    if (anchor->anchor == NULL) {
 
778
        return;
 
779
    }
 
780
    if (anchor->type >= 0 && anchor->type <= MAX_ANCHOR_TYPE) {
 
781
        lua_pushstring(L, anchor_type_enum[anchor->type]);
 
782
    } else {
 
783
        lua_pushstring(L, "Anchorpoint has an unknown type!");
 
784
        lua_error(L);
 
785
    }
 
786
    /* unsigned int selected: 1; */
 
787
    /* unsigned int ticked: 1; */
 
788
 
 
789
    lua_rawget(L, -2);
 
790
    if (!lua_istable(L, -1)) {
 
791
        /* create the table first */
 
792
        lua_pop(L, 1);
 
793
        lua_pushstring(L, anchor_type_enum[anchor->type]);
 
794
        lua_pushvalue(L, -1);
 
795
        lua_newtable(L);
 
796
        lua_rawset(L, -4);
 
797
        lua_rawget(L, -2);
 
798
    }
 
799
    /* now the 'type' table is top of stack */
 
800
    if (anchor->type == at_baselig) {
 
801
        lua_pushstring(L, anchor->anchor->name);
 
802
        lua_rawget(L, -2);
 
803
        if (!lua_istable(L, -1)) {
 
804
            /* create the table first */
 
805
            lua_pop(L, 1);
 
806
            lua_pushstring(L, anchor->anchor->name);
 
807
            lua_pushvalue(L, -1);
 
808
            lua_newtable(L);
 
809
            lua_rawset(L, -4);
 
810
            lua_rawget(L, -2);
 
811
        }
 
812
        lua_newtable(L);
 
813
        dump_intfield(L, "x", anchor->me.x);
 
814
        dump_intfield(L, "y", anchor->me.y);
 
815
        if (anchor->has_ttf_pt)
 
816
            dump_intfield(L, "ttf_pt_index", anchor->ttf_pt_index);
 
817
        dump_intfield(L, "lig_index", anchor->lig_index);
 
818
        lua_rawseti(L, -2, (anchor->lig_index + 1));
 
819
        lua_pop(L, 1);
 
820
    } else {
 
821
        lua_pushstring(L, anchor->anchor->name);
 
822
        lua_newtable(L);
 
823
        dump_intfield(L, "x", anchor->me.x);
 
824
        dump_intfield(L, "y", anchor->me.y);
 
825
        if (anchor->has_ttf_pt)
 
826
            dump_intfield(L, "ttf_pt_index", anchor->ttf_pt_index);
 
827
        dump_intfield(L, "lig_index", anchor->lig_index);
 
828
        lua_rawset(L, -3);
 
829
    }
 
830
    lua_pop(L, 1);
 
831
}
 
832
 
 
833
void handle_anchorpoint(lua_State * L, struct anchorpoint *anchor)
 
834
{
 
835
    struct anchorpoint *next;
 
836
    next = anchor;
 
837
    while (next != NULL) {
 
838
        do_handle_anchorpoint(L, next);
 
839
        next = next->next;
 
840
    }
 
841
}
 
842
 
 
843
void handle_glyphvariants(lua_State * L, struct glyphvariants *vars)
 
844
{
 
845
    int i;
 
846
    dump_stringfield(L, "variants", vars->variants);
 
847
    dump_intfield(L, "italic_correction", vars->italic_correction);
 
848
    lua_newtable(L);
 
849
    for (i = 0; i < vars->part_cnt; i++) {
 
850
        lua_newtable(L);
 
851
        dump_stringfield(L, "component", vars->parts[i].component);
 
852
        dump_intfield(L, "extender", vars->parts[i].is_extender);
 
853
        dump_intfield(L, "start", vars->parts[i].startConnectorLength);
 
854
        dump_intfield(L, "end", vars->parts[i].endConnectorLength);
 
855
        dump_intfield(L, "advance", vars->parts[i].fullAdvance);
 
856
        lua_rawseti(L, -2, (i + 1));
 
857
    }
 
858
    lua_setfield(L, -2, "parts");
 
859
}
 
860
 
 
861
void handle_mathkernvertex(lua_State * L, struct mathkernvertex *mkv)
 
862
{
 
863
    int i;
 
864
    for (i = 0; i < mkv->cnt; i++) {
 
865
        lua_newtable(L);
 
866
        dump_intfield(L, "height", mkv->mkd[i].height);
 
867
        dump_intfield(L, "kern", mkv->mkd[i].kern);
 
868
        lua_rawseti(L, -2, (i + 1));
 
869
    }
 
870
}
 
871
 
 
872
void handle_mathkern(lua_State * L, struct mathkern *mk)
 
873
{
 
874
    lua_newtable(L);
 
875
    handle_mathkernvertex(L, &(mk->top_right));
 
876
    lua_setfield(L, -2, "top_right");
 
877
    lua_newtable(L);
 
878
    handle_mathkernvertex(L, &(mk->top_left));
 
879
    lua_setfield(L, -2, "top_left");
 
880
    lua_newtable(L);
 
881
    handle_mathkernvertex(L, &(mk->bottom_right));
 
882
    lua_setfield(L, -2, "bottom_right");
 
883
    lua_newtable(L);
 
884
    handle_mathkernvertex(L, &(mk->bottom_left));
 
885
    lua_setfield(L, -2, "bottom_left");
 
886
}
 
887
 
 
888
 
 
889
 
 
890
void handle_splinechar(lua_State * L, struct splinechar *glyph, int hasvmetrics)
 
891
{
 
892
    DBounds bb;
 
893
    if (glyph->xmax == 0 && glyph->ymax == 0 && glyph->xmin == 0
 
894
        && glyph->ymin == 0) {
 
895
        SplineCharFindBounds(glyph, &bb);
 
896
        glyph->xmin = bb.minx;
 
897
        glyph->ymin = bb.miny;
 
898
        glyph->xmax = bb.maxx;
 
899
        glyph->ymax = bb.maxy;
 
900
    }
 
901
    dump_stringfield(L, "name", glyph->name);
 
902
    dump_intfield(L, "unicode", glyph->unicodeenc);
 
903
    lua_createtable(L, 4, 0);
 
904
    lua_pushnumber(L, 1);
 
905
    lua_pushnumber(L, glyph->xmin);
 
906
    lua_rawset(L, -3);
 
907
    lua_pushnumber(L, 2);
 
908
    lua_pushnumber(L, glyph->ymin);
 
909
    lua_rawset(L, -3);
 
910
    lua_pushnumber(L, 3);
 
911
    lua_pushnumber(L, glyph->xmax);
 
912
    lua_rawset(L, -3);
 
913
    lua_pushnumber(L, 4);
 
914
    lua_pushnumber(L, glyph->ymax);
 
915
    lua_rawset(L, -3);
 
916
    lua_setfield(L, -2, "boundingbox");
 
917
    /*dump_intfield(L,"orig_pos",       glyph->orig_pos); */
 
918
    if (hasvmetrics)
 
919
        dump_intfield(L, "vwidth", glyph->vwidth);
 
920
    dump_intfield(L, "width", glyph->width);
 
921
 
 
922
    if (glyph->lsidebearing != glyph->xmin) {
 
923
        dump_cond_intfield(L, "lsidebearing", glyph->lsidebearing);
 
924
    }
 
925
    /* dump_intfield(L,"ttf_glyph",   glyph->ttf_glyph);  */
 
926
 
 
927
    /* Layer layers[2];   *//* TH Not used */
 
928
    /*  int layer_cnt;    *//* TH Not used */
 
929
    /*  StemInfo *hstem;  *//* TH Not used */
 
930
    /*  StemInfo *vstem;  *//* TH Not used */
 
931
    /*  DStemInfo *dstem; *//* TH Not used */
 
932
 
 
933
    /* MinimumDistance *md; *//* TH Not used */
 
934
    /* struct charviewbase *views; *//* TH Not used */
 
935
    /* struct charinfo *charinfo;  *//* TH ? (charinfo.c) */
 
936
    /* struct splinefont *parent;  *//* TH Not used */
 
937
 
 
938
    if (glyph->glyph_class > 0) {
 
939
        dump_enumfield(L, "class", glyph->glyph_class, glyph_class_enum);
 
940
    }
 
941
    /* TH: internal fontforge stuff
 
942
       dump_intfield(L,"changed",                  glyph->changed); 
 
943
       dump_intfield(L,"changedsincelasthinted",   glyph->changedsincelasthinted); 
 
944
       dump_intfield(L,"manualhints",              glyph->manualhints); 
 
945
       dump_intfield(L,"ticked",                   glyph->ticked);
 
946
       dump_intfield(L,"changed_since_autosave",   glyph->changed_since_autosave); 
 
947
       dump_intfield(L,"widthset",                 glyph->widthset); 
 
948
       dump_intfield(L,"vconflicts",               glyph->vconflicts); 
 
949
       dump_intfield(L,"hconflicts",               glyph->hconflicts); 
 
950
       dump_intfield(L,"searcherdummy",            glyph->searcherdummy); 
 
951
       dump_intfield(L,"changed_since_search",     glyph->changed_since_search); 
 
952
       dump_intfield(L,"wasopen",                  glyph->wasopen); 
 
953
       dump_intfield(L,"namechanged",              glyph->namechanged); 
 
954
       dump_intfield(L,"blended",                  glyph->blended); 
 
955
       dump_intfield(L,"ticked2",                  glyph->ticked2);
 
956
       dump_intfield(L,"unused_so_far",            glyph->unused_so_far); 
 
957
       dump_intfield(L,"numberpointsbackards",     glyph->numberpointsbackards);  
 
958
       dump_intfield(L,"instructions_out_of_date", glyph->instructions_out_of_date);  
 
959
       dump_intfield(L,"complained_about_ptnums",  glyph->complained_about_ptnums);
 
960
       unsigned int vs_open: 1;
 
961
       unsigned int unlink_rm_ovrlp_save_undo: 1;
 
962
       unsigned int inspiro: 1;
 
963
       unsigned int lig_caret_cnt_fixed: 1;
 
964
 
 
965
 
 
966
       uint8 *ttf_instrs;
 
967
       int16 ttf_instrs_len;
 
968
       int16 countermask_cnt;
 
969
       HintMask *countermasks;
 
970
     */
 
971
 
 
972
    if (glyph->kerns != NULL) {
 
973
        lua_newtable(L);
 
974
        handle_kernpair(L, glyph->kerns);
 
975
        lua_setfield(L, -2, "kerns");
 
976
    }
 
977
    if (glyph->vkerns != NULL) {
 
978
        lua_newtable(L);
 
979
        handle_kernpair(L, glyph->vkerns);
 
980
        lua_setfield(L, -2, "vkerns");
 
981
    }
 
982
 
 
983
    if (glyph->dependents != NULL) {
 
984
        lua_newtable(L);
 
985
        handle_splinecharlist(L, glyph->dependents);
 
986
        lua_setfield(L, -2, "dependents");
 
987
 
 
988
    }
 
989
    if (glyph->possub != NULL) {
 
990
        lua_newtable(L);
 
991
        handle_generic_pst(L, glyph->possub);
 
992
        lua_setfield(L, -2, "lookups");
 
993
    }
 
994
 
 
995
    if (glyph->ligofme != NULL) {
 
996
        lua_newtable(L);
 
997
        handle_liglist(L, glyph->ligofme);
 
998
        lua_setfield(L, -2, "ligatures");
 
999
    }
 
1000
 
 
1001
    if (glyph->comment != NULL)
 
1002
        dump_stringfield(L, "comment", glyph->comment);
 
1003
 
 
1004
    /* Color color;  *//* dont care */
 
1005
 
 
1006
    if (glyph->anchor != NULL) {
 
1007
        lua_newtable(L);
 
1008
        handle_anchorpoint(L, glyph->anchor);
 
1009
        lua_setfield(L, -2, "anchors");
 
1010
    }
 
1011
 
 
1012
    if (glyph->altuni != NULL) {
 
1013
        lua_newtable(L);
 
1014
        handle_altuni(L, glyph->altuni);
 
1015
        lua_setfield(L, -2, "altuni");
 
1016
    }
 
1017
 
 
1018
    if (glyph->tex_height != TEX_UNDEF)
 
1019
        dump_intfield(L, "tex_height", glyph->tex_height);
 
1020
    if (glyph->tex_depth != TEX_UNDEF)
 
1021
        dump_intfield(L, "tex_depth", glyph->tex_depth);
 
1022
 
 
1023
    dump_cond_intfield(L, "is_extended_shape", glyph->is_extended_shape);
 
1024
    if (glyph->italic_correction != TEX_UNDEF)
 
1025
        dump_intfield(L, "italic_correction", glyph->italic_correction);
 
1026
    if (glyph->top_accent_horiz != TEX_UNDEF)
 
1027
        dump_intfield(L, "top_accent", glyph->top_accent_horiz);
 
1028
 
 
1029
    if (glyph->vert_variants != NULL) {
 
1030
        lua_newtable(L);
 
1031
        handle_glyphvariants(L, glyph->vert_variants);
 
1032
        lua_setfield(L, -2, "vert_variants");
 
1033
    }
 
1034
    if (glyph->horiz_variants != NULL) {
 
1035
        lua_newtable(L);
 
1036
        handle_glyphvariants(L, glyph->horiz_variants);
 
1037
        lua_setfield(L, -2, "horiz_variants");
 
1038
    }
 
1039
    if (glyph->mathkern != NULL) {
 
1040
        lua_newtable(L);
 
1041
        handle_mathkern(L, glyph->mathkern);
 
1042
        lua_setfield(L, -2, "mathkern");
 
1043
    }
 
1044
}
 
1045
 
 
1046
char *panose_values_0[] =
 
1047
    { "Any", "No Fit", "Text and Display", "Script", "Decorative",
 
1048
    "Pictorial"
 
1049
};
 
1050
 
 
1051
char *panose_values_1[] =
 
1052
    { "Any", "No Fit", "Cove", "Obtuse Cove", "Square Cove",
 
1053
    "Obtuse Square Cove",
 
1054
    "Square", "Thin", "Bone", "Exaggerated", "Triangle", "Normal Sans",
 
1055
    "Obtuse Sans", "Perp Sans", "Flared", "Rounded"
 
1056
};
 
1057
 
 
1058
char *panose_values_2[] =
 
1059
    { "Any", "No Fit", "Very Light", "Light", "Thin", "Book",
 
1060
    "Medium", "Demi", "Bold", "Heavy", "Black", "Nord"
 
1061
};
 
1062
 
 
1063
char *panose_values_3[] =
 
1064
    { "Any", "No Fit", "Old Style", "Modern", "Even Width",
 
1065
    "Expanded", "Condensed", "Very Expanded", "Very Condensed", "Monospaced"
 
1066
};
 
1067
 
 
1068
char *panose_values_4[] =
 
1069
    { "Any", "No Fit", "None", "Very Low", "Low", "Medium Low",
 
1070
    "Medium", "Medium High", "High", "Very High"
 
1071
};
 
1072
 
 
1073
char *panose_values_5[] =
 
1074
    { "Any", "No Fit", "Gradual/Diagonal", "Gradual/Transitional",
 
1075
    "Gradual/Vertical",
 
1076
    "Gradual/Horizontal", "Rapid/Vertical", "Rapid/Horizontal",
 
1077
    "Instant/Vertical"
 
1078
};
 
1079
 
 
1080
char *panose_values_6[] =
 
1081
    { "Any", "No Fit", "Straight Arms/Horizontal", "Straight Arms/Wedge",
 
1082
    "Straight Arms/Vertical",
 
1083
    "Straight Arms/Single Serif", "Straight Arms/Double Serif",
 
1084
    "Non-Straight Arms/Horizontal",
 
1085
    "Non-Straight Arms/Wedge", "Non-Straight Arms/Vertical",
 
1086
    "Non-Straight Arms/Single Serif",
 
1087
    "Non-Straight Arms/Double Serif"
 
1088
};
 
1089
 
 
1090
char *panose_values_7[] =
 
1091
    { "Any", "No Fit", "Normal/Contact", "Normal/Weighted", "Normal/Boxed",
 
1092
    "Normal/Flattened",
 
1093
    "Normal/Rounded", "Normal/Off Center", "Normal/Square", "Oblique/Contact",
 
1094
    "Oblique/Weighted",
 
1095
    "Oblique/Boxed", "Oblique/Flattened", "Oblique/Rounded",
 
1096
    "Oblique/Off Center", "Oblique/Square"
 
1097
};
 
1098
 
 
1099
char *panose_values_8[] =
 
1100
    { "Any", "No Fit", "Standard/Trimmed", "Standard/Pointed",
 
1101
    "Standard/Serifed", "High/Trimmed",
 
1102
    "High/Pointed", "High/Serifed", "Constant/Trimmed", "Constant/Pointed",
 
1103
    "Constant/Serifed",
 
1104
    "Low/Trimmed", "Low/Pointed", "Low/Serifed"
 
1105
};
 
1106
 
 
1107
char *panose_values_9[] =
 
1108
    { "Any", "No Fit", "Constant/Small", "Constant/Standard",
 
1109
    "Constant/Large", "Ducking/Small", "Ducking/Standard", "Ducking/Large"
 
1110
};
 
1111
 
 
1112
 
 
1113
void handle_pfminfo(lua_State * L, struct pfminfo pfm)
 
1114
{
 
1115
 
 
1116
    dump_intfield(L, "pfmset", pfm.pfmset);
 
1117
    dump_intfield(L, "winascent_add", pfm.winascent_add);
 
1118
    dump_intfield(L, "windescent_add", pfm.windescent_add);
 
1119
    dump_intfield(L, "hheadascent_add", pfm.hheadascent_add);
 
1120
    dump_intfield(L, "hheaddescent_add", pfm.hheaddescent_add);
 
1121
    dump_intfield(L, "typoascent_add", pfm.typoascent_add);
 
1122
    dump_intfield(L, "typodescent_add", pfm.typodescent_add);
 
1123
    dump_intfield(L, "subsuper_set", pfm.subsuper_set);
 
1124
    dump_intfield(L, "panose_set", pfm.panose_set);
 
1125
    dump_intfield(L, "hheadset", pfm.hheadset);
 
1126
    dump_intfield(L, "vheadset", pfm.vheadset);
 
1127
    dump_intfield(L, "pfmfamily", pfm.pfmfamily);
 
1128
    dump_intfield(L, "weight", pfm.weight);
 
1129
    dump_intfield(L, "width", pfm.width);
 
1130
    dump_intfield(L, "avgwidth", pfm.avgwidth);
 
1131
    dump_intfield(L, "firstchar", pfm.firstchar);
 
1132
    dump_intfield(L, "lastchar", pfm.lastchar);
 
1133
    lua_createtable(L, 0, 10);
 
1134
    dump_enumfield(L, "familytype", pfm.panose[0], panose_values_0);
 
1135
    dump_enumfield(L, "serifstyle", pfm.panose[1], panose_values_1);
 
1136
    dump_enumfield(L, "weight", pfm.panose[2], panose_values_2);
 
1137
    dump_enumfield(L, "proportion", pfm.panose[3], panose_values_3);
 
1138
    dump_enumfield(L, "contrast", pfm.panose[4], panose_values_4);
 
1139
    dump_enumfield(L, "strokevariation", pfm.panose[5], panose_values_5);
 
1140
    dump_enumfield(L, "armstyle", pfm.panose[6], panose_values_6);
 
1141
    dump_enumfield(L, "letterform", pfm.panose[7], panose_values_7);
 
1142
    dump_enumfield(L, "midline", pfm.panose[8], panose_values_8);
 
1143
    dump_enumfield(L, "xheight", pfm.panose[9], panose_values_9);
 
1144
    lua_setfield(L, -2, "panose");
 
1145
 
 
1146
    dump_intfield(L, "fstype", pfm.fstype);
 
1147
    dump_intfield(L, "linegap", pfm.linegap);
 
1148
    dump_intfield(L, "vlinegap", pfm.vlinegap);
 
1149
    dump_intfield(L, "hhead_ascent", pfm.hhead_ascent);
 
1150
    dump_intfield(L, "hhead_descent", pfm.hhead_descent);
 
1151
    dump_intfield(L, "hhead_descent", pfm.hhead_descent);
 
1152
    dump_intfield(L, "os2_typoascent", pfm.os2_typoascent);
 
1153
    dump_intfield(L, "os2_typodescent", pfm.os2_typodescent);
 
1154
    dump_intfield(L, "os2_typolinegap", pfm.os2_typolinegap);
 
1155
    dump_intfield(L, "os2_winascent", pfm.os2_winascent);
 
1156
    dump_intfield(L, "os2_windescent", pfm.os2_windescent);
 
1157
    dump_intfield(L, "os2_subxsize", pfm.os2_subxsize);
 
1158
    dump_intfield(L, "os2_subysize", pfm.os2_subysize);
 
1159
    dump_intfield(L, "os2_subxoff", pfm.os2_subxoff);
 
1160
    dump_intfield(L, "os2_subyoff", pfm.os2_subyoff);
 
1161
    dump_intfield(L, "os2_supxsize", pfm.os2_supxsize);
 
1162
    dump_intfield(L, "os2_supysize", pfm.os2_supysize);
 
1163
    dump_intfield(L, "os2_supxoff", pfm.os2_supxoff);
 
1164
    dump_intfield(L, "os2_supyoff", pfm.os2_supyoff);
 
1165
    dump_intfield(L, "os2_strikeysize", pfm.os2_strikeysize);
 
1166
    dump_intfield(L, "os2_strikeypos", pfm.os2_strikeypos);
 
1167
    dump_lstringfield(L, "os2_vendor", pfm.os2_vendor, 4);
 
1168
    dump_intfield(L, "os2_family_class", pfm.os2_family_class);
 
1169
    dump_intfield(L, "os2_xheight", pfm.os2_xheight);
 
1170
    dump_intfield(L, "os2_capheight", pfm.os2_capheight);
 
1171
    dump_intfield(L, "os2_defaultchar", pfm.os2_defaultchar);
 
1172
    dump_intfield(L, "os2_breakchar", pfm.os2_breakchar);
 
1173
    if (pfm.hascodepages) {
 
1174
        lua_newtable(L);
 
1175
        lua_pushnumber(L, pfm.codepages[0]);
 
1176
        lua_rawseti(L, -2, 1);
 
1177
        lua_pushnumber(L, pfm.codepages[1]);
 
1178
        lua_rawseti(L, -2, 2);
 
1179
        lua_setfield(L, -2, "codepages");
 
1180
    }
 
1181
    if (pfm.hasunicoderanges) {
 
1182
        lua_newtable(L);
 
1183
        lua_pushnumber(L, pfm.unicoderanges[0]);
 
1184
        lua_rawseti(L, -2, 1);
 
1185
        lua_pushnumber(L, pfm.unicoderanges[1]);
 
1186
        lua_rawseti(L, -2, 2);
 
1187
        lua_pushnumber(L, pfm.unicoderanges[2]);
 
1188
        lua_rawseti(L, -2, 3);
 
1189
        lua_pushnumber(L, pfm.unicoderanges[3]);
 
1190
        lua_rawseti(L, -2, 4);
 
1191
        lua_setfield(L, -2, "unicoderanges");
 
1192
    }
 
1193
}
 
1194
 
 
1195
 
 
1196
void do_handle_enc(lua_State * L, struct enc *enc)
 
1197
{
 
1198
    int i;
 
1199
 
 
1200
    dump_stringfield(L, "enc_name", enc->enc_name);
 
1201
    dump_intfield(L, "char_cnt", enc->char_cnt);
 
1202
 
 
1203
    lua_checkstack(L, 4);
 
1204
    if (enc->char_cnt && enc->unicode != NULL) {
 
1205
        lua_createtable(L, enc->char_cnt, 1);
 
1206
        for (i = 0; i < enc->char_cnt; i++) {
 
1207
            lua_pushnumber(L, i);
 
1208
            lua_pushnumber(L, enc->unicode[i]);
 
1209
            lua_rawset(L, -3);
 
1210
        }
 
1211
        lua_setfield(L, -2, "unicode");
 
1212
    }
 
1213
 
 
1214
    if (enc->char_cnt && enc->psnames != NULL) {
 
1215
        lua_createtable(L, enc->char_cnt, 1);
 
1216
        for (i = 0; i < enc->char_cnt; i++) {
 
1217
            lua_pushnumber(L, i);
 
1218
            lua_pushstring(L, enc->psnames[i]);
 
1219
            lua_rawset(L, -3);
 
1220
        }
 
1221
        lua_setfield(L, -2, "psnames");
 
1222
    }
 
1223
    dump_intfield(L, "builtin", enc->builtin);
 
1224
    dump_intfield(L, "hidden", enc->hidden);
 
1225
    dump_intfield(L, "only_1byte", enc->only_1byte);
 
1226
    dump_intfield(L, "has_1byte", enc->has_1byte);
 
1227
    dump_intfield(L, "has_2byte", enc->has_2byte);
 
1228
    dump_cond_intfield(L, "is_unicodebmp", enc->is_unicodebmp);
 
1229
    dump_cond_intfield(L, "is_unicodefull", enc->is_unicodefull);
 
1230
    dump_cond_intfield(L, "is_custom", enc->is_custom);
 
1231
    dump_cond_intfield(L, "is_original", enc->is_original);
 
1232
    dump_cond_intfield(L, "is_compact", enc->is_compact);
 
1233
    dump_cond_intfield(L, "is_japanese", enc->is_japanese);
 
1234
    dump_cond_intfield(L, "is_korean", enc->is_korean);
 
1235
    dump_cond_intfield(L, "is_tradchinese", enc->is_tradchinese);
 
1236
    dump_cond_intfield(L, "is_simplechinese", enc->is_simplechinese);
 
1237
 
 
1238
    if (enc->iso_2022_escape_len > 0) {
 
1239
        dump_lstringfield(L, "iso_2022_escape", enc->iso_2022_escape,
 
1240
                          enc->iso_2022_escape_len);
 
1241
    }
 
1242
    dump_intfield(L, "low_page", enc->low_page);
 
1243
    dump_intfield(L, "high_page", enc->high_page);
 
1244
 
 
1245
    dump_stringfield(L, "iconv_name", enc->iconv_name);
 
1246
 
 
1247
    dump_intfield(L, "char_max", enc->char_max);
 
1248
}
 
1249
 
 
1250
void handle_enc(lua_State * L, struct enc *enc)
 
1251
{
 
1252
    struct enc *next;
 
1253
    NESTED_TABLE(do_handle_enc, enc, 24);
 
1254
}
 
1255
 
 
1256
void handle_encmap(lua_State * L, struct encmap *map, int notdef_loc)
 
1257
{
 
1258
    int i;
 
1259
    dump_intfield(L, "enccount", map->enccount);
 
1260
    dump_intfield(L, "encmax", map->encmax);
 
1261
    dump_intfield(L, "backmax", map->backmax);
 
1262
    /*dump_intfield(L,"ticked",   map->ticked) ; */
 
1263
    if (map->remap != NULL) {
 
1264
        lua_newtable(L);
 
1265
        dump_intfield(L, "firstenc", map->remap->firstenc);
 
1266
        dump_intfield(L, "lastenc", map->remap->lastenc);
 
1267
        dump_intfield(L, "infont", map->remap->infont);
 
1268
        lua_setfield(L, -2, "remap");
 
1269
    }
 
1270
    lua_checkstack(L, 4);
 
1271
    if (map->encmax > 0 && map->map != NULL) {
 
1272
        lua_createtable(L, map->encmax, 1);
 
1273
        for (i = 0; i < map->encmax; i++) {
 
1274
            if (map->map[i] != -1) {
 
1275
                int l = map->map[i];
 
1276
                lua_pushnumber(L, i);
 
1277
                if (l < notdef_loc)
 
1278
                    lua_pushnumber(L, (l + 1));
 
1279
                else
 
1280
                    lua_pushnumber(L, l);
 
1281
                lua_rawset(L, -3);
 
1282
            }
 
1283
        }
 
1284
        lua_setfield(L, -2, "map");
 
1285
    }
 
1286
 
 
1287
    if (map->backmax > 0 && map->backmap != NULL) {
 
1288
        lua_newtable(L);
 
1289
        for (i = 0; i < map->backmax; i++) {
 
1290
            if (map->backmap[i] != -1) {        /* TODO: check this, because valgrind sometimes says
 
1291
                                                   "Conditional jump or move depends on uninitialised value(s)"
 
1292
                                                   needs a test file.
 
1293
                                                 */
 
1294
                if (i < notdef_loc)
 
1295
                    lua_pushnumber(L, (i + 1));
 
1296
                else
 
1297
                    lua_pushnumber(L, i);
 
1298
                lua_pushnumber(L, map->backmap[i]);
 
1299
                lua_rawset(L, -3);
 
1300
            }
 
1301
        }
 
1302
        lua_setfield(L, -2, "backmap");
 
1303
    }
 
1304
 
 
1305
    if (map->enc != NULL) {
 
1306
        lua_newtable(L);
 
1307
        handle_enc(L, map->enc);
 
1308
        lua_setfield(L, -2, "enc");
 
1309
    }
 
1310
}
 
1311
 
 
1312
static void handle_psdict(lua_State * L, struct psdict *private)
 
1313
{
 
1314
    int k;
 
1315
    if (private->keys != NULL && private->values != NULL) {
 
1316
        for (k = 0; k < private->next; k++) {
 
1317
            lua_pushstring(L, private->keys[k]);
 
1318
            lua_pushstring(L, private->values[k]);
 
1319
            lua_rawset(L, -3);
 
1320
        }
 
1321
    }
 
1322
}
 
1323
 
 
1324
void do_handle_ttflangname(lua_State * L, struct ttflangname *names)
 
1325
{
 
1326
    int k;
 
1327
    dump_stringfield(L, "lang", (char *) MSLangString(names->lang));
 
1328
    lua_checkstack(L, 4);
 
1329
    lua_createtable(L, 0, ttf_namemax);
 
1330
    for (k = 0; k < ttf_namemax; k++) {
 
1331
        lua_pushstring(L, ttfnames_enum[k]);
 
1332
        lua_pushstring(L, names->names[k]);
 
1333
        lua_rawset(L, -3);
 
1334
    }
 
1335
    lua_setfield(L, -2, "names");
 
1336
}
 
1337
 
 
1338
 
 
1339
void handle_ttflangname(lua_State * L, struct ttflangname *names)
 
1340
{
 
1341
    struct ttflangname *next;
 
1342
    NESTED_TABLE(do_handle_ttflangname, names, 2);
 
1343
}
 
1344
 
 
1345
 
 
1346
void do_handle_anchorclass(lua_State * L, struct anchorclass *anchor)
 
1347
{
 
1348
 
 
1349
    dump_stringfield(L, "name", anchor->name);
 
1350
    dump_subtable_name(L, "lookup", anchor->subtable);
 
1351
    dump_enumfield(L, "type", anchor->type, anchorclass_type_enum);
 
1352
    /*   uint8 has_base; */
 
1353
    /*  uint8 processed, has_mark, matches, ac_num; */
 
1354
    /*  uint8 ticked; */
 
1355
}
 
1356
 
 
1357
void handle_anchorclass(lua_State * L, struct anchorclass *anchor)
 
1358
{
 
1359
    struct anchorclass *next;
 
1360
    NESTED_TABLE(do_handle_anchorclass, anchor, 10);
 
1361
}
 
1362
 
 
1363
void do_handle_ttf_table(lua_State * L, struct ttf_table *ttf_tab)
 
1364
{
 
1365
 
 
1366
    dump_tag(L, "tag", ttf_tab->tag);
 
1367
    dump_intfield(L, "len", ttf_tab->len);
 
1368
    dump_intfield(L, "maxlen", ttf_tab->maxlen);
 
1369
    dump_lstringfield(L, "data", (char *) ttf_tab->data, ttf_tab->len);
 
1370
}
 
1371
 
 
1372
void handle_ttf_table(lua_State * L, struct ttf_table *ttf_tab)
 
1373
{
 
1374
    struct ttf_table *next;
 
1375
    NESTED_TABLE(do_handle_ttf_table, ttf_tab, 4);
 
1376
}
 
1377
 
 
1378
void do_handle_kernclass(lua_State * L, struct kernclass *kerns)
 
1379
{
 
1380
    int k;
 
1381
 
 
1382
    /*
 
1383
     * dump_intfield(L,"first_cnt",       kerns->first_cnt);
 
1384
     * dump_intfield(L,"second_cnt",      kerns->second_cnt);
 
1385
     */
 
1386
    lua_checkstack(L, 4);
 
1387
    lua_createtable(L, kerns->first_cnt, 1);
 
1388
    for (k = 0; k < kerns->first_cnt; k++) {
 
1389
        lua_pushnumber(L, (k + 1));
 
1390
        lua_pushstring(L, kerns->firsts[k]);
 
1391
        lua_rawset(L, -3);
 
1392
    }
 
1393
    lua_setfield(L, -2, "firsts");
 
1394
 
 
1395
    lua_createtable(L, kerns->second_cnt, 1);
 
1396
    for (k = 0; k < kerns->second_cnt; k++) {
 
1397
        lua_pushnumber(L, (k + 1));
 
1398
        lua_pushstring(L, kerns->seconds[k]);
 
1399
        lua_rawset(L, -3);
 
1400
    }
 
1401
    lua_setfield(L, -2, "seconds");
 
1402
 
 
1403
    dump_subtable_name(L, "lookup", kerns->subtable);
 
1404
    /*dump_intfield(L,"kcid", kerns->kcid); *//* probably not needed */
 
1405
 
 
1406
    lua_createtable(L, kerns->second_cnt * kerns->first_cnt, 1);
 
1407
    for (k = 0; k < (kerns->second_cnt * kerns->first_cnt); k++) {
 
1408
        if (kerns->offsets[k] != 0) {
 
1409
            lua_pushnumber(L, (k + 1));
 
1410
            lua_pushnumber(L, kerns->offsets[k]);
 
1411
            lua_rawset(L, -3);
 
1412
        }
 
1413
    }
 
1414
    lua_setfield(L, -2, "offsets");
 
1415
 
 
1416
}
 
1417
 
 
1418
void handle_kernclass(lua_State * L, struct kernclass *kerns)
 
1419
{
 
1420
    struct kernclass *next;
 
1421
    NESTED_TABLE(do_handle_kernclass, kerns, 8);
1303
1422
}
1304
1423
 
1305
1424
 
1335
1454
      lua_setfield(L,-2,s); } }
1336
1455
 
1337
1456
 
1338
 
void handle_fpst_rule (lua_State *L, struct fpst_rule *rule, int format) {
1339
 
  int k;
1340
 
 
1341
 
 
1342
 
  if (format == pst_glyphs) {
1343
 
 
1344
 
    lua_newtable(L);
1345
 
    dump_stringfield(L,"names",rule->u.glyph.names);
1346
 
    dump_stringfield(L,"back",rule->u.glyph.back);
1347
 
    dump_stringfield(L,"fore",rule->u.glyph.fore);
1348
 
    lua_setfield(L,-2,fpossub_format_enum[format]);
1349
 
 
1350
 
  } else if (format == pst_class) {
1351
 
  
1352
 
    lua_newtable(L);
1353
 
    DUMP_NUMBER_ARRAY("current", rule->u.class.ncnt,rule->u.class.nclasses);
1354
 
    DUMP_NUMBER_ARRAY("before", rule->u.class.bcnt,rule->u.class.bclasses);
1355
 
    DUMP_NUMBER_ARRAY("after", rule->u.class.fcnt,rule->u.class.fclasses);
 
1457
void handle_fpst_rule(lua_State * L, struct fpst_rule *rule, int format)
 
1458
{
 
1459
    int k;
 
1460
 
 
1461
 
 
1462
    if (format == pst_glyphs) {
 
1463
 
 
1464
        lua_newtable(L);
 
1465
        dump_stringfield(L, "names", rule->u.glyph.names);
 
1466
        dump_stringfield(L, "back", rule->u.glyph.back);
 
1467
        dump_stringfield(L, "fore", rule->u.glyph.fore);
 
1468
        lua_setfield(L, -2, fpossub_format_enum[format]);
 
1469
 
 
1470
    } else if (format == pst_class) {
 
1471
 
 
1472
        lua_newtable(L);
 
1473
        DUMP_NUMBER_ARRAY("current", rule->u.class.ncnt,
 
1474
                          rule->u.class.nclasses);
 
1475
        DUMP_NUMBER_ARRAY("before", rule->u.class.bcnt, rule->u.class.bclasses);
 
1476
        DUMP_NUMBER_ARRAY("after", rule->u.class.fcnt, rule->u.class.fclasses);
1356
1477
#if 0
1357
 
    DUMP_NUMBER_ARRAY("allclasses", 0,rule->u.class.allclasses);
 
1478
        DUMP_NUMBER_ARRAY("allclasses", 0, rule->u.class.allclasses);
1358
1479
#endif
1359
 
    lua_setfield(L,-2,fpossub_format_enum[format]);
1360
 
 
1361
 
  } else if (format == pst_coverage) {
1362
 
 
1363
 
    lua_newtable(L);
1364
 
    DUMP_STRING_ARRAY("current", rule->u.coverage.ncnt,rule->u.coverage.ncovers);
1365
 
    DUMP_STRING_ARRAY("before", rule->u.coverage.bcnt,rule->u.coverage.bcovers);
1366
 
    DUMP_STRING_ARRAY("after", rule->u.coverage.fcnt,rule->u.coverage.fcovers);
1367
 
    lua_setfield(L,-2,fpossub_format_enum[format]);
1368
 
 
1369
 
  } else if (format == pst_reversecoverage) {
1370
 
 
1371
 
    lua_newtable(L);
1372
 
    DUMP_STRING_ARRAY("current", rule->u.rcoverage.always1,rule->u.rcoverage.ncovers);
1373
 
    DUMP_STRING_ARRAY("before", rule->u.rcoverage.bcnt,rule->u.rcoverage.bcovers);
1374
 
    DUMP_STRING_ARRAY("after", rule->u.rcoverage.fcnt,rule->u.rcoverage.fcovers);
1375
 
    dump_stringfield(L,"replacements", rule->u.rcoverage.replacements);
1376
 
    lua_setfield(L,-2,fpossub_format_enum[format]);
1377
 
  } else {
1378
 
    fprintf(stderr,"handle_fpst_rule(): Unknown rule format: %d\n",format);
1379
 
  }
1380
 
  
1381
 
  if (rule->lookup_cnt>0) {
1382
 
    lua_newtable(L);
1383
 
    for (k=0;k<rule->lookup_cnt;k++) {
1384
 
      lua_pushnumber(L,(rule->lookups[k].seq+1)); 
1385
 
      if (rule->lookups[k].lookup!=NULL) {
1386
 
        lua_pushstring(L,rule->lookups[k].lookup->lookup_name);
1387
 
      } else {
1388
 
        lua_pushnil(L);
1389
 
      }
1390
 
      lua_rawset(L,-3);
1391
 
    }
1392
 
    lua_setfield(L,-2,"lookups");
1393
 
  } else {
1394
 
    /*fprintf(stderr,"handle_fpst_rule(): No lookups?\n");*/
1395
 
  }
1396
 
}
1397
 
 
1398
 
void 
1399
 
do_handle_generic_fpst(lua_State *L, struct generic_fpst *fpst) {
1400
 
  int k;
1401
 
 
1402
 
  if (fpst->type>LAST_POSSUB_TYPE_ENUM) {
1403
 
    dump_intfield(L,"type", fpst->type);
1404
 
  } else {
1405
 
    dump_enumfield(L,"type", fpst->type, possub_type_enum);
1406
 
  }
1407
 
  dump_enumfield(L,"format", fpst->format, fpossub_format_enum);
1408
 
 
1409
 
  if (fpst->format==pst_class) {
1410
 
        DUMP_EXACT_STRING_ARRAY("current_class",fpst->nccnt,fpst->nclass);
1411
 
        DUMP_EXACT_STRING_ARRAY("before_class",fpst->bccnt,fpst->bclass);
1412
 
        DUMP_EXACT_STRING_ARRAY("after_class",fpst->fccnt,fpst->fclass);
1413
 
  } else {
1414
 
        DUMP_STRING_ARRAY("current_class",fpst->nccnt,fpst->nclass);
1415
 
        DUMP_STRING_ARRAY("before_class",fpst->bccnt,fpst->bclass);
1416
 
        DUMP_STRING_ARRAY("after_class",fpst->fccnt,fpst->fclass);
1417
 
  }
1418
 
 
1419
 
  lua_checkstack(L,4);
1420
 
  if (fpst->rule_cnt>0) {
1421
 
    lua_createtable(L,fpst->rule_cnt,1);
1422
 
    for (k=0;k<fpst->rule_cnt;k++) {
1423
 
      lua_pushnumber(L,(k+1));
1424
 
      lua_newtable(L);
1425
 
      handle_fpst_rule(L,&(fpst->rules[k]),fpst->format);
1426
 
      lua_rawset(L,-3);
1427
 
    }
1428
 
    lua_setfield(L,-2,"rules");
1429
 
  }
1430
 
  /*dump_intfield (L,"ticked", fpst->ticked);*/
1431
 
}
1432
 
 
1433
 
void 
1434
 
handle_generic_fpst(lua_State *L, struct generic_fpst *fpst) {
1435
 
  struct generic_fpst *next;
1436
 
  int k = 1;                        
1437
 
  lua_checkstack(L,3);        
1438
 
  if (fpst->subtable != NULL && 
1439
 
      fpst->subtable->subtable_name != NULL) {
1440
 
    lua_pushstring(L,fpst->subtable->subtable_name);
1441
 
  } else {
1442
 
    lua_pushnumber(L,k); k++;
1443
 
  }
1444
 
  lua_createtable(L,0,10);          
1445
 
  do_handle_generic_fpst(L,fpst);   
1446
 
  lua_rawset(L,-3); 
1447
 
  next = fpst->next;                                                       
1448
 
  while (next != NULL) {                                                   
1449
 
    lua_checkstack(L,3);                                                   
1450
 
  if (next->subtable != NULL &&                                            
1451
 
      next->subtable->subtable_name != NULL) {                             
1452
 
    lua_pushstring(L,next->subtable->subtable_name);                       
1453
 
  } else {                                                                 
1454
 
    lua_pushnumber(L,k); k++;                                              
1455
 
  }                                                                        
1456
 
    lua_createtable(L,0,10);                                               
1457
 
    do_handle_generic_fpst(L, next);                                       
1458
 
    lua_rawset(L,-3);                                                      
1459
 
    next = next->next;                                                     
1460
 
  } 
1461
 
}
1462
 
 
1463
 
void
1464
 
do_handle_otfname (lua_State *L, struct otfname *oname) {
1465
 
  dump_intfield(L,"lang",        oname->lang);
1466
 
  dump_stringfield(L,"name",     oname->name);
1467
 
}
1468
 
 
1469
 
void
1470
 
handle_otfname (lua_State *L, struct otfname *oname) {
1471
 
  struct otfname *next;
1472
 
  NESTED_TABLE(do_handle_otfname,oname,2);
1473
 
}
1474
 
 
1475
 
void 
1476
 
do_handle_macname (lua_State *L, struct macname *featname) {
1477
 
  dump_intfield(L,"enc",         featname->enc);
1478
 
  dump_intfield(L,"lang",        featname->lang);
1479
 
  dump_stringfield(L,"name",     featname->name);
1480
 
}
1481
 
 
1482
 
void 
1483
 
handle_macname (lua_State *L, struct macname *featname) {
1484
 
  struct macname *next;
1485
 
  NESTED_TABLE(do_handle_macname,featname,3);
1486
 
}
1487
 
 
1488
 
void 
1489
 
do_handle_macsetting (lua_State *L, struct macsetting *settings) {
1490
 
  dump_intfield(L,"setting",            settings->setting);
1491
 
  dump_intfield(L,"strid",              settings->strid);
1492
 
  dump_intfield(L,"initially_enabled",  settings->initially_enabled);
1493
 
  if (settings->setname != NULL) {
1494
 
    lua_newtable(L);
1495
 
    handle_macname(L,settings->setname);
1496
 
    lua_setfield(L,-2,"setname");
1497
 
  }
1498
 
}
1499
 
 
1500
 
void 
1501
 
handle_macsetting (lua_State *L, struct macsetting *settings) {
1502
 
  struct macsetting *next;
1503
 
  NESTED_TABLE(do_handle_macsetting,settings,4);
1504
 
}
1505
 
 
1506
 
 
1507
 
void 
1508
 
do_handle_macfeat (lua_State *L, struct macfeat *features) {
1509
 
 
1510
 
  dump_intfield(L,"feature",         features->feature);
1511
 
  dump_intfield(L,"ismutex",         features->ismutex);
1512
 
  dump_intfield(L,"default_setting", features->default_setting);
1513
 
  dump_intfield(L,"strid",           features->strid);
1514
 
 
1515
 
  if (features->featname != NULL) {
1516
 
    lua_newtable(L);
1517
 
    handle_macname(L,features->featname);
1518
 
    lua_setfield(L,-2,"featname");
1519
 
  }
1520
 
 
1521
 
  if (features->settings != NULL) {
1522
 
    lua_newtable(L);
1523
 
    handle_macsetting(L,features->settings);
1524
 
    lua_setfield(L,-2,"settings");
1525
 
  }
1526
 
}
1527
 
 
1528
 
void 
1529
 
handle_macfeat (lua_State *L, struct macfeat *features) {
1530
 
  struct macfeat *next;
1531
 
  NESTED_TABLE(do_handle_macfeat,features,6);
 
1480
        lua_setfield(L, -2, fpossub_format_enum[format]);
 
1481
 
 
1482
    } else if (format == pst_coverage) {
 
1483
 
 
1484
        lua_newtable(L);
 
1485
        DUMP_STRING_ARRAY("current", rule->u.coverage.ncnt,
 
1486
                          rule->u.coverage.ncovers);
 
1487
        DUMP_STRING_ARRAY("before", rule->u.coverage.bcnt,
 
1488
                          rule->u.coverage.bcovers);
 
1489
        DUMP_STRING_ARRAY("after", rule->u.coverage.fcnt,
 
1490
                          rule->u.coverage.fcovers);
 
1491
        lua_setfield(L, -2, fpossub_format_enum[format]);
 
1492
 
 
1493
    } else if (format == pst_reversecoverage) {
 
1494
 
 
1495
        lua_newtable(L);
 
1496
        DUMP_STRING_ARRAY("current", rule->u.rcoverage.always1,
 
1497
                          rule->u.rcoverage.ncovers);
 
1498
        DUMP_STRING_ARRAY("before", rule->u.rcoverage.bcnt,
 
1499
                          rule->u.rcoverage.bcovers);
 
1500
        DUMP_STRING_ARRAY("after", rule->u.rcoverage.fcnt,
 
1501
                          rule->u.rcoverage.fcovers);
 
1502
        dump_stringfield(L, "replacements", rule->u.rcoverage.replacements);
 
1503
        lua_setfield(L, -2, fpossub_format_enum[format]);
 
1504
    } else {
 
1505
        fprintf(stderr, "handle_fpst_rule(): Unknown rule format: %d\n",
 
1506
                format);
 
1507
    }
 
1508
 
 
1509
    if (rule->lookup_cnt > 0) {
 
1510
        lua_newtable(L);
 
1511
        for (k = 0; k < rule->lookup_cnt; k++) {
 
1512
            lua_pushnumber(L, (rule->lookups[k].seq + 1));
 
1513
            if (rule->lookups[k].lookup != NULL) {
 
1514
                lua_pushstring(L, rule->lookups[k].lookup->lookup_name);
 
1515
            } else {
 
1516
                lua_pushnil(L);
 
1517
            }
 
1518
            lua_rawset(L, -3);
 
1519
        }
 
1520
        lua_setfield(L, -2, "lookups");
 
1521
    } else {
 
1522
        /*fprintf(stderr,"handle_fpst_rule(): No lookups?\n"); */
 
1523
    }
 
1524
}
 
1525
 
 
1526
void do_handle_generic_fpst(lua_State * L, struct generic_fpst *fpst)
 
1527
{
 
1528
    int k;
 
1529
 
 
1530
    if (fpst->type > LAST_POSSUB_TYPE_ENUM) {
 
1531
        dump_intfield(L, "type", fpst->type);
 
1532
    } else {
 
1533
        dump_enumfield(L, "type", fpst->type, possub_type_enum);
 
1534
    }
 
1535
    dump_enumfield(L, "format", fpst->format, fpossub_format_enum);
 
1536
 
 
1537
    if (fpst->format == pst_class) {
 
1538
        DUMP_EXACT_STRING_ARRAY("current_class", fpst->nccnt, fpst->nclass);
 
1539
        DUMP_EXACT_STRING_ARRAY("before_class", fpst->bccnt, fpst->bclass);
 
1540
        DUMP_EXACT_STRING_ARRAY("after_class", fpst->fccnt, fpst->fclass);
 
1541
    } else {
 
1542
        DUMP_STRING_ARRAY("current_class", fpst->nccnt, fpst->nclass);
 
1543
        DUMP_STRING_ARRAY("before_class", fpst->bccnt, fpst->bclass);
 
1544
        DUMP_STRING_ARRAY("after_class", fpst->fccnt, fpst->fclass);
 
1545
    }
 
1546
 
 
1547
    lua_checkstack(L, 4);
 
1548
    if (fpst->rule_cnt > 0) {
 
1549
        lua_createtable(L, fpst->rule_cnt, 1);
 
1550
        for (k = 0; k < fpst->rule_cnt; k++) {
 
1551
            lua_pushnumber(L, (k + 1));
 
1552
            lua_newtable(L);
 
1553
            handle_fpst_rule(L, &(fpst->rules[k]), fpst->format);
 
1554
            lua_rawset(L, -3);
 
1555
        }
 
1556
        lua_setfield(L, -2, "rules");
 
1557
    }
 
1558
    /*dump_intfield (L,"ticked", fpst->ticked); */
 
1559
}
 
1560
 
 
1561
void handle_generic_fpst(lua_State * L, struct generic_fpst *fpst)
 
1562
{
 
1563
    struct generic_fpst *next;
 
1564
    int k = 1;
 
1565
    lua_checkstack(L, 3);
 
1566
    if (fpst->subtable != NULL && fpst->subtable->subtable_name != NULL) {
 
1567
        lua_pushstring(L, fpst->subtable->subtable_name);
 
1568
    } else {
 
1569
        lua_pushnumber(L, k);
 
1570
        k++;
 
1571
    }
 
1572
    lua_createtable(L, 0, 10);
 
1573
    do_handle_generic_fpst(L, fpst);
 
1574
    lua_rawset(L, -3);
 
1575
    next = fpst->next;
 
1576
    while (next != NULL) {
 
1577
        lua_checkstack(L, 3);
 
1578
        if (next->subtable != NULL && next->subtable->subtable_name != NULL) {
 
1579
            lua_pushstring(L, next->subtable->subtable_name);
 
1580
        } else {
 
1581
            lua_pushnumber(L, k);
 
1582
            k++;
 
1583
        }
 
1584
        lua_createtable(L, 0, 10);
 
1585
        do_handle_generic_fpst(L, next);
 
1586
        lua_rawset(L, -3);
 
1587
        next = next->next;
 
1588
    }
 
1589
}
 
1590
 
 
1591
void do_handle_otfname(lua_State * L, struct otfname *oname)
 
1592
{
 
1593
    dump_intfield(L, "lang", oname->lang);
 
1594
    dump_stringfield(L, "name", oname->name);
 
1595
}
 
1596
 
 
1597
void handle_otfname(lua_State * L, struct otfname *oname)
 
1598
{
 
1599
    struct otfname *next;
 
1600
    NESTED_TABLE(do_handle_otfname, oname, 2);
 
1601
}
 
1602
 
 
1603
void do_handle_macname(lua_State * L, struct macname *featname)
 
1604
{
 
1605
    dump_intfield(L, "enc", featname->enc);
 
1606
    dump_intfield(L, "lang", featname->lang);
 
1607
    dump_stringfield(L, "name", featname->name);
 
1608
}
 
1609
 
 
1610
void handle_macname(lua_State * L, struct macname *featname)
 
1611
{
 
1612
    struct macname *next;
 
1613
    NESTED_TABLE(do_handle_macname, featname, 3);
 
1614
}
 
1615
 
 
1616
void do_handle_macsetting(lua_State * L, struct macsetting *settings)
 
1617
{
 
1618
    dump_intfield(L, "setting", settings->setting);
 
1619
    dump_intfield(L, "strid", settings->strid);
 
1620
    dump_intfield(L, "initially_enabled", settings->initially_enabled);
 
1621
    if (settings->setname != NULL) {
 
1622
        lua_newtable(L);
 
1623
        handle_macname(L, settings->setname);
 
1624
        lua_setfield(L, -2, "setname");
 
1625
    }
 
1626
}
 
1627
 
 
1628
void handle_macsetting(lua_State * L, struct macsetting *settings)
 
1629
{
 
1630
    struct macsetting *next;
 
1631
    NESTED_TABLE(do_handle_macsetting, settings, 4);
 
1632
}
 
1633
 
 
1634
 
 
1635
void do_handle_macfeat(lua_State * L, struct macfeat *features)
 
1636
{
 
1637
 
 
1638
    dump_intfield(L, "feature", features->feature);
 
1639
    dump_intfield(L, "ismutex", features->ismutex);
 
1640
    dump_intfield(L, "default_setting", features->default_setting);
 
1641
    dump_intfield(L, "strid", features->strid);
 
1642
 
 
1643
    if (features->featname != NULL) {
 
1644
        lua_newtable(L);
 
1645
        handle_macname(L, features->featname);
 
1646
        lua_setfield(L, -2, "featname");
 
1647
    }
 
1648
 
 
1649
    if (features->settings != NULL) {
 
1650
        lua_newtable(L);
 
1651
        handle_macsetting(L, features->settings);
 
1652
        lua_setfield(L, -2, "settings");
 
1653
    }
 
1654
}
 
1655
 
 
1656
void handle_macfeat(lua_State * L, struct macfeat *features)
 
1657
{
 
1658
    struct macfeat *next;
 
1659
    NESTED_TABLE(do_handle_macfeat, features, 6);
1532
1660
}
1533
1661
 
1534
1662
 
1564
1692
        0x3fff  value offset
1565
1693
*/
1566
1694
/* to be tested */
1567
 
void 
1568
 
do_handle_generic_asm (lua_State *L, struct generic_asm *sm) {
1569
 
  int i, k;
1570
 
 
1571
 
  dump_enumfield  (L,"type",  sm->type, asm_type_enum); 
1572
 
  /* backref */
1573
 
  dump_subtable_name(L, "lookup", sm->subtable);
1574
 
  /* uint8 ticked; */
1575
 
  lua_newtable(L);
1576
 
  if (sm->flags & asm_vert) {
1577
 
    lua_pushstring(L,"vert");  lua_pushboolean(L,1);   lua_rawset(L,-3);
1578
 
  }
1579
 
  if (sm->flags & asm_descending) {
1580
 
    lua_pushstring(L,"descending");  lua_pushboolean(L,1);   lua_rawset(L,-3);
1581
 
  }
1582
 
  if (sm->flags & asm_always) {
1583
 
    lua_pushstring(L,"always");  lua_pushboolean(L,1);   lua_rawset(L,-3);
1584
 
  }
1585
 
  lua_setfield(L,-2,"flags");
1586
 
 
1587
 
  if (sm->class_cnt >0) {
1588
 
    lua_newtable(L);
1589
 
    for (i=0; i<sm->class_cnt; i++) {
1590
 
      if (sm->classes[i]!=NULL) {
1591
 
        lua_pushstring(L,sm->classes[i]);
1592
 
        lua_rawseti(L,-2,(i+1));
1593
 
      }
1594
 
    }
1595
 
    lua_setfield(L,-2,"classes");
1596
 
  }
1597
 
  if (sm->state_cnt >0) {
1598
 
    lua_newtable(L);
1599
 
    for (i=0; i<(sm->class_cnt * sm->state_cnt); i++) {
1600
 
       struct asm_state as = sm->state[i];
1601
 
       dump_intfield(L,"next", as.next_state);
1602
 
       dump_intfield(L,"flags", as.flags);
1603
 
       if (sm->type==asm_context) {
1604
 
         lua_newtable(L);
1605
 
         if (as.u.context.mark_lookup!=NULL)
1606
 
           dump_stringfield(L,"mark", as.u.context.mark_lookup->lookup_name); /* backref */
1607
 
         if (as.u.context.cur_lookup!=NULL)
1608
 
           dump_stringfield(L,"cur",  as.u.context.cur_lookup->lookup_name); /* backref */
1609
 
         lua_setfield(L,-2,"context");
1610
 
       } else if  (sm->type==asm_insert) {
1611
 
         lua_newtable(L);
1612
 
         lua_pushstring(L, as.u.insert.mark_ins);
1613
 
         lua_setfield(L, -2, "mark");
1614
 
         lua_pushstring(L, as.u.insert.cur_ins);
1615
 
         lua_setfield(L, -2, "cur");
1616
 
         lua_setfield(L,-2,"insert");
1617
 
       } else if  (sm->type==asm_kern) {
1618
 
         lua_newtable(L);
1619
 
         for (k=0;k<as.u.kern.kcnt;k++) {
1620
 
           lua_pushnumber(L,as.u.kern.kerns[k]);
1621
 
           lua_rawseti(L,-2, (k+1));
1622
 
         }
1623
 
         lua_setfield(L,-2,"kerns");
1624
 
       }
1625
 
    }
1626
 
    lua_setfield(L,-2,"states");
1627
 
  }
1628
 
}
1629
 
 
1630
 
void 
1631
 
handle_generic_asm (lua_State *L, struct generic_asm *sm) {
1632
 
  struct generic_asm *next;
1633
 
  NESTED_TABLE(do_handle_generic_asm,sm,6);
1634
 
}
1635
 
 
1636
 
 
1637
 
 
1638
 
 
1639
 
void handle_MATH (lua_State *L, struct MATH *MATH) {
1640
 
    dump_intfield(L,"ScriptPercentScaleDown",MATH->ScriptPercentScaleDown);
1641
 
    dump_intfield(L,"ScriptScriptPercentScaleDown",MATH->ScriptScriptPercentScaleDown);
1642
 
    dump_intfield(L,"DelimitedSubFormulaMinHeight",MATH->DelimitedSubFormulaMinHeight);
1643
 
    dump_intfield(L,"DisplayOperatorMinHeight",MATH->DisplayOperatorMinHeight);
1644
 
    dump_intfield(L,"MathLeading",MATH->MathLeading);
1645
 
    dump_intfield(L,"AxisHeight",MATH->AxisHeight);
1646
 
    dump_intfield(L,"AccentBaseHeight",MATH->AccentBaseHeight);
1647
 
    dump_intfield(L,"FlattenedAccentBaseHeight",MATH->FlattenedAccentBaseHeight);
1648
 
    dump_intfield(L,"SubscriptShiftDown",MATH->SubscriptShiftDown);
1649
 
    dump_intfield(L,"SubscriptTopMax",MATH->SubscriptTopMax);
1650
 
    dump_intfield(L,"SubscriptBaselineDropMin",MATH->SubscriptBaselineDropMin);
1651
 
    dump_intfield(L,"SuperscriptShiftUp",MATH->SuperscriptShiftUp);
1652
 
    dump_intfield(L,"SuperscriptShiftUpCramped",MATH->SuperscriptShiftUpCramped);
1653
 
    dump_intfield(L,"SuperscriptBottomMin",MATH->SuperscriptBottomMin);
1654
 
    dump_intfield(L,"SuperscriptBaselineDropMax",MATH->SuperscriptBaselineDropMax);
1655
 
    dump_intfield(L,"SubSuperscriptGapMin",MATH->SubSuperscriptGapMin);
1656
 
    dump_intfield(L,"SuperscriptBottomMaxWithSubscript",MATH->SuperscriptBottomMaxWithSubscript);
1657
 
    dump_intfield(L,"SpaceAfterScript",MATH->SpaceAfterScript);
1658
 
    dump_intfield(L,"UpperLimitGapMin",MATH->UpperLimitGapMin);
1659
 
    dump_intfield(L,"UpperLimitBaselineRiseMin",MATH->UpperLimitBaselineRiseMin);
1660
 
    dump_intfield(L,"LowerLimitGapMin",MATH->LowerLimitGapMin);
1661
 
    dump_intfield(L,"LowerLimitBaselineDropMin",MATH->LowerLimitBaselineDropMin);
1662
 
    dump_intfield(L,"StackTopShiftUp",MATH->StackTopShiftUp);
1663
 
    dump_intfield(L,"StackTopDisplayStyleShiftUp",MATH->StackTopDisplayStyleShiftUp);
1664
 
    dump_intfield(L,"StackBottomShiftDown",MATH->StackBottomShiftDown);
1665
 
    dump_intfield(L,"StackBottomDisplayStyleShiftDown",MATH->StackBottomDisplayStyleShiftDown);
1666
 
    dump_intfield(L,"StackGapMin",MATH->StackGapMin);
1667
 
    dump_intfield(L,"StackDisplayStyleGapMin",MATH->StackDisplayStyleGapMin);
1668
 
    dump_intfield(L,"StretchStackTopShiftUp",MATH->StretchStackTopShiftUp);
1669
 
    dump_intfield(L,"StretchStackBottomShiftDown",MATH->StretchStackBottomShiftDown);
1670
 
    dump_intfield(L,"StretchStackGapAboveMin",MATH->StretchStackGapAboveMin);
1671
 
    dump_intfield(L,"StretchStackGapBelowMin",MATH->StretchStackGapBelowMin);
1672
 
    dump_intfield(L,"FractionNumeratorShiftUp",MATH->FractionNumeratorShiftUp);
1673
 
    dump_intfield(L,"FractionNumeratorDisplayStyleShiftUp",MATH->FractionNumeratorDisplayStyleShiftUp);
1674
 
    dump_intfield(L,"FractionDenominatorShiftDown",MATH->FractionDenominatorShiftDown);
1675
 
    dump_intfield(L,"FractionDenominatorDisplayStyleShiftDown",MATH->FractionDenominatorDisplayStyleShiftDown);
1676
 
    dump_intfield(L,"FractionNumeratorGapMin",MATH->FractionNumeratorGapMin);
1677
 
    dump_intfield(L,"FractionNumeratorDisplayStyleGapMin",MATH->FractionNumeratorDisplayStyleGapMin);
1678
 
    dump_intfield(L,"FractionRuleThickness",MATH->FractionRuleThickness);
1679
 
    dump_intfield(L,"FractionDenominatorGapMin",MATH->FractionDenominatorGapMin);
1680
 
    dump_intfield(L,"FractionDenominatorDisplayStyleGapMin",MATH->FractionDenominatorDisplayStyleGapMin);
1681
 
    dump_intfield(L,"SkewedFractionHorizontalGap",MATH->SkewedFractionHorizontalGap);
1682
 
    dump_intfield(L,"SkewedFractionVerticalGap",MATH->SkewedFractionVerticalGap);
1683
 
    dump_intfield(L,"OverbarVerticalGap",MATH->OverbarVerticalGap);
1684
 
    dump_intfield(L,"OverbarRuleThickness",MATH->OverbarRuleThickness);
1685
 
    dump_intfield(L,"OverbarExtraAscender",MATH->OverbarExtraAscender);
1686
 
    dump_intfield(L,"UnderbarVerticalGap",MATH->UnderbarVerticalGap);
1687
 
    dump_intfield(L,"UnderbarRuleThickness",MATH->UnderbarRuleThickness);
1688
 
    dump_intfield(L,"UnderbarExtraDescender",MATH->UnderbarExtraDescender);
1689
 
    dump_intfield(L,"RadicalVerticalGap",MATH->RadicalVerticalGap);
1690
 
    dump_intfield(L,"RadicalDisplayStyleVerticalGap",MATH->RadicalDisplayStyleVerticalGap);
1691
 
    dump_intfield(L,"RadicalRuleThickness",MATH->RadicalRuleThickness);
1692
 
    dump_intfield(L,"RadicalExtraAscender",MATH->RadicalExtraAscender);
1693
 
    dump_intfield(L,"RadicalKernBeforeDegree",MATH->RadicalKernBeforeDegree);
1694
 
    dump_intfield(L,"RadicalKernAfterDegree",MATH->RadicalKernAfterDegree);
1695
 
    dump_intfield(L,"RadicalDegreeBottomRaisePercent",MATH->RadicalDegreeBottomRaisePercent);
1696
 
    dump_intfield(L,"MinConnectorOverlap",MATH->MinConnectorOverlap);   
 
1695
void do_handle_generic_asm(lua_State * L, struct generic_asm *sm)
 
1696
{
 
1697
    int i, k;
 
1698
 
 
1699
    dump_enumfield(L, "type", sm->type, asm_type_enum);
 
1700
    /* backref */
 
1701
    dump_subtable_name(L, "lookup", sm->subtable);
 
1702
    /* uint8 ticked; */
 
1703
    lua_newtable(L);
 
1704
    if (sm->flags & asm_vert) {
 
1705
        lua_pushstring(L, "vert");
 
1706
        lua_pushboolean(L, 1);
 
1707
        lua_rawset(L, -3);
 
1708
    }
 
1709
    if (sm->flags & asm_descending) {
 
1710
        lua_pushstring(L, "descending");
 
1711
        lua_pushboolean(L, 1);
 
1712
        lua_rawset(L, -3);
 
1713
    }
 
1714
    if (sm->flags & asm_always) {
 
1715
        lua_pushstring(L, "always");
 
1716
        lua_pushboolean(L, 1);
 
1717
        lua_rawset(L, -3);
 
1718
    }
 
1719
    lua_setfield(L, -2, "flags");
 
1720
 
 
1721
    if (sm->class_cnt > 0) {
 
1722
        lua_newtable(L);
 
1723
        for (i = 0; i < sm->class_cnt; i++) {
 
1724
            if (sm->classes[i] != NULL) {
 
1725
                lua_pushstring(L, sm->classes[i]);
 
1726
                lua_rawseti(L, -2, (i + 1));
 
1727
            }
 
1728
        }
 
1729
        lua_setfield(L, -2, "classes");
 
1730
    }
 
1731
    if (sm->state_cnt > 0) {
 
1732
        lua_newtable(L);
 
1733
        for (i = 0; i < (sm->class_cnt * sm->state_cnt); i++) {
 
1734
            struct asm_state as = sm->state[i];
 
1735
            dump_intfield(L, "next", as.next_state);
 
1736
            dump_intfield(L, "flags", as.flags);
 
1737
            if (sm->type == asm_context) {
 
1738
                lua_newtable(L);
 
1739
                if (as.u.context.mark_lookup != NULL)
 
1740
                    dump_stringfield(L, "mark", as.u.context.mark_lookup->lookup_name); /* backref */
 
1741
                if (as.u.context.cur_lookup != NULL)
 
1742
                    dump_stringfield(L, "cur", as.u.context.cur_lookup->lookup_name);   /* backref */
 
1743
                lua_setfield(L, -2, "context");
 
1744
            } else if (sm->type == asm_insert) {
 
1745
                lua_newtable(L);
 
1746
                lua_pushstring(L, as.u.insert.mark_ins);
 
1747
                lua_setfield(L, -2, "mark");
 
1748
                lua_pushstring(L, as.u.insert.cur_ins);
 
1749
                lua_setfield(L, -2, "cur");
 
1750
                lua_setfield(L, -2, "insert");
 
1751
            } else if (sm->type == asm_kern) {
 
1752
                lua_newtable(L);
 
1753
                for (k = 0; k < as.u.kern.kcnt; k++) {
 
1754
                    lua_pushnumber(L, as.u.kern.kerns[k]);
 
1755
                    lua_rawseti(L, -2, (k + 1));
 
1756
                }
 
1757
                lua_setfield(L, -2, "kerns");
 
1758
            }
 
1759
        }
 
1760
        lua_setfield(L, -2, "states");
 
1761
    }
 
1762
}
 
1763
 
 
1764
void handle_generic_asm(lua_State * L, struct generic_asm *sm)
 
1765
{
 
1766
    struct generic_asm *next;
 
1767
    NESTED_TABLE(do_handle_generic_asm, sm, 6);
 
1768
}
 
1769
 
 
1770
 
 
1771
 
 
1772
 
 
1773
void handle_MATH(lua_State * L, struct MATH *MATH)
 
1774
{
 
1775
    dump_intfield(L, "ScriptPercentScaleDown", MATH->ScriptPercentScaleDown);
 
1776
    dump_intfield(L, "ScriptScriptPercentScaleDown",
 
1777
                  MATH->ScriptScriptPercentScaleDown);
 
1778
    dump_intfield(L, "DelimitedSubFormulaMinHeight",
 
1779
                  MATH->DelimitedSubFormulaMinHeight);
 
1780
    dump_intfield(L, "DisplayOperatorMinHeight",
 
1781
                  MATH->DisplayOperatorMinHeight);
 
1782
    dump_intfield(L, "MathLeading", MATH->MathLeading);
 
1783
    dump_intfield(L, "AxisHeight", MATH->AxisHeight);
 
1784
    dump_intfield(L, "AccentBaseHeight", MATH->AccentBaseHeight);
 
1785
    dump_intfield(L, "FlattenedAccentBaseHeight",
 
1786
                  MATH->FlattenedAccentBaseHeight);
 
1787
    dump_intfield(L, "SubscriptShiftDown", MATH->SubscriptShiftDown);
 
1788
    dump_intfield(L, "SubscriptTopMax", MATH->SubscriptTopMax);
 
1789
    dump_intfield(L, "SubscriptBaselineDropMin",
 
1790
                  MATH->SubscriptBaselineDropMin);
 
1791
    dump_intfield(L, "SuperscriptShiftUp", MATH->SuperscriptShiftUp);
 
1792
    dump_intfield(L, "SuperscriptShiftUpCramped",
 
1793
                  MATH->SuperscriptShiftUpCramped);
 
1794
    dump_intfield(L, "SuperscriptBottomMin", MATH->SuperscriptBottomMin);
 
1795
    dump_intfield(L, "SuperscriptBaselineDropMax",
 
1796
                  MATH->SuperscriptBaselineDropMax);
 
1797
    dump_intfield(L, "SubSuperscriptGapMin", MATH->SubSuperscriptGapMin);
 
1798
    dump_intfield(L, "SuperscriptBottomMaxWithSubscript",
 
1799
                  MATH->SuperscriptBottomMaxWithSubscript);
 
1800
    dump_intfield(L, "SpaceAfterScript", MATH->SpaceAfterScript);
 
1801
    dump_intfield(L, "UpperLimitGapMin", MATH->UpperLimitGapMin);
 
1802
    dump_intfield(L, "UpperLimitBaselineRiseMin",
 
1803
                  MATH->UpperLimitBaselineRiseMin);
 
1804
    dump_intfield(L, "LowerLimitGapMin", MATH->LowerLimitGapMin);
 
1805
    dump_intfield(L, "LowerLimitBaselineDropMin",
 
1806
                  MATH->LowerLimitBaselineDropMin);
 
1807
    dump_intfield(L, "StackTopShiftUp", MATH->StackTopShiftUp);
 
1808
    dump_intfield(L, "StackTopDisplayStyleShiftUp",
 
1809
                  MATH->StackTopDisplayStyleShiftUp);
 
1810
    dump_intfield(L, "StackBottomShiftDown", MATH->StackBottomShiftDown);
 
1811
    dump_intfield(L, "StackBottomDisplayStyleShiftDown",
 
1812
                  MATH->StackBottomDisplayStyleShiftDown);
 
1813
    dump_intfield(L, "StackGapMin", MATH->StackGapMin);
 
1814
    dump_intfield(L, "StackDisplayStyleGapMin", MATH->StackDisplayStyleGapMin);
 
1815
    dump_intfield(L, "StretchStackTopShiftUp", MATH->StretchStackTopShiftUp);
 
1816
    dump_intfield(L, "StretchStackBottomShiftDown",
 
1817
                  MATH->StretchStackBottomShiftDown);
 
1818
    dump_intfield(L, "StretchStackGapAboveMin", MATH->StretchStackGapAboveMin);
 
1819
    dump_intfield(L, "StretchStackGapBelowMin", MATH->StretchStackGapBelowMin);
 
1820
    dump_intfield(L, "FractionNumeratorShiftUp",
 
1821
                  MATH->FractionNumeratorShiftUp);
 
1822
    dump_intfield(L, "FractionNumeratorDisplayStyleShiftUp",
 
1823
                  MATH->FractionNumeratorDisplayStyleShiftUp);
 
1824
    dump_intfield(L, "FractionDenominatorShiftDown",
 
1825
                  MATH->FractionDenominatorShiftDown);
 
1826
    dump_intfield(L, "FractionDenominatorDisplayStyleShiftDown",
 
1827
                  MATH->FractionDenominatorDisplayStyleShiftDown);
 
1828
    dump_intfield(L, "FractionNumeratorGapMin", MATH->FractionNumeratorGapMin);
 
1829
    dump_intfield(L, "FractionNumeratorDisplayStyleGapMin",
 
1830
                  MATH->FractionNumeratorDisplayStyleGapMin);
 
1831
    dump_intfield(L, "FractionRuleThickness", MATH->FractionRuleThickness);
 
1832
    dump_intfield(L, "FractionDenominatorGapMin",
 
1833
                  MATH->FractionDenominatorGapMin);
 
1834
    dump_intfield(L, "FractionDenominatorDisplayStyleGapMin",
 
1835
                  MATH->FractionDenominatorDisplayStyleGapMin);
 
1836
    dump_intfield(L, "SkewedFractionHorizontalGap",
 
1837
                  MATH->SkewedFractionHorizontalGap);
 
1838
    dump_intfield(L, "SkewedFractionVerticalGap",
 
1839
                  MATH->SkewedFractionVerticalGap);
 
1840
    dump_intfield(L, "OverbarVerticalGap", MATH->OverbarVerticalGap);
 
1841
    dump_intfield(L, "OverbarRuleThickness", MATH->OverbarRuleThickness);
 
1842
    dump_intfield(L, "OverbarExtraAscender", MATH->OverbarExtraAscender);
 
1843
    dump_intfield(L, "UnderbarVerticalGap", MATH->UnderbarVerticalGap);
 
1844
    dump_intfield(L, "UnderbarRuleThickness", MATH->UnderbarRuleThickness);
 
1845
    dump_intfield(L, "UnderbarExtraDescender", MATH->UnderbarExtraDescender);
 
1846
    dump_intfield(L, "RadicalVerticalGap", MATH->RadicalVerticalGap);
 
1847
    dump_intfield(L, "RadicalDisplayStyleVerticalGap",
 
1848
                  MATH->RadicalDisplayStyleVerticalGap);
 
1849
    dump_intfield(L, "RadicalRuleThickness", MATH->RadicalRuleThickness);
 
1850
    dump_intfield(L, "RadicalExtraAscender", MATH->RadicalExtraAscender);
 
1851
    dump_intfield(L, "RadicalKernBeforeDegree", MATH->RadicalKernBeforeDegree);
 
1852
    dump_intfield(L, "RadicalKernAfterDegree", MATH->RadicalKernAfterDegree);
 
1853
    dump_intfield(L, "RadicalDegreeBottomRaisePercent",
 
1854
                  MATH->RadicalDegreeBottomRaisePercent);
 
1855
    dump_intfield(L, "MinConnectorOverlap", MATH->MinConnectorOverlap);
1697
1856
}
1698
1857
 
1699
1858
/* the handling of BASE is untested, no font */
1700
 
void handle_baselangextent (lua_State *L, struct baselangextent *ble);
1701
 
 
1702
 
void
1703
 
do_handle_baselangextent (lua_State *L, struct baselangextent *ble) {
1704
 
   dump_tag(L,"tag",ble->lang); 
1705
 
   dump_intfield(L,"ascent",ble->ascent);       
1706
 
   dump_intfield(L,"descent",ble->descent);     
1707
 
   lua_newtable(L);
1708
 
   handle_baselangextent(L, ble->features);
1709
 
   lua_setfield(L,-2,"features");
1710
 
}
1711
 
 
1712
 
 
1713
 
void handle_baselangextent (lua_State *L, struct baselangextent *ble) {
1714
 
  struct baselangextent *next;
1715
 
  NESTED_TABLE(do_handle_baselangextent,ble,4);
1716
 
}
1717
 
 
1718
 
 
1719
 
void handle_base  (lua_State *L, struct Base *Base) {
1720
 
  int i;
1721
 
  struct basescript *next = Base->scripts;
1722
 
  lua_newtable(L);
1723
 
  for ( i=0; i<Base->baseline_cnt; i++ ) {
1724
 
    lua_pushstring(L,make_tag_string(Base->baseline_tags[i]));
1725
 
    lua_rawseti(L,-2,(i+1));
1726
 
  }
1727
 
  lua_setfield(L,-2,"tags");
1728
 
  if (next != NULL) {
1729
 
    lua_newtable(L);
1730
 
    while (next != NULL) {
1731
 
      lua_pushstring(L,make_tag_string(next->script));
1732
 
      lua_newtable(L);
1733
 
      dump_intfield(L, "default_baseline", (next->def_baseline+1)) ;
1734
 
      lua_newtable(L);
1735
 
      for ( i=0; i<Base->baseline_cnt; i++ ) {
1736
 
        lua_pushnumber(L, next->baseline_pos[i]) ;
1737
 
        lua_rawseti(L,-2, (i+1));
1738
 
      }
1739
 
      lua_setfield(L, -2, "baseline");
1740
 
      lua_newtable(L);
1741
 
      handle_baselangextent(L, next->langs);
1742
 
      lua_setfield(L, -2, "lang");
1743
 
      lua_rawset(L,-3);
1744
 
      next = next->next;
1745
 
    }
1746
 
    lua_setfield(L,-2,"scripts");
1747
 
  }
1748
 
}
1749
 
 
1750
 
 
1751
 
void
1752
 
handle_axismap (lua_State *L, struct axismap *am) {
1753
 
  int i;
1754
 
  lua_checkstack(L,3);
1755
 
  lua_newtable(L);
1756
 
  for (i=0;i<am->points;i++) {
1757
 
    lua_pushnumber(L, am->blends[i] )  ;
1758
 
    lua_rawseti(L,-2, (i+1));     
1759
 
  }
1760
 
  lua_setfield(L,-2,"blends");
1761
 
  lua_newtable(L);
1762
 
  for (i=0;i<am->points;i++) {
1763
 
    lua_pushnumber(L, am->designs[i] )  ;
1764
 
    lua_rawseti(L,-2, (i+1));     
1765
 
  }
1766
 
  lua_setfield(L,-2,"designs");
1767
 
  dump_realfield(L, "min", am->min)  ;
1768
 
  dump_realfield(L, "def", am->def)  ;
1769
 
  dump_realfield(L, "max", am->max)  ;
1770
 
  if (am->axisnames != NULL ){
1771
 
    lua_newtable(L);
1772
 
    handle_macname(L, am->axisnames);
1773
 
    lua_setfield(L,-2,"axisnames");
1774
 
  }
1775
 
1776
 
 
1777
 
 
1778
 
void
1779
 
handle_mmset (lua_State *L, struct mmset *mm) {
1780
 
  int i, k;
1781
 
  lua_newtable(L);
1782
 
  for (i=0;i<mm->axis_count;i++) {
1783
 
    lua_pushstring(L, mm->axes[i]) ;
1784
 
    lua_rawseti(L,-2, (i+1));
1785
 
  }
1786
 
  lua_setfield(L,-2,"axes");
1787
 
 
1788
 
  dump_intfield(L,"instance_count",mm->instance_count);    
1789
 
  /* SplineFont *normal; */ /* this is the parent */
1790
 
  if (mm->instance_count>0) {
1791
 
    lua_newtable(L);
1792
 
    for (i=0;i<mm->instance_count*mm->axis_count;i++) {
1793
 
      lua_pushnumber(L, mm->positions[i]) ;
1794
 
      lua_rawseti(L,-2, (i+1));
1795
 
    }
1796
 
    lua_setfield(L,-2,"positions");
1797
 
 
1798
 
    /* better not to do this */
 
1859
void handle_baselangextent(lua_State * L, struct baselangextent *ble);
 
1860
 
 
1861
void do_handle_baselangextent(lua_State * L, struct baselangextent *ble)
 
1862
{
 
1863
    dump_tag(L, "tag", ble->lang);
 
1864
    dump_intfield(L, "ascent", ble->ascent);
 
1865
    dump_intfield(L, "descent", ble->descent);
 
1866
    lua_newtable(L);
 
1867
    handle_baselangextent(L, ble->features);
 
1868
    lua_setfield(L, -2, "features");
 
1869
}
 
1870
 
 
1871
 
 
1872
void handle_baselangextent(lua_State * L, struct baselangextent *ble)
 
1873
{
 
1874
    struct baselangextent *next;
 
1875
    NESTED_TABLE(do_handle_baselangextent, ble, 4);
 
1876
}
 
1877
 
 
1878
 
 
1879
void handle_base(lua_State * L, struct Base *Base)
 
1880
{
 
1881
    int i;
 
1882
    struct basescript *next = Base->scripts;
 
1883
    lua_newtable(L);
 
1884
    for (i = 0; i < Base->baseline_cnt; i++) {
 
1885
        lua_pushstring(L, make_tag_string(Base->baseline_tags[i]));
 
1886
        lua_rawseti(L, -2, (i + 1));
 
1887
    }
 
1888
    lua_setfield(L, -2, "tags");
 
1889
    if (next != NULL) {
 
1890
        lua_newtable(L);
 
1891
        while (next != NULL) {
 
1892
            lua_pushstring(L, make_tag_string(next->script));
 
1893
            lua_newtable(L);
 
1894
            dump_intfield(L, "default_baseline", (next->def_baseline + 1));
 
1895
            lua_newtable(L);
 
1896
            for (i = 0; i < Base->baseline_cnt; i++) {
 
1897
                if (next->baseline_pos != NULL) /* default omitted */
 
1898
                    lua_pushnumber(L, next->baseline_pos[i]);
 
1899
                else
 
1900
                    lua_pushnumber(L, 0);
 
1901
                lua_rawseti(L, -2, (i + 1));
 
1902
            }
 
1903
            lua_setfield(L, -2, "baseline");
 
1904
            lua_newtable(L);
 
1905
            handle_baselangextent(L, next->langs);
 
1906
            lua_setfield(L, -2, "lang");
 
1907
            lua_rawset(L, -3);
 
1908
            next = next->next;
 
1909
        }
 
1910
        lua_setfield(L, -2, "scripts");
 
1911
    }
 
1912
}
 
1913
 
 
1914
 
 
1915
void handle_axismap(lua_State * L, struct axismap *am)
 
1916
{
 
1917
    int i;
 
1918
    lua_checkstack(L, 3);
 
1919
    lua_newtable(L);
 
1920
    for (i = 0; i < am->points; i++) {
 
1921
        lua_pushnumber(L, am->blends[i]);
 
1922
        lua_rawseti(L, -2, (i + 1));
 
1923
    }
 
1924
    lua_setfield(L, -2, "blends");
 
1925
    lua_newtable(L);
 
1926
    for (i = 0; i < am->points; i++) {
 
1927
        lua_pushnumber(L, am->designs[i]);
 
1928
        lua_rawseti(L, -2, (i + 1));
 
1929
    }
 
1930
    lua_setfield(L, -2, "designs");
 
1931
    dump_realfield(L, "min", am->min);
 
1932
    dump_realfield(L, "def", am->def);
 
1933
    dump_realfield(L, "max", am->max);
 
1934
    if (am->axisnames != NULL) {
 
1935
        lua_newtable(L);
 
1936
        handle_macname(L, am->axisnames);
 
1937
        lua_setfield(L, -2, "axisnames");
 
1938
    }
 
1939
}
 
1940
 
 
1941
 
 
1942
void handle_mmset(lua_State * L, struct mmset *mm)
 
1943
{
 
1944
    int i, k;
 
1945
    lua_newtable(L);
 
1946
    for (i = 0; i < mm->axis_count; i++) {
 
1947
        lua_pushstring(L, mm->axes[i]);
 
1948
        lua_rawseti(L, -2, (i + 1));
 
1949
    }
 
1950
    lua_setfield(L, -2, "axes");
 
1951
 
 
1952
    dump_intfield(L, "instance_count", mm->instance_count);
 
1953
    /* SplineFont *normal; *//* this is the parent */
 
1954
    if (mm->instance_count > 0) {
 
1955
        lua_newtable(L);
 
1956
        for (i = 0; i < mm->instance_count * mm->axis_count; i++) {
 
1957
            lua_pushnumber(L, mm->positions[i]);
 
1958
            lua_rawseti(L, -2, (i + 1));
 
1959
        }
 
1960
        lua_setfield(L, -2, "positions");
 
1961
 
 
1962
        /* better not to do this */
1799
1963
#if 0
1800
 
    {
1801
 
      struct mmset *mmsave ;
1802
 
      lua_newtable(L);
1803
 
      for (i=0;i<mm->instance_count;i++) {
1804
 
        lua_checkstack(L,20);
1805
 
        lua_createtable(L,0,60);
1806
 
        mmsave = mm->instances[i]->mm;
1807
 
        mm->instances[i]->mm = NULL;
1808
 
        handle_splinefont(L, mm->instances[i]);
1809
 
        mm->instances[i]->mm = mmsave;
1810
 
        lua_rawseti(L,-2, (i+1));
1811
 
      }
1812
 
      lua_setfield(L,-2,"instances");
1813
 
    }
 
1964
        {
 
1965
            struct mmset *mmsave;
 
1966
            lua_newtable(L);
 
1967
            for (i = 0; i < mm->instance_count; i++) {
 
1968
                lua_checkstack(L, 20);
 
1969
                lua_createtable(L, 0, 60);
 
1970
                mmsave = mm->instances[i]->mm;
 
1971
                mm->instances[i]->mm = NULL;
 
1972
                handle_splinefont(L, mm->instances[i]);
 
1973
                mm->instances[i]->mm = mmsave;
 
1974
                lua_rawseti(L, -2, (i + 1));
 
1975
            }
 
1976
            lua_setfield(L, -2, "instances");
 
1977
        }
1814
1978
#endif
1815
1979
 
1816
 
    lua_newtable(L);
1817
 
    for (i=0;i<mm->instance_count;i++) {
1818
 
      lua_pushnumber(L, mm->defweights[i]) ;
1819
 
      lua_rawseti(L,-2, (i+1));
1820
 
    }
1821
 
    lua_setfield(L,-2,"defweights");
1822
 
  }
1823
 
  
1824
 
  if (mm->axismaps != NULL) {
1825
 
    lua_newtable(L);
1826
 
    for (i=0;i<mm->axis_count;i++) {
1827
 
      lua_newtable(L);
1828
 
      handle_axismap(L, &(mm->axismaps[i]));
1829
 
      lua_rawseti(L, -2, (i+1));
1830
 
    }
1831
 
    lua_setfield(L,-2,"axismaps"); 
1832
 
  }
1833
 
  dump_stringfield(L,"cdv",mm->cdv);    
1834
 
  dump_stringfield(L,"ndv",mm->ndv);    
1835
 
  dump_intfield(L,"named_instance_count",mm->named_instance_count);     
1836
 
 
1837
 
  if (mm->named_instance_count>0) {
1838
 
      lua_newtable(L);
1839
 
      for (i=0; i<mm->named_instance_count;i++) {
1840
 
        struct named_instance *ni = &(mm->named_instances[i]);
1841
 
        lua_newtable(L);
1842
 
 
1843
 
        lua_newtable(L);
1844
 
        for (k=0;k<=mm->axis_count;k++) {
1845
 
          lua_pushnumber(L,ni->coords[k]);
1846
 
          lua_rawseti(L,-2,(k+1));
1847
 
        }
1848
 
        lua_setfield(L,-2,"coords");
1849
 
 
1850
 
        lua_newtable(L);
1851
 
        handle_macname(L, ni->names);
1852
 
        lua_setfield(L,-2,"names");
1853
 
 
1854
 
        lua_rawseti(L,-2,(i+1));
1855
 
       }
1856
 
      lua_setfield(L,-2,"named_instances");
1857
 
  }
1858
 
  /* unsigned int changed: 1; */
1859
 
  dump_intfield(L,"apple",mm->apple);   
1860
 
}
1861
 
 
1862
 
 
1863
 
 
1864
 
void
1865
 
handle_splinefont(lua_State *L, struct splinefont *sf) {
1866
 
  int k;
1867
 
  int fix_notdef = 0;
1868
 
  int l = -1;
1869
 
 
1870
 
  dump_stringfield(L,"table_version",   LUA_OTF_VERSION);
1871
 
  dump_stringfield(L,"fontname",        sf->fontname);
1872
 
  dump_stringfield(L,"fullname",        sf->fullname);
1873
 
  dump_stringfield(L,"familyname",      sf->familyname);
1874
 
  dump_stringfield(L,"weight",          sf->weight);
1875
 
  dump_stringfield(L,"copyright",       sf->copyright);
1876
 
  dump_stringfield(L,"filename",        sf->filename);
1877
 
  /* dump_stringfield(L,"defbasefilename", sf->defbasefilename); */
1878
 
  dump_stringfield(L,"version",         sf->version);
1879
 
  dump_floatfield (L,"italicangle",     sf->italicangle);
1880
 
  dump_floatfield (L,"upos",            sf->upos);
1881
 
  dump_floatfield (L,"uwidth",          sf->uwidth);
1882
 
  dump_intfield   (L,"ascent",          sf->ascent);
1883
 
  dump_intfield   (L,"descent",         sf->descent);
1884
 
  dump_intfield   (L,"uniqueid",        sf->uniqueid);
1885
 
  dump_intfield   (L,"glyphcnt",        sf->glyphcnt);
1886
 
  dump_intfield   (L,"glyphmax",        sf->glyphmax);
1887
 
  dump_intfield   (L,"units_per_em",    sf->units_per_em);
1888
 
 
1889
 
  if (sf->possub != NULL) {
1890
 
    lua_newtable(L);
1891
 
    handle_generic_fpst(L,sf->possub);
1892
 
    lua_setfield(L,-2,"lookups");
1893
 
  }
1894
 
 
1895
 
  lua_checkstack(L,4);
1896
 
  lua_createtable(L,sf->glyphcnt,0);
1897
 
 
1898
 
  /* This after-the-fact type discovery is not brilliant,
1899
 
     I should really add a 'format' key in the structure */     
1900
 
  if ((sf->origname != NULL) &&
1901
 
      (strmatch(sf->origname+strlen(sf->origname)-4, ".pfa")==0 ||
1902
 
       strmatch(sf->origname+strlen(sf->origname)-4, ".pfb")==0)) {
1903
 
    fix_notdef = 1;
1904
 
  }
1905
 
 
1906
 
  if (fix_notdef) {
1907
 
    /* some code to ensure that the .notdef ends up in slot 0 
1908
 
       (this will actually be enforced by the CFF writer) */
1909
 
    for (k=0;k<sf->glyphcnt;k++) {
1910
 
      if (sf->glyphs[k]) {
1911
 
        if (strcmp(sf->glyphs[k]->name,".notdef") == 0) {
1912
 
          l = k;
1913
 
        }
1914
 
      }
1915
 
    }
1916
 
    if (l==-1) { /* fake a .notdef at the end */
1917
 
      l = sf->glyphcnt;
1918
 
    }
1919
 
    for (k=0;k<l;k++) {
1920
 
      lua_pushnumber(L,(k+1));
1921
 
      lua_createtable(L,0,12);
1922
 
      if (sf->glyphs[k]) {
1923
 
        handle_splinechar(L,sf->glyphs[k], sf->hasvmetrics);
1924
 
      }
1925
 
      lua_rawset(L,-3);
1926
 
    }
1927
 
    if (sf->glyphs != NULL && l<sf->glyphcnt) {
1928
 
      lua_pushnumber(L,0);
1929
 
      lua_createtable(L,0,12);
1930
 
      if (sf->glyphs[l]) {
1931
 
        handle_splinechar(L,sf->glyphs[l], sf->hasvmetrics);
1932
 
      }
1933
 
      lua_rawset(L,-3);
1934
 
    }
1935
 
  }
1936
 
  if ((l+1)<sf->glyphcnt) {
1937
 
    for (k=(l+1);k<sf->glyphcnt;k++) {
1938
 
      lua_pushnumber(L,k);
1939
 
      lua_createtable(L,0,12);
1940
 
      if (sf->glyphs[k]) {
1941
 
        handle_splinechar(L,sf->glyphs[k], sf->hasvmetrics);
1942
 
      }
1943
 
      lua_rawset(L,-3);
1944
 
    }
1945
 
  }
1946
 
  lua_setfield(L,-2,"glyphs");
1947
 
 
1948
 
  /* dump_intfield(L,"changed",                   sf->changed); */
1949
 
  dump_intfield(L,"hasvmetrics",               sf->hasvmetrics);
1950
 
  dump_intfield(L,"onlybitmaps",               sf->onlybitmaps);
1951
 
  dump_intfield(L,"serifcheck",                sf->serifcheck);
1952
 
  dump_intfield(L,"isserif",                   sf->isserif);
1953
 
  dump_intfield(L,"issans",                    sf->issans);
1954
 
  dump_intfield(L,"encodingchanged",           sf->encodingchanged);
1955
 
  dump_intfield(L,"strokedfont",               sf->strokedfont);
1956
 
  dump_intfield(L,"use_typo_metrics",          sf->use_typo_metrics);
1957
 
  dump_intfield(L,"weight_width_slope_only",   sf->weight_width_slope_only);
1958
 
  dump_intfield(L,"head_optimized_for_cleartype",sf->head_optimized_for_cleartype);
1959
 
 
1960
 
  dump_enumfield(L,"uni_interp",               (sf->uni_interp+1), uni_interp_enum);
1961
 
  
1962
 
  if (sf->map != NULL ) {
1963
 
    lua_newtable(L);
1964
 
    handle_encmap(L,sf->map, l);
1965
 
    lua_setfield(L,-2,"map");
1966
 
  }
1967
 
 
1968
 
  dump_stringfield(L,"origname",        sf->origname); /* new */
1969
 
 
1970
 
  if (sf->private != NULL) {
1971
 
    lua_newtable(L);
1972
 
    handle_psdict(L, sf->private);
1973
 
    lua_setfield(L,-2,"private");
1974
 
  }
1975
 
  
1976
 
  dump_stringfield(L,"xuid",    sf->xuid);
1977
 
  
1978
 
  lua_createtable(L,0,40);
1979
 
  handle_pfminfo(L,sf->pfminfo);
1980
 
  lua_setfield(L,-2,"pfminfo");
1981
 
  
1982
 
  if (sf->names != NULL) {
1983
 
    lua_newtable(L);
1984
 
    handle_ttflangname(L,sf->names);
1985
 
    lua_setfield(L,-2,"names");
1986
 
  }
1987
 
  
1988
 
  lua_createtable(L,0,4);
1989
 
  dump_stringfield(L,"registry",    sf->cidregistry);
1990
 
  dump_stringfield(L,"ordering",    sf->ordering);
1991
 
  dump_intfield   (L,"version",     sf->cidversion);
1992
 
  dump_intfield   (L,"supplement",  sf->supplement);
1993
 
  lua_setfield(L,-2,"cidinfo");
1994
 
  
1995
 
  /* SplineFont *cidmaster */ /* parent in a subfont */
1996
 
  if (sf->subfontcnt>0) {
1997
 
    lua_createtable(L,sf->subfontcnt,0);
1998
 
    for (k=0;k<sf->subfontcnt;k++) {
1999
 
          lua_checkstack(L,10);
2000
 
          lua_newtable(L);
2001
 
      handle_splinefont(L,sf->subfonts[k]);
2002
 
      lua_rawseti(L,-2,(k+1));
2003
 
    }
2004
 
    lua_setfield(L,-2,"subfonts");
2005
 
  }
2006
 
 
2007
 
  dump_stringfield(L,"comments",    sf->comments);
2008
 
  dump_stringfield(L,"fontlog",    sf->fontlog);
2009
 
 
2010
 
  if (sf->cvt_names != NULL) {
2011
 
    lua_newtable(L);
2012
 
    for (k=0; sf->cvt_names[k]!=END_CVT_NAMES; ++k) {
2013
 
      lua_pushstring(L, sf->cvt_names[k]);
2014
 
      lua_rawseti(L,-2,(k+1));
2015
 
    }
2016
 
    lua_setfield(L,-2,"cvt_names");
2017
 
  }
2018
 
 
2019
 
  if (sf->ttf_tables != NULL) {
2020
 
    lua_newtable(L);
2021
 
    handle_ttf_table(L,sf->ttf_tables);
2022
 
    lua_setfield(L,-2,"ttf_tables");
2023
 
  }
2024
 
 
2025
 
  if (sf->ttf_tab_saved != NULL) {
2026
 
    lua_newtable(L);
2027
 
    handle_ttf_table(L,sf->ttf_tab_saved);
2028
 
    lua_setfield(L,-2,"ttf_tab_saved");
2029
 
  }
2030
 
 
2031
 
  if (sf->texdata.type != tex_unset) {
2032
 
    lua_newtable(L);
2033
 
    dump_enumfield(L,"type",  sf->texdata.type, tex_type_enum);
2034
 
    lua_newtable(L);
2035
 
    for (k=0;k<22;k++) {
2036
 
      lua_pushnumber(L,k);
2037
 
      lua_pushnumber(L,sf->texdata.params[k]);
2038
 
      lua_rawset(L,-3);
2039
 
    }
2040
 
    lua_setfield(L,-2,"params");
2041
 
    lua_setfield(L,-2,"texdata");
2042
 
  }
2043
 
  if (sf->anchor != NULL) {
2044
 
    lua_newtable(L);
2045
 
    handle_anchorclass(L,sf->anchor);
2046
 
    lua_setfield(L,-2,"anchor_classes");
2047
 
  }
2048
 
  if (sf->kerns != NULL) { 
2049
 
    lua_newtable(L);
2050
 
    handle_kernclass(L,sf->kerns);
2051
 
    lua_setfield(L,-2,"kerns");
2052
 
  }
2053
 
  if (sf->vkerns != NULL) {
2054
 
    lua_newtable(L);
2055
 
    handle_kernclass(L,sf->vkerns);
2056
 
    lua_setfield(L,-2,"vkerns");
2057
 
  }
2058
 
  if (sf->gsub_lookups != NULL) {
2059
 
    lua_newtable(L);
2060
 
    handle_lookup(L,sf->gsub_lookups);
2061
 
    lua_setfield(L,-2,"gsub");
2062
 
  }
2063
 
  if (sf->gpos_lookups != NULL) {
2064
 
    lua_newtable(L);
2065
 
    handle_lookup(L,sf->gpos_lookups);
2066
 
    lua_setfield(L,-2,"gpos");
2067
 
  }
2068
 
 
2069
 
  if (sf->sm != NULL) {
2070
 
    lua_newtable(L);
2071
 
    handle_generic_asm(L,sf->sm);
2072
 
    lua_setfield(L,-2,"sm");
2073
 
  }
2074
 
  if (sf->features != NULL) {
2075
 
    lua_newtable(L);
2076
 
    handle_macfeat(L,sf->features);
2077
 
    lua_setfield(L,-2,"features");
2078
 
  }  
2079
 
  if (sf->mm != NULL) {
2080
 
    lua_newtable(L);
2081
 
    handle_mmset (L,sf->mm);
2082
 
    lua_setfield(L,-2,"mm");
2083
 
  }
2084
 
  dump_stringfield(L,"chosenname",    sf->chosenname);
2085
 
  
2086
 
  dump_intfield(L,"macstyle",    sf->macstyle);
2087
 
  dump_stringfield(L,"fondname",    sf->fondname);
2088
 
  
2089
 
  dump_intfield(L,"design_size",     sf->design_size);
2090
 
  dump_intfield(L,"fontstyle_id",     sf->fontstyle_id);
2091
 
  
2092
 
  if (sf->fontstyle_name != NULL) {
2093
 
    lua_newtable(L);
2094
 
    handle_otfname(L,sf->fontstyle_name);
2095
 
    lua_setfield(L,-2,"fontstyle_name");
2096
 
  }
2097
 
   
2098
 
  dump_intfield(L,"design_range_bottom",sf->design_range_bottom);
2099
 
  dump_intfield(L,"design_range_top",   sf->design_range_top);
2100
 
  dump_floatfield(L,"strokewidth",      sf->strokewidth);
2101
 
  
2102
 
  if (sf->mark_class_cnt>0) {
2103
 
    lua_newtable(L);
2104
 
    for ( k=0; k<sf->mark_class_cnt; ++k ) {
2105
 
      lua_pushnumber(L,(k+1));
2106
 
      lua_pushstring(L,sf->mark_classes[k]);
2107
 
      lua_rawset(L,-3);
2108
 
    }
2109
 
    lua_setfield(L,-1,"mark_classes");
2110
 
 
2111
 
    lua_newtable(L);
2112
 
    for ( k=0; k<sf->mark_class_cnt; ++k ) {
2113
 
      lua_pushnumber(L,(k+1));
2114
 
      lua_pushstring(L,sf->mark_class_names[k]);
2115
 
      lua_rawset(L,-3);
2116
 
    }
2117
 
    lua_setfield(L,-1,"mark_class_names");
2118
 
  }
2119
 
  
2120
 
  dump_intfield(L,"creationtime",     sf->creationtime);
2121
 
  dump_intfield(L,"modificationtime", sf->modificationtime);
2122
 
 
2123
 
  dump_intfield(L,"os2_version",      sf->os2_version);
2124
 
  dump_intfield(L,"sfd_version",     sf->sfd_version);
2125
 
 
2126
 
  if (sf->MATH != NULL) {
2127
 
    lua_newtable(L);
2128
 
    handle_MATH(L, sf->MATH);
2129
 
    lua_setfield(L,-2,"math");
2130
 
  }
2131
 
  
2132
 
  if (sf->loadvalidation_state != 0) {
2133
 
    int val, st;
2134
 
    lua_newtable(L);
2135
 
    val = 1;
2136
 
    st = sf->loadvalidation_state;
2137
 
    if (st & lvs_bad_ps_fontname) { 
2138
 
       lua_pushliteral(L, "bad_ps_fontname"); lua_rawseti(L,-2,val++); 
2139
 
    }
2140
 
    if (st & lvs_bad_glyph_table) { 
2141
 
       lua_pushliteral(L, "bad_glyph_table"); lua_rawseti(L,-2,val++); 
2142
 
    }
2143
 
    if (st & lvs_bad_cff_table) { 
2144
 
       lua_pushliteral(L, "bad_cff_table"); lua_rawseti(L,-2,val++); 
2145
 
    }
2146
 
    if (st & lvs_bad_metrics_table) { 
2147
 
       lua_pushliteral(L, "bad_metrics_table"); lua_rawseti(L,-2,val++); 
2148
 
    }
2149
 
    if (st & lvs_bad_cmap_table) { 
2150
 
       lua_pushliteral(L, "bad_cmap_table"); lua_rawseti(L,-2,val++); 
2151
 
    }
2152
 
    if (st & lvs_bad_bitmaps_table) { 
2153
 
       lua_pushliteral(L, "bad_bitmaps_table"); lua_rawseti(L,-2,val++); 
2154
 
    }
2155
 
    if (st & lvs_bad_gx_table) { 
2156
 
       lua_pushliteral(L, "bad_gx_table"); lua_rawseti(L,-2,val++); 
2157
 
    }
2158
 
    if (st & lvs_bad_ot_table) { 
2159
 
       lua_pushliteral(L, "bad_ot_table"); lua_rawseti(L,-2,val++); 
2160
 
    }
2161
 
    if (st & lvs_bad_os2_version) { 
2162
 
       lua_pushliteral(L, "bad_os2_version"); lua_rawseti(L,-2,val++); 
2163
 
    }
2164
 
    if (st & lvs_bad_sfnt_header) { 
2165
 
       lua_pushliteral(L, "bad_sfnt_header"); lua_rawseti(L,-2,val++); 
2166
 
    }
2167
 
    lua_setfield(L,-2,"validation_state");
2168
 
  }
2169
 
 
2170
 
  if (sf->horiz_base != NULL) {
2171
 
    lua_newtable(L);
2172
 
    handle_base(L, sf->horiz_base);
2173
 
    lua_setfield(L,-2,"horiz_base");
2174
 
  }
2175
 
  if (sf->vert_base != NULL) {
2176
 
    lua_newtable(L);
2177
 
    handle_base(L, sf->vert_base);
2178
 
    lua_setfield(L,-2,"vert_base");
2179
 
  }
2180
 
  dump_intfield(L,"extrema_bound",     sf->extrema_bound);
2181
 
}
2182
 
 
2183
 
int 
2184
 
ff_make_table (lua_State *L) {
2185
 
  SplineFont *sf;
2186
 
  sf = *(check_isfont(L,1));
2187
 
  if (sf == NULL) {
2188
 
    lua_pushboolean(L,0);
2189
 
  } else {
2190
 
    lua_createtable(L,0,60);
2191
 
    handle_splinefont(L,sf);
2192
 
  }
2193
 
  return 1;
2194
 
}
2195
 
 
2196
 
void do_ff_info (lua_State *L, SplineFont *sf) {
2197
 
  lua_newtable(L);
2198
 
  dump_stringfield(L,"familyname",      sf->familyname);
2199
 
  dump_stringfield(L,"fontname",        sf->fontname);
2200
 
  dump_stringfield(L,"fullname",        sf->fullname);
2201
 
  dump_intfield   (L,"italicangle",     sf->italicangle);
2202
 
  dump_stringfield(L,"version",         sf->version);
2203
 
  dump_stringfield(L,"weight",          sf->weight);
2204
 
 
2205
 
}
2206
 
 
2207
 
static int 
2208
 
ff_info (lua_State *L) {
2209
 
  SplineFont *sf;
2210
 
  FILE *l;
2211
 
  int i;
2212
 
  const char *fontname;
2213
 
  int openflags = 1;
2214
 
  fontname = luaL_checkstring(L,1);
2215
 
  if (!strlen(fontname)) {
2216
 
        lua_pushfstring(L,"font loading failed: empty string given\n", fontname);
2217
 
        lua_error(L);
2218
 
        return 1;
2219
 
  } 
2220
 
  /* test fontname for existance */
2221
 
  if ((l = fopen(fontname,"r"))) {
2222
 
        fclose(l); 
2223
 
  } else {
2224
 
        lua_pushfstring(L,"font loading failed for %s (read error)\n", fontname);
2225
 
        lua_error(L);
2226
 
  }
2227
 
  sf = ReadSplineFontInfo((char *)fontname,openflags);
2228
 
  if (sf==NULL) {
2229
 
    lua_pushfstring(L,"font loading failed for %s\n", fontname);
2230
 
    lua_error(L);
2231
 
  } else {
2232
 
        if (sf->next != NULL) {
2233
 
      SplineFont *sf_next;
2234
 
          i = 1;
2235
 
          lua_newtable(L);
2236
 
          while (sf) {
2237
 
                do_ff_info(L, sf);
2238
 
                lua_rawseti(L,-2,i);
2239
 
                i++;
2240
 
        sf_next = sf->next;
2241
 
                SplineFontFree(sf);
2242
 
                sf = sf_next;
2243
 
          }
2244
 
        } else {
2245
 
          do_ff_info(L, sf);
2246
 
          SplineFontFree(sf);
2247
 
        }         
2248
 
  }
2249
 
  return 1;
2250
 
}
2251
 
 
2252
 
static void ff_do_cff (SplineFont *sf, char *filename, unsigned char **buf, int *bufsiz) {
2253
 
  FILE *f;
2254
 
  int32 *bsizes = NULL;
2255
 
  int flags = ps_flag_nocffsugar + ps_flag_nohints;
2256
 
  EncMap *map;
2257
 
 
2258
 
  map = EncMap1to1(sf->glyphcnt);
2259
 
 
2260
 
  if(WriteTTFFont(filename, sf, ff_cff, bsizes, bf_none, flags, map, ly_fore)) {
2261
 
    /* success */
2262
 
    f = fopen(filename,"rb");
2263
 
    readbinfile(f , buf, bufsiz);
2264
 
    /*fprintf(stdout,"\n%s => CFF, size: %d\n", sf->filename, *bufsiz);*/
2265
 
    fclose(f);
2266
 
    return;
2267
 
  } 
2268
 
  /* errors */
2269
 
  fprintf(stdout,"\n%s => CFF, failed\n", sf->filename);
 
1980
        lua_newtable(L);
 
1981
        for (i = 0; i < mm->instance_count; i++) {
 
1982
            lua_pushnumber(L, mm->defweights[i]);
 
1983
            lua_rawseti(L, -2, (i + 1));
 
1984
        }
 
1985
        lua_setfield(L, -2, "defweights");
 
1986
    }
 
1987
 
 
1988
    if (mm->axismaps != NULL) {
 
1989
        lua_newtable(L);
 
1990
        for (i = 0; i < mm->axis_count; i++) {
 
1991
            lua_newtable(L);
 
1992
            handle_axismap(L, &(mm->axismaps[i]));
 
1993
            lua_rawseti(L, -2, (i + 1));
 
1994
        }
 
1995
        lua_setfield(L, -2, "axismaps");
 
1996
    }
 
1997
    dump_stringfield(L, "cdv", mm->cdv);
 
1998
    dump_stringfield(L, "ndv", mm->ndv);
 
1999
    dump_intfield(L, "named_instance_count", mm->named_instance_count);
 
2000
 
 
2001
    if (mm->named_instance_count > 0) {
 
2002
        lua_newtable(L);
 
2003
        for (i = 0; i < mm->named_instance_count; i++) {
 
2004
            struct named_instance *ni = &(mm->named_instances[i]);
 
2005
            lua_newtable(L);
 
2006
 
 
2007
            lua_newtable(L);
 
2008
            for (k = 0; k <= mm->axis_count; k++) {
 
2009
                lua_pushnumber(L, ni->coords[k]);
 
2010
                lua_rawseti(L, -2, (k + 1));
 
2011
            }
 
2012
            lua_setfield(L, -2, "coords");
 
2013
 
 
2014
            lua_newtable(L);
 
2015
            handle_macname(L, ni->names);
 
2016
            lua_setfield(L, -2, "names");
 
2017
 
 
2018
            lua_rawseti(L, -2, (i + 1));
 
2019
        }
 
2020
        lua_setfield(L, -2, "named_instances");
 
2021
    }
 
2022
    /* unsigned int changed: 1; */
 
2023
    dump_intfield(L, "apple", mm->apple);
 
2024
}
 
2025
 
 
2026
 
 
2027
 
 
2028
void handle_splinefont(lua_State * L, struct splinefont *sf)
 
2029
{
 
2030
    int k;
 
2031
    int fix_notdef = 0;
 
2032
    int l = -1;
 
2033
 
 
2034
    dump_stringfield(L, "table_version", LUA_OTF_VERSION);
 
2035
    dump_stringfield(L, "fontname", sf->fontname);
 
2036
    dump_stringfield(L, "fullname", sf->fullname);
 
2037
    dump_stringfield(L, "familyname", sf->familyname);
 
2038
    dump_stringfield(L, "weight", sf->weight);
 
2039
    dump_stringfield(L, "copyright", sf->copyright);
 
2040
    dump_stringfield(L, "filename", sf->filename);
 
2041
    /* dump_stringfield(L,"defbasefilename", sf->defbasefilename); */
 
2042
    dump_stringfield(L, "version", sf->version);
 
2043
    dump_floatfield(L, "italicangle", sf->italicangle);
 
2044
    dump_floatfield(L, "upos", sf->upos);
 
2045
    dump_floatfield(L, "uwidth", sf->uwidth);
 
2046
    dump_intfield(L, "ascent", sf->ascent);
 
2047
    dump_intfield(L, "descent", sf->descent);
 
2048
    dump_intfield(L, "uniqueid", sf->uniqueid);
 
2049
    dump_intfield(L, "glyphcnt", sf->glyphcnt);
 
2050
    dump_intfield(L, "glyphmax", sf->glyphmax);
 
2051
    dump_intfield(L, "units_per_em", sf->units_per_em);
 
2052
 
 
2053
    if (sf->possub != NULL) {
 
2054
        lua_newtable(L);
 
2055
        handle_generic_fpst(L, sf->possub);
 
2056
        lua_setfield(L, -2, "lookups");
 
2057
    }
 
2058
 
 
2059
    lua_checkstack(L, 4);
 
2060
    lua_createtable(L, sf->glyphcnt, 0);
 
2061
 
 
2062
    /* This after-the-fact type discovery is not brilliant,
 
2063
       I should really add a 'format' key in the structure */
 
2064
    if ((sf->origname != NULL) &&
 
2065
        (strmatch(sf->origname + strlen(sf->origname) - 4, ".pfa") == 0 ||
 
2066
         strmatch(sf->origname + strlen(sf->origname) - 4, ".pfb") == 0)) {
 
2067
        fix_notdef = 1;
 
2068
    }
 
2069
 
 
2070
    if (fix_notdef) {
 
2071
        /* some code to ensure that the .notdef ends up in slot 0 
 
2072
           (this will actually be enforced by the CFF writer) */
 
2073
        for (k = 0; k < sf->glyphcnt; k++) {
 
2074
            if (sf->glyphs[k]) {
 
2075
                if (strcmp(sf->glyphs[k]->name, ".notdef") == 0) {
 
2076
                    l = k;
 
2077
                }
 
2078
            }
 
2079
        }
 
2080
        if (l == -1) {          /* fake a .notdef at the end */
 
2081
            l = sf->glyphcnt;
 
2082
        }
 
2083
        for (k = 0; k < l; k++) {
 
2084
            if (sf->glyphs[k]) {
 
2085
                lua_pushnumber(L, (k + 1));
 
2086
                lua_createtable(L, 0, 12);
 
2087
                handle_splinechar(L, sf->glyphs[k], sf->hasvmetrics);
 
2088
                lua_rawset(L, -3);
 
2089
            }
 
2090
        }
 
2091
        if (sf->glyphs != NULL && l < sf->glyphcnt) {
 
2092
            lua_pushnumber(L, 0);
 
2093
            if (sf->glyphs[l]) {
 
2094
                lua_createtable(L, 0, 12);
 
2095
                handle_splinechar(L, sf->glyphs[l], sf->hasvmetrics);
 
2096
            } else {
 
2097
                lua_createtable(L, 0, 0);
 
2098
            }
 
2099
            lua_rawset(L, -3);
 
2100
        }
 
2101
    }
 
2102
    if ((l + 1) < sf->glyphcnt) {
 
2103
        for (k = (l + 1); k < sf->glyphcnt; k++) {
 
2104
            if (sf->glyphs[k]) {
 
2105
                lua_pushnumber(L, k);
 
2106
                lua_createtable(L, 0, 12);
 
2107
                handle_splinechar(L, sf->glyphs[k], sf->hasvmetrics);
 
2108
                lua_rawset(L, -3);
 
2109
            }
 
2110
        }
 
2111
    }
 
2112
    lua_setfield(L, -2, "glyphs");
 
2113
 
 
2114
    /* dump_intfield(L,"changed",                   sf->changed); */
 
2115
    dump_intfield(L, "hasvmetrics", sf->hasvmetrics);
 
2116
    dump_intfield(L, "onlybitmaps", sf->onlybitmaps);
 
2117
    dump_intfield(L, "serifcheck", sf->serifcheck);
 
2118
    dump_intfield(L, "isserif", sf->isserif);
 
2119
    dump_intfield(L, "issans", sf->issans);
 
2120
    dump_intfield(L, "encodingchanged", sf->encodingchanged);
 
2121
    dump_intfield(L, "strokedfont", sf->strokedfont);
 
2122
    dump_intfield(L, "use_typo_metrics", sf->use_typo_metrics);
 
2123
    dump_intfield(L, "weight_width_slope_only", sf->weight_width_slope_only);
 
2124
    dump_intfield(L, "head_optimized_for_cleartype",
 
2125
                  sf->head_optimized_for_cleartype);
 
2126
 
 
2127
    dump_enumfield(L, "uni_interp", (sf->uni_interp + 1), uni_interp_enum);
 
2128
 
 
2129
    if (sf->map != NULL) {
 
2130
        lua_newtable(L);
 
2131
        handle_encmap(L, sf->map, l);
 
2132
        lua_setfield(L, -2, "map");
 
2133
    }
 
2134
 
 
2135
    dump_stringfield(L, "origname", sf->origname);      /* new */
 
2136
 
 
2137
    if (sf->private != NULL) {
 
2138
        lua_newtable(L);
 
2139
        handle_psdict(L, sf->private);
 
2140
        lua_setfield(L, -2, "private");
 
2141
    }
 
2142
 
 
2143
    dump_stringfield(L, "xuid", sf->xuid);
 
2144
 
 
2145
    lua_createtable(L, 0, 40);
 
2146
    handle_pfminfo(L, sf->pfminfo);
 
2147
    lua_setfield(L, -2, "pfminfo");
 
2148
 
 
2149
    if (sf->names != NULL) {
 
2150
        lua_newtable(L);
 
2151
        handle_ttflangname(L, sf->names);
 
2152
        lua_setfield(L, -2, "names");
 
2153
    }
 
2154
 
 
2155
    lua_createtable(L, 0, 4);
 
2156
    dump_stringfield(L, "registry", sf->cidregistry);
 
2157
    dump_stringfield(L, "ordering", sf->ordering);
 
2158
    dump_intfield(L, "version", sf->cidversion);
 
2159
    dump_intfield(L, "supplement", sf->supplement);
 
2160
    lua_setfield(L, -2, "cidinfo");
 
2161
 
 
2162
    /* SplineFont *cidmaster *//* parent in a subfont */
 
2163
    if (sf->subfontcnt > 0) {
 
2164
        lua_createtable(L, sf->subfontcnt, 0);
 
2165
        for (k = 0; k < sf->subfontcnt; k++) {
 
2166
            lua_checkstack(L, 10);
 
2167
            lua_newtable(L);
 
2168
            handle_splinefont(L, sf->subfonts[k]);
 
2169
            lua_rawseti(L, -2, (k + 1));
 
2170
        }
 
2171
        lua_setfield(L, -2, "subfonts");
 
2172
    }
 
2173
 
 
2174
    dump_stringfield(L, "comments", sf->comments);
 
2175
    dump_stringfield(L, "fontlog", sf->fontlog);
 
2176
 
 
2177
    if (sf->cvt_names != NULL) {
 
2178
        lua_newtable(L);
 
2179
        for (k = 0; sf->cvt_names[k] != END_CVT_NAMES; ++k) {
 
2180
            lua_pushstring(L, sf->cvt_names[k]);
 
2181
            lua_rawseti(L, -2, (k + 1));
 
2182
        }
 
2183
        lua_setfield(L, -2, "cvt_names");
 
2184
    }
 
2185
 
 
2186
    if (sf->ttf_tables != NULL) {
 
2187
        lua_newtable(L);
 
2188
        handle_ttf_table(L, sf->ttf_tables);
 
2189
        lua_setfield(L, -2, "ttf_tables");
 
2190
    }
 
2191
 
 
2192
    if (sf->ttf_tab_saved != NULL) {
 
2193
        lua_newtable(L);
 
2194
        handle_ttf_table(L, sf->ttf_tab_saved);
 
2195
        lua_setfield(L, -2, "ttf_tab_saved");
 
2196
    }
 
2197
 
 
2198
    if (sf->texdata.type != tex_unset) {
 
2199
        lua_newtable(L);
 
2200
        dump_enumfield(L, "type", sf->texdata.type, tex_type_enum);
 
2201
        lua_newtable(L);
 
2202
        for (k = 0; k < 22; k++) {
 
2203
            lua_pushnumber(L, k);
 
2204
            lua_pushnumber(L, sf->texdata.params[k]);
 
2205
            lua_rawset(L, -3);
 
2206
        }
 
2207
        lua_setfield(L, -2, "params");
 
2208
        lua_setfield(L, -2, "texdata");
 
2209
    }
 
2210
    if (sf->anchor != NULL) {
 
2211
        lua_newtable(L);
 
2212
        handle_anchorclass(L, sf->anchor);
 
2213
        lua_setfield(L, -2, "anchor_classes");
 
2214
    }
 
2215
    if (sf->kerns != NULL) {
 
2216
        lua_newtable(L);
 
2217
        handle_kernclass(L, sf->kerns);
 
2218
        lua_setfield(L, -2, "kerns");
 
2219
    }
 
2220
    if (sf->vkerns != NULL) {
 
2221
        lua_newtable(L);
 
2222
        handle_kernclass(L, sf->vkerns);
 
2223
        lua_setfield(L, -2, "vkerns");
 
2224
    }
 
2225
    if (sf->gsub_lookups != NULL) {
 
2226
        lua_newtable(L);
 
2227
        handle_lookup(L, sf->gsub_lookups, sf);
 
2228
        lua_setfield(L, -2, "gsub");
 
2229
    }
 
2230
    if (sf->gpos_lookups != NULL) {
 
2231
        lua_newtable(L);
 
2232
        handle_lookup(L, sf->gpos_lookups, sf);
 
2233
        lua_setfield(L, -2, "gpos");
 
2234
    }
 
2235
 
 
2236
    if (sf->sm != NULL) {
 
2237
        lua_newtable(L);
 
2238
        handle_generic_asm(L, sf->sm);
 
2239
        lua_setfield(L, -2, "sm");
 
2240
    }
 
2241
    if (sf->features != NULL) {
 
2242
        lua_newtable(L);
 
2243
        handle_macfeat(L, sf->features);
 
2244
        lua_setfield(L, -2, "features");
 
2245
    }
 
2246
    if (sf->mm != NULL) {
 
2247
        lua_newtable(L);
 
2248
        handle_mmset(L, sf->mm);
 
2249
        lua_setfield(L, -2, "mm");
 
2250
    }
 
2251
    dump_stringfield(L, "chosenname", sf->chosenname);
 
2252
 
 
2253
    dump_intfield(L, "macstyle", sf->macstyle);
 
2254
    dump_stringfield(L, "fondname", sf->fondname);
 
2255
 
 
2256
    dump_intfield(L, "design_size", sf->design_size);
 
2257
    dump_intfield(L, "fontstyle_id", sf->fontstyle_id);
 
2258
 
 
2259
    if (sf->fontstyle_name != NULL) {
 
2260
        lua_newtable(L);
 
2261
        handle_otfname(L, sf->fontstyle_name);
 
2262
        lua_setfield(L, -2, "fontstyle_name");
 
2263
    }
 
2264
 
 
2265
    dump_intfield(L, "design_range_bottom", sf->design_range_bottom);
 
2266
    dump_intfield(L, "design_range_top", sf->design_range_top);
 
2267
    dump_floatfield(L, "strokewidth", sf->strokewidth);
 
2268
 
 
2269
    if (sf->mark_class_cnt > 0) {
 
2270
        lua_newtable(L);
 
2271
        for (k = 0; k < sf->mark_class_cnt; k++) {
 
2272
            if (sf->mark_class_names[k] != NULL) {
 
2273
                lua_pushstring(L, sf->mark_class_names[k]);
 
2274
                lua_pushstring(L, sf->mark_classes[k]);
 
2275
                lua_rawset(L, -3);
 
2276
            }
 
2277
        }
 
2278
        lua_setfield(L, -2, "mark_classes");
 
2279
    }
 
2280
 
 
2281
    dump_intfield(L, "creationtime", sf->creationtime);
 
2282
    dump_intfield(L, "modificationtime", sf->modificationtime);
 
2283
 
 
2284
    dump_intfield(L, "os2_version", sf->os2_version);
 
2285
    dump_intfield(L, "sfd_version", sf->sfd_version);
 
2286
 
 
2287
    if (sf->MATH != NULL) {
 
2288
        lua_newtable(L);
 
2289
        handle_MATH(L, sf->MATH);
 
2290
        lua_setfield(L, -2, "math");
 
2291
    }
 
2292
 
 
2293
    if (sf->loadvalidation_state != 0) {
 
2294
        int val, st;
 
2295
        lua_newtable(L);
 
2296
        val = 1;
 
2297
        st = sf->loadvalidation_state;
 
2298
        if (st & lvs_bad_ps_fontname) {
 
2299
            lua_pushliteral(L, "bad_ps_fontname");
 
2300
            lua_rawseti(L, -2, val++);
 
2301
        }
 
2302
        if (st & lvs_bad_glyph_table) {
 
2303
            lua_pushliteral(L, "bad_glyph_table");
 
2304
            lua_rawseti(L, -2, val++);
 
2305
        }
 
2306
        if (st & lvs_bad_cff_table) {
 
2307
            lua_pushliteral(L, "bad_cff_table");
 
2308
            lua_rawseti(L, -2, val++);
 
2309
        }
 
2310
        if (st & lvs_bad_metrics_table) {
 
2311
            lua_pushliteral(L, "bad_metrics_table");
 
2312
            lua_rawseti(L, -2, val++);
 
2313
        }
 
2314
        if (st & lvs_bad_cmap_table) {
 
2315
            lua_pushliteral(L, "bad_cmap_table");
 
2316
            lua_rawseti(L, -2, val++);
 
2317
        }
 
2318
        if (st & lvs_bad_bitmaps_table) {
 
2319
            lua_pushliteral(L, "bad_bitmaps_table");
 
2320
            lua_rawseti(L, -2, val++);
 
2321
        }
 
2322
        if (st & lvs_bad_gx_table) {
 
2323
            lua_pushliteral(L, "bad_gx_table");
 
2324
            lua_rawseti(L, -2, val++);
 
2325
        }
 
2326
        if (st & lvs_bad_ot_table) {
 
2327
            lua_pushliteral(L, "bad_ot_table");
 
2328
            lua_rawseti(L, -2, val++);
 
2329
        }
 
2330
        if (st & lvs_bad_os2_version) {
 
2331
            lua_pushliteral(L, "bad_os2_version");
 
2332
            lua_rawseti(L, -2, val++);
 
2333
        }
 
2334
        if (st & lvs_bad_sfnt_header) {
 
2335
            lua_pushliteral(L, "bad_sfnt_header");
 
2336
            lua_rawseti(L, -2, val++);
 
2337
        }
 
2338
        lua_setfield(L, -2, "validation_state");
 
2339
    }
 
2340
 
 
2341
    if (sf->horiz_base != NULL) {
 
2342
        lua_newtable(L);
 
2343
        handle_base(L, sf->horiz_base);
 
2344
        lua_setfield(L, -2, "horiz_base");
 
2345
    }
 
2346
    if (sf->vert_base != NULL) {
 
2347
        lua_newtable(L);
 
2348
        handle_base(L, sf->vert_base);
 
2349
        lua_setfield(L, -2, "vert_base");
 
2350
    }
 
2351
    dump_intfield(L, "extrema_bound", sf->extrema_bound);
 
2352
}
 
2353
 
 
2354
int ff_make_table(lua_State * L)
 
2355
{
 
2356
    SplineFont *sf;
 
2357
    sf = *(check_isfont(L, 1));
 
2358
    if (sf == NULL) {
 
2359
        lua_pushboolean(L, 0);
 
2360
    } else {
 
2361
        lua_createtable(L, 0, 60);
 
2362
        handle_splinefont(L, sf);
 
2363
    }
 
2364
    return 1;
 
2365
}
 
2366
 
 
2367
void do_ff_info(lua_State * L, SplineFont * sf)
 
2368
{
 
2369
    lua_newtable(L);
 
2370
    dump_stringfield(L, "familyname", sf->familyname);
 
2371
    dump_stringfield(L, "fontname", sf->fontname);
 
2372
    dump_stringfield(L, "fullname", sf->fullname);
 
2373
    dump_intfield(L, "italicangle", sf->italicangle);
 
2374
    dump_stringfield(L, "version", sf->version);
 
2375
    dump_stringfield(L, "weight", sf->weight);
 
2376
 
 
2377
}
 
2378
 
 
2379
static int ff_info(lua_State * L)
 
2380
{
 
2381
    SplineFont *sf;
 
2382
    FILE *l;
 
2383
    int i;
 
2384
    const char *fontname;
 
2385
    int openflags = 1;
 
2386
    fontname = luaL_checkstring(L, 1);
 
2387
    if (!strlen(fontname)) {
 
2388
        lua_pushnil(L);
 
2389
        lua_pushfstring(L, "font loading failed: empty string given\n",
 
2390
                        fontname);
 
2391
        return 2;
 
2392
    }
 
2393
    /* test fontname for existance */
 
2394
    if ((l = fopen(fontname, "r"))) {
 
2395
        fclose(l);
 
2396
    } else {
 
2397
        lua_pushnil(L);
 
2398
        lua_pushfstring(L, "font loading failed for %s (read error)\n",
 
2399
                        fontname);
 
2400
        return 2;
 
2401
    }
 
2402
    sf = ReadSplineFontInfo((char *) fontname, openflags);
 
2403
    if (sf == NULL) {
 
2404
        lua_pushnil(L);
 
2405
        lua_pushfstring(L, "font loading failed for %s\n", fontname);
 
2406
        return 2;
 
2407
    } else {
 
2408
        if (sf->next != NULL) {
 
2409
            SplineFont *sf_next;
 
2410
            i = 1;
 
2411
            lua_newtable(L);
 
2412
            while (sf) {
 
2413
                do_ff_info(L, sf);
 
2414
                lua_rawseti(L, -2, i);
 
2415
                i++;
 
2416
                sf_next = sf->next;
 
2417
                SplineFontFree(sf);
 
2418
                sf = sf_next;
 
2419
            }
 
2420
        } else {
 
2421
            do_ff_info(L, sf);
 
2422
            SplineFontFree(sf);
 
2423
        }
 
2424
    }
 
2425
    return 1;
 
2426
}
 
2427
 
 
2428
static void ff_do_cff(SplineFont * sf, char *filename, unsigned char **buf,
 
2429
                      int *bufsiz)
 
2430
{
 
2431
    FILE *f;
 
2432
    int32 *bsizes = NULL;
 
2433
    int flags = ps_flag_nocffsugar + ps_flag_nohints;
 
2434
    EncMap *map;
 
2435
 
 
2436
    map = EncMap1to1(sf->glyphcnt);
 
2437
 
 
2438
    if (WriteTTFFont
 
2439
        (filename, sf, ff_cff, bsizes, bf_none, flags, map, ly_fore)) {
 
2440
        /* success */
 
2441
        f = fopen(filename, "rb");
 
2442
        readbinfile(f, buf, bufsiz);
 
2443
        /*fprintf(stdout,"\n%s => CFF, size: %d\n", sf->filename, *bufsiz); */
 
2444
        fclose(f);
 
2445
        return;
 
2446
    }
 
2447
    /* errors */
 
2448
    fprintf(stdout, "\n%s => CFF, failed\n", sf->filename);
2270
2449
 
2271
2450
}
2272
2451
 
2273
2452
/* exported for writecff.c */
2274
2453
 
2275
 
int ff_createcff (char *file, unsigned char **buf, int *bufsiz) {
2276
 
  SplineFont *sf;
2277
 
  int k ;
2278
 
  char s[] = "tempfile.cff";
2279
 
  int openflags = 1;
2280
 
  int notdefpos = 0;
2281
 
  sf =  ReadSplineFont(file,openflags);
2282
 
  if (sf) {
2283
 
    /* this is not the best way. nicer to have no temp file at all */
2284
 
    ff_do_cff(sf, s, buf,bufsiz);
2285
 
        for (k=0;k<sf->glyphcnt;k++) {
2286
 
          if (sf->glyphs[k] && strcmp(sf->glyphs[k]->name,".notdef")==0) {
2287
 
                notdefpos=k;
2288
 
                break;
2289
 
          }
2290
 
        }
2291
 
    remove(s);
2292
 
        SplineFontFree(sf);
2293
 
  }
2294
 
  return notdefpos;
 
2454
int ff_createcff(char *file, unsigned char **buf, int *bufsiz)
 
2455
{
 
2456
    SplineFont *sf;
 
2457
    int k;
 
2458
    char s[] = "tempfile.cff";
 
2459
    int openflags = 1;
 
2460
    int notdefpos = 0;
 
2461
    sf = ReadSplineFont(file, openflags);
 
2462
    if (sf) {
 
2463
        /* this is not the best way. nicer to have no temp file at all */
 
2464
        ff_do_cff(sf, s, buf, bufsiz);
 
2465
        for (k = 0; k < sf->glyphcnt; k++) {
 
2466
            if (sf->glyphs[k] && strcmp(sf->glyphs[k]->name, ".notdef") == 0) {
 
2467
                notdefpos = k;
 
2468
                break;
 
2469
            }
 
2470
        }
 
2471
        remove(s);
 
2472
        SplineFontFree(sf);
 
2473
    }
 
2474
    return notdefpos;
2295
2475
}
2296
2476
 
2297
 
int ff_get_ttc_index(char *ffname, char*psname) {
2298
 
  SplineFont *sf;
2299
 
  int i = 0;
2300
 
  int openflags = 1;
2301
 
  int index = 0;
 
2477
int ff_get_ttc_index(char *ffname, char *psname)
 
2478
{
 
2479
    SplineFont *sf;
 
2480
    int i = 0;
 
2481
    int openflags = 1;
 
2482
    int index = -1;
2302
2483
 
2303
 
  sf = ReadSplineFontInfo((char *)ffname,openflags);
2304
 
  if (sf==NULL) {
2305
 
    perror("font loading failed unexpectedly\n");
2306
 
    exit(EXIT_FAILURE);
2307
 
  } 
2308
 
  while (sf != NULL) {
2309
 
        if (strcmp(sf->fontname,psname)==0) {
2310
 
          index = i;
2311
 
          break;
2312
 
        }
2313
 
        i++;
2314
 
        sf = sf->next;
2315
 
  }
2316
 
  return index;
 
2484
    sf = ReadSplineFontInfo((char *) ffname, openflags);
 
2485
    if (sf == NULL) {
 
2486
        perror("font loading failed unexpectedly\n");
 
2487
        exit(EXIT_FAILURE);
 
2488
    }
 
2489
    while (sf != NULL) {
 
2490
        if (strcmp(sf->fontname, psname) == 0) {
 
2491
            index = i;
 
2492
            break;
 
2493
        }
 
2494
        i++;
 
2495
        sf = sf->next;
 
2496
    }
 
2497
    return index;
2317
2498
}
2318
2499
 
2319
2500
static int warning_given = 0;
2320
2501
 
2321
 
static int 
2322
 
ffold_info (lua_State *L) {
2323
 
    if (warning_given<5) {
2324
 
        fprintf (stderr, "Warning: The 'fontforge' table has been renamed to 'fontloader'.\n");
2325
 
        fprintf (stderr, "  Please update your source file(s) accordingly.\n");
2326
 
        warning_given ++;
 
2502
static int ffold_info(lua_State * L)
 
2503
{
 
2504
    if (warning_given < 5) {
 
2505
        fprintf(stderr,
 
2506
                "Warning: The 'fontforge' table has been renamed to 'fontloader'.\n");
 
2507
        fprintf(stderr, "  Please update your source file(s) accordingly.\n");
 
2508
        warning_given++;
2327
2509
    }
2328
2510
    return ff_info(L);
2329
2511
}
2330
2512
 
2331
 
static int 
2332
 
ffold_open (lua_State *L) {
2333
 
    fprintf (stderr, "Warning: The 'fontforge' table has been renamed to 'fontloader'.\n");
2334
 
    fprintf (stderr, "  Please update your source file(s) accordingly.\n");
 
2513
static int ffold_open(lua_State * L)
 
2514
{
 
2515
    fprintf(stderr,
 
2516
            "Warning: The 'fontforge' table has been renamed to 'fontloader'.\n");
 
2517
    fprintf(stderr, "  Please update your source file(s) accordingly.\n");
2335
2518
    return ff_open(L);
2336
2519
}
2337
2520
 
2338
2521
 
2339
2522
static struct luaL_reg fflib[] = {
2340
 
  {"open", ffold_open},
2341
 
  {"info", ffold_info},
2342
 
  {"close", ff_close},
2343
 
  {"apply_afmfile", ff_apply_afmfile},
2344
 
  {"apply_featurefile", ff_apply_featurefile},
2345
 
  {"to_table", ff_make_table},
2346
 
  {NULL, NULL}
 
2523
    {"open", ffold_open},
 
2524
    {"info", ffold_info},
 
2525
    {"close", ff_close},
 
2526
    {"apply_afmfile", ff_apply_afmfile},
 
2527
    {"apply_featurefile", ff_apply_featurefile},
 
2528
    {"to_table", ff_make_table},
 
2529
    {NULL, NULL}
2347
2530
};
2348
2531
 
2349
2532
static struct luaL_reg fllib[] = {
2350
 
  {"open", ff_open},
2351
 
  {"info", ff_info},
2352
 
  {"close", ff_close},
2353
 
  {"apply_afmfile", ff_apply_afmfile},
2354
 
  {"apply_featurefile", ff_apply_featurefile},
2355
 
  {"to_table", ff_make_table},
2356
 
  {NULL, NULL}
 
2533
    {"open", ff_open},
 
2534
    {"info", ff_info},
 
2535
    {"close", ff_close},
 
2536
    {"apply_afmfile", ff_apply_afmfile},
 
2537
    {"apply_featurefile", ff_apply_featurefile},
 
2538
    {"to_table", ff_make_table},
 
2539
    {NULL, NULL}
2357
2540
};
2358
2541
 
2359
 
static const struct luaL_reg fflib_m [] = {
2360
 
  {"__gc", ff_close }, /* doesnt work yet! */
2361
 
  {NULL, NULL}  /* sentinel */
 
2542
static const struct luaL_reg fflib_m[] = {
 
2543
    {"__gc", ff_close},         /* doesnt work yet! */
 
2544
    {NULL, NULL}                /* sentinel */
2362
2545
};
2363
2546
 
2364
2547
extern char *SaveTablesPref;
2365
 
extern char *coord_sep ;
 
2548
extern char *coord_sep;
2366
2549
 
2367
 
int luaopen_ff (lua_State *L) {
2368
 
  InitSimpleStuff();
2369
 
  setlocale(LC_ALL,"C"); /* undo whatever InitSimpleStuff has caused */
2370
 
  coord_sep = ",";
2371
 
  FF_SetUiInterface(&luaui_interface);
2372
 
  default_encoding = FindOrMakeEncoding("ISO8859-1");
2373
 
  SaveTablesPref = "VORG,JSTF,acnt,bsln,fdsc,fmtx,hsty,just,trak,Zapf,LINO";
2374
 
  luaL_newmetatable(L,FONT_METATABLE);
2375
 
  luaL_register(L, NULL, fflib_m);
2376
 
  luaL_openlib(L, "fontforge", fflib, 0);
2377
 
  luaL_openlib(L, "fontloader", fllib, 0);
2378
 
  return 1;
 
2550
int luaopen_ff(lua_State * L)
 
2551
{
 
2552
    InitSimpleStuff();
 
2553
    setlocale(LC_ALL, "C");     /* undo whatever InitSimpleStuff has caused */
 
2554
    coord_sep = ",";
 
2555
    FF_SetUiInterface(&luaui_interface);
 
2556
    default_encoding = FindOrMakeEncoding("ISO8859-1");
 
2557
    SaveTablesPref = "VORG,JSTF,acnt,bsln,fdsc,fmtx,hsty,just,trak,Zapf,LINO";
 
2558
    luaL_newmetatable(L, FONT_METATABLE);
 
2559
    luaL_register(L, NULL, fflib_m);
 
2560
    luaL_openlib(L, "fontforge", fflib, 0);
 
2561
    luaL_openlib(L, "fontloader", fllib, 0);
 
2562
    return 1;
2379
2563
}
2380