[cairo-commit] src/cairo-output-stream.c src/cairo-pdf-surface.c src/cairo-ps-surface.c

Kristian Høgsberg krh at kemper.freedesktop.org
Mon Jun 19 19:47:09 PDT 2006


 src/cairo-output-stream.c |   46 ++++++++++++++++++++++++++++++----------------
 src/cairo-pdf-surface.c   |    5 ++---
 src/cairo-ps-surface.c    |    5 ++---
 3 files changed, 34 insertions(+), 22 deletions(-)

New commits:
diff-tree cd5e08a9fee70b1ed2252d24e04db806769babcd (from a3f2d92f11a1ab4d30dd0e33a0cd5ee19495eeb1)
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Mon Jun 19 22:42:32 2006 -0400

    Implement 0-padding and field width for _cairo_output_stream_printf().
    
    Use it instead of %c%c in PS and PDF surfaces.

diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c
index 833c2a2..b7b0377 100644
--- a/src/cairo-output-stream.c
+++ b/src/cairo-output-stream.c
@@ -268,9 +268,9 @@ void
 _cairo_output_stream_vprintf (cairo_output_stream_t *stream,
 			      const char *fmt, va_list ap)
 {
-    char buffer[512];
-    char *p;
-    const char *f;
+    char buffer[512], single_fmt[32];
+    char *p, *end;
+    const char *f, *start;
     int length_modifier;
 
     if (stream->status)
@@ -289,10 +289,16 @@ _cairo_output_stream_vprintf (cairo_outp
 	    continue;
 	}
 
+	start = f;
 	f++;
 
-	_cairo_output_stream_write (stream, buffer, p - buffer);
-	p = buffer;
+	if (*f == '0')
+	    f++;
+
+	if (isdigit (*f)) {
+	    strtol (f, &end, 10);
+	    f = end;
+	}
 
 	length_modifier = 0;
 	if (*f == 'l') {
@@ -300,28 +306,36 @@ _cairo_output_stream_vprintf (cairo_outp
 	    f++;
 	}
 
+	/* Reuse the format string for this conversion. */
+	memcpy (single_fmt, start, f + 1 - start);
+	single_fmt[f + 1 - start] = '\0';
+
+	/* Flush contents of buffer before snprintf()'ing into it. */
+	_cairo_output_stream_write (stream, buffer, p - buffer);
+	p = buffer;
+
+	/* We group signed and usigned together in this swith, the
+	 * only thing that matters here is the size of the arguments,
+	 * since we're just passing the data through to sprintf(). */
 	switch (*f | length_modifier) {
 	case '%':
 	    buffer[0] = *f;
 	    buffer[1] = 0;
 	    break;
 	case 'd':
-	    snprintf (buffer, sizeof buffer, "%d", va_arg (ap, int));
-	    break;
-	case 'd' | LENGTH_MODIFIER_LONG:
-	    snprintf (buffer, sizeof buffer, "%ld", va_arg (ap, long int));
-	    break;
 	case 'u':
-	    snprintf (buffer, sizeof buffer, "%u", va_arg (ap, unsigned int));
+	case 'o':
+	    snprintf (buffer, sizeof buffer, single_fmt, va_arg (ap, int));
 	    break;
+	case 'd' | LENGTH_MODIFIER_LONG:
 	case 'u' | LENGTH_MODIFIER_LONG:
-	    snprintf (buffer, sizeof buffer, "%lu", va_arg (ap, long unsigned int));
-	    break;
-	case 'o':
-	    snprintf (buffer, sizeof buffer, "%o", va_arg (ap, int));
+	case 'o' | LENGTH_MODIFIER_LONG:
+	    snprintf (buffer, sizeof buffer,
+		      single_fmt, va_arg (ap, long int));
 	    break;
 	case 's':
-	    snprintf (buffer, sizeof buffer, "%s", va_arg (ap, const char *));
+	    snprintf (buffer, sizeof buffer,
+		      single_fmt, va_arg (ap, const char *));
 	    break;
 	case 'f':
 	    _cairo_dtostr (buffer, sizeof buffer, va_arg (ap, double));
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 2c3fa4b..8df2102 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -2576,15 +2576,14 @@ _cairo_pdf_surface_show_glyphs (void			*
 	}
 
 	_cairo_output_stream_printf (surface->output,
-				     "%f %f %f %f %f %f Tm <%c%c> Tj\r\n",
+				     "%f %f %f %f %f %f Tm <%02x> Tj\r\n",
 				     scaled_font->scale.xx,
 				     scaled_font->scale.yx,
 				     -scaled_font->scale.xy,
 				     -scaled_font->scale.yy,
 				     glyphs[i].x,
 				     glyphs[i].y,
-				     hex_digit (subset_glyph_index >> 4),
-				     hex_digit (subset_glyph_index));
+				     subset_glyph_index);
     }
 
     _cairo_output_stream_printf (surface->output,
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 729639e..78db1bf 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -1913,10 +1913,9 @@ _cairo_ps_surface_show_glyphs (void		   
 	}
 
 	_cairo_output_stream_printf (surface->stream,
-				     "%f %f M <%c%c> S\n",
+				     "%f %f M <%02x> S\n",
 				     glyphs[i].x, glyphs[i].y,
-				     hex_digit (subset_glyph_index >> 4),
-				     hex_digit (subset_glyph_index));
+				     subset_glyph_index);
     }
 
     return _cairo_output_stream_get_status (surface->stream);


More information about the cairo-commit mailing list