2006-05-24 14:03:49 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2006 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
* appear in supporting documentation, and that the name of
|
|
|
|
|
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
* permission. Red Hat, Inc. makes no representations about the
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
|
|
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Author: Carl D. Worth <cworth@cworth.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <cairo.h>
|
2006-06-10 09:15:31 -07:00
|
|
|
|
2006-05-24 14:03:49 -07:00
|
|
|
#include <cairo-pdf.h>
|
2007-04-21 02:50:53 -04:00
|
|
|
#include <cairo-boilerplate-pdf.h>
|
2006-05-24 14:03:49 -07:00
|
|
|
|
2006-06-10 09:15:31 -07:00
|
|
|
#include <cairo-ps.h>
|
2007-04-20 03:33:58 -04:00
|
|
|
#include <cairo-boilerplate-ps.h>
|
2006-06-10 09:15:31 -07:00
|
|
|
|
|
|
|
|
#include <cairo-svg.h>
|
2007-04-21 03:08:26 -04:00
|
|
|
#include <cairo-boilerplate-svg.h>
|
2006-06-10 09:15:31 -07:00
|
|
|
|
2006-05-24 14:03:49 -07:00
|
|
|
#include "cairo-test.h"
|
|
|
|
|
|
|
|
|
|
/* This test exists to test cairo_surface_set_fallback_resolution
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define INCHES_TO_POINTS(in) ((in) * 72.0)
|
|
|
|
|
#define SIZE INCHES_TO_POINTS(1)
|
|
|
|
|
|
2006-06-10 08:21:18 -07:00
|
|
|
static void
|
2006-07-11 22:19:39 -04:00
|
|
|
draw_with_ppi (cairo_t *cr, double width, double height, double ppi)
|
2006-06-10 08:21:18 -07:00
|
|
|
{
|
|
|
|
|
char message[80];
|
2006-08-14 21:34:03 -04:00
|
|
|
cairo_text_extents_t extents;
|
2006-06-10 08:21:18 -07:00
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
|
|
cairo_new_path (cr);
|
|
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, .05 * SIZE / 2.0);
|
|
|
|
|
cairo_arc (cr, SIZE / 2.0, SIZE / 2.0,
|
|
|
|
|
0.75 * SIZE / 2.0,
|
|
|
|
|
0, 2.0 * M_PI);
|
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
|
|
cairo_arc (cr, SIZE / 2.0, SIZE / 2.0,
|
|
|
|
|
0.6 * SIZE / 2.0,
|
|
|
|
|
0, 2.0 * M_PI);
|
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
|
|
sprintf (message, "Fallback PPI: %g", ppi);
|
|
|
|
|
cairo_set_source_rgb (cr, 1, 1, 1); /* white */
|
|
|
|
|
cairo_set_font_size (cr, .1 * SIZE / 2.0);
|
2006-08-14 21:34:03 -04:00
|
|
|
cairo_text_extents (cr, message, &extents);
|
|
|
|
|
cairo_move_to (cr, (SIZE-extents.width)/2.0-extents.x_bearing,
|
|
|
|
|
(SIZE-extents.height)/2.0-extents.y_bearing);
|
2006-06-10 08:21:18 -07:00
|
|
|
cairo_show_text (cr, message);
|
|
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 09:15:31 -07:00
|
|
|
#define NUM_BACKENDS 3
|
|
|
|
|
typedef enum {
|
|
|
|
|
PDF, PS, SVG
|
|
|
|
|
} backend_t;
|
|
|
|
|
static const char *backend_filename[NUM_BACKENDS] = {
|
|
|
|
|
"fallback-resolution.pdf",
|
|
|
|
|
"fallback-resolution.ps",
|
|
|
|
|
"fallback-resolution.svg"
|
|
|
|
|
};
|
|
|
|
|
|
2006-05-24 14:03:49 -07:00
|
|
|
int
|
|
|
|
|
main (void)
|
|
|
|
|
{
|
2006-08-08 01:16:49 -07:00
|
|
|
cairo_surface_t *surface = NULL;
|
2006-05-24 14:03:49 -07:00
|
|
|
cairo_t *cr;
|
|
|
|
|
cairo_status_t status;
|
2007-05-08 20:25:21 +01:00
|
|
|
cairo_test_status_t ret = CAIRO_TEST_SUCCESS;
|
2006-06-10 08:21:18 -07:00
|
|
|
double ppi[] = { 600., 300., 150., 75., 37.5 };
|
2006-06-10 09:15:31 -07:00
|
|
|
backend_t backend;
|
|
|
|
|
int page, num_pages;
|
2006-05-24 14:03:49 -07:00
|
|
|
|
2006-06-10 09:15:31 -07:00
|
|
|
num_pages = sizeof (ppi) / sizeof (ppi[0]);
|
2006-05-24 14:03:49 -07:00
|
|
|
|
2006-07-11 22:19:39 -04:00
|
|
|
cairo_test_init ("fallback-resolution");
|
2006-05-24 14:03:49 -07:00
|
|
|
|
2006-06-10 09:15:31 -07:00
|
|
|
for (backend=0; backend < NUM_BACKENDS; backend++) {
|
|
|
|
|
|
|
|
|
|
/* Create backend-specific surface and force image fallbacks. */
|
|
|
|
|
switch (backend) {
|
|
|
|
|
case PDF:
|
|
|
|
|
surface = cairo_pdf_surface_create (backend_filename[backend],
|
|
|
|
|
SIZE, SIZE);
|
2007-04-21 02:50:53 -04:00
|
|
|
cairo_boilerplate_pdf_surface_force_fallbacks (surface);
|
2006-06-10 09:15:31 -07:00
|
|
|
break;
|
|
|
|
|
case PS:
|
|
|
|
|
surface = cairo_ps_surface_create (backend_filename[backend],
|
|
|
|
|
SIZE, SIZE);
|
2007-04-20 03:33:58 -04:00
|
|
|
cairo_boilerplate_ps_surface_force_fallbacks (surface);
|
2006-06-10 09:15:31 -07:00
|
|
|
break;
|
|
|
|
|
case SVG:
|
|
|
|
|
surface = cairo_svg_surface_create (backend_filename[backend],
|
2006-11-12 20:45:50 +01:00
|
|
|
SIZE, SIZE);
|
2007-04-21 03:08:26 -04:00
|
|
|
cairo_boilerplate_svg_surface_force_fallbacks (surface);
|
2006-11-12 20:45:50 +01:00
|
|
|
cairo_svg_surface_restrict_to_version (surface, CAIRO_SVG_VERSION_1_2);
|
2006-06-10 09:15:31 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
|
|
|
|
|
for (page = 0; page < num_pages; page++)
|
|
|
|
|
{
|
|
|
|
|
cairo_surface_set_fallback_resolution (surface, ppi[page], ppi[page]);
|
|
|
|
|
|
2006-07-11 22:19:39 -04:00
|
|
|
draw_with_ppi (cr, SIZE, SIZE, ppi[page]);
|
2006-06-10 09:15:31 -07:00
|
|
|
|
2006-11-12 20:45:50 +01:00
|
|
|
cairo_show_page (cr);
|
2006-06-10 09:15:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = cairo_status (cr);
|
|
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_test_log ("Failed to create pdf surface for file %s: %s\n",
|
|
|
|
|
backend_filename[backend],
|
|
|
|
|
cairo_status_to_string (status));
|
2007-05-08 20:25:21 +01:00
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
break;
|
2006-06-10 09:15:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("fallback-resolution: Please check %s to ensure it looks correct.\n",
|
|
|
|
|
backend_filename[backend]);
|
2006-05-24 14:03:49 -07:00
|
|
|
}
|
|
|
|
|
|
2007-03-02 12:30:14 -08:00
|
|
|
cairo_test_fini ();
|
|
|
|
|
|
2007-05-08 20:25:21 +01:00
|
|
|
return ret;
|
2006-05-24 14:03:49 -07:00
|
|
|
}
|