static PyObject * pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { double width_in_points, height_in_points; PyObject *file, *writer; if (!PyArg_ParseTuple(args, "Odd:PDFSurface.__new__", &file, &width_in_points, &height_in_points)) return NULL; if (PyObject_TypeCheck (file, &PyBaseString_Type)) { /* string (filename) argument */ return PycairoSurface_FromSurface ( cairo_pdf_surface_create (PyString_AsString(file), width_in_points, height_in_points), NULL); } /* file or file-like object argument */ writer = PyObject_GetAttrString (file, "write"); if (writer == NULL || !PyCallable_Check (writer)) { Py_XDECREF(writer); PyErr_SetString(PyExc_TypeError, "PDFSurface argument 1 must be a filename (str), file object, or an object " "that has a \"write\" method (like StringIO)"); return NULL; } Py_DECREF(writer); return PycairoSurface_FromSurface ( cairo_pdf_surface_create_for_stream (_write_func, file, width_in_points, height_in_points), file); }
static PyObject * pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { const char *filename; double width_in_points, height_in_points; cairo_surface_t *surface; PyObject *o; if (!PyArg_ParseTuple(args, "sdd:PDFSurface.__new__", &filename, &width_in_points, &height_in_points)) return NULL; o = type->tp_alloc(type, 0); if (o) { surface = cairo_pdf_surface_create (filename, width_in_points, height_in_points); if (Pycairo_Check_Status (cairo_surface_status (surface))) { cairo_surface_destroy (surface); Py_DECREF(o); return NULL; } ((PycairoPDFSurface *)o)->surface = surface; } return o; }
static void export_pdf (void) { 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_pdf_surface_create (settings.outfile, 1, 1); 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_pdf_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)); }
int svg2pdf(const char *svg_filename, const char *pdf_filename) { RsvgHandle *svg_handle; RsvgDimensionData dimension_data; cairo_surface_t *surface; cairo_t *cr; rsvg_set_default_dpi(72.0); svg_handle = rsvg_handle_new_from_file(svg_filename, NULL); if(svg_handle == NULL) { return 0; } rsvg_handle_set_dpi(svg_handle, 72.0); rsvg_handle_get_dimensions(svg_handle, &dimension_data); surface = cairo_pdf_surface_create(pdf_filename, dimension_data.width, dimension_data.height); if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { return 0; } cr = cairo_create(surface); if(cairo_status(cr) != CAIRO_STATUS_SUCCESS) { return 0; } if(!rsvg_handle_render_cairo(svg_handle, cr)) { return 0; } cairo_show_page(cr); cairo_surface_destroy(surface); cairo_destroy(cr); g_object_unref(svg_handle); return 1; }
void init_pdf (char *outname) { surface = cairo_pdf_surface_create(outname, PAPER_WIDTH, PAPER_HEIGHT); cr = cairo_create(surface); layout = pango_cairo_create_layout (cr); }
int main (int argc, char **argv) { char *CodUsuario; char *sql; program = argv [0]; TamanhoFonte = 8.0; // padrao LarguraPagina = WIDTH_POINTS; AlturaPagina = HEIGHT_POINTS; program = argv [0]; if (argc != 2) usage (); sql = argv [1]; if ((CodUsuario = getenv ("XMONEY_UID")) == NULL) { printf ("$XMONEY_UID not set!\n"); exit (1); } printf ("XMONEY_UID = %s\n", CodUsuario); char *filename = g_strdup_printf ("/var/spool/xmoney/%s.pdf", CodUsuario); cairo_surface_t *surface = cairo_pdf_surface_create (filename, LarguraPagina, AlturaPagina); cairo_t *cr = cairo_create (surface); impressao_geral (cr, sql); cairo_surface_destroy (surface); cairo_destroy (cr); g_free (filename); return 0; }
void TreeNode::draw() const { std::ofstream ofs(NODE_FILENAME); cairo_t *cr; cairo_surface_t *surface; CGAL::Bbox_2 bbox = region.bbox(); assert(bbox.xmin() >= 0.0); assert(bbox.ymin() >= 0.0); #ifdef PDF_OUTPUT surface = cairo_pdf_surface_create(IMG_FILENAME, bbox.xmax(), bbox.ymax()); #endif #ifdef PNG_OUTPUT surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bbox.xmax(), bbox.ymax()); #endif cr = cairo_create(surface); cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 10.0); draw_region(cr); draw_text(cr); write_centroid(ofs); cairo_show_page(cr); cairo_destroy(cr); #ifdef PNG_OUTPUT cairo_surface_write_to_png(surface, IMG_FILENAME); #endif cairo_surface_destroy(surface); }
int main(void) { cairo_surface_t *surface; cairo_t *cr; surface = cairo_pdf_surface_create("pdffile.pdf", 504, 648); cr = cairo_create(surface); cairo_set_source_rgb(cr, 0, 0, 0); cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, 40.0); cairo_move_to(cr, 100.0, 300.0); cairo_show_text(cr, "Disziplin ist Macht."); cairo_show_page(cr); cairo_pdf_surface_set_size(surface, 500, 500); cairo_set_font_size (cr, 14.0); cairo_move_to(cr, 110.0, 300.0); cairo_show_text(cr, "Disziplin ist Macht."); cairo_show_page(cr); cairo_surface_destroy(surface); cairo_destroy(cr); return 0; }
int conv_pdf (RioData *data, const char *filename) { int status; /* Determine original image height & width */ uint32_t height, width; status = rio_data_get_metadata_uint32 (data, RIO_KEY_IMAGE_ROWS, &height) && rio_data_get_metadata_uint32 (data, RIO_KEY_IMAGE_COLS, &width); if (!status) { fprintf (stderr, "ERROR: Could not determine image dimensions.\n"); return 0; } /* Create output surface */ cairo_surface_t *pdf = cairo_pdf_surface_create (filename, width, height); if (cairo_surface_status (pdf) != CAIRO_STATUS_SUCCESS) { fprintf (stderr, "ERROR: Could not create PDF surface for %s: %s\n", filename, cairo_status_to_string (cairo_surface_status (pdf))); return 0; } /* FIXME naively assumes that all will be fine from now on. */ svg_draw (data, pdf); cairo_surface_finish (pdf); return 1; }
static void generate_reference (double ppi_x, double ppi_y, const char *filename) { cairo_surface_t *surface, *target; cairo_t *cr; cairo_status_t status; surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE*ppi_x/72, SIZE*ppi_y/72); cr = cairo_create (surface); cairo_surface_destroy (surface); /* As we wish to mimic a PDF surface, copy across the default font options * from the PDF backend. */ { cairo_surface_t *pdf; cairo_font_options_t *options; options = cairo_font_options_create (); pdf = cairo_pdf_surface_create ("tmp.pdf", 1, 1); cairo_surface_get_font_options (pdf, options); cairo_surface_destroy (pdf); cairo_set_font_options (cr, options); cairo_font_options_destroy (options); } #if SET_TOLERANCE cairo_set_tolerance (cr, 3.0); #endif cairo_save (cr); { cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); } cairo_restore (cr); cairo_scale (cr, ppi_x/72., ppi_y/72.); draw (cr, SIZE, SIZE); surface = cairo_surface_reference (cairo_get_target (cr)); cairo_destroy (cr); target = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE, SIZE); cr = cairo_create (target); cairo_scale (cr, 72./ppi_x, 72./ppi_y); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); status = cairo_surface_write_to_png (cairo_get_target (cr), filename); cairo_destroy (cr); if (status) { fprintf (stderr, "Failed to generate reference image '%s': %s\n", filename, cairo_status_to_string (status)); exit (1); } }
IoObject *IoCairoPDFSurface_create(IoCairoPDFSurface *self, IoObject *locals, IoMessage *m) { char *filename = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)); double w = IoMessage_locals_doubleArgAt_(m, locals, 1); double h = IoMessage_locals_doubleArgAt_(m, locals, 2); return IoCairoSurface_newWithRawSurface_(IOSTATE, m, cairo_pdf_surface_create(filename, w, h)); }
cairo_surface_t * _cairo_boilerplate_pdf_create_surface (const char *name, cairo_content_t content, int width, int height, int max_width, int max_height, cairo_boilerplate_mode_t mode, int id, void **closure) { pdf_target_closure_t *ptc; cairo_surface_t *surface; cairo_status_t status; /* Sanitize back to a real cairo_content_t value. */ if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED) content = CAIRO_CONTENT_COLOR_ALPHA; *closure = ptc = xmalloc (sizeof (pdf_target_closure_t)); ptc->width = width; ptc->height = height; xasprintf (&ptc->filename, "%s-out.pdf", name); xunlink (ptc->filename); surface = cairo_pdf_surface_create (ptc->filename, width, height); if (cairo_surface_status (surface)) goto CLEANUP_FILENAME; cairo_surface_set_fallback_resolution (surface, 72., 72.); if (content == CAIRO_CONTENT_COLOR) { ptc->target = surface; surface = cairo_surface_create_similar (ptc->target, CAIRO_CONTENT_COLOR, width, height); if (cairo_surface_status (surface)) goto CLEANUP_TARGET; } else { ptc->target = NULL; } status = cairo_surface_set_user_data (surface, &pdf_closure_key, ptc, NULL); if (status == CAIRO_STATUS_SUCCESS) return surface; cairo_surface_destroy (surface); surface = cairo_boilerplate_surface_create_in_error (status); CLEANUP_TARGET: cairo_surface_destroy (ptc->target); CLEANUP_FILENAME: free (ptc->filename); free (ptc); return surface; }
static cairo_test_status_t preamble (cairo_test_context_t *ctx) { cairo_surface_t *surface; cairo_t *cr; cairo_status_t status; size_t i; char *filename; const char *path = cairo_test_mkdir (CAIRO_TEST_OUTPUT_DIR) ? CAIRO_TEST_OUTPUT_DIR : "."; if (! cairo_test_is_target_enabled (ctx, "pdf")) return CAIRO_TEST_UNTESTED; xasprintf (&filename, "%s/%s.pdf", path, BASENAME); /* The initial size passed here is the default size that will be * inheritable by each page. That is, any page for which this * initial size applies will not have its own /MediaBox entry in * its dictionary. */ surface = cairo_pdf_surface_create (filename, INCHES_TO_POINTS(8.5), INCHES_TO_POINTS(11)); cr = cairo_create (surface); cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, TEXT_SIZE); for (i = 0; i < ARRAY_LENGTH (pages); i++) { cairo_pdf_surface_set_size (surface, pages[i].width_in_points, pages[i].height_in_points); 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); free (filename); if (status) { cairo_test_log (ctx, "Failed to create pdf surface for file %s: %s\n", filename, cairo_status_to_string (status)); return CAIRO_TEST_FAILURE; } printf ("pdf-features: Please check %s to ensure it looks/prints correctly.\n", filename); return CAIRO_TEST_SUCCESS; }
int edit_fac() { int nlu,temwh,i,temet; width = 0; height=0; nbpol =0; temwh = 0; temet = 0; ydeb=0; dy=0; nuli=0; for ( i=0; i < CSFnco; ++i) parlf[i].y = 0; while ( (nlu=lect_fis()) > 0 ) { if ( strncmp(ze, "PAGSUIV",7) == 0) break; if ( ze[0] == '#') { nmot = isolmot(ze,nlu); memopol(); continue; } else if ( ze[0] == '$') { nmot = isolmot(ze,nlu); temet = entete(); continue; } // param lu active cairo if (temwh == 0 && width != 0 && height != 0) { surface = cairo_pdf_surface_create(nomfic, width,height); status = cairo_surface_status(surface); if (!surface || status!=CAIRO_STATUS_SUCCESS) { // printf("erreur cairo fic pdf\n"); message(25); return -1; } cr = cairo_create(surface); if ( temet == 1) { // active en tete cairo_save(cr); //cairo_scale(cr, 1./dpp, 1./dpp); pattern = cairo_pattern_create_for_surface(etsurf); cairo_translate(cr,0,0); cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST); cairo_set_source(cr,pattern); cairo_paint(cr); cairo_restore(cr); } cairo_set_source_rgb(cr, 0, 0, 0); temwh = 1; } if (temwh == 0) continue; // cr,surface non crees // ou erreur ligne avant creation cairo systematique 1er lig windows fic txt nmot = isolmot(ze,nlu); interp(); } // fin boucle lect fgets if (temwh == 0) return -1; // cr, surface non crees for ( i=0; i < CSFnco; ++i) { if (parlf[i].y == 1) { i=-1; break; } // y a-t-il des cde lignes ? } if ( i == -1) implf(); // imprim lignes details cairo_destroy(cr); cairo_surface_destroy(surface); return 0; }
static void glide_window_export_pdf_real (GlideWindow *w, const gchar *filename) { cairo_surface_t *pdf_surface; cairo_t *cr; gint width, height; gint o_slide; int i = 0; glide_window_fullscreen_stage (w); while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE); width = clutter_actor_get_width (w->priv->stage); height = clutter_actor_get_height (w->priv->stage); pdf_surface = cairo_pdf_surface_create (filename, width, height); cr = cairo_create (pdf_surface); o_slide = glide_stage_manager_get_current_slide (w->priv->manager); for (i = 0; i < glide_document_get_n_slides (w->priv->document); i++) { guchar *pixels; guchar *p; GdkPixbuf *pb; glide_stage_manager_set_current_slide (w->priv->manager, i); pixels = clutter_stage_read_pixels (CLUTTER_STAGE (w->priv->stage), 0, 0, width, height); for (p = pixels + width * height * 4; p > pixels; p -= 3) *(--p) = 255; pb = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, width, height, width * 4, (GdkPixbufDestroyNotify) g_free, NULL); gdk_cairo_set_source_pixbuf (cr, pb, 0, 0); cairo_rectangle (cr, 0, 0, width, height); cairo_fill (cr); cairo_surface_show_page (pdf_surface); g_object_unref (G_OBJECT (pb)); } cairo_surface_flush (pdf_surface); cairo_destroy (cr); cairo_surface_destroy (pdf_surface); glide_window_unfullscreen_stage (w); glide_stage_manager_set_current_slide (w->priv->manager, o_slide); }
void ofCairoRenderer::setup(string _filename, Type _type, bool multiPage_, bool b3D_, ofRectangle _viewport){ if( _viewport.width == 0 || _viewport.height == 0 ){ _viewport.set(0, 0, ofGetWidth(), ofGetHeight()); } filename = _filename; type = _type; streamBuffer.clear(); if(type == FROM_FILE_EXTENSION){ string ext = ofFilePath::getFileExt(filename); if(ofToLower(ext)=="svg"){ type = SVG; }else if(ofToLower(ext)=="pdf"){ type = PDF; }else{ // default to image type = IMAGE; } } switch(type){ case PDF: if(filename==""){ surface = cairo_pdf_surface_create_for_stream(&ofCairoRenderer::stream_function,this,_viewport.width, _viewport.height); }else{ surface = cairo_pdf_surface_create(ofToDataPath(filename).c_str(),_viewport.width, _viewport.height); } break; case SVG: if(filename==""){ surface = cairo_svg_surface_create_for_stream(&ofCairoRenderer::stream_function,this,_viewport.width, _viewport.height); }else{ surface = cairo_svg_surface_create(ofToDataPath(filename).c_str(),_viewport.width, _viewport.height); } break; case IMAGE: imageBuffer.allocate(_viewport.width, _viewport.height, 4); surface = cairo_image_surface_create_for_data(imageBuffer.getPixels(),CAIRO_FORMAT_ARGB32,_viewport.width, _viewport.height,_viewport.width*4); break; case FROM_FILE_EXTENSION: ofLogFatalError("ofCairoRenderer") << "Type not determined from file extension!"; break; default: ofLogError("ofCairoRenderer") << "Unknown type encountered!"; break; } cr = cairo_create(surface); cairo_set_antialias(cr,CAIRO_ANTIALIAS_SUBPIXEL); viewportRect = _viewport; viewport(viewportRect); page = 0; b3D = b3D_; multiPage = multiPage_; setStyle(ofGetStyle()); }
static cairo_surface_t * create_source_surface (int size) { cairo_surface_t *surface; surface = cairo_pdf_surface_create ("pdf-surface-source.out.pdf", size, size); cairo_surface_set_fallback_resolution (surface, 72., 72.); return surface; }
Drawer * DrawerInit(int width, int height, char fileTypePDF, const char * filePath) { Drawer * self = malloc(sizeof(Drawer)); if(fileTypePDF) { self->surface = cairo_pdf_surface_create(filePath, width, height); } else { self->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); } self->context = cairo_create(self->surface); return self; }
void dv_export_all_viewports() { double w, h; dv_export_viewports_get_size_r(DVG->VP, &w, &h); cairo_surface_t * surface; cairo_t * cr; /* PNG */ surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); dv_export_viewports_to_img_r(DVG->VP, surface, 0.0, 0.0); cairo_surface_write_to_png(surface, "00dv.png"); fprintf(stdout, "Exported all viewports to 00dv.png\n"); cairo_surface_destroy(surface); GdkRGBA white[1]; gdk_rgba_parse(white, "white"); /* EPS */ /* surface = cairo_ps_surface_create("00dv.eps", w, h); cairo_ps_surface_set_eps(surface, TRUE); cr = cairo_create(surface); // Whiten background cairo_set_source_rgba(cr, white->red, white->green, white->blue, white->alpha); cairo_paint(cr); dv_export_viewports_to_eps_r(DVG->VP, cr, 0.0, 0.0); fprintf(stdout, "Exported all viewports to 00dv.eps\n"); cairo_destroy(cr); cairo_surface_destroy(surface); */ /* SVG */ surface = cairo_svg_surface_create("00dv.svg", w, h); cr = cairo_create(surface); // Whiten background cairo_set_source_rgba(cr, white->red, white->green, white->blue, white->alpha); cairo_paint(cr); dv_export_viewports_to_svg_r(DVG->VP, cr, 0.0, 0.0); fprintf(stdout, "Exported all viewports to 00dv.svg\n"); cairo_destroy(cr); cairo_surface_destroy(surface); /* PDF */ surface = cairo_pdf_surface_create("00dv.pdf", w, h); cr = cairo_create(surface); // Whiten background cairo_set_source_rgba(cr, white->red, white->green, white->blue, white->alpha); cairo_paint(cr); dv_export_viewports_to_pdf_r(DVG->VP, cr, 0.0, 0.0); fprintf(stdout, "Exported all viewports to 00dv.pdf\n"); cairo_destroy(cr); cairo_surface_destroy(surface); return; }
void Figure::output_pdf (const std::string &s) { std::string os = H.dir + (s == "" ? H.title : s) + ".pdf"; double real_h = w() * (top()-bottom()) / (right()-left()); cairo_surface_t * pdf = cairo_pdf_surface_create (os.c_str(), w(), real_h); cairo_t * pcr = cairo_create (pdf); paint (pcr, false, true); cairo_show_page (pcr); cairo_destroy (pcr); cairo_surface_destroy (pdf); }
/* PDF,PS */ static int lcairo_create_pdf_surface(lua_State *L){ #ifdef CAIRO_HAS_PDF_SURFACE const char *filename=luaL_checkstring(L,1); double w=luaL_checknumber(L,2); double h=luaL_checknumber(L,3); cairo_surface_t *p = (cairo_surface_t*)cairo_pdf_surface_create(filename,w,h); luaT_pushudata(L, p, tSurface_id); return 1; #else luaL_error(L,"Installed Cairo does not support PDF"); return 0; #endif }
/*! \brief Export a print-style PDF file of the current page. * \par Function Description * Exports the current page as a PDF file to \a filename. The * export is carried out using a normal paper size and margins, as if * printing. * * \param w_current A #GschemToplevel structure. * \param filename The filename for generated PDF. * * \returns TRUE if the operation was successful. */ gboolean x_print_export_pdf_page (GschemToplevel *w_current, const gchar *filename) { PAGE *page; cairo_surface_t *surface; cairo_status_t status; cairo_t *cr; GtkPageSetup *setup; double width, height; EdaConfig *cfg; gboolean is_color; page = w_current->toplevel->page_current; setup = x_print_default_page_setup (w_current->toplevel, page ); width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_POINTS); height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_POINTS); surface = cairo_pdf_surface_create (filename, width, height); cr = cairo_create (surface); cairo_translate (cr, gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS), gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS)); width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); /* Find out if colour printing is enabled */ cfg = eda_config_get_context_for_path (s_page_get_filename (page)); is_color = !eda_config_get_boolean (cfg, CFG_GROUP_PRINTING, CFG_KEY_PRINTING_MONOCHROME, NULL); x_print_draw_page (w_current->toplevel, page, cr, NULL, width, height, is_color, FALSE); cairo_destroy (cr); cairo_surface_finish (surface); status = cairo_surface_status (surface); if (status != CAIRO_STATUS_SUCCESS) { g_warning (_("Failed to write PDF to '%s': %s\n"), filename, cairo_status_to_string (status)); return FALSE; } g_object_unref (setup); cairo_surface_destroy (surface); return TRUE; }
/*================================================================================== pspltrgn - subroutine to set which small plot region to use This routine is called by pschem in psvdraw_new in order to plot multiple ternary chemographies on a single page. Each page can hold MAXPLOTSPERPAGE. If another is requested, then a new document will be created with a name similar to that of the first, and the process will begin again. This overrides any settings made in psssc2, and assumes that x and y (real-unit) bounds are 0.0-1.0. Note that if this routine is called, then plot_aspect_ratio will be ignored. Note that plotnum is a zero-based index ==================================================================================*/ void pspltrgn_ (int *plotnum) { char *outFileName = malloc((strlen(dmh_fileNameRoot)+50) * sizeof(char)); int plotPosition = *plotnum % MAXPLOTSPERPAGE; int pageNum = *plotnum / MAXPLOTSPERPAGE; int boxEdge, rowNum, colNum; DEBUGPRINT(("In pspltrgn. Plotnum = %i, plotPosition = %i, pageNum = %i\n", *plotnum, plotPosition, pageNum)); if (plotPosition == 0 && pageNum > 0) { /* we need to start a new page, so let's close the current one, and start a new one with a related name */ DEBUGPRINT(("In pspltrgn. Closing current page and starting a new one with\n page number=%i and file type=%i\n", pageNum, dmh_outputFileType)); closeSurface(); // close existing surface switch(dmh_outputFileType) { case PDFTYPE: sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "pdf"); dmh_surf = cairo_pdf_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight); break; case PSTYPE: sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "ps"); dmh_surf = cairo_ps_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight); cairo_ps_surface_set_eps (dmh_surf, 1); break; case SVGTYPE: sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "svg"); dmh_surf = cairo_svg_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight); break; } dmh_cr = cairo_create (dmh_surf); cairo_identity_matrix(dmh_cr); cairo_set_line_join(dmh_cr, CAIRO_LINE_JOIN_ROUND); dmh_min_tracked_x = DBL_MAX; } /* Set the location on the page for the small plot */ dmh_aspectRatio = 1.0; /* Ignores plot_aspect_ratio. */ boxEdge = (dmh_pageWidth - LEFTMARGIN - RIGHTMARGIN - MULTIPLOTGUTTER) / 2; rowNum = plotPosition / 2; colNum = plotPosition % 2; dmh_xoffset = LEFTMARGIN + ((boxEdge + MULTIPLOTGUTTER) * colNum); dmh_yoffset = (dmh_pageHeight * 0.5) + (boxEdge * 1.5) + MULTIPLOTGUTTER - (boxEdge * (rowNum+1)) - (MULTIPLOTGUTTER * rowNum); dmh_xscale = boxEdge; dmh_yscale = boxEdge; DEBUGPRINT(("End pspltrgn. boxEdge=%i; r,c=(%i,%i); scale=(%f, %f); offset=(%f, %f); DevPtRange=(%f,%f)-(%f,%f).\n", boxEdge, rowNum, colNum, dmh_xscale, dmh_yscale, dmh_xoffset, dmh_yoffset,deviceX(0), deviceY(0), deviceX(1), deviceY(1))); }
static void save_as_pdf (GtkWidget *widget, const char *filename) { GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); cairo_surface_t *surface = cairo_pdf_surface_create( filename, 1.0 * allocation.width, 1.0 * allocation.height ); cairo_t *cr = cairo_create(surface); gtk_widget_draw(widget, cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
void dv_export_viewport() { dv_view_t * V = DVG->activeV; if (!V) { fprintf(stderr, "Warning: there is no active V to export.\n"); return; } dv_viewport_t * VP = V->mainVP; if (!VP) { fprintf(stderr, "Warning: there is no main VP for the active V.\n"); return; } cairo_surface_t * surface; /* resize to remove ruler areas */ double surface_width = VP->vpw - 2 * DVG->opts.ruler_width; double surface_height = VP->vph - 2 * DVG->opts.ruler_width; /* PNG */ surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, surface_width, surface_height); dv_viewport_export_to_surface(VP, surface); cairo_surface_write_to_png(surface, "00dv.png"); fprintf(stdout, "Exported viewport %ld to 00dv.png\n", VP - DVG->VP); cairo_surface_destroy(surface); /* EPS */ /* surface = cairo_ps_surface_create("00dv.eps", surface_width, surface_height); cairo_ps_surface_set_eps(surface, TRUE); dv_viewport_export_to_surface(VP, surface); fprintf(stdout, "Exported viewport %ld to 00dv.eps\n", VP - DVG->VP); cairo_surface_destroy(surface); */ /* SVG */ surface = cairo_svg_surface_create("00dv.svg", surface_width, surface_height); dv_viewport_export_to_surface(VP, surface); fprintf(stdout, "Exported viewport %ld to 00dv.svg\n", VP - DVG->VP); cairo_surface_destroy(surface); /* PDF */ surface = cairo_pdf_surface_create("00dv.pdf", surface_width, surface_height); dv_viewport_export_to_surface(VP, surface); fprintf(stdout, "Exported viewport %ld to 00dv.pdf\n", VP - DVG->VP); cairo_surface_destroy(surface); return; }
void buffer_to_pdf (Ebook * ebook) { GtkTextBuffer * buffer; GtkTextIter start, end; Pqueue queue; gchar * size, *editor_font; /* A4 initial */ queue.ebook = ebook; queue.pos = 0; queue.page_count = 1; queue.width = 8.3 * POINTS; queue.height = 11.7 * POINTS; queue.page_height = 40.0; g_return_if_fail (ebook); g_return_if_fail (ebook->filename); size = gconf_client_get_string (ebook->client, ebook->paper_size.key, NULL); buffer = GTK_TEXT_BUFFER(gtk_builder_get_object (ebook->builder, "textbuffer1")); queue.progressbar = GTK_PROGRESS_BAR(gtk_builder_get_object (ebook->builder, "progressbar")); queue.statusbar = GTK_STATUSBAR(gtk_builder_get_object (ebook->builder, "statusbar")); gtk_text_buffer_get_bounds (buffer, &start, &end); queue.text = g_strdup(gtk_text_buffer_get_text (buffer, &start, &end, TRUE)); editor_font = gconf_client_get_string(ebook->client, ebook->editor_font.key, NULL); if (0 == g_strcmp0 (size, "A5")) { queue.width = a5_width * POINTS; queue.height = a5_height * POINTS; } if (0 == g_strcmp0 (size, "B5")) { queue.width = b5_width * POINTS; queue.height = b5_height * POINTS; } queue.surface = cairo_pdf_surface_create (ebook->filename, queue.width, queue.height); queue.cr = cairo_create (queue.surface); queue.context = pango_cairo_create_context (queue.cr); /* pango_cairo_create_layout is wasteful with a lot of text. */ queue.desc = pango_font_description_from_string (editor_font); queue.layout = make_new_page (queue.context, queue.desc, queue.height, queue.width); pango_layout_set_text (queue.layout, queue.text, -1); cairo_move_to (queue.cr, SIDE_MARGIN / 2, EDGE_MARGIN / 2); gtk_progress_bar_set_fraction (queue.progressbar, 0.0); queue.lines_per_page = pango_layout_get_line_count (queue.layout); queue.iter = pango_layout_get_iter (queue.layout); create_pages (&queue); }
void ofCairoRenderer::setup(string filename, Type type, bool multiPage_, bool b3D_){ switch(type){ case PDF: surface = cairo_pdf_surface_create(ofToDataPath(filename).c_str(),ofGetWidth(),ofGetHeight()); break; case SVG: surface = cairo_svg_surface_create(ofToDataPath(filename).c_str(),ofGetWidth(),ofGetHeight()); break; } cr = cairo_create(surface); viewportRect.set(0,0,ofGetWidth(),ofGetHeight()); viewport(viewportRect); page = 0; b3D = b3D_; multiPage = multiPage_; }
void CairoBox::out_pdf(const char* filename, int wpts, int hpts) { cairo_surface_t* surface; cairo_t* cr; surface = cairo_pdf_surface_create(filename, wpts, hpts); cr = cairo_create (surface); cairo_set_source_rgb (cr, 0, 0, 0); // user coordinates -- see cairo_pdf_surface_create graphic(cr, 0, 0, wpts, hpts); cairo_show_page(cr); cairo_destroy (cr); cairo_surface_destroy(surface); return; }
/*! \brief Export a figure-style PDF file of the current page. * \par Function Description * Exports the current page as a PDF file to \a filename. The export * is carried out using a page size matching the size of the visible * extents of the schematic page. * * \param w_current A #GschemToplevel structure. * \param filename The filename for generated PDF. * * \returns TRUE if the operation was successful. */ gboolean x_print_export_pdf (GschemToplevel *w_current, const gchar *filename) { cairo_surface_t *surface; cairo_status_t cr_status; cairo_t *cr; int status, wx_min, wy_min, wx_max, wy_max; double width, height; /* First, calculate a transformation matrix for the cairo * context. We want to center the extents of the page in the * available page area. */ status = world_get_object_glist_bounds (w_current->toplevel, s_page_objects (w_current->toplevel->page_current), &wx_min, &wy_min, &wx_max, &wy_max); if (status) { width = (wx_max - wx_min) * DEFAULT_ADOBE_PDF_PPI / DEFAULT_GSCHEM_PPI; height = (wy_max - wy_min) * DEFAULT_ADOBE_PDF_PPI / DEFAULT_GSCHEM_PPI; } else { /* Fallback size if there are no drawable objects */ width = height = DEFAULT_PDF_SIZE; } surface = cairo_pdf_surface_create (filename, width, height); cr = cairo_create (surface); x_print_draw_page (w_current->toplevel, w_current->toplevel->page_current, cr, NULL, width, height, w_current->toplevel->image_color, FALSE); cairo_destroy (cr); cairo_surface_finish (surface); cr_status = cairo_surface_status (surface); if (cr_status != CAIRO_STATUS_SUCCESS) { g_warning (_("Failed to write PDF to '%1$s': %2$s\n"), filename, cairo_status_to_string (cr_status)); return FALSE; } cairo_surface_destroy (surface); return TRUE; }
int main (int argc, char *argv[]) { GError *error = NULL; RsvgHandle *handle; RsvgDimensionData dim; double width, height; const char *filename = argv[1]; const char *output_filename = argv[2]; cairo_surface_t *surface; cairo_t *cr; cairo_status_t status; if (argc != 3) FAIL ("usage: svg2pdf input_file.svg output_file.pdf"); g_type_init (); rsvg_set_default_dpi (72.0); handle = rsvg_handle_new_from_file (filename, &error); if (error != NULL) FAIL (error->message); rsvg_handle_get_dimensions (handle, &dim); width = dim.width; height = dim.height; surface = cairo_pdf_surface_create (output_filename, width, height); cr = cairo_create (surface); /* Clear background */ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ cairo_paint (cr); rsvg_handle_render_cairo (handle, cr); status = cairo_status (cr); if (status) FAIL (cairo_status_to_string (status)); cairo_destroy (cr); cairo_surface_destroy (surface); return 0; }