void show(bool clear = true) { if (clear) { cairo_surface_show_page(m_s); } else { cairo_surface_copy_page(m_s); } }
static cairo_status_t _cairo_paginated_surface_finish (void *abstract_surface) { cairo_paginated_surface_t *surface = abstract_surface; cairo_status_t status = CAIRO_STATUS_SUCCESS; if (surface->page_is_blank == FALSE || surface->page_num == 1) { cairo_surface_show_page (abstract_surface); status = cairo_surface_status (abstract_surface); } if (status == CAIRO_STATUS_SUCCESS) { cairo_surface_finish (surface->target); status = cairo_surface_status (surface->target); } if (status == CAIRO_STATUS_SUCCESS) { cairo_surface_finish (surface->meta); status = cairo_surface_status (surface->meta); } cairo_surface_destroy (surface->target); cairo_surface_destroy (surface->meta); return status; }
static VALUE cr_surface_show_page (VALUE self) { cairo_surface_show_page (_SELF); cr_surface_check_status (_SELF); return self; }
static cairo_int_status_t _cairo_paginated_surface_copy_page (void *abstract_surface) { cairo_status_t status; cairo_paginated_surface_t *surface = abstract_surface; status = _start_page (surface); if (status) return status; status = _paint_page (surface); if (status) return status; surface->page_num++; /* XXX: It might make sense to add some suport here for calling * cairo_surface_copy_page on the target surface. It would be an * optimization for the output, but the interaction with image * fallbacks gets tricky. For now, we just let the target see a * show_page and we implement the copying by simply not destroying * the meta-surface. */ cairo_surface_show_page (surface->target); return cairo_surface_status (surface->target); }
static PyObject * surface_show_page (PycairoSurface *o) { Py_BEGIN_ALLOW_THREADS cairo_surface_show_page (o->surface); Py_END_ALLOW_THREADS RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface); Py_RETURN_NONE; }
nsresult gfxWindowsSurface::EndPage() { if (mForPrinting) cairo_surface_show_page(CairoSurface()); int result = ::EndPage(mDC); if (result <= 0) return NS_ERROR_FAILURE; return NS_OK; }
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); }
// Currently, this is the only print event we need to deal with in Thebes. nsresult gfxOS2Surface::EndPage() { printf("gfxOS2Surface::EndPage - mSurfType= %d\n", mSurfType); if (mSurfType == os2Print) cairo_surface_show_page(CairoSurface()); else NS_WARNING("gfxOS2Surface::EndPage() called on non-printing surface\n"); return NS_OK; }
static SeedValue seed_cairo_surface_show_page (SeedContext ctx, SeedObject function, SeedObject this_object, gsize argument_count, const SeedValue arguments[], SeedException *exception) { CHECK_THIS(); cairo_surface_show_page (seed_object_to_cairo_surface(ctx, this_object, exception)); return seed_make_undefined (ctx); }
nsresult gfxWindowsSurface::EndPage() { #ifdef NS_PRINTING if (mForPrinting) cairo_surface_show_page(CairoSurface()); int result = ::EndPage(mDC); if (result <= 0) return NS_ERROR_FAILURE; return NS_OK; #else return NS_ERROR_FAILURE; #endif }
/* The only reason we go through all these machinations to write a PNG * image is to _really ensure_ that the data actually landed in our * buffer through the paginated surface to the test_paginated_surface. * * If we didn't implement this function then the default * cairo_surface_write_to_png would result in the paginated_surface's * acquire_source_image function replaying the recording-surface to an * intermediate image surface. And in that case the * test_paginated_surface would not be involved and wouldn't be * tested. */ static cairo_status_t _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface, const char *filename) { test_paginated_closure_t *tpc; cairo_status_t status; /* show page first. the automatic show_page is too late for us */ cairo_surface_show_page (surface); status = cairo_surface_status (surface); if (status) return status; tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key); return cairo_surface_write_to_png (tpc->target, filename); }
void render_page(page_t *page_meta, PopplerPage *page) {; cairo_t *cairoctx; cairo_surface_t *surface; double width, height; char outfilename[NAME_MAX]; poppler_page_get_size(page, &width, &height); snprintf(outfilename, sizeof outfilename - 1, "img-%d.svg", page_meta->pagenum); surface = cairo_svg_surface_create(outfilename, width, height); cairoctx = cairo_create(surface); if (cairoctx == NULL) ERROR("Cannot create a Cairo buffer"); poppler_page_render(page, cairoctx); cairo_surface_show_page(surface); cairo_surface_destroy(surface); cairo_destroy(cairoctx); }
static cairo_surface_t * _cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface, int page, int width, int height) { test_paginated_closure_t *tpc; cairo_status_t status; /* XXX separate finish as per PDF */ if (page != 0) return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); /* show page first. the automatic show_page is too late for us */ cairo_surface_show_page (surface); status = cairo_surface_status (surface); if (status) return cairo_boilerplate_surface_create_in_error (status); tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key); return _cairo_boilerplate_get_image_surface (tpc->target, 0, width, height); }
static cairo_int_status_t _cairo_paginated_surface_show_page (void *abstract_surface) { cairo_status_t status; cairo_paginated_surface_t *surface = abstract_surface; status = _start_page (surface); if (unlikely (status)) return (cairo_int_status_t)status; status = (cairo_status_t)_paint_page (surface); if (unlikely (status)) return (cairo_int_status_t)status; cairo_surface_show_page (surface->target); status = (cairo_status_t)surface->target->status; if (unlikely (status)) return (cairo_int_status_t)status; status = (cairo_status_t)surface->recording_surface->status; if (unlikely (status)) return (cairo_int_status_t)status; if (! surface->base.finished) { cairo_surface_destroy (surface->recording_surface); surface->recording_surface = _create_recording_surface_for_target (surface->target, surface->content); status = (cairo_status_t)surface->recording_surface->status; if (unlikely (status)) return (cairo_int_status_t)status; surface->page_num++; surface->base.is_clear = TRUE; } return (cairo_int_status_t)CAIRO_STATUS_SUCCESS; }
static cairo_int_status_t _cairo_paginated_surface_show_page (void *abstract_surface) { cairo_status_t status; cairo_paginated_surface_t *surface = abstract_surface; status = _start_page (surface); if (status) return status; status = _paint_page (surface); if (status) return status; cairo_surface_show_page (surface->target); status = cairo_surface_status (surface->target); if (status) return status; status = cairo_surface_status (surface->meta); if (status) return status; cairo_surface_destroy (surface->meta); surface->meta = _cairo_meta_surface_create (surface->content, surface->width, surface->height); status = cairo_surface_status (surface->meta); if (status) return status; surface->page_num++; surface->page_is_blank = TRUE; return CAIRO_STATUS_SUCCESS; }
/* The only reason we go through all these machinations to write a PNG * image is to _really ensure_ that the data actually landed in our * buffer through the paginated surface to the test_paginated_surface. * * If we didn't implement this function then the default * cairo_surface_write_to_png would result in the paginated_surface's * acquire_source_image function replaying the meta-surface to an * intermediate image surface. And in that case the * test_paginated_surface would not be involved and wouldn't be * tested. */ cairo_status_t _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface, const char *filename) { cairo_surface_t *image; cairo_format_t format; test_paginated_closure_t *tpc; cairo_status_t status; /* show page first. the automatic show_page is too late for us */ cairo_surface_show_page (surface); status = cairo_surface_status (surface); if (status) return status; tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key); format = cairo_boilerplate_format_from_content (tpc->content); image = cairo_image_surface_create_for_data (tpc->data, format, tpc->width, tpc->height, tpc->stride); status = cairo_surface_write_to_png (image, filename); if (status) { CAIRO_BOILERPLATE_LOG ("Error writing %s: %s. Exiting\n", filename, cairo_status_to_string (status)); exit (1); } cairo_surface_destroy (image); return CAIRO_STATUS_SUCCESS; }
static cairo_test_status_t test_cairo_surface_show_page (cairo_surface_t *surface) { cairo_surface_show_page (surface); return CAIRO_TEST_SUCCESS; }
static int surface_show_page (lua_State *L) { cairo_surface_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_SURFACE); cairo_surface_show_page(*obj); return 0; }
nsresult PrintTargetPS::EndPage() { cairo_surface_show_page(mCairoSurface); return NS_OK; }
nsresult gfxPDFSurface::EndPage() { cairo_surface_show_page(CairoSurface()); return NS_OK; }
int main(int argc, char **argv){ float width=8.5*72.0; float height=11.0*72.0; float xoff=0; float yoff=0; float fontsize=-1; int havey=0; float dpp=300.0/72.0; char *text=NULL; int c,long_option_index; cairo_surface_t *cs; cairo_t *ct; cairo_text_extents_t extents; while((c=getopt_long(argc,argv,optstring,options,&long_option_index))!=EOF){ switch(c){ case 'W': case 'H': case 'x': case 'y': { float temp; if(strstr(optarg,"cm")){ temp=atof(optarg)*28.3464566929; }else if (strstr(optarg,"mm")){ temp=atof(optarg)*2.83464566929; }else if (strstr(optarg,"pt")){ temp=atof(optarg); }else{ temp=atof(optarg)*72.0; } switch(c){ case 'W': width=temp; break; case 'H': height=temp; break; case 'x': xoff=temp; break; case 'y': yoff=temp; havey=1; break; } } break; case 'r': if(strstr(optarg,"dpcm")){ dpp=atof(optarg)*.03527777777778; }else if (strstr(optarg,"dpmm")){ dpp=atof(optarg)*.35277777777778; }else if (strstr(optarg,"dpp")){ dpp=atof(optarg); }else{ dpp=atof(optarg)*.01388888888889; } break; case 'f': fontsize=atof(optarg); break; case 't': text=strdup(optarg); break; case 'h': usage(stdout); exit(0); case 'v': fprintf(stderr,"pngxpdf "VERSION"\n"); default: usage(stderr); } } /* set up our surface */ cs = cairo_pdf_surface_create_for_stream (pdf_write, NULL, width, height); if(!cs || cairo_surface_status(cs)!=CAIRO_STATUS_SUCCESS){ fprintf(stderr,"CAIRO ERROR: Unable to create PDF surface.\n\n"); exit(1); } ct = cairo_create(cs); if(fontsize<=0){ fontsize=height*15./792.; if(fontsize<5)fontsize=5; } cairo_set_font_size(ct, fontsize); if(text){ cairo_text_extents(ct, text, &extents); if(!havey) yoff = -extents.height-fontsize*4; } /* Iterate through PNG files inline */ while(optind<argc){ int ww, hh; char *filename = argv[optind]; cairo_pattern_t *pattern; cairo_surface_t *ps=cairo_image_surface_create_from_png(filename); cairo_status_t status = cairo_surface_status(ps); if(!ps || status!=CAIRO_STATUS_SUCCESS){ fprintf(stderr,"CAIRO ERROR: Unable to load PNG file %s: %s\n\n",filename,cairo_status_to_string(status)); exit(1); } ww = cairo_image_surface_get_width(ps); hh = cairo_image_surface_get_height(ps); cairo_save(ct); cairo_scale(ct, 1./dpp, 1./dpp); pattern = cairo_pattern_create_for_surface(ps); cairo_translate(ct,(width*dpp - (ww-1))*.5,((height+yoff)*dpp - (hh-1))*.5); cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST); cairo_set_source(ct,pattern); cairo_paint(ct); cairo_restore(ct); /* draw comment text */ if(text){ cairo_set_source_rgba(ct, 1,1,1,.75); cairo_move_to(ct, width-extents.width-fontsize*1.5, height-fontsize*1.5); cairo_text_path (ct, text); cairo_set_line_width(ct,3.); cairo_set_line_join(ct,CAIRO_LINE_JOIN_ROUND); cairo_stroke(ct); cairo_set_source_rgb(ct, 0,0,0); cairo_move_to(ct, width-extents.width-fontsize*1.5, height-fontsize*1.5); cairo_show_text(ct, text); } cairo_surface_show_page(cs); cairo_surface_destroy(ps); optind++; } cairo_destroy(ct); cairo_surface_destroy(cs); }