static void begin_print (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { gtk_print_operation_set_n_pages(operation, 1); }
static void begin_print (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { PrintData *data = (PrintData *)user_data; //char *contents; int i; double height; height = gtk_print_context_get_height (context) - HEADER_HEIGHT - HEADER_GAP; data->lines_per_page = floor (height / data->font_size); //g_file_get_contents (data->filename, &contents, NULL, NULL); //data->lines = g_strsplit (contents, "\n", 0); //g_free (contents); i = 0; while (data->lines[i] != NULL) i++; data->num_lines = i; data->num_pages = (data->num_lines - 1) / data->lines_per_page + 1; gtk_print_operation_set_n_pages (operation, data->num_pages); }
static void begin_print_text (GtkPrintOperation * op, GtkPrintContext * cnt, gpointer data) { gchar *buf; gint i = 0; gdouble ph; /* load file */ g_file_get_contents (options.common_data.uri, &buf, NULL, NULL); text = g_strsplit (buf, "\n", 0); g_free (buf); while (text[i] != NULL) i++; ph = gtk_print_context_get_height (cnt); if (options.print_data.headers) ph -= HEADER_HEIGHT + HEADER_GAP; nlines = ph / FONTSIZE; npages = i / nlines + 1; gtk_print_operation_set_n_pages (op, npages); /* set font */ if (options.common_data.font) fdesc = pango_font_description_from_string (options.common_data.font); else { fdesc = pango_font_description_from_string (FONTNAME); pango_font_description_set_size (fdesc, FONTSIZE * PANGO_SCALE); } }
static void begin_print (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { PrintData *data = (PrintData *)user_data; GBytes *bytes; int i; double height; height = gtk_print_context_get_height (context) - HEADER_HEIGHT - HEADER_GAP; data->lines_per_page = floor (height / data->font_size); bytes = g_resources_lookup_data (data->resourcename, 0, NULL); data->lines = g_strsplit (g_bytes_get_data (bytes, NULL), "\n", 0); g_bytes_unref (bytes); i = 0; while (data->lines[i] != NULL) i++; data->num_lines = i; data->num_pages = (data->num_lines - 1) / data->lines_per_page + 1; gtk_print_operation_set_n_pages (operation, data->num_pages); }
int main (int argc, char **argv) { GtkPrintOperation *print; TestPrintFileOperation *print_file; gtk_init (&argc, &argv); /* Test some random drawing, with per-page paper settings */ print = gtk_print_operation_new (); gtk_print_operation_set_n_pages (print, 2); gtk_print_operation_set_unit (print, GTK_UNIT_MM); gtk_print_operation_set_export_filename (print, "test.pdf"); g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL); g_signal_connect (print, "request_page_setup", G_CALLBACK (request_page_setup), NULL); gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL); /* Test subclassing of GtkPrintOperation */ print_file = test_print_file_operation_new ("testprint.c"); test_print_file_operation_set_font_size (print_file, 12.0); gtk_print_operation_set_export_filename (GTK_PRINT_OPERATION (print_file), "test2.pdf"); gtk_print_operation_run (GTK_PRINT_OPERATION (print_file), GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL); return 0; }
static void print_job_begin_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { PlannerPrintJob *job; PlannerPrintJobPriv *priv; GList *l; PlannerView *view; int n_pages = 0; job = (PlannerPrintJob *)user_data; priv = job->priv; job->cr = gtk_print_context_get_cairo_context (context); job->pc = context; priv->paper_height = gtk_print_context_get_height (context); priv->paper_width = gtk_print_context_get_width (context); print_job_update_size (job); planner_print_job_set_font_regular (job); job->x_pad = planner_print_job_get_extents (job, "#") / 2; for (l = priv->views; l; l = l->next) { view = l->data; planner_view_print_init (view, job); n_pages += planner_view_print_get_n_pages (view); } gtk_print_operation_set_n_pages (operation, (n_pages > 0) ? n_pages : 1); }
static void begin_print (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { GdictPrintData *data = user_data; gchar *contents; gdouble height; height = gtk_print_context_get_height (context) - HEADER_HEIGHT (10) - HEADER_GAP (3); contents = gdict_defbox_get_text (data->defbox, NULL); data->lines = g_strsplit (contents, "\n", 0); data->n_lines = g_strv_length (data->lines); data->lines_per_page = floor (height / data->font_size); data->n_pages = (data->n_lines - 1) / data->lines_per_page + 1; gtk_print_operation_set_n_pages (operation, data->n_pages); g_free (contents); }
static void begin_print (GtkPrintOperation *operation, GtkPrintContext */*context*/, gpointer /*user_data*/) { //printf("%s\n",__FUNCTION__); gtk_print_operation_set_n_pages (operation, 1); }
static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, PrintData *data) { // fputs("DEBUG: begin_print() called\n", stderr); gtk_print_operation_set_n_pages (operation, data->num_pages); gtk_print_operation_set_use_full_page (operation, data->use_full_page); }
//! //! @brief Pagination algorithm to calculate how many pages are needed //! @param operation Unused GtkPrintOperation //! @param context Pointer co a GtkPrintContext to draw on //! @param page_nr Integer of the current page number being draw //! @param data Painter to a PageInfo struct to use for information //! @return Return true when pagination finishes //! @sa _done() _begin_print() draw() _begin_print() //! static gboolean _paginate (GtkPrintOperation *operation, GtkPrintContext *context, GwPrintData *data ) { printf("paginate!\n"); //Declarations GwPageInfo *page; GwPageInfo *prev_page; GList *iter; GtkTextIter end_bound; GtkTextIter start_bound; GtkTextView *view; GtkTextBuffer *buffer; //Initializations view = gw_searchwindow_get_current_textview (data->window); buffer = gtk_text_view_get_buffer (view); //Get the draw bounds if (gtk_text_buffer_get_has_selection (buffer)) { gtk_text_buffer_get_selection_bounds (buffer, &start_bound, &end_bound); } else { gtk_text_buffer_get_start_iter (buffer, &start_bound); gtk_text_buffer_get_end_iter (buffer, &end_bound); } //Create the first page if (data->pages == NULL) { page = gw_pageinfo_new (start_bound, end_bound); _draw_page_results (context, page, data); data->pages = g_list_append (data->pages, page); return FALSE; } iter = g_list_last (data->pages); prev_page = GW_PAGEINFO (iter->data); //Finish paginating if (gtk_text_iter_get_line (&(prev_page->end)) == gtk_text_iter_get_line (&end_bound)) { gtk_print_operation_set_n_pages (operation, g_list_length (data->pages)); return TRUE; } //Add another page page = gw_pageinfo_new (prev_page->end, end_bound); _draw_page_results (context, page, data); data->pages = g_list_append (data->pages, page); return FALSE; }
static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, gpointer user_data) { int pages = doPrint(prt,context,NULL,-1); if(pages <= 0) { gtk_print_operation_cancel(prt); return; } gtk_print_operation_set_n_pages(prt,pages); }
static void begin_print (GtkPrintOperation *operation, GtkPrintContext *context, PrintData *print_data) { PangoFontDescription *desc; PangoLayoutLine *layout_line; double width, height; double page_height; GList *page_breaks; int num_lines; int line; width = gtk_print_context_get_width (context); height = gtk_print_context_get_height (context); print_data->layout = gtk_print_context_create_pango_layout (context); desc = pango_font_description_from_string (print_data->font); pango_layout_set_font_description (print_data->layout, desc); pango_font_description_free (desc); pango_layout_set_width (print_data->layout, width * PANGO_SCALE); pango_layout_set_text (print_data->layout, print_data->text, -1); num_lines = pango_layout_get_line_count (print_data->layout); page_breaks = NULL; page_height = 0; for (line = 0; line < num_lines; line++) { PangoRectangle ink_rect, logical_rect; double line_height; layout_line = pango_layout_get_line (print_data->layout, line); pango_layout_line_get_extents (layout_line, &ink_rect, &logical_rect); line_height = logical_rect.height / 1024.0; if (page_height + line_height > height) { page_breaks = g_list_prepend (page_breaks, GINT_TO_POINTER (line)); page_height = 0; } page_height += line_height; } page_breaks = g_list_reverse (page_breaks); gtk_print_operation_set_n_pages (operation, g_list_length (page_breaks) + 1); print_data->page_breaks = page_breaks; }
void print(zathura_t* zathura) { g_return_if_fail(zathura != NULL); g_return_if_fail(zathura->document != NULL); GtkPrintOperation* print_operation = gtk_print_operation_new(); /* print operation settings */ gtk_print_operation_set_job_name(print_operation, zathura_document_get_path(zathura->document)); gtk_print_operation_set_allow_async(print_operation, TRUE); gtk_print_operation_set_n_pages(print_operation, zathura_document_get_number_of_pages(zathura->document)); gtk_print_operation_set_current_page(print_operation, zathura_document_get_current_page_number(zathura->document)); gtk_print_operation_set_use_full_page(print_operation, TRUE); if (zathura->print.settings != NULL) { gtk_print_operation_set_print_settings(print_operation, zathura->print.settings); } if (zathura->print.page_setup != NULL) { gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup); } gtk_print_operation_set_embed_page_setup(print_operation, TRUE); /* print operation signals */ g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura); g_signal_connect(print_operation, "end-print", G_CALLBACK(cb_print_end), zathura); g_signal_connect(print_operation, "request-page-setup", G_CALLBACK(cb_print_request_page_setup), zathura); /* print */ GError* error = NULL; GtkPrintOperationResult result = gtk_print_operation_run(print_operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(zathura->ui.session->gtk.window), &error); if (result == GTK_PRINT_OPERATION_RESULT_ERROR) { girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing failed: %s"), error->message); g_error_free(error); } else if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { g_clear_object(&zathura->print.settings); g_clear_object(&zathura->print.page_setup); /* save previous settings */ zathura->print.settings = g_object_ref(gtk_print_operation_get_print_settings(print_operation)); zathura->print.page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(print_operation)); } g_object_unref(print_operation); }
static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) { cairo_t *cr; PangoLayout *layout; double w, h; struct graphics_context gc = { .printer = 1 }; cr = gtk_print_context_get_cairo_context(context); gc.cr = cr; layout=gtk_print_context_create_pango_layout(context); w = gtk_print_context_get_width(context); h = gtk_print_context_get_height(context); /* Do the profile on the top half of the page.. */ plot(&gc, w, h/2, current_dive); pango_cairo_show_layout(cr,layout); g_object_unref(layout); } static void begin_print(GtkPrintOperation *operation, gpointer user_data) { } static GtkPrintSettings *settings = NULL; void do_print(void) { GtkPrintOperation *print; GtkPrintOperationResult res; print = gtk_print_operation_new(); if (settings != NULL) gtk_print_operation_set_print_settings(print, settings); gtk_print_operation_set_n_pages(print, 1); g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL); g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL); res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(main_window), NULL); if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (settings != NULL) g_object_unref(settings); settings = g_object_ref(gtk_print_operation_get_print_settings(print)); } g_object_unref(print); }
void XAP_UnixDialog_Print::BeginPrint(GtkPrintContext *context) { // Note: Help landscape printing survive, don't do anything on the cairo // context in this function. Any transformations etc. shall take place in // PrintPage, because GtkPrint may do some transformations itself (which // will come out differently if we scale here). cairo_t* cr = gtk_print_context_get_cairo_context (context); // // The cairo context is automatically unref'd at the end of the print // so we need to reference it to allow it to be deleted by the PrintGraphics // class cairo_reference(cr); gtk_print_operation_set_n_pages (m_pPO,m_iNumberPages); AP_FrameData *pFrameData = static_cast<AP_FrameData *>(m_pFrame->getFrameData()); xxx_UT_DEBUGMSG(("Initial Cairo Context %x \n",cr)); m_pPrintGraphics = (GR_Graphics *) new GR_CairoPrintGraphics(cr, gr_PRINTRES); double ScreenRes = m_pView->getGraphics()->getDeviceResolution(); static_cast<GR_CairoPrintGraphics *>(m_pPrintGraphics) ->setResolutionRatio(gr_PRINTRES/ScreenRes); if(m_pView->getViewMode() == VIEW_PRINT ) { m_pPrintLayout = m_pDL; m_pPrintView = m_pView; m_pPrintLayout->setQuickPrint(m_pPrintGraphics); m_bDidQuickPrint = true; if(pFrameData->m_bShowPara) { m_pPrintView->setShowPara(false); m_bShowParagraphs = true; } else m_bShowParagraphs = false; } else { m_pPrintLayout = new FL_DocLayout(m_pView->getDocument(),m_pPrintGraphics); m_pPrintView = new FV_View(XAP_App::getApp(),0,m_pPrintLayout); m_pPrintView->getLayout()->fillLayouts(); m_pPrintView->getLayout()->formatAll(); m_pPrintView->getLayout()->recalculateTOCFields(); m_bDidQuickPrint = false; } m_pPrintGraphics->startPrint(); }
void e_contact_print (EBookClient *book_client, EBookQuery *query, const GSList *contact_list, GtkPrintOperationAction action) { GtkPrintOperation *operation; EContactPrintContext *ctxt; ctxt = g_new0 (EContactPrintContext, 1); ctxt->action = action; ctxt->contact_list = e_client_util_copy_object_slist (NULL, contact_list); ctxt->style = g_new0 (EContactPrintStyle, 1); ctxt->page_nr = 0; ctxt->pages = 0; operation = e_print_operation_new (); gtk_print_operation_set_n_pages (operation, 1); g_object_set_data_full ( G_OBJECT (operation), "contact-print-ctx", ctxt, g_free); g_signal_connect ( operation, "begin-print", G_CALLBACK (contact_begin_print), ctxt); g_signal_connect ( operation, "draw_page", G_CALLBACK (contact_draw_page), ctxt); g_signal_connect ( operation, "end-print", G_CALLBACK (contact_end_print), ctxt); if (book_client) { gchar *query_str = e_book_query_to_string (query); e_book_client_get_view ( book_client, query_str, NULL, get_view_ready_cb, operation); g_free (query_str); } else { gtk_print_operation_run (operation, action, NULL, NULL); g_object_unref (operation); } }
int main (int argc, char **argv) { GtkPrintOperation *print; GtkPrintSettings *settings; settings = gtk_print_settings_new (); /* gtk_print_settings_set_printer (settings, "printer"); */ print = gtk_print_operation_new (); gtk_print_operation_set_print_settings (print, settings); gtk_print_operation_set_n_pages (print, 1); gtk_print_operation_set_unit (print, GTK_UNIT_MM); g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL); gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT, NULL, NULL); return 0; }
static void photos_print_operation_init (PhotosPrintOperation *self) { GtkPrintSettings *settings; self->unit = GTK_UNIT_INCH; self->left_margin = 0.0; self->top_margin = 0.0; self->scale_factor = 100.0; settings = gtk_print_settings_new (); gtk_print_operation_set_print_settings (GTK_PRINT_OPERATION (self), settings); g_object_unref (settings); gtk_print_operation_set_custom_tab_label (GTK_PRINT_OPERATION (self), _("Image Settings")); gtk_print_operation_set_embed_page_setup (GTK_PRINT_OPERATION (self), TRUE); gtk_print_operation_set_n_pages (GTK_PRINT_OPERATION (self), 1); }
static gboolean paginate(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { DocInfo *dinfo = user_data; /* for whatever reason we get called one more time after we returned TRUE, so avoid adding * an empty page at the end */ if (dinfo->fr.chrg.cpMin >= dinfo->fr.chrg.cpMax) return TRUE; gtk_progress_bar_pulse(GTK_PROGRESS_BAR(main_widgets.progressbar)); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_widgets.progressbar), _("Paginating")); g_array_append_val(dinfo->pages, dinfo->fr.chrg.cpMin); dinfo->fr.chrg.cpMin = (gint) scintilla_send_message(dinfo->sci, SCI_FORMATRANGE, FALSE, (sptr_t) &dinfo->fr); gtk_print_operation_set_n_pages(operation, dinfo->pages->len); return dinfo->fr.chrg.cpMin >= dinfo->fr.chrg.cpMax; }
void calendar_begin_print (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { GUI *appGUI = (GUI *) user_data; GtkPageSetup *setup; if (config.cal_print_page_orientation == LANDSCAPE) { setup = gtk_page_setup_new (); gtk_page_setup_set_orientation (setup, GTK_PAGE_ORIENTATION_LANDSCAPE); gtk_print_operation_set_default_page_setup (operation, setup); g_object_unref (setup); } appGUI->print_lines_per_page = 1; appGUI->print_nlines = 1; appGUI->print_npages = 1; gtk_print_operation_set_n_pages (operation, appGUI->print_npages); }
GtkPrintOperation * biorhythm_print_operation_new (BiorhythmChart *chart) { GtkPrintOperation *print; GtkPageSetup *page_setup; print = gtk_print_operation_new (); gtk_print_operation_set_n_pages (print, 1); gtk_print_operation_set_job_name (print, "Print Biorhythm"); gtk_print_operation_set_embed_page_setup (print, FALSE); page_setup = gtk_page_setup_new (); gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE); gtk_print_operation_set_default_page_setup (print, page_setup); g_signal_connect (print, "draw_page", G_CALLBACK (biorhythm_print_draw_page), chart); return print; }
GtkPrintOperation * create_print_operation (DiagramData *data, const char *name) { PrintData *print_data; GtkPrintOperation *operation; GtkPageSetup * setup; int num_pages; /* gets deleted in end_print */ print_data = g_new0 (PrintData, 1); print_data->data = g_object_ref (data); print_data->renderer = g_object_new (DIA_TYPE_CAIRO_RENDERER, NULL); operation = gtk_print_operation_new (); gtk_print_operation_set_job_name (operation, name); setup = gtk_print_operation_get_default_page_setup (operation); if (!setup) setup = gtk_page_setup_new (); _dia_to_gtk_page_setup (print_data->data, setup); gtk_print_operation_set_default_page_setup (operation, setup); g_object_unref (setup); /* similar logic draw_page() but we need to set the total pages in advance */ if (data->paper.fitto) { num_pages = data->paper.fitwidth * data->paper.fitheight; } else { int nx = ceil((data->extents.right - data->extents.left) / data->paper.width); int ny = ceil((data->extents.bottom - data->extents.top) / data->paper.height); num_pages = nx * ny; } gtk_print_operation_set_n_pages (operation, num_pages); gtk_print_operation_set_unit (operation, GTK_UNIT_MM); g_signal_connect (operation, "draw_page", G_CALLBACK (draw_page), print_data); g_signal_connect (operation, "begin_print", G_CALLBACK (begin_print), print_data); g_signal_connect (operation, "end_print", G_CALLBACK (end_print), print_data); return operation; }
static void contact_begin_print (GtkPrintOperation *operation, GtkPrintContext *context, EContactPrintContext *ctxt) { GtkPageSetup *setup; gdouble page_width; e_contact_build_style (ctxt->style); setup = gtk_print_context_get_page_setup (context); page_width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); ctxt->context = context; ctxt->x = ctxt->y = .0; ctxt->column = 0; ctxt->first_contact = TRUE; ctxt->first_section = TRUE; ctxt->section = NULL; ctxt->column_spacing = gtk_print_context_get_dpi_x (context) / 4; ctxt->column_width = (page_width + ctxt->column_spacing) / ctxt->style->num_columns - ctxt->column_spacing; ctxt->letter_heading_font = pango_font_description_new (); pango_font_description_set_family ( ctxt->letter_heading_font, pango_font_description_get_family ( ctxt->style->headings_font)); pango_font_description_set_size ( ctxt->letter_heading_font, pango_font_description_get_size ( ctxt->style->headings_font) * 1.5); if (ctxt->contact_list != NULL) { ctxt->page_nr = -1; ctxt->pages = 1; g_slist_foreach (ctxt->contact_list, (GFunc) contact_draw, ctxt); gtk_print_operation_set_n_pages (operation, ctxt->pages); } }
static void gui_editor_begin_print (GtkPrintOperation *operation, GtkPrintContext *context, GUIEditor *editor) { g_assert (editor->buffer); /* Create a print compositor from the buffer */ editor->print_compositor = gtk_source_print_compositor_new (editor->buffer); /* Set some formatting options for pages */ gtk_source_print_compositor_set_print_header (editor->print_compositor, TRUE); gtk_source_print_compositor_set_print_footer (editor->print_compositor, TRUE); gtk_source_print_compositor_set_header_format (editor->print_compositor, TRUE, NULL, "%N/%Q", NULL); gtk_source_print_compositor_set_footer_format (editor->print_compositor, TRUE, NULL, PACKAGE_URL, NULL); gtk_source_print_compositor_set_left_margin (editor->print_compositor, 15.0, GTK_UNIT_MM); gtk_source_print_compositor_set_right_margin (editor->print_compositor, 15.0, GTK_UNIT_MM); gtk_source_print_compositor_set_bottom_margin (editor->print_compositor, 15.0, GTK_UNIT_MM); /* Pagination */ while (!gtk_source_print_compositor_paginate (editor->print_compositor, context)); gtk_print_operation_set_n_pages (operation, gtk_source_print_compositor_get_n_pages (editor->print_compositor)); }
/* Callback for beginning the print operation, we give the printed pages our tab width from the preferences, and the margins from the page setup dialog. */ static void on_begin_print(GtkPrintOperation *print, GtkPrintContext *context, I7Document *document) { I7App *theapp = i7_app_get(); GSettings *prefs = i7_app_get_prefs(theapp); GtkSourcePrintCompositor *compositor = gtk_source_print_compositor_new(i7_document_get_buffer(document)); g_signal_connect(print, "draw-page", G_CALLBACK(on_draw_page), compositor); g_signal_connect(print, "end-print", G_CALLBACK(on_end_print), compositor); /* Design our printed page */ unsigned tabwidth = g_settings_get_uint(prefs, PREFS_TAB_WIDTH); if(tabwidth == 0) tabwidth = DEFAULT_TAB_WIDTH; gtk_source_print_compositor_set_tab_width(compositor, tabwidth); gtk_source_print_compositor_set_wrap_mode(compositor, GTK_WRAP_WORD_CHAR); PangoFontDescription *font = get_font_description(); gchar *fontstring = pango_font_description_to_string(font); pango_font_description_free(font); gtk_source_print_compositor_set_body_font_name(compositor, fontstring); g_free(fontstring); GtkPageSetup *setup = i7_app_get_page_setup(i7_app_get()); gtk_source_print_compositor_set_top_margin(compositor, gtk_page_setup_get_top_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM); gtk_source_print_compositor_set_bottom_margin(compositor, gtk_page_setup_get_bottom_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM); gtk_source_print_compositor_set_left_margin(compositor, gtk_page_setup_get_left_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM); gtk_source_print_compositor_set_right_margin(compositor, gtk_page_setup_get_right_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM); /* Display a notification in the status bar while paginating */ i7_document_display_status_message(document, _("Paginating..."), PRINT_OPERATIONS); while(!gtk_source_print_compositor_paginate(compositor, context)) { i7_document_display_progress_percentage(document, gtk_source_print_compositor_get_pagination_progress(compositor)); while(gtk_events_pending()) gtk_main_iteration(); } i7_document_display_progress_percentage(document, 0.0); i7_document_remove_status_message(document, PRINT_OPERATIONS); gtk_print_operation_set_n_pages(print, gtk_source_print_compositor_get_n_pages(compositor)); }
static void cb_begin_print(GtkPrintOperation *op, GtkPrintContext *ctx, gpointer data) { gint layout_height; gchar *text; GtkTextIter start, end; GtkTextBuffer *buffer = gtk_text_view_get_buffer(data); PangoTabArray *tabs; gtk_text_buffer_get_bounds(buffer, &start, &end); text = g_strchomp(gtk_text_buffer_get_text(buffer, &start, &end, FALSE)); page_width = gtk_print_context_get_width(ctx); page_height = gtk_print_context_get_height(ctx); font_desc = gtk_widget_get_style(data)->font_desc; layout = gtk_print_context_create_pango_layout(ctx); pango_layout_set_width(layout, page_width * PANGO_SCALE); pango_layout_set_font_description(layout, font_desc); pango_layout_set_text(layout, text, -1); get_tab_array(&tabs, ctx, data); if (tabs) { pango_layout_set_tabs(layout, tabs); pango_tab_array_free(tabs); } pango_layout_get_size(layout, NULL, &layout_height); line_count = pango_layout_get_line_count(layout); text_height = pango_font_description_get_size(font_desc) / PANGO_SCALE; lines_per_page = page_height / text_height; n_pages = (line_count - 1) / lines_per_page + 1; gtk_print_operation_set_n_pages(op, n_pages); g_free(text); }
gint yad_print_run (void) { GtkWidget *dlg; GtkWidget *box, *img, *lbl; gchar *uri, *job_name = NULL; GtkPrintCapabilities pcap; GtkPrintOperationAction act = GTK_PRINT_OPERATION_ACTION_PRINT; gint resp, ret = 0; GError *err = NULL; /* check if file is exists */ if (options.common_data.uri && options.common_data.uri[0]) { if (!g_file_test (options.common_data.uri, G_FILE_TEST_EXISTS)) { g_printerr (_("File %s not found.\n"), options.common_data.uri); return 1; } } else { g_printerr (_("Filename is not specified.\n")); return 1; } /* create print dialog */ dlg = gtk_print_unix_dialog_new (options.data.dialog_title, NULL); gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_NORMAL); gtk_print_unix_dialog_set_embed_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), TRUE); pcap = GTK_PRINT_CAPABILITY_PAGE_SET | GTK_PRINT_CAPABILITY_COPIES | GTK_PRINT_CAPABILITY_COLLATE | GTK_PRINT_CAPABILITY_REVERSE | GTK_PRINT_CAPABILITY_NUMBER_UP | GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT; if (options.common_data.preview && options.print_data.type != YAD_PRINT_RAW) pcap |= GTK_PRINT_CAPABILITY_PREVIEW; gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dlg), pcap); if (!settings.print_settings) settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg)); uri = g_build_filename (g_get_current_dir (), "yad.pdf", NULL); gtk_print_settings_set (settings.print_settings, "output-uri", g_filename_to_uri (uri, NULL, NULL)); g_free (uri); gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (dlg), settings.print_settings); if (settings.page_setup) gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), settings.page_setup); /* set window behavior */ gtk_widget_set_name (dlg, "yad-dialog-window"); if (options.data.sticky) gtk_window_stick (GTK_WINDOW (dlg)); gtk_window_set_resizable (GTK_WINDOW (dlg), !options.data.fixed); gtk_window_set_keep_above (GTK_WINDOW (dlg), options.data.ontop); gtk_window_set_decorated (GTK_WINDOW (dlg), !options.data.undecorated); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), options.data.skip_taskbar); gtk_window_set_skip_pager_hint (GTK_WINDOW (dlg), options.data.skip_taskbar); /* set window size and position */ if (!options.data.geometry) { gtk_window_set_default_size (GTK_WINDOW (dlg), options.data.width, options.data.height); if (options.data.center) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER); else if (options.data.mouse) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE); } else { /* parse geometry, if given. must be after showing widget */ gtk_widget_realize (dlg); gtk_window_parse_geometry (GTK_WINDOW (dlg), options.data.geometry); } /* create yad's top box */ if (options.data.dialog_text || options.data.dialog_image) { #if !GTK_CHECK_VERSION(3,0,0) box = gtk_hbox_new (FALSE, 0); #else box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); #endif if (options.data.dialog_image) { GdkPixbuf *pb = NULL; pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON); img = gtk_image_new_from_pixbuf (pb); if (pb) g_object_unref (pb); gtk_widget_set_name (img, "yad-dialog-image"); gtk_box_pack_start (GTK_BOX (box), img, FALSE, FALSE, 2); } if (options.data.dialog_text) { gchar *buf = g_strcompress (options.data.dialog_text); lbl = gtk_label_new (NULL); if (!options.data.no_markup) gtk_label_set_markup (GTK_LABEL (lbl), buf); else gtk_label_set_text (GTK_LABEL (lbl), buf); gtk_widget_set_name (lbl, "yad-dialog-label"); gtk_label_set_selectable (GTK_LABEL (lbl), options.data.selectable_labels); gtk_misc_set_alignment (GTK_MISC (lbl), options.data.text_align, 0.5); if (options.data.geometry || options.data.width != -1) gtk_label_set_line_wrap (GTK_LABEL (lbl), TRUE); gtk_box_pack_start (GTK_BOX (box), lbl, TRUE, TRUE, 2); g_signal_connect (G_OBJECT (lbl), "size-allocate", G_CALLBACK (size_allocate_cb), NULL); g_free (buf); } /* add tob box to dialog */ gtk_widget_show_all (box); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, TRUE, TRUE, 5); gtk_box_reorder_child (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, 0); } do { resp = gtk_dialog_run (GTK_DIALOG (dlg)); switch (resp) { case GTK_RESPONSE_APPLY: /* ask for preview */ act = GTK_PRINT_OPERATION_ACTION_PREVIEW; case GTK_RESPONSE_OK: /* run print */ settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg)); settings.page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dlg)); job_name = g_strdup_printf ("yad-%s-%d", g_path_get_basename (options.common_data.uri), getpid ()); if (options.print_data.type != YAD_PRINT_RAW) { /* print text or image */ GtkPrintOperation *op = gtk_print_operation_new (); gtk_print_operation_set_unit (op, GTK_UNIT_POINTS); gtk_print_operation_set_print_settings (op, settings.print_settings); gtk_print_operation_set_default_page_setup (op, settings.page_setup); gtk_print_operation_set_job_name (op, job_name); switch (options.print_data.type) { case YAD_PRINT_TEXT: g_signal_connect (G_OBJECT (op), "begin-print", G_CALLBACK (begin_print_text), NULL); g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_text), NULL); break; case YAD_PRINT_IMAGE: gtk_print_operation_set_n_pages (op, 1); g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_image), NULL); break; default:; } if (gtk_print_operation_run (op, act, NULL, &err) == GTK_PRINT_OPERATION_RESULT_ERROR) { g_printerr (_("Printing failed: %s\n"), err->message); ret = 1; } } else { /* print raw ps or pdf data */ GtkPrinter *prnt; GtkPrintJob *job; prnt = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (dlg)); if (g_str_has_suffix (options.common_data.uri, ".ps")) { if (!gtk_printer_accepts_ps (prnt)) { g_printerr (_("Printer doesn't support ps format.\n")); ret = 1; } } else if (g_str_has_suffix (options.common_data.uri, ".pdf")) { if (!gtk_printer_accepts_pdf (prnt)) { g_printerr (_("Printer doesn't support pdf format.\n")); ret = 1; } } else { g_printerr (_("This file type is not supported for raw printing.\n")); ret = 1; } if (ret == 1) break; job = gtk_print_job_new (job_name, prnt, settings.print_settings, settings.page_setup); if (gtk_print_job_set_source_file (job, options.common_data.uri, &err)) { gtk_print_job_send (job, (GtkPrintJobCompleteFunc) raw_print_done, &ret, NULL); gtk_main (); } else { g_printerr (_("Load source file failed: %s\n"), err->message); ret = 1; } } break; default: ret = 1; break; } } while (resp == GTK_RESPONSE_APPLY); gtk_widget_destroy (dlg); write_settings (); return ret; }
GtkPrintOperation * xviewer_print_operation_new (XviewerImage *image, GtkPrintSettings *print_settings, GtkPageSetup *page_setup) { GtkPrintOperation *print; XviewerPrintData *data; gint width, height; xviewer_debug (DEBUG_PRINTING); print = gtk_print_operation_new (); data = g_slice_new0 (XviewerPrintData); data->left_margin = 0; data->top_margin = 0; data->scale_factor = 100; data->image = g_object_ref (image); data->unit = GTK_UNIT_INCH; xviewer_image_get_size (image, &width, &height); if (page_setup == NULL) page_setup = gtk_page_setup_new (); if (height >= width) { gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT); } else { gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE); } gtk_print_operation_set_print_settings (print, print_settings); gtk_print_operation_set_default_page_setup (print, page_setup); gtk_print_operation_set_n_pages (print, 1); gtk_print_operation_set_job_name (print, xviewer_image_get_caption (image)); gtk_print_operation_set_embed_page_setup (print, TRUE); g_signal_connect (print, "draw_page", G_CALLBACK (xviewer_print_draw_page), data); g_signal_connect (print, "create-custom-widget", G_CALLBACK (xviewer_print_create_custom_widget), data); g_signal_connect (print, "custom-widget-apply", G_CALLBACK (xviewer_print_custom_widget_apply), data); g_signal_connect (print, "end-print", G_CALLBACK (xviewer_print_end_print), data); g_signal_connect (print, "update-custom-widget", G_CALLBACK (xviewer_print_image_setup_update), data); gtk_print_operation_set_custom_tab_label (print, _("Image Settings")); return print; }
static GimpPDBStatusType print_image (gint32 image_ID, gboolean interactive, GError **error) { GtkPrintOperation *operation; GtkPrintOperationResult result; gchar *temp_proc; gint32 layer; PrintData data; /* create a print layer from the projection */ layer = gimp_layer_new_from_visible (image_ID, image_ID, PRINT_PROC_NAME); operation = gtk_print_operation_new (); gtk_print_operation_set_n_pages (operation, 1); print_operation_set_name (operation, image_ID); print_page_setup_load (operation, image_ID); /* fill in the PrintData struct */ data.image_id = image_ID; data.drawable_id = layer; data.unit = gimp_get_default_unit (); data.image_unit = gimp_image_get_unit (image_ID); data.offset_x = 0; data.offset_y = 0; data.center = CENTER_BOTH; data.use_full_page = FALSE; data.operation = operation; gimp_image_get_resolution (image_ID, &data.xres, &data.yres); print_settings_load (&data); gtk_print_operation_set_unit (operation, GTK_UNIT_PIXEL); g_signal_connect (operation, "begin-print", G_CALLBACK (begin_print), &data); g_signal_connect (operation, "draw-page", G_CALLBACK (draw_page), &data); g_signal_connect (operation, "end-print", G_CALLBACK (end_print), &image_ID); print_operation = operation; temp_proc = print_temp_proc_install (image_ID); gimp_extension_enable (); if (interactive) { gimp_ui_init (PLUG_IN_BINARY, FALSE); g_signal_connect_swapped (operation, "end-print", G_CALLBACK (print_settings_save), &data); g_signal_connect (operation, "create-custom-widget", G_CALLBACK (create_custom_widget), &data); gtk_print_operation_set_custom_tab_label (operation, _("Image Settings")); result = gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, error); } else { result = gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT, NULL, error); } gimp_uninstall_temp_proc (temp_proc); g_free (temp_proc); print_operation = NULL; g_object_unref (operation); if (gimp_drawable_is_valid (layer)) gimp_drawable_delete (layer); switch (result) { case GTK_PRINT_OPERATION_RESULT_APPLY: case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS: return GIMP_PDB_SUCCESS; case GTK_PRINT_OPERATION_RESULT_CANCEL: return GIMP_PDB_CANCEL; case GTK_PRINT_OPERATION_RESULT_ERROR: return GIMP_PDB_EXECUTION_ERROR; } return GIMP_PDB_EXECUTION_ERROR; }
/** * Function called first when try to print the transaction list * initialize the variables and calculate the number of pages * * \param operation GtkPrintOperation * \param context GtkPrintContext * \param null * * \return FALSE * */ gboolean print_transactions_list_begin ( GtkPrintOperation *operation, GtkPrintContext *context, gpointer null ) { CustomList *custom_list; gint size_transaction; gint size_title = 0; gint size_archive = 0; gdouble transactions_per_page_double; gint nb_pages; gint number_of_archives = 0; devel_debug (NULL); /* we need to calculate the number of pages */ cr = gtk_print_context_get_cairo_context (context); custom_list = transaction_model_get_model (); /* get the size of the title */ if (gsb_data_print_config_get_draw_title () && title_string && strlen (title_string)) size_title = pango_font_description_get_size (gsb_data_print_config_get_font_title ())/PANGO_SCALE; /* we need the number of archives and of transactions to print * number_of_archives will be set to 0 if no draw archives */ print_transactions_list_get_visibles_lines (&number_of_archives, &total_transactions_to_print ); /* xxx mk_include 2 fois de suite modifie qd même des fichiers */ /* get the size of a complete transaction and an archive */ size_row = pango_font_description_get_size (gsb_data_print_config_get_font_transactions ())/PANGO_SCALE; size_transaction = size_row * custom_list -> nb_rows_by_transaction + 2*gsb_data_print_config_get_draw_lines (); size_archive = size_row + 2*gsb_data_print_config_get_draw_lines (); /* the heigh of a page decrease of 1 line if we use the columns titles */ page_height = gtk_print_context_get_height (context) - gsb_data_print_config_get_draw_columns_name ()*size_transaction; /* how much transactions we can show in a page : */ transactions_per_page_double = page_height / size_transaction; if (!size_title && !gsb_data_print_config_get_draw_archives ()) { /* simple way : no archives and no title */ nb_pages = ceil ( total_transactions_to_print / transactions_per_page_double ); transactions_in_first_page = floor (transactions_per_page_double); } else { /* there are title or archives, it's more complex because it will have less transactions * on the first page */ gint first_page_height = page_height - size_title - size_archive*number_of_archives; transactions_in_first_page = floor (first_page_height / size_transaction); nb_pages = 1 + ceil ( (total_transactions_to_print - transactions_in_first_page)/ transactions_per_page_double ); } /* set the number of page */ gtk_print_operation_set_n_pages ( GTK_PRINT_OPERATION (operation), nb_pages ); /* save the nb of transactions per page */ transactions_per_page = floor (transactions_per_page_double); /* calculate the size and position of the columns */ page_width = gtk_print_context_get_width (context); print_transactions_list_calculate_columns (page_width); total_transactions_printed = 0; current_row_to_print = 0; return FALSE; }