add Font.texture binding

This commit is contained in:
Jérôme Hodé 2023-11-07 01:13:53 +01:00
parent 2ef1a00038
commit bd7cc641f7
3 changed files with 14 additions and 0 deletions

View File

@ -294,6 +294,7 @@ function main(){
baseSize: { get: true }, baseSize: { get: true },
glyphCount: { get: true }, glyphCount: { get: true },
glyphPadding: { get: true }, glyphPadding: { get: true },
texture: { get: true },
}, },
//destructor: "UnloadFont" //destructor: "UnloadFont"
} }

View File

@ -137,6 +137,8 @@ interface Font {
glyphCount: number, glyphCount: number,
/** Padding around the glyph characters */ /** Padding around the glyph characters */
glyphPadding: number, glyphPadding: number,
/** Texture atlas containing the glyphs */
texture: Texture,
} }
declare var Font: { declare var Font: {
prototype: Font; prototype: Font;

View File

@ -846,10 +846,21 @@ static JSValue js_Font_get_glyphPadding(JSContext* ctx, JSValueConst this_val) {
return ret; return ret;
} }
static JSValue js_Font_get_texture(JSContext* ctx, JSValueConst this_val) {
Font* ptr = JS_GetOpaque2(ctx, this_val, js_Font_class_id);
Texture2D texture = ptr->texture;
Texture2D* ret_ptr = (Texture2D*)js_malloc(ctx, sizeof(Texture2D));
*ret_ptr = texture;
JSValue ret = JS_NewObjectClass(ctx, js_Texture_class_id);
JS_SetOpaque(ret, ret_ptr);
return ret;
}
static const JSCFunctionListEntry js_Font_proto_funcs[] = { static const JSCFunctionListEntry js_Font_proto_funcs[] = {
JS_CGETSET_DEF("baseSize",js_Font_get_baseSize,NULL), JS_CGETSET_DEF("baseSize",js_Font_get_baseSize,NULL),
JS_CGETSET_DEF("glyphCount",js_Font_get_glyphCount,NULL), JS_CGETSET_DEF("glyphCount",js_Font_get_glyphCount,NULL),
JS_CGETSET_DEF("glyphPadding",js_Font_get_glyphPadding,NULL), JS_CGETSET_DEF("glyphPadding",js_Font_get_glyphPadding,NULL),
JS_CGETSET_DEF("texture",js_Font_get_texture,NULL),
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Font", JS_PROP_CONFIGURABLE), JS_PROP_STRING_DEF("[Symbol.toStringTag]","Font", JS_PROP_CONFIGURABLE),
}; };