[cairo-commit] svgslides/src svgslides-output.c,1.3,1.4

Keith Packard commit at pdx.freedesktop.org
Thu May 26 23:53:43 PDT 2005


Committed by: keithp

Update of /cvs/cairo/svgslides/src
In directory gabe:/tmp/cvs-serv7021/src

Modified Files:
	svgslides-output.c 
Log Message:
2005-05-26  Keith Packard  <keithp at keithp.com>

	* src/svgslides-output.c: (svgslides_document_output_pdf):
	Update to new API.
	Set fixed margin of 1/2".  Scale each slide to fit
	within the margin while preserving the aspect ratio.


Index: svgslides-output.c
===================================================================
RCS file: /cvs/cairo/svgslides/src/svgslides-output.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- svgslides-output.c	18 Apr 2005 00:07:08 -0000	1.3
+++ svgslides-output.c	27 May 2005 06:53:41 -0000	1.4
@@ -134,6 +134,12 @@
     return NULL;
 }
 
+#define PDF_PAGE_WIDTH_POINTS   (11.0 * 72)
+#define PDF_PAGE_HEIGHT_POINTS  (8.5 * 72)
+#define MARGIN			(0.5 * 72)
+#define PDF_DRAW_WIDTH_POINTS	(PDF_PAGE_WIDTH_POINTS - MARGIN*2)
+#define PDF_DRAW_HEIGHT_POINTS	(PDF_PAGE_HEIGHT_POINTS - MARGIN*2)
+
 static void
 svgslides_document_output_pdf (SVGSlidesDocument *document,
 			       const char *filename)
@@ -142,11 +148,14 @@
     cairo_t *cr;
     SVGSlidesSlide *slide;
     int i, width, height;
+    cairo_surface_t *surface;
+    double scale_x, scale_y, scale;
 
-    file = fopen (filename, "w");
-    cr = cairo_create ();
-
-    cairo_set_target_pdf (cr, file, 11, 8.5, 300, 300);
+    surface = cairo_pdf_surface_create (filename, 
+					PDF_PAGE_WIDTH_POINTS,
+					PDF_PAGE_HEIGHT_POINTS);
+    cr = cairo_create (surface);
+    cairo_surface_destroy (surface);
 
     for (i = 0; i < document->slides->len; i++) {
 	slide = g_ptr_array_index (document->slides, i);
@@ -154,14 +163,22 @@
 	printf ("slide %d, \"%s\"\n", i, slide->title);
 
 	svg_cairo_get_size (slide->svg, &width, &height);
-
+	cairo_save (cr);
+	scale_x = PDF_DRAW_WIDTH_POINTS / (double) width;
+	scale_y = PDF_DRAW_HEIGHT_POINTS / (double) height;
+	if (scale_x < scale_y)
+	    scale = scale_x;
+	else
+	    scale = scale_y;
+	cairo_translate (cr, MARGIN, MARGIN);
+	cairo_scale (cr, scale, scale);
 	svg_cairo_render (slide->svg, cr);
+	cairo_restore (cr);
 
 	cairo_show_page (cr);
     }
 
     cairo_destroy (cr); 
-    fclose (file);
 }
 
 int




More information about the cairo-commit mailing list