il_base *ilA_contents_path (const ilA_path *path, size_t *size, void **data, const ilA_file **res) { const ilA_file *iface; il_base *base = ilA_stdiofile(path, ILA_FILE_READ, &iface); if (!base) { char *tostr = ilA_path_tochars(path); il_error("Unable to open file %s", tostr); free(tostr); return NULL; } if (res) { *res = iface; } *data = ilA_contents(iface, base, size); return base; }
ilG_gui_textlayout *ilG_gui_textlayout_new(ilG_context *ctx, const char *lang, enum ilG_gui_textdir direction, const char *script, il_base *font, const ilA_file *tc, double pt, il_string *source) { il_return_null_on_fail(ctx && lang && script && font && source); struct text_globalctx *gctx = il_base_get(&ctx->base, "il.graphics.gui.text.ctx", NULL, NULL); if (!gctx) { gctx = calloc(1, sizeof(struct text_globalctx)); il_return_null_on_fail(!FT_Init_FreeType(&gctx->library)); il_base_set(&ctx->base, "il.graphics.gui.text.ctx", gctx, sizeof(struct text_globalctx), IL_VOID); } ilG_gui_textlayout *l = il_new(&ilG_gui_textlayout_type); l->context = ctx; l->lang = strdup(lang); l->script = strdup(script); l->font = il_ref(font); l->direction = direction; l->pt = pt; l->source = il_string_ref(source); size_t size; void *data = ilA_contents(tc, font, &size); if (!data) { il_error("Could not open font"); return NULL; } il_return_null_on_fail(!FT_New_Memory_Face(gctx->library, data, size, 0, &l->ft_face)); il_return_null_on_fail(!FT_Set_Char_Size(l->ft_face, 0, pt * 64, 0, 0)); l->hb_ft_font = hb_ft_font_create(l->ft_face, NULL); l->buf = hb_buffer_create(); hb_buffer_set_unicode_funcs(l->buf, hb_icu_get_unicode_funcs()); if (direction == ILG_GUI_DEFAULTDIR) { // TODO: find out how to determine this based on script direction = ILG_GUI_LTR; } hb_buffer_set_direction(l->buf, direction + 3); // Hacky solution hb_buffer_set_script(l->buf, hb_script_from_string(script, -1)); hb_buffer_set_language(l->buf, hb_language_from_string(lang, -1)); hb_buffer_add_utf8(l->buf, source->data, source->length, 0, source->length); hb_shape(l->hb_ft_font, l->buf, NULL, 0); l->glyph_info = hb_buffer_get_glyph_infos(l->buf, &l->glyph_count); l->glyph_pos = hb_buffer_get_glyph_positions(l->buf, &l->glyph_count); return l; }
ilA_mesh *ilA_mesh_load(il_base *file, const ilA_file *iface) { size_t size; void *data = ilA_contents(iface, file, &size); return ilA_mesh_loadmem("", data, size); // TODO: add a file name getter to the file typeclass }
void ilG_tex_loadasset(ilG_tex *self, const struct ilA_file *iface, void *file) { size_t size; void *contents = ilA_contents(iface, file, &size); ilG_tex_loadimage(self, ilA_img_load(contents, size)); }