Change how Cairo is presented to Lua scripts.
Makes the whole thing a bit more stable and less weird.
This commit is contained in:
parent
9366c42026
commit
a1b79a55d2
|
@ -2,7 +2,7 @@
|
||||||
* ld-lua.c
|
* ld-lua.c
|
||||||
*
|
*
|
||||||
* This file is a part of logdiag.
|
* This file is a part of logdiag.
|
||||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
* Copyright Přemysl Janouch 2010, 2011, 2012. All rights reserved.
|
||||||
*
|
*
|
||||||
* See the file LICENSE for licensing information.
|
* See the file LICENSE for licensing information.
|
||||||
*
|
*
|
||||||
|
@ -44,9 +44,10 @@ struct _LdLuaPrivate
|
||||||
* -> The rendering function
|
* -> The rendering function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LD_LUA_LIBRARY_NAME "logdiag"
|
#define LD_LUA_LIBRARY_NAME "logdiag"
|
||||||
#define LD_LUA_DATA_INDEX LD_LUA_LIBRARY_NAME "_data"
|
#define LD_LUA_DATA_INDEX LD_LUA_LIBRARY_NAME "_data"
|
||||||
#define LD_LUA_SYMBOLS_INDEX LD_LUA_LIBRARY_NAME "_symbols"
|
#define LD_LUA_SYMBOLS_INDEX LD_LUA_LIBRARY_NAME "_symbols"
|
||||||
|
#define LD_LUA_META_INDEX LD_LUA_LIBRARY_NAME "_meta"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LdLuaData:
|
* LdLuaData:
|
||||||
|
@ -88,7 +89,6 @@ static gboolean read_symbol_area (lua_State *L, int index, LdRectangle *area);
|
||||||
static gboolean read_terminals (lua_State *L, int index,
|
static gboolean read_terminals (lua_State *L, int index,
|
||||||
LdPointArray **terminals);
|
LdPointArray **terminals);
|
||||||
|
|
||||||
static void push_cairo_object (lua_State *L, LdLuaDrawData *draw_data);
|
|
||||||
static gdouble get_cairo_scale (cairo_t *cr);
|
static gdouble get_cairo_scale (cairo_t *cr);
|
||||||
static int ld_lua_cairo_save (lua_State *L);
|
static int ld_lua_cairo_save (lua_State *L);
|
||||||
static int ld_lua_cairo_restore (lua_State *L);
|
static int ld_lua_cairo_restore (lua_State *L);
|
||||||
|
@ -163,6 +163,24 @@ ld_lua_class_init (LdLuaClass *klass)
|
||||||
g_type_class_add_private (klass, sizeof (LdLuaPrivate));
|
g_type_class_add_private (klass, sizeof (LdLuaPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
push_cairo_metatable (lua_State *L)
|
||||||
|
{
|
||||||
|
luaL_Reg *fn;
|
||||||
|
|
||||||
|
luaL_newmetatable (L, LD_LUA_META_INDEX);
|
||||||
|
|
||||||
|
/* Create a method table. */
|
||||||
|
lua_newtable (L);
|
||||||
|
for (fn = ld_lua_cairo_table; fn->name; fn++)
|
||||||
|
{
|
||||||
|
lua_pushcfunction (L, fn->func);
|
||||||
|
lua_setfield (L, -2, fn->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_setfield (L, -2, "__index");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ld_lua_init (LdLua *self)
|
ld_lua_init (LdLua *self)
|
||||||
{
|
{
|
||||||
|
@ -175,7 +193,7 @@ ld_lua_init (LdLua *self)
|
||||||
L = self->priv->L = lua_newstate (ld_lua_alloc, NULL);
|
L = self->priv->L = lua_newstate (ld_lua_alloc, NULL);
|
||||||
g_return_if_fail (L != NULL);
|
g_return_if_fail (L != NULL);
|
||||||
|
|
||||||
/* TODO: lua_atpanic () */
|
/* XXX: Might not be a bad idea to use lua_atpanic(). */
|
||||||
|
|
||||||
/* Load some safe libraries. */
|
/* Load some safe libraries. */
|
||||||
lua_pushcfunction (L, luaopen_string);
|
lua_pushcfunction (L, luaopen_string);
|
||||||
|
@ -191,7 +209,7 @@ ld_lua_init (LdLua *self)
|
||||||
luaL_register (L, LD_LUA_LIBRARY_NAME, ld_lua_logdiag_lib);
|
luaL_register (L, LD_LUA_LIBRARY_NAME, ld_lua_logdiag_lib);
|
||||||
|
|
||||||
/* Store user data to the registry. */
|
/* Store user data to the registry. */
|
||||||
ud = lua_newuserdata (L, sizeof (LdLuaData));
|
ud = lua_newuserdata (L, sizeof *ud);
|
||||||
ud->self = self;
|
ud->self = self;
|
||||||
ud->load_callback = NULL;
|
ud->load_callback = NULL;
|
||||||
ud->load_user_data = NULL;
|
ud->load_user_data = NULL;
|
||||||
|
@ -201,6 +219,8 @@ ld_lua_init (LdLua *self)
|
||||||
/* Create an empty symbol table. */
|
/* Create an empty symbol table. */
|
||||||
lua_newtable (L);
|
lua_newtable (L);
|
||||||
lua_setfield (L, LUA_REGISTRYINDEX, LD_LUA_SYMBOLS_INDEX);
|
lua_setfield (L, LUA_REGISTRYINDEX, LD_LUA_SYMBOLS_INDEX);
|
||||||
|
|
||||||
|
push_cairo_metatable (L);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -278,7 +298,7 @@ ld_lua_load_file (LdLua *self, const gchar *filename,
|
||||||
g_return_val_if_fail (filename != NULL, FALSE);
|
g_return_val_if_fail (filename != NULL, FALSE);
|
||||||
g_return_val_if_fail (callback != NULL, FALSE);
|
g_return_val_if_fail (callback != NULL, FALSE);
|
||||||
|
|
||||||
/* XXX: If something from the following fails, Lua will call exit(). */
|
/* XXX: If something from the following fails, Lua will panic. */
|
||||||
lua_getfield (self->priv->L, LUA_REGISTRYINDEX, LD_LUA_DATA_INDEX);
|
lua_getfield (self->priv->L, LUA_REGISTRYINDEX, LD_LUA_DATA_INDEX);
|
||||||
ud = lua_touserdata (self->priv->L, -1);
|
ud = lua_touserdata (self->priv->L, -1);
|
||||||
lua_pop (self->priv->L, 1);
|
lua_pop (self->priv->L, 1);
|
||||||
|
@ -344,7 +364,7 @@ ld_lua_private_draw (LdLua *self, LdLuaSymbol *symbol, cairo_t *cr)
|
||||||
static int
|
static int
|
||||||
ld_lua_private_draw_cb (lua_State *L)
|
ld_lua_private_draw_cb (lua_State *L)
|
||||||
{
|
{
|
||||||
LdLuaDrawData *data;
|
LdLuaDrawData *data, *luadata;
|
||||||
|
|
||||||
data = lua_touserdata (L, -1);
|
data = lua_touserdata (L, -1);
|
||||||
|
|
||||||
|
@ -357,9 +377,28 @@ ld_lua_private_draw_cb (lua_State *L)
|
||||||
lua_getfield (L, -1, "render");
|
lua_getfield (L, -1, "render");
|
||||||
luaL_checktype (L, -1, LUA_TFUNCTION);
|
luaL_checktype (L, -1, LUA_TFUNCTION);
|
||||||
|
|
||||||
/* Call the function do draw the symbol. */
|
/* Create a Cairo wrapper object. */
|
||||||
push_cairo_object (L, data);
|
luadata = lua_newuserdata (L, sizeof *data);
|
||||||
lua_pcall (L, 1, 0, 0);
|
memcpy (luadata, data, sizeof *data);
|
||||||
|
lua_getfield (L, LUA_REGISTRYINDEX, LD_LUA_META_INDEX);
|
||||||
|
lua_setmetatable (L, -2);
|
||||||
|
|
||||||
|
/* Force it to stay alive for a bit longer. */
|
||||||
|
lua_pushvalue (L, -1);
|
||||||
|
lua_insert (L, 1);
|
||||||
|
|
||||||
|
/* Draw the symbol. */
|
||||||
|
if (lua_pcall (L, 1, 0, 0))
|
||||||
|
{
|
||||||
|
g_warning ("Lua error: %s", lua_tostring (L, -1));
|
||||||
|
lua_pop (L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy the userdata back and invalidate it, so that malicious Lua
|
||||||
|
* scripts won't succeed at drawing onto a long invalid Cairo context.
|
||||||
|
*/
|
||||||
|
memcpy (data, luadata, sizeof *data);
|
||||||
|
memset (luadata, 0, sizeof *data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,7 +601,7 @@ read_symbol_area (lua_State *L, int index, LdRectangle *area)
|
||||||
|
|
||||||
area->x = MIN (x1, x2);
|
area->x = MIN (x1, x2);
|
||||||
area->y = MIN (y1, y2);
|
area->y = MIN (y1, y2);
|
||||||
area->width = ABS (x2 - x1);
|
area->width = ABS (x2 - x1);
|
||||||
area->height = ABS (y2 - y1);
|
area->height = ABS (y2 - y1);
|
||||||
|
|
||||||
lua_pop (L, 4);
|
lua_pop (L, 4);
|
||||||
|
@ -622,32 +661,6 @@ read_terminals_fail:
|
||||||
|
|
||||||
/* ===== Cairo ============================================================= */
|
/* ===== Cairo ============================================================= */
|
||||||
|
|
||||||
static void
|
|
||||||
push_cairo_object (lua_State *L, LdLuaDrawData *draw_data)
|
|
||||||
{
|
|
||||||
luaL_Reg *fn;
|
|
||||||
|
|
||||||
/* Create a table. */
|
|
||||||
lua_newtable (L);
|
|
||||||
|
|
||||||
/* Add methods. */
|
|
||||||
/* XXX: The light user data pointer gets invalid after the end of
|
|
||||||
* "render" function invocation. If the script stores the "cr" object
|
|
||||||
* in some global variable and then tries to reuse it the next time,
|
|
||||||
* the application may go SIGSEGV.
|
|
||||||
*
|
|
||||||
* The solution is creating a full user data instead, referencing
|
|
||||||
* the cairo object and dereferencing it upon garbage collection
|
|
||||||
* of the user data object.
|
|
||||||
*/
|
|
||||||
for (fn = ld_lua_cairo_table; fn->name; fn++)
|
|
||||||
{
|
|
||||||
lua_pushlightuserdata (L, draw_data);
|
|
||||||
lua_pushcclosure (L, fn->func, 1);
|
|
||||||
lua_setfield (L, -2, fn->name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gdouble
|
static gdouble
|
||||||
get_cairo_scale (cairo_t *cr)
|
get_cairo_scale (cairo_t *cr)
|
||||||
{
|
{
|
||||||
|
@ -657,6 +670,11 @@ get_cairo_scale (cairo_t *cr)
|
||||||
return dx;
|
return dx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LD_LUA_CAIRO_GET_DATA \
|
||||||
|
data = luaL_checkudata (L, 1, LD_LUA_META_INDEX); \
|
||||||
|
if (!data->cr) \
|
||||||
|
return luaL_error (L, "Tried to use an invalid Cairo object");
|
||||||
|
|
||||||
#define LD_LUA_CAIRO_BEGIN(name) \
|
#define LD_LUA_CAIRO_BEGIN(name) \
|
||||||
static int \
|
static int \
|
||||||
ld_lua_cairo_ ## name (lua_State *L) \
|
ld_lua_cairo_ ## name (lua_State *L) \
|
||||||
|
@ -669,7 +687,7 @@ ld_lua_cairo_ ## name (lua_State *L) \
|
||||||
|
|
||||||
#define LD_LUA_CAIRO_TRIVIAL(name) \
|
#define LD_LUA_CAIRO_TRIVIAL(name) \
|
||||||
LD_LUA_CAIRO_BEGIN (name) \
|
LD_LUA_CAIRO_BEGIN (name) \
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1)); \
|
LD_LUA_CAIRO_GET_DATA \
|
||||||
cairo_ ## name (data->cr); \
|
cairo_ ## name (data->cr); \
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
|
||||||
|
@ -685,7 +703,7 @@ LD_LUA_CAIRO_TRIVIAL (clip)
|
||||||
LD_LUA_CAIRO_TRIVIAL (clip_preserve)
|
LD_LUA_CAIRO_TRIVIAL (clip_preserve)
|
||||||
|
|
||||||
LD_LUA_CAIRO_BEGIN (save)
|
LD_LUA_CAIRO_BEGIN (save)
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
if (data->save_count + 1)
|
if (data->save_count + 1)
|
||||||
{
|
{
|
||||||
data->save_count++;
|
data->save_count++;
|
||||||
|
@ -694,7 +712,7 @@ LD_LUA_CAIRO_BEGIN (save)
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
|
||||||
LD_LUA_CAIRO_BEGIN (restore)
|
LD_LUA_CAIRO_BEGIN (restore)
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
if (data->save_count)
|
if (data->save_count)
|
||||||
{
|
{
|
||||||
data->save_count--;
|
data->save_count--;
|
||||||
|
@ -703,24 +721,23 @@ LD_LUA_CAIRO_BEGIN (restore)
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
|
||||||
LD_LUA_CAIRO_BEGIN (get_line_width)
|
LD_LUA_CAIRO_BEGIN (get_line_width)
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
lua_pushnumber (L, cairo_get_line_width (data->cr)
|
lua_pushnumber (L, cairo_get_line_width (data->cr)
|
||||||
* get_cairo_scale (data->cr));
|
* get_cairo_scale (data->cr));
|
||||||
LD_LUA_CAIRO_END (1)
|
LD_LUA_CAIRO_END (1)
|
||||||
|
|
||||||
LD_LUA_CAIRO_BEGIN (set_line_width)
|
LD_LUA_CAIRO_BEGIN (set_line_width)
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
cairo_set_line_width (data->cr, luaL_checknumber (L, 1)
|
cairo_set_line_width (data->cr, luaL_checknumber (L, 2)
|
||||||
/ get_cairo_scale (data->cr));
|
/ get_cairo_scale (data->cr));
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
|
||||||
LD_LUA_CAIRO_BEGIN (translate)
|
LD_LUA_CAIRO_BEGIN (translate)
|
||||||
lua_Number x, y;
|
lua_Number x, y;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
|
x = luaL_checknumber (L, 2);
|
||||||
x = luaL_checknumber (L, 1);
|
y = luaL_checknumber (L, 3);
|
||||||
y = luaL_checknumber (L, 2);
|
|
||||||
|
|
||||||
cairo_translate (data->cr, x, y);
|
cairo_translate (data->cr, x, y);
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
@ -728,10 +745,9 @@ LD_LUA_CAIRO_END (0)
|
||||||
LD_LUA_CAIRO_BEGIN (scale)
|
LD_LUA_CAIRO_BEGIN (scale)
|
||||||
lua_Number sx, sy;
|
lua_Number sx, sy;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
|
sx = luaL_checknumber (L, 2);
|
||||||
sx = luaL_checknumber (L, 1);
|
sy = luaL_checknumber (L, 3);
|
||||||
sy = luaL_checknumber (L, 2);
|
|
||||||
|
|
||||||
cairo_scale (data->cr, sx, sy);
|
cairo_scale (data->cr, sx, sy);
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
@ -739,18 +755,17 @@ LD_LUA_CAIRO_END (0)
|
||||||
LD_LUA_CAIRO_BEGIN (rotate)
|
LD_LUA_CAIRO_BEGIN (rotate)
|
||||||
lua_Number angle;
|
lua_Number angle;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
angle = luaL_checknumber (L, 1);
|
angle = luaL_checknumber (L, 2);
|
||||||
cairo_rotate (data->cr, angle);
|
cairo_rotate (data->cr, angle);
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
|
||||||
LD_LUA_CAIRO_BEGIN (move_to)
|
LD_LUA_CAIRO_BEGIN (move_to)
|
||||||
lua_Number x, y;
|
lua_Number x, y;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
|
x = luaL_checknumber (L, 2);
|
||||||
x = luaL_checknumber (L, 1);
|
y = luaL_checknumber (L, 3);
|
||||||
y = luaL_checknumber (L, 2);
|
|
||||||
|
|
||||||
cairo_move_to (data->cr, x, y);
|
cairo_move_to (data->cr, x, y);
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
@ -758,10 +773,9 @@ LD_LUA_CAIRO_END (0)
|
||||||
LD_LUA_CAIRO_BEGIN (line_to)
|
LD_LUA_CAIRO_BEGIN (line_to)
|
||||||
lua_Number x, y;
|
lua_Number x, y;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
|
x = luaL_checknumber (L, 2);
|
||||||
x = luaL_checknumber (L, 1);
|
y = luaL_checknumber (L, 3);
|
||||||
y = luaL_checknumber (L, 2);
|
|
||||||
|
|
||||||
cairo_line_to (data->cr, x, y);
|
cairo_line_to (data->cr, x, y);
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
@ -769,14 +783,13 @@ LD_LUA_CAIRO_END (0)
|
||||||
LD_LUA_CAIRO_BEGIN (curve_to)
|
LD_LUA_CAIRO_BEGIN (curve_to)
|
||||||
lua_Number x1, y1, x2, y2, x3, y3;
|
lua_Number x1, y1, x2, y2, x3, y3;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
|
x1 = luaL_checknumber (L, 2);
|
||||||
x1 = luaL_checknumber (L, 1);
|
y1 = luaL_checknumber (L, 3);
|
||||||
y1 = luaL_checknumber (L, 2);
|
x2 = luaL_checknumber (L, 4);
|
||||||
x2 = luaL_checknumber (L, 3);
|
y2 = luaL_checknumber (L, 5);
|
||||||
y2 = luaL_checknumber (L, 4);
|
x3 = luaL_checknumber (L, 6);
|
||||||
x3 = luaL_checknumber (L, 5);
|
y3 = luaL_checknumber (L, 7);
|
||||||
y3 = luaL_checknumber (L, 6);
|
|
||||||
|
|
||||||
cairo_curve_to (data->cr, x1, y1, x2, y2, x3, y3);
|
cairo_curve_to (data->cr, x1, y1, x2, y2, x3, y3);
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
@ -784,13 +797,12 @@ LD_LUA_CAIRO_END (0)
|
||||||
LD_LUA_CAIRO_BEGIN (arc)
|
LD_LUA_CAIRO_BEGIN (arc)
|
||||||
lua_Number xc, yc, radius, angle1, angle2;
|
lua_Number xc, yc, radius, angle1, angle2;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
|
xc = luaL_checknumber (L, 2);
|
||||||
xc = luaL_checknumber (L, 1);
|
yc = luaL_checknumber (L, 3);
|
||||||
yc = luaL_checknumber (L, 2);
|
radius = luaL_checknumber (L, 4);
|
||||||
radius = luaL_checknumber (L, 3);
|
angle1 = luaL_checknumber (L, 5);
|
||||||
angle1 = luaL_checknumber (L, 4);
|
angle2 = luaL_checknumber (L, 6);
|
||||||
angle2 = luaL_checknumber (L, 5);
|
|
||||||
|
|
||||||
cairo_arc (data->cr, xc, yc, radius, angle1, angle2);
|
cairo_arc (data->cr, xc, yc, radius, angle1, angle2);
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
@ -798,13 +810,12 @@ LD_LUA_CAIRO_END (0)
|
||||||
LD_LUA_CAIRO_BEGIN (arc_negative)
|
LD_LUA_CAIRO_BEGIN (arc_negative)
|
||||||
lua_Number xc, yc, radius, angle1, angle2;
|
lua_Number xc, yc, radius, angle1, angle2;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
|
xc = luaL_checknumber (L, 2);
|
||||||
xc = luaL_checknumber (L, 1);
|
yc = luaL_checknumber (L, 3);
|
||||||
yc = luaL_checknumber (L, 2);
|
radius = luaL_checknumber (L, 4);
|
||||||
radius = luaL_checknumber (L, 3);
|
angle1 = luaL_checknumber (L, 5);
|
||||||
angle1 = luaL_checknumber (L, 4);
|
angle2 = luaL_checknumber (L, 6);
|
||||||
angle2 = luaL_checknumber (L, 5);
|
|
||||||
|
|
||||||
cairo_arc_negative (data->cr, xc, yc, radius, angle1, angle2);
|
cairo_arc_negative (data->cr, xc, yc, radius, angle1, angle2);
|
||||||
LD_LUA_CAIRO_END (0)
|
LD_LUA_CAIRO_END (0)
|
||||||
|
@ -816,8 +827,8 @@ LD_LUA_CAIRO_BEGIN (show_text)
|
||||||
int width, height;
|
int width, height;
|
||||||
double x, y;
|
double x, y;
|
||||||
|
|
||||||
data = lua_touserdata (L, lua_upvalueindex (1));
|
LD_LUA_CAIRO_GET_DATA
|
||||||
text = luaL_checkstring (L, 1);
|
text = luaL_checkstring (L, 2);
|
||||||
|
|
||||||
layout = pango_cairo_create_layout (data->cr);
|
layout = pango_cairo_create_layout (data->cr);
|
||||||
pango_layout_set_text (layout, text, -1);
|
pango_layout_set_text (layout, text, -1);
|
||||||
|
|
|
@ -26,50 +26,50 @@ local terminals = {{-2, 0}, {2, 2}, {2, -2}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-2, 0)
|
cr:move_to (-2, 0)
|
||||||
cr.line_to (0, 0)
|
cr:line_to (0, 0)
|
||||||
|
|
||||||
cr.move_to (0, 0.5)
|
cr:move_to (0, 0.5)
|
||||||
cr.line_to (2, 2)
|
cr:line_to (2, 2)
|
||||||
|
|
||||||
cr.move_to (0, -0.5)
|
cr:move_to (0, -0.5)
|
||||||
cr.line_to (2, -2)
|
cr:line_to (2, -2)
|
||||||
|
|
||||||
-- The ohmic connection
|
-- The ohmic connection
|
||||||
cr.move_to (0, -1)
|
cr:move_to (0, -1)
|
||||||
cr.line_to (0, 1)
|
cr:line_to (0, 1)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_npn = function (cr)
|
local render_npn = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
cr.save ()
|
cr:save ()
|
||||||
cr.translate (0, 0.5)
|
cr:translate (0, 0.5)
|
||||||
cr.rotate (math.atan2 (-2, 1.5))
|
cr:rotate (math.atan2 (-2, 1.5))
|
||||||
|
|
||||||
cr.move_to (-0.4, 0.8)
|
cr:move_to (-0.4, 0.8)
|
||||||
cr.line_to (0, 1.4)
|
cr:line_to (0, 1.4)
|
||||||
cr.line_to (0.4, 0.8)
|
cr:line_to (0.4, 0.8)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_pnp = function (cr)
|
local render_pnp = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
cr.save ()
|
cr:save ()
|
||||||
cr.translate (2, -2)
|
cr:translate (2, -2)
|
||||||
cr.rotate (math.atan2 (2, 1.5))
|
cr:rotate (math.atan2 (2, 1.5))
|
||||||
|
|
||||||
cr.move_to (-0.4, 1.3)
|
cr:move_to (-0.4, 1.3)
|
||||||
cr.line_to (0, 1.9)
|
cr:line_to (0, 1.9)
|
||||||
cr.line_to (0.4, 1.3)
|
cr:line_to (0.4, 1.3)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbols
|
-- Register the symbols
|
||||||
|
|
|
@ -27,59 +27,59 @@ local terminals_p = {{-2, -1}, {2, 1}, {2, 0}, {2, -1}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-0.3, 1)
|
cr:move_to (-0.3, 1)
|
||||||
cr.line_to (-0.3, -1)
|
cr:line_to (-0.3, -1)
|
||||||
|
|
||||||
cr.move_to (0, 1)
|
cr:move_to (0, 1)
|
||||||
cr.line_to (2, 1)
|
cr:line_to (2, 1)
|
||||||
|
|
||||||
cr.move_to (0, 0)
|
cr:move_to (0, 0)
|
||||||
cr.line_to (2, 0)
|
cr:line_to (2, 0)
|
||||||
|
|
||||||
cr.move_to (0, -1)
|
cr:move_to (0, -1)
|
||||||
cr.line_to (2, -1)
|
cr:line_to (2, -1)
|
||||||
|
|
||||||
-- Source, gate, drain
|
-- Source, gate, drain
|
||||||
cr.move_to (0, -1.5)
|
cr:move_to (0, -1.5)
|
||||||
cr.line_to (0, -0.5)
|
cr:line_to (0, -0.5)
|
||||||
|
|
||||||
cr.move_to (0, -0.3)
|
cr:move_to (0, -0.3)
|
||||||
cr.line_to (0, 0.3)
|
cr:line_to (0, 0.3)
|
||||||
|
|
||||||
cr.move_to (0, 0.5)
|
cr:move_to (0, 0.5)
|
||||||
cr.line_to (0, 1.5)
|
cr:line_to (0, 1.5)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_n = function (cr)
|
local render_n = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The left-side terminal
|
-- The left-side terminal
|
||||||
cr.move_to (-2, 1)
|
cr:move_to (-2, 1)
|
||||||
cr.line_to (-0.3, 1)
|
cr:line_to (-0.3, 1)
|
||||||
|
|
||||||
-- The arrow
|
-- The arrow
|
||||||
cr.move_to (0.9, -0.4)
|
cr:move_to (0.9, -0.4)
|
||||||
cr.line_to (0.4, 0)
|
cr:line_to (0.4, 0)
|
||||||
cr.line_to (0.9, 0.4)
|
cr:line_to (0.9, 0.4)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_p = function (cr)
|
local render_p = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The left-side terminal
|
-- The left-side terminal
|
||||||
cr.move_to (-2, -1)
|
cr:move_to (-2, -1)
|
||||||
cr.line_to (-0.3, -1)
|
cr:line_to (-0.3, -1)
|
||||||
|
|
||||||
-- The arrow
|
-- The arrow
|
||||||
cr.move_to (0.4, -0.4)
|
cr:move_to (0.4, -0.4)
|
||||||
cr.line_to (0.9, 0)
|
cr:line_to (0.9, 0)
|
||||||
cr.line_to (0.4, 0.4)
|
cr:line_to (0.4, 0.4)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbols
|
-- Register the symbols
|
||||||
|
|
|
@ -27,47 +27,47 @@ local terminals_p = {{-2, -1}, {2, 1}, {2, -1}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (0, 1)
|
cr:move_to (0, 1)
|
||||||
cr.line_to (2, 1)
|
cr:line_to (2, 1)
|
||||||
|
|
||||||
cr.move_to (0, -1)
|
cr:move_to (0, -1)
|
||||||
cr.line_to (2, -1)
|
cr:line_to (2, -1)
|
||||||
|
|
||||||
-- The ohmic connection
|
-- The ohmic connection
|
||||||
cr.move_to (0, -1.5)
|
cr:move_to (0, -1.5)
|
||||||
cr.line_to (0, 1.5)
|
cr:line_to (0, 1.5)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_n = function (cr)
|
local render_n = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The left-side terminal
|
-- The left-side terminal
|
||||||
cr.move_to (-2, 1)
|
cr:move_to (-2, 1)
|
||||||
cr.line_to (0, 1)
|
cr:line_to (0, 1)
|
||||||
|
|
||||||
-- The arrow
|
-- The arrow
|
||||||
cr.move_to (-1, 0.6)
|
cr:move_to (-1, 0.6)
|
||||||
cr.line_to (-0.5, 1)
|
cr:line_to (-0.5, 1)
|
||||||
cr.line_to (-1, 1.4)
|
cr:line_to (-1, 1.4)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_p = function (cr)
|
local render_p = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The left-side terminal
|
-- The left-side terminal
|
||||||
cr.move_to (-2, -1)
|
cr:move_to (-2, -1)
|
||||||
cr.line_to (0, -1)
|
cr:line_to (0, -1)
|
||||||
|
|
||||||
-- The arrow
|
-- The arrow
|
||||||
cr.move_to (-0.4, -0.6)
|
cr:move_to (-0.4, -0.6)
|
||||||
cr.line_to (-1, -1)
|
cr:line_to (-1, -1)
|
||||||
cr.line_to (-0.4, -1.4)
|
cr:line_to (-0.4, -1.4)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbols
|
-- Register the symbols
|
||||||
|
|
|
@ -17,23 +17,23 @@ local terminals = {{-4, -1}, {-4, 1}, {5, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The main shape
|
-- The main shape
|
||||||
cr.move_to (-2, -2)
|
cr:move_to (-2, -2)
|
||||||
cr.line_to (1, -2)
|
cr:line_to (1, -2)
|
||||||
cr.arc (1, 0, 2, math.pi * 1.5, math.pi * 0.5)
|
cr:arc (1, 0, 2, math.pi * 1.5, math.pi * 0.5)
|
||||||
cr.line_to (-2, 2)
|
cr:line_to (-2, 2)
|
||||||
cr.close_path ()
|
cr:close_path ()
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-4, -1)
|
cr:move_to (-4, -1)
|
||||||
cr.line_to (-2, -1)
|
cr:line_to (-2, -1)
|
||||||
|
|
||||||
cr.move_to (-4, 1)
|
cr:move_to (-4, 1)
|
||||||
cr.line_to (-2, 1)
|
cr:line_to (-2, 1)
|
||||||
|
|
||||||
cr.move_to (3, 0)
|
cr:move_to (3, 0)
|
||||||
cr.line_to (5, 0)
|
cr:line_to (5, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -17,23 +17,23 @@ local terminals = {{-4, 0}, {4, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The triangle
|
-- The triangle
|
||||||
cr.move_to (-2, -2)
|
cr:move_to (-2, -2)
|
||||||
cr.line_to (2, 0)
|
cr:line_to (2, 0)
|
||||||
cr.line_to (-2, 2)
|
cr:line_to (-2, 2)
|
||||||
cr.close_path ()
|
cr:close_path ()
|
||||||
|
|
||||||
-- The circle
|
-- The circle
|
||||||
cr.new_sub_path ()
|
cr:new_sub_path ()
|
||||||
cr.arc (2.25, 0, 0.25, 0, 2 * math.pi)
|
cr:arc (2.25, 0, 0.25, 0, 2 * math.pi)
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-4, 0)
|
cr:move_to (-4, 0)
|
||||||
cr.line_to (-2, 0)
|
cr:line_to (-2, 0)
|
||||||
|
|
||||||
cr.move_to (2.5, 0)
|
cr:move_to (2.5, 0)
|
||||||
cr.line_to (4, 0)
|
cr:line_to (4, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -17,38 +17,38 @@ local terminals = {{-4, -1}, {-4, 1}, {5, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The main shape
|
-- The main shape
|
||||||
cr.move_to (-2, -2)
|
cr:move_to (-2, -2)
|
||||||
cr.line_to (0, -2)
|
cr:line_to (0, -2)
|
||||||
cr.curve_to (2, -2, 3, 0, 3, 0)
|
cr:curve_to (2, -2, 3, 0, 3, 0)
|
||||||
cr.curve_to (3, 0, 2, 2, 0, 2)
|
cr:curve_to (3, 0, 2, 2, 0, 2)
|
||||||
cr.line_to (-2, 2)
|
cr:line_to (-2, 2)
|
||||||
cr.curve_to (-1, 1, -1, -1, -2, -2)
|
cr:curve_to (-1, 1, -1, -1, -2, -2)
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.save ()
|
cr:save ()
|
||||||
|
|
||||||
-- Crop the contacts according to
|
-- Crop the contacts according to
|
||||||
-- the left side of the main shape
|
-- the left side of the main shape
|
||||||
cr.move_to (-4, 2)
|
cr:move_to (-4, 2)
|
||||||
cr.line_to (-2, 2)
|
cr:line_to (-2, 2)
|
||||||
cr.curve_to (-1, 1, -1, -1, -2, -2)
|
cr:curve_to (-1, 1, -1, -1, -2, -2)
|
||||||
cr.line_to (-4, -2)
|
cr:line_to (-4, -2)
|
||||||
cr.close_path ()
|
cr:close_path ()
|
||||||
cr.clip ()
|
cr:clip ()
|
||||||
|
|
||||||
cr.move_to (-4, -1)
|
cr:move_to (-4, -1)
|
||||||
cr.line_to (-1, -1)
|
cr:line_to (-1, -1)
|
||||||
|
|
||||||
cr.move_to (-4, 1)
|
cr:move_to (-4, 1)
|
||||||
cr.line_to (-1, 1)
|
cr:line_to (-1, 1)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
|
|
||||||
cr.move_to (3, 0)
|
cr:move_to (3, 0)
|
||||||
cr.line_to (5, 0)
|
cr:line_to (5, 0)
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -17,20 +17,20 @@ local terminals = {{-1, 0}, {1, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The vertical lines
|
-- The vertical lines
|
||||||
cr.move_to (-0.2, -1)
|
cr:move_to (-0.2, -1)
|
||||||
cr.line_to (-0.2, 1)
|
cr:line_to (-0.2, 1)
|
||||||
|
|
||||||
cr.move_to (0.2, -2)
|
cr:move_to (0.2, -2)
|
||||||
cr.line_to (0.2, 2)
|
cr:line_to (0.2, 2)
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-1, 0)
|
cr:move_to (-1, 0)
|
||||||
cr.line_to (-0.2, 0)
|
cr:line_to (-0.2, 0)
|
||||||
|
|
||||||
cr.move_to (0.2, 0)
|
cr:move_to (0.2, 0)
|
||||||
cr.line_to (1, 0)
|
cr:line_to (1, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -17,20 +17,20 @@ local terminals = {{0, -1}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The vertical line
|
-- The vertical line
|
||||||
cr.move_to (0, -1)
|
cr:move_to (0, -1)
|
||||||
cr.line_to (0, 0.5)
|
cr:line_to (0, 0.5)
|
||||||
|
|
||||||
-- The horizontal lines
|
-- The horizontal lines
|
||||||
cr.move_to (-1, 0.5)
|
cr:move_to (-1, 0.5)
|
||||||
cr.line_to (1, 0.5)
|
cr:line_to (1, 0.5)
|
||||||
|
|
||||||
cr.move_to (-0.75, 1.1)
|
cr:move_to (-0.75, 1.1)
|
||||||
cr.line_to (0.75, 1.1)
|
cr:line_to (0.75, 1.1)
|
||||||
|
|
||||||
cr.move_to (-0.5, 1.7)
|
cr:move_to (-0.5, 1.7)
|
||||||
cr.line_to (0.5, 1.7)
|
cr:line_to (0.5, 1.7)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -17,8 +17,8 @@ local terminals = {}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The disk
|
-- The disk
|
||||||
cr.arc (0, 0, 0.3, 0, math.pi * 2)
|
cr:arc (0, 0, 0.3, 0, math.pi * 2)
|
||||||
cr.fill ()
|
cr:fill ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -17,29 +17,29 @@ local terminals = {{-2, 0}, {2, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The circle
|
-- The circle
|
||||||
cr.save ()
|
cr:save ()
|
||||||
|
|
||||||
cr.arc (0, 0, 1, 0, 2 * math.pi)
|
cr:arc (0, 0, 1, 0, 2 * math.pi)
|
||||||
cr.stroke_preserve ()
|
cr:stroke_preserve ()
|
||||||
cr.clip ()
|
cr:clip ()
|
||||||
|
|
||||||
cr.move_to (-1, -1)
|
cr:move_to (-1, -1)
|
||||||
cr.line_to (1, 1)
|
cr:line_to (1, 1)
|
||||||
|
|
||||||
cr.move_to (1, -1)
|
cr:move_to (1, -1)
|
||||||
cr.line_to (-1, 1)
|
cr:line_to (-1, 1)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-2, 0)
|
cr:move_to (-2, 0)
|
||||||
cr.line_to (-1, 0)
|
cr:line_to (-1, 0)
|
||||||
|
|
||||||
cr.move_to (1, 0)
|
cr:move_to (1, 0)
|
||||||
cr.line_to (2, 0)
|
cr:line_to (2, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -35,45 +35,45 @@ local terminals = {{-2, 0}, {2, 0}, {0, -2}, {0, 2}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render_A = function (cr)
|
local render_A = function (cr)
|
||||||
-- The circle
|
-- The circle
|
||||||
cr.arc (0, 0, 2, 0, math.pi * 2)
|
cr:arc (0, 0, 2, 0, math.pi * 2)
|
||||||
|
|
||||||
-- The letter A
|
-- The letter A
|
||||||
cr.move_to (-0.4, 0.5)
|
cr:move_to (-0.4, 0.5)
|
||||||
cr.line_to (0, -0.5)
|
cr:line_to (0, -0.5)
|
||||||
cr.line_to (0.4, 0.5)
|
cr:line_to (0.4, 0.5)
|
||||||
|
|
||||||
cr.move_to (-0.3, 0.25)
|
cr:move_to (-0.3, 0.25)
|
||||||
cr.line_to (0.3, 0.25)
|
cr:line_to (0.3, 0.25)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_V = function (cr)
|
local render_V = function (cr)
|
||||||
-- The circle
|
-- The circle
|
||||||
cr.arc (0, 0, 2, 0, math.pi * 2)
|
cr:arc (0, 0, 2, 0, math.pi * 2)
|
||||||
|
|
||||||
-- The letter V
|
-- The letter V
|
||||||
cr.move_to (-0.4, -0.5)
|
cr:move_to (-0.4, -0.5)
|
||||||
cr.line_to (0, 0.5)
|
cr:line_to (0, 0.5)
|
||||||
cr.line_to (0.4, -0.5)
|
cr:line_to (0.4, -0.5)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_ohm = function (cr)
|
local render_ohm = function (cr)
|
||||||
-- The circle
|
-- The circle
|
||||||
cr.arc (0, 0, 2, 0, math.pi * 2)
|
cr:arc (0, 0, 2, 0, math.pi * 2)
|
||||||
|
|
||||||
-- The capital letter omega
|
-- The capital letter omega
|
||||||
cr.move_to (-0.5, 0.5)
|
cr:move_to (-0.5, 0.5)
|
||||||
cr.line_to (-0.15, 0.5)
|
cr:line_to (-0.15, 0.5)
|
||||||
cr.curve_to (-0.15, 0.5, -0.4, 0.3, -0.4, 0)
|
cr:curve_to (-0.15, 0.5, -0.4, 0.3, -0.4, 0)
|
||||||
cr.curve_to (-0.4, -0.25, -0.25, -0.5, 0, -0.5)
|
cr:curve_to (-0.4, -0.25, -0.25, -0.5, 0, -0.5)
|
||||||
cr.curve_to (0.25, -0.5, 0.4, -0.25, 0.4, 0)
|
cr:curve_to (0.25, -0.5, 0.4, -0.25, 0.4, 0)
|
||||||
cr.curve_to (0.4, 0.3, 0.15, 0.5, 0.15, 0.5)
|
cr:curve_to (0.4, 0.3, 0.15, 0.5, 0.15, 0.5)
|
||||||
cr.line_to (0.5, 0.5)
|
cr:line_to (0.5, 0.5)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbols
|
-- Register the symbols
|
||||||
|
|
|
@ -26,21 +26,21 @@ local terminals = {}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render_plus = function (cr)
|
local render_plus = function (cr)
|
||||||
-- The plus sign
|
-- The plus sign
|
||||||
cr.move_to (0, -0.4)
|
cr:move_to (0, -0.4)
|
||||||
cr.line_to (0, 0.4)
|
cr:line_to (0, 0.4)
|
||||||
|
|
||||||
cr.move_to (-0.4, 0)
|
cr:move_to (-0.4, 0)
|
||||||
cr.line_to (0.4, 0)
|
cr:line_to (0.4, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_minus = function (cr)
|
local render_minus = function (cr)
|
||||||
-- The minus sign
|
-- The minus sign
|
||||||
cr.move_to (-0.4, 0)
|
cr:move_to (-0.4, 0)
|
||||||
cr.line_to (0.4, 0)
|
cr:line_to (0.4, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbols
|
-- Register the symbols
|
||||||
|
|
|
@ -17,17 +17,17 @@ local terminals = {{-2, 0}, {2, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The switch contact
|
-- The switch contact
|
||||||
cr.move_to (1.3, -1.3)
|
cr:move_to (1.3, -1.3)
|
||||||
cr.line_to (-1, 0)
|
cr:line_to (-1, 0)
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-2, 0)
|
cr:move_to (-2, 0)
|
||||||
cr.line_to (-1, 0)
|
cr:line_to (-1, 0)
|
||||||
|
|
||||||
cr.move_to (1, 0)
|
cr:move_to (1, 0)
|
||||||
cr.line_to (2, 0)
|
cr:line_to (2, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -17,13 +17,13 @@ local terminals = {{-1, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The circle
|
-- The circle
|
||||||
cr.arc (0, 0, 0.3, 0, math.pi * 2)
|
cr:arc (0, 0, 0.3, 0, math.pi * 2)
|
||||||
|
|
||||||
-- The contact
|
-- The contact
|
||||||
cr.move_to (-1, 0)
|
cr:move_to (-1, 0)
|
||||||
cr.line_to (-0.3, 0)
|
cr:line_to (-0.3, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -26,35 +26,35 @@ local terminals = {{-2, 0}, {2, 0}, {0, -2}, {0, 2}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The circle
|
-- The circle
|
||||||
cr.arc (0, 0, 2, 0, math.pi * 2)
|
cr:arc (0, 0, 2, 0, math.pi * 2)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_ac = function (cr)
|
local render_ac = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The AC symbol
|
-- The AC symbol
|
||||||
cr.move_to (-1, 0.25)
|
cr:move_to (-1, 0.25)
|
||||||
cr.curve_to (-0.4, -1.5, 0.4, 1.5, 1, -0.25)
|
cr:curve_to (-0.4, -1.5, 0.4, 1.5, 1, -0.25)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_dc = function (cr)
|
local render_dc = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The DC symbol
|
-- The DC symbol
|
||||||
cr.move_to (-1, -0.25)
|
cr:move_to (-1, -0.25)
|
||||||
cr.line_to (1, -0.25)
|
cr:line_to (1, -0.25)
|
||||||
|
|
||||||
cr.move_to (-1, 0.25)
|
cr:move_to (-1, 0.25)
|
||||||
cr.line_to (-0.2, 0.25)
|
cr:line_to (-0.2, 0.25)
|
||||||
|
|
||||||
cr.move_to (0.2, 0.25)
|
cr:move_to (0.2, 0.25)
|
||||||
cr.line_to (1, 0.25)
|
cr:line_to (1, 0.25)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbols
|
-- Register the symbols
|
||||||
|
|
|
@ -17,20 +17,20 @@ local terminals = {{-2, 0}, {2, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The vertical lines
|
-- The vertical lines
|
||||||
cr.move_to (-0.2, -1)
|
cr:move_to (-0.2, -1)
|
||||||
cr.line_to (-0.2, 1)
|
cr:line_to (-0.2, 1)
|
||||||
|
|
||||||
cr.move_to (0.2, -1)
|
cr:move_to (0.2, -1)
|
||||||
cr.line_to (0.2, 1)
|
cr:line_to (0.2, 1)
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-2, 0)
|
cr:move_to (-2, 0)
|
||||||
cr.line_to (-0.2, 0)
|
cr:line_to (-0.2, 0)
|
||||||
|
|
||||||
cr.move_to (0.2, 0)
|
cr:move_to (0.2, 0)
|
||||||
cr.line_to (2, 0)
|
cr:line_to (2, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -45,79 +45,79 @@ local terminals = {{-2, 0}, {2, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The triangle
|
-- The triangle
|
||||||
cr.move_to (-1, -1)
|
cr:move_to (-1, -1)
|
||||||
cr.line_to (1, 0)
|
cr:line_to (1, 0)
|
||||||
cr.line_to (-1, 1)
|
cr:line_to (-1, 1)
|
||||||
cr.line_to (-1, -1)
|
cr:line_to (-1, -1)
|
||||||
|
|
||||||
-- The vertical line
|
-- The vertical line
|
||||||
cr.move_to (1, 1)
|
cr:move_to (1, 1)
|
||||||
cr.line_to (1, -1)
|
cr:line_to (1, -1)
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-2, 0)
|
cr:move_to (-2, 0)
|
||||||
cr.line_to (2, 0)
|
cr:line_to (2, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_zener = function (cr)
|
local render_zener = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
cr.move_to (1, 1)
|
cr:move_to (1, 1)
|
||||||
cr.line_to (0.5, 1)
|
cr:line_to (0.5, 1)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_arrow = function (cr)
|
local render_arrow = function (cr)
|
||||||
cr.move_to (0, 0)
|
cr:move_to (0, 0)
|
||||||
cr.line_to (0, -1.5)
|
cr:line_to (0, -1.5)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
|
|
||||||
cr.move_to (-0.3, -0.7)
|
cr:move_to (-0.3, -0.7)
|
||||||
cr.line_to (0, -1.5)
|
cr:line_to (0, -1.5)
|
||||||
cr.line_to (0.3, -0.7)
|
cr:line_to (0.3, -0.7)
|
||||||
cr.close_path ()
|
cr:close_path ()
|
||||||
|
|
||||||
cr.fill ()
|
cr:fill ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_radiation = function (cr)
|
local render_radiation = function (cr)
|
||||||
cr.save ()
|
cr:save ()
|
||||||
cr.translate (-0.4, 0)
|
cr:translate (-0.4, 0)
|
||||||
render_arrow (cr)
|
render_arrow (cr)
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
|
|
||||||
cr.save ()
|
cr:save ()
|
||||||
cr.translate (0.4, 0)
|
cr:translate (0.4, 0)
|
||||||
render_arrow (cr)
|
render_arrow (cr)
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_led = function (cr)
|
local render_led = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
cr.save ()
|
cr:save ()
|
||||||
cr.translate (-0.3, -1.0)
|
cr:translate (-0.3, -1.0)
|
||||||
cr.rotate (math.atan2 (1, 1))
|
cr:rotate (math.atan2 (1, 1))
|
||||||
|
|
||||||
render_radiation (cr)
|
render_radiation (cr)
|
||||||
|
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_photo = function (cr)
|
local render_photo = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
cr.save ()
|
cr:save ()
|
||||||
cr.translate (0.75, -2.05)
|
cr:translate (0.75, -2.05)
|
||||||
cr.rotate (math.atan2 (-1, -1))
|
cr:rotate (math.atan2 (-1, -1))
|
||||||
|
|
||||||
render_radiation (cr)
|
render_radiation (cr)
|
||||||
|
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
|
@ -26,22 +26,22 @@ local terminals = {{-2, 0}, {2, 0}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The arcs
|
-- The arcs
|
||||||
cr.arc (-1.5, 0, 0.5, math.pi, 0)
|
cr:arc (-1.5, 0, 0.5, math.pi, 0)
|
||||||
cr.arc (-0.5, 0, 0.5, math.pi, 0)
|
cr:arc (-0.5, 0, 0.5, math.pi, 0)
|
||||||
cr.arc (0.5, 0, 0.5, math.pi, 0)
|
cr:arc (0.5, 0, 0.5, math.pi, 0)
|
||||||
cr.arc (1.5, 0, 0.5, math.pi, 0)
|
cr:arc (1.5, 0, 0.5, math.pi, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_core = function (cr)
|
local render_core = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The core
|
-- The core
|
||||||
cr.move_to (-2, -1)
|
cr:move_to (-2, -1)
|
||||||
cr.line_to (2, -1)
|
cr:line_to (2, -1)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbols
|
-- Register the symbols
|
||||||
|
|
|
@ -38,63 +38,63 @@ local terminals_pot = {{-2, 0}, {2, 0}, {2, -2}}
|
||||||
-- Rendering
|
-- Rendering
|
||||||
local render = function (cr)
|
local render = function (cr)
|
||||||
-- The rectangle
|
-- The rectangle
|
||||||
cr.move_to (-1.5, -0.5)
|
cr:move_to (-1.5, -0.5)
|
||||||
cr.line_to (1.5, -0.5)
|
cr:line_to (1.5, -0.5)
|
||||||
cr.line_to (1.5, 0.5)
|
cr:line_to (1.5, 0.5)
|
||||||
cr.line_to (-1.5, 0.5)
|
cr:line_to (-1.5, 0.5)
|
||||||
cr.line_to (-1.5, -0.5)
|
cr:line_to (-1.5, -0.5)
|
||||||
|
|
||||||
-- The terminals
|
-- The terminals
|
||||||
cr.move_to (-2, 0)
|
cr:move_to (-2, 0)
|
||||||
cr.line_to (-1.5, 0)
|
cr:line_to (-1.5, 0)
|
||||||
|
|
||||||
cr.move_to (1.5, 0)
|
cr:move_to (1.5, 0)
|
||||||
cr.line_to (2, 0)
|
cr:line_to (2, 0)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_adj = function (cr)
|
local render_adj = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The arrow
|
-- The arrow
|
||||||
cr.move_to (-1, 1)
|
cr:move_to (-1, 1)
|
||||||
cr.line_to (1, -1)
|
cr:line_to (1, -1)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
|
|
||||||
cr.save ()
|
cr:save ()
|
||||||
cr.translate (1.5, -1.5)
|
cr:translate (1.5, -1.5)
|
||||||
cr.rotate (math.atan2 (1, 1))
|
cr:rotate (math.atan2 (1, 1))
|
||||||
|
|
||||||
cr.move_to (0, 0)
|
cr:move_to (0, 0)
|
||||||
cr.line_to (0.3, 0.8)
|
cr:line_to (0.3, 0.8)
|
||||||
cr.line_to (-0.3, 0.8)
|
cr:line_to (-0.3, 0.8)
|
||||||
cr.close_path ()
|
cr:close_path ()
|
||||||
|
|
||||||
cr.fill ()
|
cr:fill ()
|
||||||
cr.restore ()
|
cr:restore ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local render_pot = function (cr)
|
local render_pot = function (cr)
|
||||||
render (cr)
|
render (cr)
|
||||||
|
|
||||||
-- The contact
|
-- The contact
|
||||||
cr.move_to (0, -2)
|
cr:move_to (0, -2)
|
||||||
cr.line_to (2, -2)
|
cr:line_to (2, -2)
|
||||||
|
|
||||||
-- The arrow
|
-- The arrow
|
||||||
cr.move_to (0, -2)
|
cr:move_to (0, -2)
|
||||||
cr.line_to (0, -1)
|
cr:line_to (0, -1)
|
||||||
|
|
||||||
cr.stroke ()
|
cr:stroke ()
|
||||||
|
|
||||||
cr.move_to (0, -0.5)
|
cr:move_to (0, -0.5)
|
||||||
cr.line_to (0.3, -1.3)
|
cr:line_to (0.3, -1.3)
|
||||||
cr.line_to (-0.3, -1.3)
|
cr:line_to (-0.3, -1.3)
|
||||||
cr.close_path ()
|
cr:close_path ()
|
||||||
|
|
||||||
cr.fill ()
|
cr:fill ()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register the symbol
|
-- Register the symbol
|
||||||
|
|
Loading…
Reference in New Issue