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); }
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 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 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); }
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 * 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; }
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; }
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 GimpPDBStatusType print_image (gint32 image_ID, gboolean interactive, GError **error) { GtkPrintOperation *operation; GtkPrintOperationResult result; 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.draw_crop_marks = 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), &layer); 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")); gtk_print_operation_set_embed_page_setup (operation, TRUE); result = gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, error); if (result == GTK_PRINT_OPERATION_RESULT_APPLY || result == GTK_PRINT_OPERATION_RESULT_IN_PROGRESS) { print_page_setup_save (operation, image_ID); } } else { result = gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT, NULL, error); } g_object_unref (operation); if (gimp_item_is_valid (layer)) gimp_item_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; }