Merge pull request #296 from lite-xl/font-copy-api

Add a C API copy method for font_desc objects
This commit is contained in:
Adam 2021-06-24 12:47:16 -04:00 committed by GitHub
commit 83a604dfb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -22,9 +22,9 @@ style.tab_width = common.round(170 * SCALE)
-- On High DPI monitor or non RGB monitor you may consider using antialiasing grayscale instead. -- On High DPI monitor or non RGB monitor you may consider using antialiasing grayscale instead.
-- The antialiasing grayscale with full hinting is interesting for crisp font rendering. -- The antialiasing grayscale with full hinting is interesting for crisp font rendering.
style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 13 * SCALE) style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 13 * SCALE)
style.big_font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 40 * SCALE) style.big_font = style.font:copy(40 * SCALE)
style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 14 * SCALE, {antialiasing="grayscale", hinting="full"}) style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 14 * SCALE, {antialiasing="grayscale", hinting="full"})
style.icon_big_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 20 * SCALE, {antialiasing="grayscale", hinting="full"}) style.icon_big_font = style.icon_font:copy(20 * SCALE)
style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 13 * SCALE) style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 13 * SCALE)
style.background = { common.color "#2e2e32" } style.background = { common.color "#2e2e32" }

View File

@ -55,6 +55,21 @@ static int f_load(lua_State *L) {
} }
static int f_copy(lua_State *L) {
FontDesc *self = luaL_checkudata(L, 1, API_TYPE_FONT);
float size;
if (lua_gettop(L) >= 2) {
size = luaL_checknumber(L, 2);
} else {
size = self->size;
}
FontDesc *new_font_desc = lua_newuserdata(L, font_desc_alloc_size(self->filename));
font_desc_init(new_font_desc, self->filename, size, self->options);
luaL_setmetatable(L, API_TYPE_FONT);
return 1;
}
static int f_set_tab_size(lua_State *L) { static int f_set_tab_size(lua_State *L) {
FontDesc *self = luaL_checkudata(L, 1, API_TYPE_FONT); FontDesc *self = luaL_checkudata(L, 1, API_TYPE_FONT);
int n = luaL_checknumber(L, 2); int n = luaL_checknumber(L, 2);
@ -123,6 +138,7 @@ static int f_set_size(lua_State *L) {
static const luaL_Reg lib[] = { static const luaL_Reg lib[] = {
{ "__gc", f_gc }, { "__gc", f_gc },
{ "load", f_load }, { "load", f_load },
{ "copy", f_copy },
{ "set_tab_size", f_set_tab_size }, { "set_tab_size", f_set_tab_size },
{ "get_width", f_get_width }, { "get_width", f_get_width },
{ "get_width_subpixel", f_get_width_subpixel }, { "get_width_subpixel", f_get_width_subpixel },