rendernode-extract: Save files with the same name as the node

Instead of "gtk-foo.ext", use "filename-foo.ext". That avoids confusion
when having extracted things before.
This commit is contained in:
Benjamin Otte 2024-07-08 08:35:53 +02:00
parent 287b27dad3
commit 2f18d5584d

View File

@ -38,7 +38,8 @@ static guint font_count;
static GHashTable *fonts;
static void
extract_texture (GskRenderNode *node)
extract_texture (GskRenderNode *node,
const char *basename)
{
GdkTexture *texture;
char *filename;
@ -50,7 +51,7 @@ extract_texture (GskRenderNode *node)
texture = gsk_texture_scale_node_get_texture (node);
do {
filename = g_strdup_printf ("gtk-texture-%u.png", texture_count);
filename = g_strdup_printf ("%s-texture-%u.png", basename, texture_count);
path = g_build_path ("/", directory, filename, NULL);
if (!g_file_test (path, G_FILE_TEST_EXISTS))
@ -79,7 +80,8 @@ extract_texture (GskRenderNode *node)
}
static void
extract_font (GskRenderNode *node)
extract_font (GskRenderNode *node,
const char *basename)
{
PangoFont *font;
hb_font_t *hb_font;
@ -120,7 +122,7 @@ extract_font (GskRenderNode *node)
g_hash_table_add (fonts, sum);
do {
filename = g_strdup_printf ("gtk-font-%u.ttf", font_count);
filename = g_strdup_printf ("%s-font-%u.ttf", basename, font_count);
path = g_build_path ("/", directory, filename, NULL);
if (!g_file_test (path, G_FILE_TEST_EXISTS))
@ -156,13 +158,14 @@ extract_font (GskRenderNode *node)
}
static void
extract_from_node (GskRenderNode *node)
extract_from_node (GskRenderNode *node,
const char *basename)
{
switch (gsk_render_node_get_node_type (node))
{
case GSK_CONTAINER_NODE:
for (unsigned int i = 0; i < gsk_container_node_get_n_children (node); i++)
extract_from_node (gsk_container_node_get_child (node, i));
extract_from_node (gsk_container_node_get_child (node, i), basename);
break;
case GSK_CAIRO_NODE:
@ -179,81 +182,81 @@ extract_from_node (GskRenderNode *node)
case GSK_TEXTURE_NODE:
case GSK_TEXTURE_SCALE_NODE:
extract_texture (node);
extract_texture (node, basename);
break;
case GSK_TRANSFORM_NODE:
extract_from_node (gsk_transform_node_get_child (node));
extract_from_node (gsk_transform_node_get_child (node), basename);
break;
case GSK_OPACITY_NODE:
extract_from_node (gsk_opacity_node_get_child (node));
extract_from_node (gsk_opacity_node_get_child (node), basename);
break;
case GSK_COLOR_MATRIX_NODE:
extract_from_node (gsk_color_matrix_node_get_child (node));
extract_from_node (gsk_color_matrix_node_get_child (node), basename);
break;
case GSK_REPEAT_NODE:
extract_from_node (gsk_repeat_node_get_child (node));
extract_from_node (gsk_repeat_node_get_child (node), basename);
break;
case GSK_CLIP_NODE:
extract_from_node (gsk_clip_node_get_child (node));
extract_from_node (gsk_clip_node_get_child (node), basename);
break;
case GSK_ROUNDED_CLIP_NODE:
extract_from_node (gsk_rounded_clip_node_get_child (node));
extract_from_node (gsk_rounded_clip_node_get_child (node), basename);
break;
case GSK_SHADOW_NODE:
extract_from_node (gsk_shadow_node_get_child (node));
extract_from_node (gsk_shadow_node_get_child (node), basename);
break;
case GSK_BLEND_NODE:
extract_from_node (gsk_blend_node_get_bottom_child (node));
extract_from_node (gsk_blend_node_get_top_child (node));
extract_from_node (gsk_blend_node_get_bottom_child (node), basename);
extract_from_node (gsk_blend_node_get_top_child (node), basename);
break;
case GSK_CROSS_FADE_NODE:
extract_from_node (gsk_cross_fade_node_get_start_child (node));
extract_from_node (gsk_cross_fade_node_get_end_child (node));
extract_from_node (gsk_cross_fade_node_get_start_child (node), basename);
extract_from_node (gsk_cross_fade_node_get_end_child (node), basename);
break;
case GSK_TEXT_NODE:
extract_font (node);
extract_font (node, basename);
break;
case GSK_BLUR_NODE:
extract_from_node (gsk_blur_node_get_child (node));
extract_from_node (gsk_blur_node_get_child (node), basename);
break;
case GSK_DEBUG_NODE:
extract_from_node (gsk_debug_node_get_child (node));
extract_from_node (gsk_debug_node_get_child (node), basename);
break;
case GSK_GL_SHADER_NODE:
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
for (unsigned int i = 0; i < gsk_gl_shader_node_get_n_children (node); i++)
extract_from_node (gsk_gl_shader_node_get_child (node, i));
extract_from_node (gsk_gl_shader_node_get_child (node, i), basename);
G_GNUC_END_IGNORE_DEPRECATIONS
break;
case GSK_MASK_NODE:
extract_from_node (gsk_mask_node_get_source (node));
extract_from_node (gsk_mask_node_get_mask (node));
extract_from_node (gsk_mask_node_get_source (node), basename);
extract_from_node (gsk_mask_node_get_mask (node), basename);
break;
case GSK_FILL_NODE:
extract_from_node (gsk_fill_node_get_child (node));
extract_from_node (gsk_fill_node_get_child (node), basename);
break;
case GSK_STROKE_NODE:
extract_from_node (gsk_stroke_node_get_child (node));
extract_from_node (gsk_stroke_node_get_child (node), basename);
break;
case GSK_SUBSURFACE_NODE:
extract_from_node (gsk_subsurface_node_get_child (node));
extract_from_node (gsk_subsurface_node_get_child (node), basename);
break;
case GSK_NOT_A_RENDER_NODE:
@ -266,10 +269,15 @@ static void
file_extract (const char *filename)
{
GskRenderNode *node;
char *basename, *dot;
node = load_node_file (filename);
basename = g_path_get_basename (filename);
dot = strrchr (basename, '.');
if (dot)
*dot = 0;
extract_from_node (node);
extract_from_node (node, basename);
gsk_render_node_unref (node);
}