w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

font.c
Go to the documentation of this file.
1 #include "luaharfbuzz.h"
2 
3 static int font_new(lua_State *L) {
4  Font *f;
5  Face *face = luaL_checkudata(L, 1, "harfbuzz.Face");
6 
7  f = (Font *)lua_newuserdata(L, sizeof(*f));
8  luaL_getmetatable(L, "harfbuzz.Font");
9  lua_setmetatable(L, -2);
10 
11  *f = hb_font_create(*face);
12 
13  // Set default scale to be the face's upem value
14  unsigned int upem = hb_face_get_upem(*face);
16 
17  // Set shaping functions to OpenType functions
19  return 1;
20 }
21 
22 static int font_set_scale(lua_State *L) {
23  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
24  int x_scale = luaL_checkinteger(L, 2);
25  int y_scale = luaL_checkinteger(L, 3);
26 
27  hb_font_set_scale(*f, x_scale, y_scale);
28  return 0;
29 }
30 
31 static int font_get_scale(lua_State *L) {
32  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
33  int x_scale, y_scale;
34 
35  hb_font_get_scale(*f, &x_scale, &y_scale);
36 
37  lua_pushinteger(L, x_scale);
39  return 2;
40 }
41 
43  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
45 
47  lua_createtable(L, 0, 3);
48 
49  lua_pushnumber(L, extents.ascender);
50  lua_setfield(L, -2, "ascender");
51 
52  lua_pushnumber(L, extents.descender);
53  lua_setfield(L, -2, "descender");
54 
55  lua_pushnumber(L, extents.line_gap);
56  lua_setfield(L, -2, "line_gap");
57  } else {
58  lua_pushnil(L);
59  }
60 
61  return 1;
62 }
63 
65  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
67 
69  lua_createtable(L, 0, 3);
70 
71  lua_pushnumber(L, extents.ascender);
72  lua_setfield(L, -2, "ascender");
73 
74  lua_pushnumber(L, extents.descender);
75  lua_setfield(L, -2, "descender");
76 
77  lua_pushnumber(L, extents.line_gap);
78  lua_setfield(L, -2, "line_gap");
79  } else {
80  lua_pushnil(L);
81  }
82 
83  return 1;
84 }
85 
87  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
90 
92  lua_createtable(L, 0, 4);
93 
94  lua_pushnumber(L, extents.x_bearing);
95  lua_setfield(L, -2, "x_bearing");
96 
97  lua_pushnumber(L, extents.y_bearing);
98  lua_setfield(L, -2, "y_bearing");
99 
100  lua_pushnumber(L, extents.width);
101  lua_setfield(L, -2, "width");
102 
103  lua_pushnumber(L, extents.height);
104  lua_setfield(L, -2, "height");
105  } else {
106  lua_pushnil(L);
107  }
108 
109  return 1;
110 }
111 
113  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
115 
116 #define NAME_LEN 128
117  char name[NAME_LEN];
120  else
121  lua_pushnil(L);
122 #undef NAME_LEN
123 
124  return 1;
125 }
126 
128  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
129  const char *name = luaL_checkstring(L, 2);
131 
134  else
135  lua_pushnil(L);
136 
137  return 1;
138 }
139 
141  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
143 
145  return 1;
146 }
147 
149  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
151 
153  return 1;
154 }
155 
157  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
160 
161  if (hb_font_get_nominal_glyph(*f, uni, &glyph))
163  else
164  lua_pushnil(L);
165 
166  return 1;
167 }
168 
169 
170 static int font_destroy(lua_State *L) {
171  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
172 
173  hb_font_destroy(*f);
174  return 0;
175 }
176 
178  Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font");
181 
182  if (hb_blob_get_length(blob) != 0) {
183  Blob *b = (Blob *)lua_newuserdata(L, sizeof(*b));
184  luaL_getmetatable(L, "harfbuzz.Blob");
185  lua_setmetatable(L, -2);
186 
187  *b = blob;
188  } else {
189  lua_pushnil(L);
190  }
191 
192  return 1;
193 }
194 
195 static const struct luaL_Reg font_methods[] = {
196  { "__gc", font_destroy },
197  { "set_scale", font_set_scale },
198  { "get_scale", font_get_scale },
199  { "get_h_extents", font_get_h_extents },
200  { "get_v_extents", font_get_v_extents },
201  { "get_glyph_extents", font_get_glyph_extents },
202  { "get_glyph_name", font_get_glyph_name },
203  { "get_glyph_from_name", font_get_glyph_from_name },
204  { "get_glyph_h_advance", font_get_glyph_h_advance },
205  { "get_glyph_v_advance", font_get_glyph_v_advance },
206  { "get_nominal_glyph", font_get_nominal_glyph },
207  { "ot_color_glyph_get_png", font_ot_color_glyph_get_png },
208  { NULL, NULL }
209 };
210 
211 static const struct luaL_Reg font_functions[] = {
212  { "new", font_new },
213  { NULL, NULL }
214 };
215 
217  return register_class(L, "harfbuzz.Font", font_methods, font_functions, NULL);
218 }
#define name
Definition: Font.hpp:55
int register_class(lua_State *L, const char *name, const luaL_Reg *methods, const luaL_Reg *functions, const luahb_constant_t *constants)
Definition: class_utils.c:4
#define b
Definition: jpegint.h:372
mpz_t * f
Definition: gen-fib.c:34
double y_scale
Definition: hbf2gf.c:275
#define NULL
Definition: ftobjs.h:61
FT_Face face
Definition: cffdrivr.c:659
unsigned int hb_blob_get_length(hb_blob_t *blob)
Definition: hb-blob.cc:324
uint32_t hb_codepoint_t
Definition: hb-common.h:106
unsigned int hb_face_get_upem(const hb_face_t *face)
Definition: hb-face.cc:484
hb_font_t * hb_font_create(hb_face_t *face)
Definition: hb-font.cc:1523
hb_position_t hb_font_get_glyph_h_advance(hb_font_t *font, hb_codepoint_t glyph)
Definition: hb-font.cc:902
hb_bool_t hb_font_get_v_extents(hb_font_t *font, hb_font_extents_t *extents)
Definition: hb-font.cc:783
void hb_font_get_scale(hb_font_t *font, int *x_scale, int *y_scale)
Definition: hb-font.cc:1932
hb_bool_t hb_font_get_nominal_glyph(hb_font_t *font, hb_codepoint_t unicode, hb_codepoint_t *glyph)
Definition: hb-font.cc:835
hb_bool_t hb_font_get_glyph_name(hb_font_t *font, hb_codepoint_t glyph, char *name, unsigned int size)
Definition: hb-font.cc:1133
void hb_font_set_scale(hb_font_t *font, int x_scale, int y_scale)
Definition: hb-font.cc:1909
hb_bool_t hb_font_get_glyph_from_name(hb_font_t *font, const char *name, int len, hb_codepoint_t *glyph)
Definition: hb-font.cc:1157
hb_bool_t hb_font_get_glyph_extents(hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents)
Definition: hb-font.cc:1087
void hb_font_destroy(hb_font_t *font)
Definition: hb-font.cc:1643
hb_position_t hb_font_get_glyph_v_advance(hb_font_t *font, hb_codepoint_t glyph)
Definition: hb-font.cc:921
hb_bool_t hb_font_get_h_extents(hb_font_t *font, hb_font_extents_t *extents)
Definition: hb-font.cc:764
hb_blob_t * hb_ot_color_glyph_reference_png(hb_font_t *font, hb_codepoint_t glyph)
Definition: hb-ot-color.cc:307
void hb_ot_font_set_funcs(hb_font_t *font)
Definition: hb-ot-font.cc:316
int lua_setmetatable(lua_State *L, int objindex)
Definition: lapi.c:846
void lua_pushinteger(lua_State *L, lua_Integer n)
Definition: lapi.c:466
void lua_setfield(lua_State *L, int idx, const char *k)
Definition: lapi.c:777
void lua_pushnumber(lua_State *L, lua_Number n)
Definition: lapi.c:458
void lua_pushnil(lua_State *L)
Definition: lapi.c:450
const char * lua_pushstring(lua_State *L, const char *s)
Definition: lapi.c:491
void lua_createtable(lua_State *L, int narray, int nrec)
Definition: lapi.c:684
void * lua_newuserdata(lua_State *L, size_t size)
Definition: lapi.c:1184
lua_Integer luaL_checkinteger(lua_State *L, int arg)
Definition: lauxlib.c:430
void * luaL_checkudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.c:333
#define luaL_getmetatable(L, n)
Definition: lauxlib.h:135
#define luaL_checkstring(L, n)
Definition: lauxlib.h:124
static int font_ot_color_glyph_get_png(lua_State *L)
Definition: font.c:177
static int font_get_glyph_v_advance(lua_State *L)
Definition: font.c:148
static const struct luaL_Reg font_methods[]
Definition: font.c:195
static int font_get_glyph_h_advance(lua_State *L)
Definition: font.c:140
static int font_get_h_extents(lua_State *L)
Definition: font.c:42
#define NAME_LEN
static int font_set_scale(lua_State *L)
Definition: font.c:22
static int font_new(lua_State *L)
Definition: font.c:3
static int font_get_scale(lua_State *L)
Definition: font.c:31
static int font_get_glyph_extents(lua_State *L)
Definition: font.c:86
static const struct luaL_Reg font_functions[]
Definition: font.c:211
static int font_get_nominal_glyph(lua_State *L)
Definition: font.c:156
static int font_destroy(lua_State *L)
Definition: font.c:170
int register_font(lua_State *L)
Definition: font.c:216
static int font_get_glyph_name(lua_State *L)
Definition: font.c:112
static int font_get_v_extents(lua_State *L)
Definition: font.c:64
static int font_get_glyph_from_name(lua_State *L)
Definition: font.c:127
Definition: pbmfont.h:4
TTF_USHORT upem
Definition: ttf2afm.c:109
TT_Glyph glyph
Definition: ttf2pfb.c:162
@ L
Definition: ubidiimp.h:45