/* Worker function used by both export_ps and export_eps */ static void export_postscript (gboolean is_eps) { cairo_surface_t *surface; cairo_rectangle_t extents; cairo_matrix_t mtx; cairo_t *cr; GList *iter; /* Create a surface. To begin with, we don't know the size. */ surface = cairo_ps_surface_create (settings.outfile, 1, 1); cairo_ps_surface_set_eps (surface, is_eps); cr = cairo_create (surface); g_object_set (renderer, "cairo-context", cr, NULL); for (iter = geda_list_get_glist (toplevel->pages); iter != NULL; iter = g_list_next (iter)) { PAGE *page = (PAGE *) iter->data; export_layout_page (page, &extents, &mtx); cairo_ps_surface_set_size (surface, extents.width, extents.height); cairo_set_matrix (cr, &mtx); export_draw_page (page); cairo_show_page (cr); } cairo_surface_finish (surface); export_cairo_check_error (cairo_surface_status (surface)); }
// cairo_public void // cairo_ps_surface_set_size (cairo_surface_t *surface, // double width_in_points, // double height_in_points); static int l_cairo_ps_surface_set_size(lua_State* L) { cairo_surface_t *surface = get_cairo_surface_t (L, 1); double width_in_points = luaL_checknumber(L, 2); double height_in_points = luaL_checknumber(L, 3); cairo_ps_surface_set_size (surface, width_in_points, height_in_points); return 0; }
IoObject *IoCairoPDFSurface_setSize(IoCairoPDFSurface *self, IoObject *locals, IoMessage *m) { double w = IoMessage_locals_doubleArgAt_(m, locals, 0); double h = IoMessage_locals_doubleArgAt_(m, locals, 1); cairo_ps_surface_set_size(SURFACE(self), w, h); CHECK_STATUS(self); return self; }
static PyObject * ps_surface_set_size (PycairoPSSurface *o, PyObject *args) { double width_in_points, height_in_points; if (!PyArg_ParseTuple(args, "dd:PSSurface.set_size", &width_in_points, &height_in_points)) return NULL; cairo_ps_surface_set_size (o->surface, width_in_points, height_in_points); Py_RETURN_NONE; }
static cairo_test_status_t preamble (cairo_test_context_t *ctx) { cairo_surface_t *surface; /* get the error surface */ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX); #if CAIRO_HAS_GL_SURFACE cairo_gl_surface_set_size (surface, 0, 0); cairo_gl_surface_swapbuffers (surface); #endif #if CAIRO_HAS_OS2_SURFACE cairo_os2_surface_set_hwnd (surface, 0); cairo_os2_surface_set_size (surface, 0, 0); cairo_os2_surface_set_manual_window_refresh (surface, FALSE); #endif #if CAIRO_HAS_PDF_SURFACE cairo_pdf_surface_restrict_to_version (surface, CAIRO_PDF_VERSION_1_4); cairo_pdf_surface_set_size (surface, 0, 0); #endif #if CAIRO_HAS_PS_SURFACE cairo_ps_surface_set_eps (surface, FALSE); cairo_ps_surface_set_size (surface, 0, 0); cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2); cairo_ps_surface_dsc_comment (surface, NULL); cairo_ps_surface_dsc_begin_setup (surface); cairo_ps_surface_dsc_begin_page_setup (surface); #endif #if CAIRO_HAS_XCB_SURFACE cairo_xcb_surface_set_size (surface, 0, 0); #endif #if CAIRO_HAS_XLIB_SURFACE cairo_xlib_surface_set_size (surface, 0, 0); cairo_xlib_surface_set_drawable (surface, 0, 0, 0); #endif cairo_surface_set_mime_data (surface, NULL, NULL, 0, NULL, 0); cairo_surface_set_device_offset (surface, 0, 0); cairo_surface_set_fallback_resolution (surface, 0, 0); cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; }
static void unix_start_page (GtkPrintOperation *op, GtkPrintContext *print_context, GtkPageSetup *page_setup) { GtkPrintOperationUnix *op_unix; GtkPaperSize *paper_size; cairo_surface_type_t type; gdouble w, h; op_unix = op->priv->platform_data; paper_size = gtk_page_setup_get_paper_size (page_setup); w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS); h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS); type = cairo_surface_get_type (op_unix->surface); if ((op->priv->manual_number_up < 2) || (op->priv->page_position % op->priv->manual_number_up == 0)) { if (type == CAIRO_SURFACE_TYPE_PS) { cairo_ps_surface_set_size (op_unix->surface, w, h); cairo_ps_surface_dsc_begin_page_setup (op_unix->surface); switch (gtk_page_setup_get_orientation (page_setup)) { case GTK_PAGE_ORIENTATION_PORTRAIT: case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: cairo_ps_surface_dsc_comment (op_unix->surface, "%%PageOrientation: Portrait"); break; case GTK_PAGE_ORIENTATION_LANDSCAPE: case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: cairo_ps_surface_dsc_comment (op_unix->surface, "%%PageOrientation: Landscape"); break; } } else if (type == CAIRO_SURFACE_TYPE_PDF) { if (!op->priv->manual_orientation) { w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS); h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS); } cairo_pdf_surface_set_size (op_unix->surface, w, h); } } }
static int surface_set_size (lua_State *L) { cairo_surface_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_SURFACE); cairo_surface_type_t type = cairo_surface_get_type(*obj); double width = luaL_checknumber(L, 2), height = luaL_checknumber(L, 3); #ifdef CAIRO_HAS_PDF_SURFACE if (type == CAIRO_SURFACE_TYPE_PDF) cairo_pdf_surface_set_size(*obj, width, height); #endif #if defined(CAIRO_HAS_PDF_SURFACE) && defined(CAIRO_HAS_PS_SURFACE) else #endif #ifdef CAIRO_HAS_PS_SURFACE if (type == CAIRO_SURFACE_TYPE_PS) cairo_ps_surface_set_size(*obj, width, height); #endif else return luaL_error(L, "method 'set_size' only works on PostScript and" " PDF surfaces"); return 0; }
static void unix_start_page (GtkPrintOperation *op, GtkPrintContext *print_context, GtkPageSetup *page_setup) { GtkPrintOperationUnix *op_unix; GtkPaperSize *paper_size; cairo_surface_type_t type; gdouble w, h; op_unix = op->priv->platform_data; paper_size = gtk_page_setup_get_paper_size (page_setup); w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS); h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS); type = cairo_surface_get_type (op_unix->surface); if (type == CAIRO_SURFACE_TYPE_PS) cairo_ps_surface_set_size (op_unix->surface, w, h); else if (type == CAIRO_SURFACE_TYPE_PDF) cairo_pdf_surface_set_size (op_unix->surface, w, h); }
void SurfaceEps::setSize( double widthInPoints, double heightInPoints ) { cairo_ps_surface_set_size( mCairoSurface, widthInPoints, heightInPoints ); }
static cairo_test_status_t test_cairo_ps_surface_set_size (cairo_surface_t *surface) { cairo_ps_surface_set_size (surface, 5, 5); return CAIRO_TEST_SUCCESS; }
int main (void) { cairo_test_context_t ctx; cairo_surface_t *surface; cairo_t *cr; cairo_status_t status; const char *filename; size_t i; char dsc[255]; cairo_test_init (&ctx, "ps-features"); if (! cairo_test_is_target_enabled (&ctx, "ps")) { cairo_test_fini (&ctx); return CAIRO_TEST_UNTESTED; } filename = "ps-features.ps"; /* 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); 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"); cr = cairo_create (surface); cairo_select_font_face (cr, "Bitstream Vera Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, TEXT_SIZE); for (i=0; i < ARRAY_SIZE(pages); i++) { cairo_ps_surface_set_size (surface, pages[i].width_in_points, pages[i].height_in_points); 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); } 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) { cairo_test_log (&ctx, "Failed to create ps surface for file %s: %s\n", filename, cairo_status_to_string (status)); return CAIRO_TEST_FAILURE; } printf ("ps-features: Please check %s to ensure it looks/prints correctly.\n", filename); cairo_test_fini (&ctx); return CAIRO_TEST_SUCCESS; }