[tool] Optimize COLR glyph dump
Move palette colors fetching out of gid iteration so not fetching all the colors of a palette each time.
This commit is contained in:
parent
0b76e8130e
commit
5c1a023f67
33
src/main.cc
33
src/main.cc
|
@ -172,6 +172,20 @@ static void
|
|||
layered_glyph_dump (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index)
|
||||
{
|
||||
hb_face_t *face = hb_font_get_face (font);
|
||||
unsigned palette_count = hb_ot_color_palette_get_count (face);
|
||||
for (unsigned palette = 0; palette < palette_count; ++palette)
|
||||
{
|
||||
unsigned num_colors = hb_ot_color_palette_get_colors (face, palette, 0, nullptr, nullptr);
|
||||
if (!num_colors) continue;
|
||||
|
||||
hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
|
||||
hb_ot_color_palette_get_colors (face, palette, 0, &num_colors, colors);
|
||||
if (!num_colors)
|
||||
{
|
||||
free (colors);
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned num_glyphs = hb_face_get_glyph_count (face);
|
||||
for (hb_codepoint_t gid = 0; gid < num_glyphs; ++gid)
|
||||
{
|
||||
|
@ -192,13 +206,6 @@ layered_glyph_dump (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index
|
|||
continue;
|
||||
}
|
||||
|
||||
unsigned palette_count = hb_ot_color_palette_get_count (face);
|
||||
for (unsigned palette = 0; palette < palette_count; ++palette)
|
||||
{
|
||||
unsigned num_colors = hb_ot_color_palette_get_colors (face, palette, 0, nullptr, nullptr);
|
||||
if (!num_colors)
|
||||
continue;
|
||||
|
||||
char output_path[255];
|
||||
sprintf (output_path, "out/colr-%u-%u-%u.svg", gid, palette, face_index);
|
||||
FILE *f = fopen (output_path, "wb");
|
||||
|
@ -210,10 +217,6 @@ layered_glyph_dump (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index
|
|||
user_data.ascender = extents.y_bearing;
|
||||
user_data.f = f;
|
||||
|
||||
hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
|
||||
hb_ot_color_palette_get_colors (face, palette, 0, &num_colors, colors);
|
||||
if (num_colors)
|
||||
{
|
||||
for (unsigned layer = 0; layer < num_layers; ++layer)
|
||||
{
|
||||
hb_color_t color = 0x000000FF;
|
||||
|
@ -228,16 +231,14 @@ layered_glyph_dump (hb_font_t *font, hb_draw_funcs_t *funcs, unsigned face_index
|
|||
printf ("Failed to decompose layer %d while %d\n", layers[layer].glyph, gid);
|
||||
fprintf (f, "\"/>\n");
|
||||
}
|
||||
}
|
||||
free (colors);
|
||||
|
||||
fprintf (f, "</svg>");
|
||||
fclose (f);
|
||||
}
|
||||
free (layers);
|
||||
}
|
||||
|
||||
|
||||
free (layers);
|
||||
free (colors);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,7 +280,7 @@ dump_glyphs (hb_blob_t *blob, const char *font_name)
|
|||
FILE *font_name_file = fopen ("out/.dumped_font_name", "r");
|
||||
if (font_name_file != nullptr)
|
||||
{
|
||||
fprintf (stderr, "Purge or move ./out folder in order to run a new glyph dump,\n"
|
||||
fprintf (stderr, "Purge or rename ./out folder if you like to run a glyph dump,\n"
|
||||
"run it like `rm -rf out && mkdir out && src/main font-file.ttf`\n");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue