[cairo-commit] 2 commits - src/cairo-svg-surface.c test/Makefile.am util/cairo-trace
Chris Wilson
ickle at kemper.freedesktop.org
Wed Nov 5 07:13:16 PST 2008
src/cairo-svg-surface.c | 50 +++++++++++++++++++++++++++++++++---
test/Makefile.am | 1
util/cairo-trace/trace.c | 65 +++++++++++++++++++++++++++--------------------
3 files changed, 85 insertions(+), 31 deletions(-)
New commits:
commit 199c0e71139fe9baf83e74ea69c01629ace5f9a2
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Nov 5 15:12:19 2008 +0000
[svg] Embed jpeg data.
Support jpeg embedding for svg output.
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 039cc39..8c23242 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -43,12 +43,13 @@
#include "cairoint.h"
#include "cairo-svg.h"
#include "cairo-analysis-surface-private.h"
-#include "cairo-svg-surface-private.h"
+#include "cairo-jpeg-info-private.h"
#include "cairo-meta-surface-private.h"
#include "cairo-output-stream-private.h"
#include "cairo-path-fixed-private.h"
#include "cairo-paginated-private.h"
#include "cairo-scaled-font-subsets-private.h"
+#include "cairo-svg-surface-private.h"
typedef struct cairo_svg_page cairo_svg_page_t;
@@ -976,12 +977,54 @@ base64_write_func (void *closure,
}
static cairo_int_status_t
+_cairo_surface_base64_encode_jpeg (cairo_surface_t *surface,
+ cairo_output_stream_t *output)
+{
+ const unsigned char *mime_data;
+ unsigned int mime_data_length;
+ cairo_jpeg_info_t jpeg_info;
+ base64_write_closure_t info;
+ cairo_status_t status;
+
+ cairo_surface_get_mime_data (surface, CAIRO_MIME_TYPE_JPEG,
+ &mime_data, &mime_data_length);
+ if (mime_data == NULL)
+ return CAIRO_INT_STATUS_UNSUPPORTED;
+
+ status = _cairo_jpeg_get_info (mime_data, mime_data_length, &jpeg_info);
+ if (status)
+ return status;
+
+ _cairo_output_stream_printf (output, "data:image/jpeg;base64,");
+
+ info.output = output;
+ info.in_mem = 0;
+ info.trailing = 0;
+
+ status = base64_write_func (&info, mime_data, mime_data_length);
+ if (status)
+ return status;
+
+ if (info.in_mem > 0) {
+ memset (info.src + info.in_mem, 0, 3 - info.in_mem);
+ info.trailing = 3 - info.in_mem;
+ info.in_mem = 3;
+ status = base64_write_func (&info, NULL, 0);
+ }
+
+ return status;
+}
+
+static cairo_int_status_t
_cairo_surface_base64_encode (cairo_surface_t *surface,
cairo_output_stream_t *output)
{
cairo_status_t status;
base64_write_closure_t info;
- unsigned int i;
+
+ status = _cairo_surface_base64_encode_jpeg (surface, output);
+ if (status != CAIRO_INT_STATUS_UNSUPPORTED)
+ return status;
info.output = output;
info.in_mem = 0;
@@ -996,8 +1039,7 @@ _cairo_surface_base64_encode (cairo_surface_t *surface,
return status;
if (info.in_mem > 0) {
- for (i = info.in_mem; i < 3; i++)
- info.src[i] = '\x0';
+ memset (info.src + info.in_mem, 0, 3 - info.in_mem);
info.trailing = 3 - info.in_mem;
info.in_mem = 3;
status = base64_write_func (&info, NULL, 0);
diff --git a/test/Makefile.am b/test/Makefile.am
index db1acf1..d9d4d39 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -701,6 +701,7 @@ REFERENCE_IMAGES = \
mime-data.ref.png \
mime-data.ps.ref.png \
mime-data.pdf.ref.png \
+ mime-data.svg.ref.png \
miter-precision.ref.png \
miter-precision.ps2.ref.png \
miter-precision.ps3.ref.png \
commit 2261590875b4be7aa258c51e766f68974750e9e7
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Nov 5 15:11:32 2008 +0000
[trace] Trim a few bytes from glyph arrays
Remove some redundant whitespace from the glyph arrays to improve
readability and shrink the output file size.
diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index c12820e..2ca184f 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -2206,7 +2206,10 @@ _emit_glyphs (cairo_scaled_font_t *font,
x = glyphs->x;
y = glyphs->y;
if (n < num_glyphs) { /* need full glyph range */
- fprintf (logfile, "[ %g %g [", x, y);
+ bool first;
+
+ fprintf (logfile, "[%g %g [", x, y);
+ first = true;
while (num_glyphs--) {
cairo_text_extents_t extents;
@@ -2215,10 +2218,14 @@ _emit_glyphs (cairo_scaled_font_t *font,
{
x = glyphs->x;
y = glyphs->y;
- fprintf (logfile, " ] %g %g [", x, y);
+ fprintf (logfile, "] %g %g [", x, y);
+ first = true;
}
- fprintf (logfile, " %lu", glyphs->index);
+ if (! first)
+ fprintf (logfile, " ");
+ fprintf (logfile, "%lu", glyphs->index);
+ first = false;
cairo_scaled_font_glyph_extents (font, glyphs, 1, &extents);
x += extents.x_advance;
@@ -2226,37 +2233,41 @@ _emit_glyphs (cairo_scaled_font_t *font,
glyphs++;
}
- fprintf (logfile, " ] ]");
+ fprintf (logfile, "]]");
} else {
struct _data_stream stream;
- fprintf (logfile, "[ %g %g <~", x, y);
- _write_base85_data_start (&stream);
- while (num_glyphs--) {
- cairo_text_extents_t extents;
- unsigned char c;
-
- if (fabs (glyphs->x - x) > TOLERANCE ||
- fabs (glyphs->y - y) > TOLERANCE)
- {
- x = glyphs->x;
- y = glyphs->y;
- _write_base85_data_end (&stream);
- fprintf (logfile, "~> %g %g <~", x, y);
- _write_base85_data_start (&stream);
- }
+ if (num_glyphs == 1) {
+ fprintf (logfile, "[%g %g <%x>]", x, y, glyphs->index);
+ } else {
+ fprintf (logfile, "[%g %g <~", x, y);
+ _write_base85_data_start (&stream);
+ while (num_glyphs--) {
+ cairo_text_extents_t extents;
+ unsigned char c;
+
+ if (fabs (glyphs->x - x) > TOLERANCE ||
+ fabs (glyphs->y - y) > TOLERANCE)
+ {
+ x = glyphs->x;
+ y = glyphs->y;
+ _write_base85_data_end (&stream);
+ fprintf (logfile, "~> %g %g <~", x, y);
+ _write_base85_data_start (&stream);
+ }
- c = glyphs->index;
- _write_base85_data (&stream, &c, 1);
+ c = glyphs->index;
+ _write_base85_data (&stream, &c, 1);
- cairo_scaled_font_glyph_extents (font, glyphs, 1, &extents);
- x += extents.x_advance;
- y += extents.y_advance;
+ cairo_scaled_font_glyph_extents (font, glyphs, 1, &extents);
+ x += extents.x_advance;
+ y += extents.y_advance;
- glyphs++;
+ glyphs++;
+ }
+ _write_base85_data_end (&stream);
+ fprintf (logfile, "~>]");
}
- _write_base85_data_end (&stream);
- fprintf (logfile, "~> ]");
}
}
More information about the cairo-commit
mailing list