Bug#264484: librsvg2: support SVG property, baseline-shift

Nick Lewycky Nick Lewycky <nicholas@mxc.ca>, 264484@bugs.debian.org
Sun, 08 Aug 2004 22:35:49 -0400


This is a multi-part MIME message sent by reportbug.

--===============1148999525==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Package: librsvg2
Severity: normal
Tags: patch

The SVG property "baseline-shift" is used for superscript and
subscript text. This patch implements support for it.

-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.7
Locale: LANG=C, LC_CTYPE=C

--===============1148999525==
Content-Type: text/x-c; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="librsvg2-baseline.diff"

diff -u librsvg2-2.7.2/debian/changelog librsvg2-2.7.2/debian/changelog
--- librsvg2-2.7.2/debian/changelog
+++ librsvg2-2.7.2/debian/changelog
@@ -1,3 +1,9 @@
+librsvg2 (2.7.2-5.1) unstable; urgency=low
+
+  * Add support for baseline-shift.
+
+ -- Nicholas Lewycky <nicholas@spi-inc.org>  Sun,  8 Aug 2004 20:20:06 -0500
+
 librsvg2 (2.7.2-5) unstable; urgency=medium
 
   * Rebuild with libgnutls11 (closes: #263682).
only in patch2:
unchanged:
--- librsvg2-2.7.2.orig/rsvg-css.c
+++ librsvg2-2.7.2/rsvg-css.c
@@ -693,6 +693,27 @@
 		return str;
 }
 
+gint
+rsvg_css_parse_baseline_shift (const char * str, gdouble pixels_per_inch,
+                               gdouble width_or_height, gdouble font_size,
+                               gint inherit)
+{
+	if (!str)
+		return NULL;	
+	else if (!strcmp (str, "inherit"))
+		return inherit;
+	else if (!strcmp (str, "baseline"))
+		return 0;
+	else if (!strcmp (str, "sub"))
+		return font_size * -0.54;        /* not quite spec */
+	else if (!strcmp (str, "super"))
+		return font_size * 0.54;
+	else
+		return rsvg_css_parse_normalized_length (str, pixels_per_inch,
+												 width_or_height, font_size);
+	}
+}
+
 #if !defined(HAVE_STRTOK_R) && !GLIB_CHECK_VERSION(2, 3, 2)
 
 static char *
only in patch2:
unchanged:
--- librsvg2-2.7.2.orig/rsvg-styles.c
+++ librsvg2-2.7.2/rsvg-styles.c
@@ -51,6 +51,20 @@
 	return 0;
 }
 
+static gint
+rsvg_state_baseline_shift (RsvgState * cur_state, RsvgState * parent_state)
+{
+	if (cur_state)
+		{
+			if (cur_state->has_baseline_shift)
+				return cur_state->baseline_shift;
+			else if (parent_state)
+				return parent_state->baseline_shift;
+		}
+	
+	return 0;
+}
+
 gdouble
 rsvg_viewport_percentage (gdouble width, gdouble height)
 {
@@ -645,6 +659,13 @@
 						}
 				}
 		}
+	else if (rsvg_css_param_match (str, "baseline-shift"))
+		{
+			gint current_baseline_shift = rsvg_state_baseline_shift (state, parent_state);
+			state->has_baseline_shift = TRUE;
+			state->baseline_shift = rsvg_css_parse_baseline_shift (str + arg_off, ctx->dpi,
+																   (gdouble)ctx->height, state->font_size, current_baseline_shift);
+		}
 }
 
 void rsvg_parse_style_pair (RsvgHandle *ctx, RsvgState *state, 
only in patch2:
unchanged:
--- librsvg2-2.7.2.orig/rsvg-styles.h
+++ librsvg2-2.7.2/rsvg-styles.h
@@ -125,6 +125,9 @@
 	guint32 current_color;
 	gboolean has_current_color;
 
+	gint baseline_shift;
+	gboolean has_baseline_shift;
+
 	GdkPixbuf *save_pixbuf;
 };
 
only in patch2:
unchanged:
--- librsvg2-2.7.2.orig/rsvg-text.c
+++ librsvg2-2.7.2/rsvg-text.c
@@ -156,7 +156,10 @@
 		line_ink_rect = ink_rect; /* nothing to draw anyway */
 	else
 		pango_layout_line_get_pixel_extents (line, &line_ink_rect, NULL);
-	
+
+	if (state->has_baseline_shift)
+		line_ink_rect.y -= state->baseline_shift;
+
 	bitmap.rows       = ink_rect.height;
 	bitmap.width      = ink_rect.width;
 	bitmap.pitch      = bitmap.width;
@@ -211,7 +214,7 @@
 	gradctx.y1 = line_ink_rect.y + logical_rect.height;
 	for (i = 0; i < 6; i++)
 		gradctx.affine[i] = state->affine[i];
-	
+
 	rsvg_render_paint_server (render, state->fill, &gradctx);
 
 	opacity = state->fill_opacity * state->opacity;
only in patch2:
unchanged:
--- librsvg2-2.7.2.orig/rsvg-text-vectors.c
+++ librsvg2-2.7.2/rsvg-text-vectors.c
@@ -135,7 +135,7 @@
 {
 	RsvgTextLayout * layout;
 	PangoFontDescription *font_desc;
-	
+
 	if (ctx->pango_context == NULL)
 		ctx->pango_context = rsvg_text_get_pango_context (ctx);
 	
@@ -506,11 +506,16 @@
 			PangoRectangle   rect;
 			PangoLayoutLine *line;
 			gint             baseline;
+			RsvgState       *state;
 			
 			line = pango_layout_iter_get_line (iter);
 			
 			pango_layout_iter_get_line_extents (iter, NULL, &rect);
 			baseline = pango_layout_iter_get_baseline (iter);
+
+			state = rsvg_state_current(layout->ctx);
+			if (state && state->has_baseline_shift)
+				baseline -= state->baseline_shift;
 			
 			rsvg_text_layout_render_line (layout, line,
 										  render_func,

--===============1148999525==--