GtkPrintOperation * e_print_operation_new (void) { GtkPrintOperation *operation; GtkPrintSettings *settings; GtkPageSetup *page_setup; GKeyFile *key_file; operation = gtk_print_operation_new (); key_file = g_key_file_new (); load_key_file (key_file); settings = load_settings (key_file); gtk_print_operation_set_print_settings (operation, settings); g_object_unref (settings); page_setup = load_page_setup (key_file); gtk_print_operation_set_default_page_setup (operation, page_setup); g_object_unref (page_setup); g_signal_connect ( operation, "done", G_CALLBACK (print_done_cb), key_file); return operation; }
static GtkPrintOperation *create_print_operation(GtkTextView *text_view) { GtkPrintOperation *op; static GtkPageSetup *page_setup = NULL; op = gtk_print_operation_new(); if (settings) gtk_print_operation_set_print_settings(op, settings); if (!page_setup) { page_setup = gtk_page_setup_new(); gtk_page_setup_set_top_margin(page_setup, 25.0, GTK_UNIT_MM); gtk_page_setup_set_bottom_margin(page_setup, 20.0, GTK_UNIT_MM); gtk_page_setup_set_left_margin(page_setup, 20.0, GTK_UNIT_MM); gtk_page_setup_set_right_margin(page_setup, 20.0, GTK_UNIT_MM); } gtk_print_operation_set_default_page_setup(op, page_setup); g_signal_connect(op, "begin-print", G_CALLBACK(cb_begin_print), text_view); g_signal_connect(op, "draw-page", G_CALLBACK(cb_draw_page), NULL); g_signal_connect(op, "end-print", G_CALLBACK(cb_end_print), NULL); return op; }
void XAP_UnixDialog_Print::PrintDirectly(XAP_Frame * pFrame, const char * szFilename, const char * szPrinter) { m_pFrame = pFrame; setupPrint(); if(szFilename) { gtk_print_operation_set_export_filename(m_pPO, szFilename); gtk_print_operation_run (m_pPO,GTK_PRINT_OPERATION_ACTION_EXPORT, NULL,NULL); } else { GtkPrintSettings * pSettings = gtk_print_operation_get_print_settings(m_pPO); if(szPrinter) { gtk_print_settings_set_printer(pSettings, szPrinter); } else { gtk_print_settings_set_printer(pSettings, GTK_PRINT_SETTINGS_PRINTER); } gtk_print_operation_set_print_settings(m_pPO,pSettings); gtk_print_operation_run (m_pPO,GTK_PRINT_OPERATION_ACTION_PRINT, NULL,NULL); } cleanup(); }
static void printing_print_gtk(GeanyDocument *doc) { GtkPrintOperation *op; GtkPrintOperationResult res = GTK_PRINT_OPERATION_RESULT_ERROR; GError *error = NULL; DocInfo *dinfo; PrintWidgets *widgets; /** TODO check for monospace font, detect the widest character in the font and * use it at font_width */ widgets = g_new0(PrintWidgets, 1); dinfo = g_new0(DocInfo, 1); /* all other fields are initialised in begin_print() */ dinfo->doc = doc; op = gtk_print_operation_new(); gtk_print_operation_set_unit(op, GTK_UNIT_POINTS); gtk_print_operation_set_show_progress(op, TRUE); #if GTK_CHECK_VERSION(2, 18, 0) gtk_print_operation_set_embed_page_setup(op, TRUE); #endif g_signal_connect(op, "begin-print", G_CALLBACK(begin_print), dinfo); g_signal_connect(op, "end-print", G_CALLBACK(end_print), dinfo); g_signal_connect(op, "draw-page", G_CALLBACK(draw_page), dinfo); g_signal_connect(op, "status-changed", G_CALLBACK(status_changed), doc->file_name); g_signal_connect(op, "create-custom-widget", G_CALLBACK(create_custom_widget), widgets); g_signal_connect(op, "custom-widget-apply", G_CALLBACK(custom_widget_apply), widgets); if (settings != NULL) gtk_print_operation_set_print_settings(op, settings); if (page_setup != NULL) gtk_print_operation_set_default_page_setup(op, page_setup); res = gtk_print_operation_run( op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(main_widgets.window), &error); if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (settings != NULL) g_object_unref(settings); settings = g_object_ref(gtk_print_operation_get_print_settings(op)); /* status message is printed in the status-changed handler */ } else if (res == GTK_PRINT_OPERATION_RESULT_ERROR) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of %s failed (%s)."), doc->file_name, error->message); g_error_free(error); } g_object_unref(op); g_free(dinfo); g_free(widgets); }
void x_print (GschemToplevel *w_current) { static GtkPrintSettings *settings = NULL; GtkPageSetup *setup; GtkPrintOperation *print; GtkPrintOperationResult res; GError *err = NULL; int num_pages = 1; /* Create the print operation and set it up */ print = GTK_PRINT_OPERATION (g_object_new (GTK_TYPE_PRINT_OPERATION, "n-pages", num_pages, "use-full-page", FALSE, "unit", GTK_UNIT_POINTS, NULL)); if (settings != NULL) { gtk_print_operation_set_print_settings (print, settings); } setup = x_print_default_page_setup (w_current->toplevel, w_current->toplevel->page_current); gtk_print_operation_set_default_page_setup (print, setup); g_signal_connect (print, "draw_page", G_CALLBACK (draw_page__print_operation), w_current); res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (w_current->main_window), &err); if (res == GTK_PRINT_OPERATION_RESULT_ERROR) { /* If printing failed due to an error, show an error dialog */ GtkWidget *error_dialog = gtk_message_dialog_new (GTK_WINDOW (w_current->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Error printing file:\n%1$s"), err->message); g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (error_dialog); g_error_free (err); } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { /* We're supposed to store the print settings, so do that */ if (settings != NULL) { g_object_unref (settings); } settings = GTK_PRINT_SETTINGS (g_object_ref (gtk_print_operation_get_print_settings (print))); } /* Clean up */ g_object_unref (print); }
GtkWidget * do_printing (GtkWidget *do_widget) { GtkPrintOperation *operation; GtkPrintSettings *settings; PrintData *data; GError *error = NULL; operation = gtk_print_operation_new (); data = g_new0 (PrintData, 1); data->resourcename = g_strdup ("/sources/printing.c"); data->font_size = 12.0; g_signal_connect (G_OBJECT (operation), "begin-print", G_CALLBACK (begin_print), data); g_signal_connect (G_OBJECT (operation), "draw-page", G_CALLBACK (draw_page), data); g_signal_connect (G_OBJECT (operation), "end-print", G_CALLBACK (end_print), data); gtk_print_operation_set_use_full_page (operation, FALSE); gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS); gtk_print_operation_set_embed_page_setup (operation, TRUE); settings = gtk_print_settings_new (); gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_BASENAME, "gtk-demo"); gtk_print_operation_set_print_settings (operation, settings); gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (do_widget), &error); g_object_unref (operation); g_object_unref (settings); if (error) { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message); g_error_free (error); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (dialog); } return NULL; }
void a_print(VikWindow *vw, VikViewport *vvp) { /* TODO: make print_settings non-static when saving_settings_to_file is * implemented. Keep it static for now to retain settings for each * viking session */ static GtkPrintSettings *print_settings = NULL; GtkPrintOperation *print_oper; GtkPrintOperationResult res; PrintData data; print_oper = gtk_print_operation_new (); data.num_pages = 1; data.vw = vw; data.vvp = vvp; data.offset_x = 0; data.offset_y = 0; data.center = VIK_PRINT_CENTER_BOTH; data.use_full_page = FALSE; data.operation = print_oper; data.xmpp = vik_viewport_get_xmpp(vvp); data.ympp = vik_viewport_get_ympp(vvp); data.width = vik_viewport_get_width(vvp); data.height = vik_viewport_get_height(vvp); data.xres = data.yres = 230; /* FIXME */ if (print_settings != NULL) gtk_print_operation_set_print_settings (print_oper, print_settings); g_signal_connect (print_oper, "begin_print", G_CALLBACK (begin_print), &data); g_signal_connect (print_oper, "draw_page", G_CALLBACK (draw_page), &data); g_signal_connect (print_oper, "end-print", G_CALLBACK (end_print), &data); g_signal_connect (print_oper, "create-custom-widget", G_CALLBACK (create_custom_widget_cb), &data); gtk_print_operation_set_custom_tab_label (print_oper, _("Image Settings")); res = gtk_print_operation_run (print_oper, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (vw), NULL); if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (print_settings != NULL) g_object_unref (print_settings); print_settings = g_object_ref (gtk_print_operation_get_print_settings (print_oper)); } g_object_unref (print_oper); }
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 gnc_print_operation_init(GtkPrintOperation *op) { g_return_if_fail(op); /* Restore print settings */ G_LOCK(print_settings); if (print_settings) gtk_print_operation_set_print_settings(op, print_settings); G_UNLOCK(print_settings); /* Restore page setup */ G_LOCK(page_setup); if (page_setup) gtk_print_operation_set_default_page_setup(op, page_setup); G_UNLOCK(page_setup); }
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); }
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; }
/* File->Print... */ void action_print(GtkAction *action, I7Document *document) { GError *error = NULL; I7App *theapp = i7_app_get(); GtkPrintOperation *print = gtk_print_operation_new(); GtkPrintSettings *settings = i7_app_get_print_settings(theapp); if(settings) gtk_print_operation_set_print_settings(print, settings); g_signal_connect(print, "begin-print", G_CALLBACK(on_begin_print), document); GtkPrintOperationResult result = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(document), &error); if(result == GTK_PRINT_OPERATION_RESULT_APPLY) i7_app_set_print_settings(theapp, g_object_ref(gtk_print_operation_get_print_settings(print))); else if(result == GTK_PRINT_OPERATION_RESULT_ERROR) /* TRANSLATORS: File->Print... */ error_dialog(GTK_WINDOW(document), error, _("There was an error printing: ")); g_object_unref(print); }
static void print_or_preview (GSimpleAction *action, GtkPrintOperationAction print_action) { GtkPrintOperation *print; PrintData *print_data; print_data = g_new0 (PrintData, 1); print_data->text = get_text (); print_data->font = g_strdup ("Sans 12"); print = gtk_print_operation_new (); gtk_print_operation_set_track_print_status (print, TRUE); if (settings != NULL) gtk_print_operation_set_print_settings (print, settings); if (page_setup != NULL) gtk_print_operation_set_default_page_setup (print, page_setup); g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), print_data); g_signal_connect (print, "end-print", G_CALLBACK (end_print), print_data); g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), print_data); g_signal_connect (print, "create_custom_widget", G_CALLBACK (create_custom_widget), print_data); g_signal_connect (print, "custom_widget_apply", G_CALLBACK (custom_widget_apply), print_data); g_signal_connect (print, "preview", G_CALLBACK (preview_cb), print_data); g_signal_connect (print, "done", G_CALLBACK (print_done), print_data); gtk_print_operation_set_export_filename (print, "test.pdf"); #if 0 gtk_print_operation_set_allow_async (print, TRUE); #endif gtk_print_operation_run (print, print_action, GTK_WINDOW (main_window), NULL); g_object_unref (print); }
//! //! @brief Sets up a print operation for the current results //! //! The function checks the results of the results text buffer, and then attempts //! to set up a print operation. If a section of the search results are highlighted //! only those results are printed. //! void gw_print (const GtkPrintOperationAction ACTION, GwSearchWindow *window) { //Declarations GwPrintData *data; GtkPrintOperation *operation; GtkPrintOperationResult res; //Initializations data = gw_printdata_new (window); operation = gtk_print_operation_new (); //Force at least some minimal margins on the pages that print gtk_print_operation_set_default_page_setup (operation, NULL); gtk_print_operation_set_use_full_page (operation, FALSE); gtk_print_operation_set_unit (operation, GTK_UNIT_MM); if (_settings != NULL) gtk_print_operation_set_print_settings (operation, _settings); 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, "paginate", G_CALLBACK (_paginate), data); g_signal_connect (operation, "done", G_CALLBACK (_done), data); res = gtk_print_operation_run (operation, ACTION, NULL, 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 (operation)); } //Cleanup gw_printdata_free (data); g_object_unref (operation); }
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; }
void CmOutputPrinter(int select_file, int show_dialog) { GtkPrintOperation *print; GtkPrintOperationResult res; char buf[MESSAGE_BUF_SIZE]; struct objlist *graobj, *g2wobj; int id, g2wid, g2woid, opt; N_VALUE *g2winst; GError *error; struct print_obj pobj; GtkPaperSize *paper_size; GtkPageSetup *page_setup; if (Menulock || Globallock) return; if (select_file && ! SetFileHidden()) return; FileAutoScale(); AdjustAxis(); graobj = chkobject("gra"); if (graobj == NULL) return; g2wobj = chkobject("gra2gtkprint"); if (g2wobj == NULL) return; g2wid = newobj(g2wobj); if (g2wid < 0) return; putobj(g2wobj, "use_opacity", g2wid, &Menulocal.use_opacity); g2winst = chkobjinst(g2wobj, g2wid); _getobj(g2wobj, "oid", g2winst, &g2woid); id = newobj(graobj); init_graobj(graobj, id, "gra2gtkprint", g2woid); print = gtk_print_operation_new(); gtk_print_operation_set_n_pages(print, 1); #if GTK_CHECK_VERSION(2, 18, 0) gtk_print_operation_set_has_selection(print, FALSE); gtk_print_operation_set_support_selection(print, FALSE); gtk_print_operation_set_embed_page_setup(print, FALSE); #endif gtk_print_operation_set_use_full_page(print, TRUE); if (PrintSettings == NULL) PrintSettings = gtk_print_settings_new(); if (Menulocal.PaperId == PAPER_ID_CUSTOM) { paper_size = gtk_paper_size_new_custom(Menulocal.PaperName, Menulocal.PaperName, Menulocal.PaperWidth / 100.0, Menulocal.PaperHeight / 100.0, GTK_UNIT_MM); } else { paper_size = gtk_paper_size_new(Menulocal.PaperName); } page_setup = gtk_page_setup_new(); gtk_page_setup_set_paper_size(page_setup, paper_size); if (Menulocal.PaperLandscape) { gtk_page_setup_set_orientation(page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE); } else { gtk_page_setup_set_orientation(page_setup, GTK_PAGE_ORIENTATION_PORTRAIT); } gtk_print_operation_set_default_page_setup(print, page_setup); gtk_print_operation_set_print_settings(print, PrintSettings); pobj.graobj = graobj; pobj.id = id; pobj.g2wobj = g2wobj; pobj.g2winst = g2winst; g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), &pobj); switch (show_dialog) { case PRINT_SHOW_DIALOG_NONE: opt = GTK_PRINT_OPERATION_ACTION_PRINT; break; case PRINT_SHOW_DIALOG_PREVIEW: opt = GTK_PRINT_OPERATION_ACTION_PREVIEW; break; case PRINT_SHOW_DIALOG_DIALOG: opt = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; break; default: opt = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; } res = gtk_print_operation_run(print, opt, GTK_WINDOW(TopLevel), &error); if (res == GTK_PRINT_OPERATION_RESULT_ERROR) { snprintf(buf, sizeof(buf), _("Printing error: %s"), error->message); message_box(NULL, buf, _("Print"), RESPONS_ERROR); g_error_free(error); } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (PrintSettings) g_object_unref(PrintSettings); PrintSettings = g_object_ref(gtk_print_operation_get_print_settings(print)); } g_object_unref(print); delobj(graobj, id); delobj(g2wobj, g2wid); if (select_file && NgraphApp.FileWin.data.data) { FileWinUpdate(NgraphApp.FileWin.data.data, TRUE); } }
static void finish_print (PortalData *portal, GtkPrinter *printer, GtkPageSetup *page_setup, GtkPrintSettings *settings) { GtkPrintOperation *op = portal->op; GtkPrintOperationPrivate *priv = op->priv; GtkPrintJob *job; GtkPrintOperationPortal *op_portal; cairo_t *cr; if (portal->do_print) { gtk_print_operation_set_print_settings (op, settings); priv->print_context = _gtk_print_context_new (op); _gtk_print_context_set_hard_margins (priv->print_context, 0, 0, 0, 0); gtk_print_operation_set_default_page_setup (op, page_setup); _gtk_print_context_set_page_setup (priv->print_context, page_setup); op_portal = g_new0 (GtkPrintOperationPortal, 1); priv->platform_data = op_portal; priv->free_platform_data = (GDestroyNotify) op_portal_free; priv->start_page = portal_start_page; priv->end_page = portal_end_page; priv->end_run = portal_end_run; job = gtk_print_job_new (priv->job_name, printer, settings, page_setup); op_portal->job = job; op_portal->proxy = g_object_ref (portal->proxy); op_portal->token = portal->token; op_portal->surface = gtk_print_job_get_surface (job, &priv->error); if (op_portal->surface == NULL) { portal->result = GTK_PRINT_OPERATION_RESULT_ERROR; portal->do_print = FALSE; goto out; } cr = cairo_create (op_portal->surface); gtk_print_context_set_cairo_context (priv->print_context, cr, 72, 72); cairo_destroy (cr); priv->print_pages = gtk_print_job_get_pages (job); priv->page_ranges = gtk_print_job_get_page_ranges (job, &priv->num_page_ranges); priv->manual_num_copies = gtk_print_job_get_num_copies (job); priv->manual_collation = gtk_print_job_get_collate (job); priv->manual_reverse = gtk_print_job_get_reverse (job); priv->manual_page_set = gtk_print_job_get_page_set (job); priv->manual_scale = gtk_print_job_get_scale (job); priv->manual_orientation = gtk_print_job_get_rotate (job); priv->manual_number_up = gtk_print_job_get_n_up (job); priv->manual_number_up_layout = gtk_print_job_get_n_up_layout (job); } out: if (portal->print_cb) portal->print_cb (op, portal->parent, portal->do_print, portal->result); if (portal->destroy) portal->destroy (portal); }
int PrintText(const char *name, gchar *text) { GKeyFile *conf = GetConf(); GtkPrintOperation *prt; const gchar *font; GtkPageSetup *page_setup = NULL; GtkPrintSettings *print_settings = NULL; if(!text) return -EINVAL; prt = gtk_print_operation_new(); if(!prt) return -1; // Set job parameters g_object_set_data_full(G_OBJECT(prt),"3270Text",g_strsplit(g_strchomp(text),"\n",-1),(void (*)(gpointer)) g_strfreev); // Set print font = GetString("Print","Font",""); if(!*font) font = GetString("Terminal","Font","Courier"); g_object_set_data_full(G_OBJECT(prt),"3270FontName",g_strdup(font),g_free); // Configure print operation gtk_print_operation_set_job_name(prt,name); gtk_print_operation_set_allow_async(prt,0); gtk_print_operation_set_show_progress(prt,1); gtk_print_operation_set_custom_tab_label(prt,_( "Font" )); g_signal_connect(prt, "begin-print", G_CALLBACK(begin_print), 0); g_signal_connect(prt, "draw-page", G_CALLBACK(draw_page), 0); #ifdef HAVE_PRINT_FONT_DIALOG g_signal_connect(prt, "create-custom-widget", G_CALLBACK(create_custom_widget), 0); g_signal_connect(prt, "custom-widget-apply", G_CALLBACK(custom_widget_apply), 0); #endif g_signal_connect(prt, "done", G_CALLBACK(print_done), 0); if(conf) { #if GTK_CHECK_VERSION(2,12,0) gchar *ptr = g_key_file_get_string(conf,"Print Settings","output-uri",NULL); if(ptr) { gchar *uri = NULL; switch(*(ptr++)) { case '$': if(g_str_has_prefix(ptr,"home/")) uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr+5); #if GTK_CHECK_VERSION(2,14,0) else if(g_str_has_prefix(ptr,"documents/")) uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS),ptr+10); else if(g_str_has_prefix(ptr,"desktop/")) uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP),ptr+8); #endif break; case '~': uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr); break; } if(uri) { g_key_file_set_string(conf,"Print Settings","output-uri",uri); g_free(uri); } } print_settings = gtk_print_settings_new_from_key_file(conf,NULL,NULL); page_setup = gtk_page_setup_new_from_key_file(conf,NULL,NULL); if(!page_setup) page_setup = gtk_page_setup_new(); #else // GTK_CHECK_VERSION(2,12,0) print_settings = gtk_print_settings_new(); if(print_settings) { gchar **list; int f; list = g_key_file_get_keys(conf,"PrintSettings",NULL,NULL); if(list) { for(f=0;list[f];f++) gtk_print_settings_set(print_settings,list[f],g_key_file_get_string(conf,"PrintSettings",list[f],NULL)); g_strfreev(list); } } page_setup = gtk_page_setup_new(); #endif } else { page_setup = gtk_page_setup_new(); gtk_print_operation_set_print_settings(prt,gtk_print_settings_new()); } Trace("page_setup: %p print_settings: %p",page_setup,print_settings); gtk_print_operation_set_print_settings(prt,print_settings); gtk_print_operation_set_default_page_setup(prt,page_setup); // Run Print dialog gtk_print_operation_run(prt,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(topwindow),NULL); g_object_unref(prt); return 0; }
GtkWidget * do_printing (GtkWidget *do_widget) { GtkPrintOperation *operation; GtkPrintSettings *settings; PrintData *data; gchar *uri, *ext; const gchar *dir; GError *error = NULL; operation = gtk_print_operation_new (); data = g_new0 (PrintData, 1); data->filename = demo_find_file ("printing.c", NULL); data->font_size = 12.0; g_signal_connect (G_OBJECT (operation), "begin-print", G_CALLBACK (begin_print), data); g_signal_connect (G_OBJECT (operation), "draw-page", G_CALLBACK (draw_page), data); g_signal_connect (G_OBJECT (operation), "end-print", G_CALLBACK (end_print), data); gtk_print_operation_set_use_full_page (operation, FALSE); gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS); gtk_print_operation_set_embed_page_setup (operation, TRUE); settings = gtk_print_settings_new (); dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); if (dir == NULL) dir = g_get_home_dir (); if (g_strcmp0 (gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT), "ps") == 0) ext = ".ps"; else if (g_strcmp0 (gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT), "svg") == 0) ext = ".svg"; else ext = ".pdf"; uri = g_strconcat ("file://", dir, "/", "gtk-demo", ext, NULL); gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri); gtk_print_operation_set_print_settings (operation, settings); gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (do_widget), &error); g_object_unref (operation); g_object_unref (settings); g_free (uri); if (error) { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message); g_error_free (error); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (dialog); } return NULL; }
/** * Prints the current page. * * If printing on WIN32, in order to prevent the font from being tiny, (see bug #591177), * A GtkPrintOperation object needs to be created so that the unit can be set, and then * webkit_web_frame_print_full() needs to be called to use that GtkPrintOperation. On * other platforms (specifically linux - not sure about MacOSX), the version of webkit may * not contain the function webkit_web_frame_print_full(), so webkit_web_frame_print() is * called instead (the font size problem doesn't show up on linux). * * @param self HTML renderer object */ static void impl_webkit_print( GncHtml* self, const gchar* jobname, gboolean export_pdf ) { #if !HAVE(WEBKIT_WEB_FRAME_PRINT_FULL) extern void webkit_web_frame_print( WebKitWebFrame * frame ); #endif gchar *export_filename = NULL; GncHtmlWebkitPrivate* priv; WebKitWebFrame* frame; #if HAVE(WEBKIT_WEB_FRAME_PRINT_FULL) GtkPrintOperation* op = gtk_print_operation_new(); GError* error = NULL; GtkPrintSettings *print_settings; #endif priv = GNC_HTML_WEBKIT_GET_PRIVATE(self); frame = webkit_web_view_get_main_frame( priv->web_view ); #if HAVE(WEBKIT_WEB_FRAME_PRINT_FULL) gnc_print_operation_init( op, jobname ); print_settings = gtk_print_operation_get_print_settings (op); if (!print_settings) { print_settings = gtk_print_settings_new(); gtk_print_operation_set_print_settings(op, print_settings); } #ifdef G_OS_WIN32 gtk_print_operation_set_unit( op, GTK_UNIT_POINTS ); #endif // Make sure to generate a full export filename if (g_str_has_suffix(jobname, ".pdf")) { export_filename = g_strdup(jobname); } else { export_filename = g_strconcat(jobname, ".pdf", NULL); } // Two different modes of operation. Either export to PDF, or run the // normal print dialog if (export_pdf) { GtkWidget *dialog; gint result; gchar *export_dirname = NULL; gchar* basename; // Before we save the PDF file, we always as the user for the export // file name. We will store the chosen directory in the gtk print settings // as well. dialog = gtk_file_chooser_dialog_new (_("Export to PDF File"), NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); // Does the jobname look like a valid full file path? basename = g_path_get_basename(jobname); if (strcmp(basename, jobname) != 0) { gchar *tmp_basename; gchar *tmp_dirname = g_path_get_dirname(jobname); if (g_file_test(tmp_dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { // Yes, the jobname starts with a directory name that actually // exists. Hence we use this as output directory. export_dirname = tmp_dirname; tmp_dirname = NULL; // As the prefix part of the "jobname" is the directory path, we // need to extract the suffix part for the filename. tmp_basename = g_path_get_basename(export_filename); g_free(export_filename); export_filename = tmp_basename; } g_free(tmp_dirname); } g_free(basename); // Set the output file name from the given jobname gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), export_filename); // Do we have a stored output directory? if (!export_dirname && gtk_print_settings_has_key(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR)) { const char* tmp_dirname = gtk_print_settings_get(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR); // Only use the directory subsequently if it exists. if (g_file_test(tmp_dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { export_dirname = g_strdup(tmp_dirname); } } // If we have an already existing directory, propose it now. if (export_dirname) { gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), export_dirname); } g_free(export_dirname); result = gtk_dialog_run (GTK_DIALOG (dialog)); // Weird. In gtk_dialog_run, the gtk code will run a fstat() on the // proposed new output filename, which of course fails with "file not // found" as this file doesn't exist. It will still show a warning output // in the trace file, though. if (result == GTK_RESPONSE_ACCEPT) { // The user pressed "Ok", so use the file name for the actual file output. gchar *dirname; char *tmp = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); g_free(export_filename); export_filename = tmp; // Store the directory part of the file for later dirname = g_path_get_dirname(export_filename); if (g_file_test(dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { gtk_print_settings_set(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR, dirname); } g_free(dirname); } gtk_widget_destroy (dialog); if (result != GTK_RESPONSE_ACCEPT) { // User pressed cancel - no saving of the PDF file here. g_free(export_filename); g_object_unref( op ); return; } // This function expects the full filename including (absolute?) path gtk_print_operation_set_export_filename(op, export_filename); // Run the "Export to PDF" print operation webkit_web_frame_print_full( frame, op, GTK_PRINT_OPERATION_ACTION_EXPORT, &error ); } else { // Also store this export file name as output URI in the settings if (gtk_print_settings_has_key(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI)) { // Get the previous output URI, extract the directory part, and // append the current filename. const gchar *olduri = gtk_print_settings_get(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI); gchar *dirname = g_path_get_dirname(olduri); gchar *newuri = (g_strcmp0(dirname, ".") == 0) ? g_strdup(export_filename) : g_build_filename(dirname, export_filename, NULL); //g_warning("olduri=%s newuri=%s", olduri, newuri); // This function expects the full filename including protocol, path, and name gtk_print_settings_set(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI, newuri); g_free(newuri); g_free(dirname); } else { // No stored output URI from the print settings, so just set our export filename gtk_print_settings_set(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI, export_filename); } // Run the normal printing dialog webkit_web_frame_print_full( frame, op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, &error ); } if ( error != NULL ) { GtkWidget* window = gtk_widget_get_toplevel( GTK_WIDGET(priv->web_view) ); GtkWidget* dialog = gtk_message_dialog_new( gtk_widget_is_toplevel(window) ? GTK_WINDOW(window) : NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message ); g_error_free( error ); g_signal_connect( dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL); gtk_widget_show( dialog ); } // Remember to save the printing settings after this print job gnc_print_operation_save_print_settings(op); g_object_unref( op ); g_free(export_filename); #else webkit_web_frame_print( frame ); #endif }
void XAP_UnixDialog_Print::setupPrint() { double blockMrgnLeft, blockMrgnRight, mrgnTop, mrgnBottom, mrgnLeft, mrgnRight = 0.; double width, height; bool portrait; m_pView = static_cast<FV_View*>(m_pFrame->getCurrentView()); m_pPO = gtk_print_operation_new(); // // Set filename if it's not present already // std::string sURI = m_pView->getDocument()->getPrintFilename(); if(sURI.empty()) { const std::string & filename = m_pView->getDocument()->getFilename(); if(!filename.empty()) { sURI = filename; UT_addOrReplacePathSuffix(sURI, ".pdf"); } } if(!sURI.empty()) { GtkPrintSettings * pSettings = gtk_print_settings_new(); gtk_print_settings_set(pSettings, GTK_PRINT_SETTINGS_OUTPUT_URI, sURI.c_str() ); gtk_print_operation_set_print_settings(m_pPO,pSettings); g_object_unref(pSettings); } s_getPageMargins(m_pView, blockMrgnLeft, blockMrgnRight, mrgnLeft, mrgnRight, mrgnTop, mrgnBottom); portrait = m_pView->getPageSize().isPortrait(); width = m_pView->getPageSize().Width (DIM_MM); height = m_pView->getPageSize().Height (DIM_MM); m_pPageSetup = gtk_page_setup_new(); const char * pszName = m_pView->getPageSize().getPredefinedName(); bool isPredefined = false; const char * pszGtkName = NULL; if(pszName == NULL) { } else if(g_ascii_strcasecmp(pszName,"Custom") == 0) { } else if(g_ascii_strcasecmp(pszName,"A0") == 0) { isPredefined = true; pszGtkName = "iso_a0"; } else if(g_ascii_strcasecmp(pszName,"A1") == 0) { isPredefined = true; pszGtkName = "iso_a1"; } else if(g_ascii_strcasecmp(pszName,"A2") == 0) { isPredefined = true; pszGtkName = "iso_a2"; } else if(g_ascii_strcasecmp(pszName,"A3") == 0) { isPredefined = true; pszGtkName = "iso_a3"; } else if(g_ascii_strcasecmp(pszName,"A4") == 0) { isPredefined = true; pszGtkName = "iso_a4"; } else if(g_ascii_strcasecmp(pszName,"A5") == 0) { isPredefined = true; pszGtkName = "iso_a5"; } else if(g_ascii_strcasecmp(pszName,"A6") == 0) { isPredefined = true; pszGtkName = "iso_a6"; } else if(g_ascii_strcasecmp(pszName,"A7") == 0) { isPredefined = true; pszGtkName = "iso_a7"; } else if(g_ascii_strcasecmp(pszName,"A8") == 0) { isPredefined = true; pszGtkName = "iso_a8"; } else if(g_ascii_strcasecmp(pszName,"A9") == 0) { isPredefined = true; pszGtkName = "iso_a9"; } else if(g_ascii_strcasecmp(pszName,"B0") == 0) { isPredefined = true; pszGtkName = "iso_b0"; } else if(g_ascii_strcasecmp(pszName,"B1") == 0) { isPredefined = true; pszGtkName = "iso_b1"; } else if(g_ascii_strcasecmp(pszName,"B2") == 0) { isPredefined = true; pszGtkName = "iso_b2"; } else if(g_ascii_strcasecmp(pszName,"B3") == 0) { isPredefined = true; pszGtkName = "iso_b3"; } else if(g_ascii_strcasecmp(pszName,"B4") == 0) { isPredefined = true; pszGtkName = "iso_b4"; } else if(g_ascii_strcasecmp(pszName,"B4") == 0) { isPredefined = true; pszGtkName = "iso_b4"; } else if(g_ascii_strcasecmp(pszName,"B5") == 0) { isPredefined = true; pszGtkName = "iso_b5"; } else if(g_ascii_strcasecmp(pszName,"B6") == 0) { isPredefined = true; pszGtkName = "iso_b6"; } else if(g_ascii_strcasecmp(pszName,"B7") == 0) { isPredefined = true; pszGtkName = "iso_b7"; } else if(g_ascii_strcasecmp(pszName,"Legal") == 0) { isPredefined = true; pszGtkName = "na_legal"; } else if(g_ascii_strcasecmp(pszName,"Letter") == 0) { isPredefined = true; pszGtkName = "na_letter"; } if(isPredefined) { m_pGtkPageSize = gtk_paper_size_new(static_cast<const gchar *>(pszGtkName)); } else { /* * Width() and Height() will return the paper size as shown in the UI. * Gtk wants the real paper size, however, and will swap the two * itself when we specify the orientation. */ m_pGtkPageSize = gtk_paper_size_new_custom("custom", "custom", portrait ? width : height, portrait ? height : width, GTK_UNIT_MM); } // // Set the Page Size // gtk_page_setup_set_paper_size(m_pPageSetup,m_pGtkPageSize); // // Set the margins // gtk_page_setup_set_top_margin(m_pPageSetup,mrgnTop,GTK_UNIT_INCH); gtk_page_setup_set_bottom_margin(m_pPageSetup,mrgnBottom,GTK_UNIT_INCH); gtk_page_setup_set_left_margin(m_pPageSetup,mrgnLeft,GTK_UNIT_INCH); gtk_page_setup_set_right_margin(m_pPageSetup,mrgnRight,GTK_UNIT_INCH); // // Set orientation // if( portrait) gtk_page_setup_set_orientation(m_pPageSetup,GTK_PAGE_ORIENTATION_PORTRAIT); else gtk_page_setup_set_orientation(m_pPageSetup,GTK_PAGE_ORIENTATION_LANDSCAPE); gtk_print_operation_set_default_page_setup(m_pPO,m_pPageSetup); gtk_print_operation_set_use_full_page (m_pPO, true); m_pDL = m_pView->getLayout(); m_iCurrentPage = m_pDL->findPage(m_pView->getCurrentPage()); m_iNumberPages = (gint) m_pDL->countPages(); gtk_print_operation_set_current_page(m_pPO,m_iCurrentPage); g_signal_connect (m_pPO, "begin_print", G_CALLBACK (s_Begin_Print), this); g_signal_connect (m_pPO, "draw_page", G_CALLBACK (s_Print_Page), this); }
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; }
static gboolean print_settings_load_from_key_file (PrintData *data, GKeyFile *key_file) { GtkPrintOperation *operation = data->operation; GtkPrintSettings *settings; gchar **keys; gsize n_keys; gint i; settings = gtk_print_operation_get_print_settings (operation); if (! settings) settings = gtk_print_settings_new (); keys = g_key_file_get_keys (key_file, PRINT_SETTINGS_NAME, &n_keys, NULL); if (! keys) return FALSE; for (i = 0; i < n_keys; i++) { gchar *value; value = g_key_file_get_value (key_file, PRINT_SETTINGS_NAME, keys[i], NULL); if (value) { gtk_print_settings_set (settings, keys[i], value); g_free (value); } } g_strfreev (keys); if (g_key_file_has_key (key_file, "image-setup", "unit", NULL)) { data->unit = g_key_file_get_integer (key_file, "image-setup", "unit", NULL); } if (g_key_file_has_key (key_file, "image-setup", "x-resolution", NULL) && g_key_file_has_key (key_file, "image-setup", "y-resolution", NULL)) { data->xres = g_key_file_get_double (key_file, "image-setup", "x-resolution", NULL); data->yres = g_key_file_get_double (key_file, "image-setup", "y-resolution", NULL); } if (g_key_file_has_key (key_file, "image-setup", "x-offset", NULL) && g_key_file_has_key (key_file, "image-setup", "y-offset", NULL)) { data->offset_x = g_key_file_get_double (key_file, "image-setup", "x-offset", NULL); data->offset_y = g_key_file_get_double (key_file, "image-setup", "y-offset", NULL); } if (g_key_file_has_key (key_file, "image-setup", "center-mode", NULL)) { data->center = g_key_file_get_integer (key_file, "image-setup", "center-mode", NULL); } if (g_key_file_has_key (key_file, "image-setup", "use-full-page", NULL)) { data->use_full_page = g_key_file_get_boolean (key_file, "image-setup", "use-full-page", NULL); } if (g_key_file_has_key (key_file, "image-setup", "crop-marks", NULL)) { data->draw_crop_marks = g_key_file_get_boolean (key_file, "image-setup", "crop-marks", NULL); } gtk_print_operation_set_print_settings (operation, settings); return TRUE; }