--- src/cc-interface-png.cc 2026-04-01 08:29:03.000000000 +0800 +++ src/cc-interface-png.cc 2026-05-07 03:12:00.000000000 +0800 @@ -476,28 +476,24 @@ auto draw_svg = +[] (GtkDrawingArea *da, cairo_t *cr, int w, int h, gpointer data) { - GError *error = NULL; RsvgHandle *handle = static_cast(data); - GdkRectangle allocation; - gtk_widget_get_allocation(GTK_WIDGET(da), &allocation); - // Scale the SVG to fit the widget (optional, adjust as needed) - gboolean has_width, has_height, has_viewbox; - RsvgLength width, height; - RsvgRectangle viewbox; RsvgDimensionData dimension_data; - rsvg_handle_get_intrinsic_dimensions(handle, &has_width, &width, &has_height, &height, - &has_viewbox, &viewbox); rsvg_handle_get_dimensions(handle, &dimension_data); - std::cout << "in draw_svg(): dims " << dimension_data.width << " " << dimension_data.height << " " - << " em: " << dimension_data.em << " ex: " << dimension_data.ex << std::endl; - double scale = static_cast(w / dimension_data.em); + double scale = 1.0; + if (dimension_data.width > 0) { + scale = static_cast(w) / static_cast(dimension_data.width); + } + + cairo_save(cr); cairo_scale(cr, scale, scale); - cairo_translate(cr, dimension_data.em/2.0, dimension_data.ex/2.0); - // Render the SVG - rsvg_handle_render_document(handle, cr, &viewbox, &error); + if (!rsvg_handle_render_cairo(handle, cr)) { + g_printerr("Error rendering SVG with librsvg\n"); + } + + cairo_restore(cr); }; auto on_drawing_area_resize = +[] (GtkDrawingArea *da, int w, int h, gpointer data) {