void FontLoadFromJSON(Font *f, const char *imgPath, const char *jsonPath) { yajl_val node = YAJLReadFile(jsonPath); if (node == NULL) { fprintf(stderr, "Error parsing font JSON '%s'\n", jsonPath); goto bail; } memset(f, 0, sizeof *f); // Load definitions from JSON data YAJLVec2i(&f->Size, node, "Size"); YAJLInt(&f->Stride, node, "Stride"); // Padding order is: left/top/right/bottom const yajl_val paddingNode = YAJLFindNode(node, "Padding"); f->Padding.Left = (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(paddingNode)->values[0]); f->Padding.Top = (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(paddingNode)->values[1]); f->Padding.Right = (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(paddingNode)->values[2]); f->Padding.Bottom = (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(paddingNode)->values[3]); YAJLVec2i(&f->Gap, node, "Gap"); bool proportional = false; YAJLBool(&proportional, node, "Proportional"); FontLoad(f, imgPath, proportional); bail: yajl_tree_free(node); }
char *YAJLGetStr(yajl_val node, const char *name) { char *in = YAJL_GET_STRING(YAJLFindNode(node, name)); char *out; CSTRDUP(out, in); return out; }