MCPcopy Create free account
hub / github.com/crownengine/crown / compile

Function compile

src/resource/font_resource.cpp:63–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61 }
62
63 s32 compile(CompileOptions &opts)
64 {
65 Buffer buf = opts.read();
66
67 TempAllocator4096 ta;
68 JsonObject obj(ta);
69 JsonArray glyphs(ta);
70
71 RETURN_IF_ERROR(sjson::parse(obj, buf));
72 RETURN_IF_ERROR(sjson::parse_array(glyphs, obj["glyphs"]));
73
74 const u32 texture_size = RETURN_IF_ERROR(sjson::parse_int(obj["size"]));
75 const u32 font_size = RETURN_IF_ERROR(sjson::parse_int(obj["font_size"]));
76 RETURN_IF_FALSE(FONT_RESOURCE, font_size > 0
77 , opts
78 , "Font size must be > 0"
79 );
80
81 s32 err = 0;
82 Array<GlyphInfo> _glyphs(default_allocator());
83 err = parse_glyphs(_glyphs, glyphs);
84 ENSURE_OR_RETURN(FONT_RESOURCE, err == 0, opts);
85 std::sort(array::begin(_glyphs), array::end(_glyphs));
86
87 opts.write(RESOURCE_HEADER(RESOURCE_VERSION_FONT));
88 opts.write(texture_size);
89 opts.write(font_size);
90 opts.write(array::size(_glyphs));
91
92 for (u32 i = 0; i < array::size(_glyphs); ++i)
93 opts.write(_glyphs[i].cp);
94
95 for (u32 i = 0; i < array::size(_glyphs); ++i) {
96 opts.write(_glyphs[i].gd.x);
97 opts.write(_glyphs[i].gd.y);
98 opts.write(_glyphs[i].gd.width);
99 opts.write(_glyphs[i].gd.height);
100 opts.write(_glyphs[i].gd.x_offset);
101 opts.write(_glyphs[i].gd.y_offset);
102 opts.write(_glyphs[i].gd.x_advance);
103 }
104
105 return 0;
106 }
107
108} // namespace font_resource_internal
109

Callers

nothing calls this directly

Calls 10

parse_glyphsFunction · 0.85
parseFunction · 0.70
parse_arrayFunction · 0.50
parse_intFunction · 0.50
sortFunction · 0.50
beginFunction · 0.50
endFunction · 0.50
sizeFunction · 0.50
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected