2006-05-02 12:36:23 -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>
|
|
|
|
|
*/
|
|
|
|
|
|
2015-02-26 15:03:43 +01:00
|
|
|
#include "cairo-test.h"
|
|
|
|
|
|
2006-05-02 12:36:23 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <cairo.h>
|
|
|
|
|
#include <cairo-ps.h>
|
|
|
|
|
|
|
|
|
|
/* This test exists to test the various features of cairo-ps.h.
|
|
|
|
|
*
|
|
|
|
|
* Currently, this test exercises the following function calls:
|
|
|
|
|
*
|
|
|
|
|
* cairo_ps_surface_set_size
|
2006-05-03 12:38:49 -07:00
|
|
|
* cairo_ps_surface_dsc_comment
|
|
|
|
|
* cairo_ps_surface_dsc_begin_setup
|
|
|
|
|
* cairo_ps_surface_dsc_begin_page_setup
|
2006-05-02 12:36:23 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define INCHES_TO_POINTS(in) ((in) * 72.0)
|
|
|
|
|
#define MM_TO_POINTS(mm) ((mm) / 25.4 * 72.0)
|
|
|
|
|
#define TEXT_SIZE 12
|
2013-09-08 20:10:03 +00:00
|
|
|
#define BASENAME "ps-features.out"
|
2006-05-02 12:36:23 -07:00
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
static struct {
|
2006-05-02 12:36:23 -07:00
|
|
|
const char *page_size;
|
2006-05-03 00:26:22 -07:00
|
|
|
const char *page_size_alias;
|
2006-05-02 12:36:23 -07:00
|
|
|
const char *orientation;
|
|
|
|
|
double width_in_points;
|
|
|
|
|
double height_in_points;
|
|
|
|
|
} pages[] = {
|
2006-05-03 00:26:22 -07:00
|
|
|
{"na_letter_8.5x11in", "letter", "portrait",
|
2006-05-02 12:36:23 -07:00
|
|
|
INCHES_TO_POINTS(8.5), INCHES_TO_POINTS(11)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"na_letter_8.5x11in", "letter", "landscape",
|
2006-05-02 12:36:23 -07:00
|
|
|
INCHES_TO_POINTS(11), INCHES_TO_POINTS(8.5)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a4_210x297mm", "a4", "portrait",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(210), MM_TO_POINTS(297)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a4_210x297mm", "a4", "landscape",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(297), MM_TO_POINTS(210)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a5_148x210mm", "a5", "portrait",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(148), MM_TO_POINTS(210)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a5_148x210mm", "a5", "landscape",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(210), MM_TO_POINTS(148)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a6_105x148mm", "a6", "portrait",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(105), MM_TO_POINTS(148)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a6_105x148mm", "a6", "landscape",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(148), MM_TO_POINTS(105)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a7_74x105mm", "a7", "portrait",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(74), MM_TO_POINTS(105)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a7_74x105mm", "a7", "landscape",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(105), MM_TO_POINTS(74)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a8_52x74mm", "a8", "portrait",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(52), MM_TO_POINTS(74)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a8_52x74mm", "a8", "landscape",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(74), MM_TO_POINTS(52)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a9_37x52mm", "a9", "portrait",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(37), MM_TO_POINTS(52)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a9_37x52mm", "a9", "landscape",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(52), MM_TO_POINTS(37)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a10_26x37mm", "a10", "portrait",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(26), MM_TO_POINTS(37)},
|
2006-05-03 00:26:22 -07:00
|
|
|
{"iso_a10_26x37mm", "a10", "landscape",
|
2006-05-02 12:36:23 -07:00
|
|
|
MM_TO_POINTS(37), MM_TO_POINTS(26)}
|
|
|
|
|
};
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
static cairo_test_status_t
|
|
|
|
|
preamble (cairo_test_context_t *ctx)
|
2006-05-02 12:36:23 -07:00
|
|
|
{
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
cairo_t *cr;
|
|
|
|
|
cairo_status_t status;
|
2006-08-08 01:16:49 -07:00
|
|
|
size_t i;
|
2006-05-03 00:26:22 -07:00
|
|
|
char dsc[255];
|
2013-09-08 20:10:03 +00:00
|
|
|
char *filename;
|
|
|
|
|
const char *path = cairo_test_mkdir (CAIRO_TEST_OUTPUT_DIR) ? CAIRO_TEST_OUTPUT_DIR : ".";
|
2006-05-02 12:36:23 -07:00
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
if (! (cairo_test_is_target_enabled (ctx, "ps2") ||
|
|
|
|
|
cairo_test_is_target_enabled (ctx, "ps3")))
|
2008-09-27 21:53:21 +01:00
|
|
|
{
|
2008-01-10 13:04:52 +00:00
|
|
|
return CAIRO_TEST_UNTESTED;
|
|
|
|
|
}
|
2006-05-02 12:36:23 -07:00
|
|
|
|
2013-09-08 20:10:03 +00:00
|
|
|
xasprintf (&filename, "%s/%s.ps", path, BASENAME);
|
2006-05-02 12:36:23 -07:00
|
|
|
/* We demonstrate that the initial size doesn't matter (we're
|
|
|
|
|
* passing 0,0), if we use cairo_ps_surface_set_size on the first
|
|
|
|
|
* page. */
|
|
|
|
|
surface = cairo_ps_surface_create (filename, 0, 0);
|
|
|
|
|
|
2006-05-03 00:26:22 -07:00
|
|
|
cairo_ps_surface_dsc_comment (surface, "%%Title: ps-features");
|
|
|
|
|
cairo_ps_surface_dsc_comment (surface, "%%Copyright: Copyright (C) 2006 Red Hat, Inc.");
|
|
|
|
|
|
|
|
|
|
cairo_ps_surface_dsc_begin_setup (surface);
|
|
|
|
|
cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize letter");
|
|
|
|
|
cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor White");
|
|
|
|
|
|
2006-05-02 12:36:23 -07:00
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
|
2010-06-12 16:20:37 +02:00
|
|
|
cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
|
2006-05-02 12:36:23 -07:00
|
|
|
CAIRO_FONT_SLANT_NORMAL,
|
|
|
|
|
CAIRO_FONT_WEIGHT_NORMAL);
|
|
|
|
|
cairo_set_font_size (cr, TEXT_SIZE);
|
|
|
|
|
|
2011-03-16 16:48:18 +01:00
|
|
|
for (i = 0; i < ARRAY_LENGTH (pages); i++) {
|
2006-05-02 12:36:23 -07:00
|
|
|
cairo_ps_surface_set_size (surface,
|
|
|
|
|
pages[i].width_in_points,
|
|
|
|
|
pages[i].height_in_points);
|
2006-05-03 00:26:22 -07:00
|
|
|
cairo_ps_surface_dsc_begin_page_setup (surface);
|
|
|
|
|
snprintf (dsc, 255, "%%IncludeFeature: *PageSize %s", pages[i].page_size_alias);
|
|
|
|
|
cairo_ps_surface_dsc_comment (surface, dsc);
|
|
|
|
|
if (i % 2) {
|
|
|
|
|
snprintf (dsc, 255, "%%IncludeFeature: *MediaType Glossy");
|
|
|
|
|
cairo_ps_surface_dsc_comment (surface, dsc);
|
|
|
|
|
}
|
2006-06-06 15:25:49 -07:00
|
|
|
|
2006-05-02 12:36:23 -07:00
|
|
|
cairo_move_to (cr, TEXT_SIZE, TEXT_SIZE);
|
|
|
|
|
cairo_show_text (cr, pages[i].page_size);
|
|
|
|
|
cairo_show_text (cr, " - ");
|
|
|
|
|
cairo_show_text (cr, pages[i].orientation);
|
|
|
|
|
cairo_show_page (cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = cairo_status (cr);
|
|
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
|
|
if (status) {
|
2008-09-03 16:38:03 +01:00
|
|
|
cairo_test_log (ctx, "Failed to create ps surface for file %s: %s\n",
|
2006-05-02 12:36:23 -07:00
|
|
|
filename, cairo_status_to_string (status));
|
2013-09-08 20:10:03 +00:00
|
|
|
free (filename);
|
2006-05-02 12:36:23 -07:00
|
|
|
return CAIRO_TEST_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-03 00:26:22 -07:00
|
|
|
printf ("ps-features: Please check %s to ensure it looks/prints correctly.\n", filename);
|
2013-09-08 20:10:03 +00:00
|
|
|
free (filename);
|
2006-05-02 12:36:23 -07:00
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
2008-09-03 16:38:03 +01:00
|
|
|
|
|
|
|
|
CAIRO_TEST (ps_features,
|
|
|
|
|
"Check PS specific API",
|
|
|
|
|
"ps, api", /* keywords */
|
|
|
|
|
NULL, /* requirements */
|
|
|
|
|
0, 0,
|
|
|
|
|
preamble, NULL)
|