Hi Werner,
Here is the patch. I think you might want to do some stylistic changes, but
let's start with something concrete. Strictly speaking the logic is a little
different from how it was, for the case of malformed svg documents where
"start_glyph_id > end_glyph_id" (normal is "=" and "<"). I think the new
behavior is better - malformed svg documents get rendered so you see something,
and hopefully something wildly wrong, thus letting you know that it is
malformed (in the old, malformed svg glyphs don't render).
Also currently the code does not check that glyph_index is between
start_glyph_id and end_glyph_id . Should it? This is the part where those
Google fonts a few weeks ago would have been flagged as faulty. Should a
"fprintf( stderr, ..." be where "start_glyph_id > end_glyph_id" and also if
glyph_index is outside start_glyph_id and end_glyph_id ?
I don't feel strongly either way, but removing 25 lines, and a large "if ...
then ..." makes it easier to read.
Hin-Tak
On Friday, 30 June 2023 at 01:43:51 BST, Hin-Tak Leung
<ht...@users.sourceforge.net> wrote:
...
I think I'll prepare a patch for removing rsvg_handle_render_document(), but I
don't feel too strongly that way - it is functionally the same, just removing
about 20 lines and makes the file easier to read (in the future).
...
From 216f39cec1fe8719762aad593568015bd01622cb Mon Sep 17 00:00:00 2001
From: Hin-Tak Leung <ht...@users.sourceforge.net>
Date: Fri, 30 Jun 2023 02:45:38 +0100
Subject: [PATCH] * src/rsvg-port.c (rsvg_port_preset_slot): simplify usage of
rsvg_handle_render_*
* src/rsvg-port.c (rsvg_port_preset_slot): Remove usage of `rsvg_handle_render_document'
(and `rsvg_handle_render_cairo'). They are functionally the same as
`rsvg_handle_render_layer' (and `rsvg_handle_render_cairo_sub') with argument
id set to NULL.
Signed-off-by: Hin-Tak Leung <ht...@users.sourceforge.net>
---
src/rsvg-port.c | 80 +++++++++++++++++--------------------------------
1 file changed, 27 insertions(+), 53 deletions(-)
diff --git a/src/rsvg-port.c b/src/rsvg-port.c
index 16faa14..5861e19 100644
--- a/src/rsvg-port.c
+++ b/src/rsvg-port.c
@@ -334,69 +334,43 @@
/* If the document contains only one glyph, `start_glyph_id` and */
/* `end_glyph_id` have the same value. Otherwise `end_glyph_id` */
/* is larger. */
- if ( start_glyph_id == end_glyph_id )
- {
- /* Render the whole document to the recording surface. */
-#if LIBRSVG_CHECK_VERSION( 2, 52, 0 )
- {
- RsvgRectangle viewport =
- {
- .x = 0,
- .y = 0,
- .width = (double)dimension_svg.width,
- .height = (double)dimension_svg.height,
- };
-
-
- ret = rsvg_handle_render_document( handle,
- rec_cr,
- &viewport,
- NULL );
- }
-#else
- ret = rsvg_handle_render_cairo( handle, rec_cr );
-#endif
-
- if ( ret == FALSE )
- {
- error = FT_Err_Invalid_SVG_Document;
- goto CleanCairo;
- }
- }
- else if ( start_glyph_id < end_glyph_id )
- {
- char str[32] = "#glyph";
+ /* NULL = Render the whole document */
+ char *id = NULL;
+ char str[32] = "#glyph";
+ if ( start_glyph_id < end_glyph_id )
+ {
/* Render only the element with its ID equal to `glyph<ID>`. */
sprintf( str + 6, "%u", slot->glyph_index );
+ id = str;
+ }
#if LIBRSVG_CHECK_VERSION( 2, 52, 0 )
+ {
+ RsvgRectangle viewport =
{
- RsvgRectangle viewport =
- {
- .x = 0,
- .y = 0,
- .width = (double)dimension_svg.width,
- .height = (double)dimension_svg.height,
- };
-
-
- ret = rsvg_handle_render_layer( handle,
- rec_cr,
- str,
- &viewport,
- NULL );
- }
+ .x = 0,
+ .y = 0,
+ .width = (double)dimension_svg.width,
+ .height = (double)dimension_svg.height,
+ };
+
+
+ ret = rsvg_handle_render_layer( handle,
+ rec_cr,
+ id,
+ &viewport,
+ NULL );
+ }
#else
- ret = rsvg_handle_render_cairo_sub( handle, rec_cr, str );
+ ret = rsvg_handle_render_cairo_sub( handle, rec_cr, id );
#endif
- if ( ret == FALSE )
- {
- error = FT_Err_Invalid_SVG_Document;
- goto CleanCairo;
- }
+ if ( ret == FALSE )
+ {
+ error = FT_Err_Invalid_SVG_Document;
+ goto CleanCairo;
}
/* Get the bounding box of the drawing. */
--
2.41.0