diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c index 833c2a2a7..b7b03773c 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_output_stream_t *stream, 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_output_stream_t *stream, 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)); + case 'u': + case 'o': + snprintf (buffer, sizeof buffer, single_fmt, 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)); - break; 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 2c3fa4b41..8df210208 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -2576,15 +2576,14 @@ _cairo_pdf_surface_show_glyphs (void *abstract_surface, } _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 729639e52..78db1bf02 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -1913,10 +1913,9 @@ _cairo_ps_surface_show_glyphs (void *abstract_surface, } _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);