In the spirit of cooperative open source development, in case it's of assistance, this code is currently allowing me to at least print one page of text, though it A should be implemented in the core / in gtk_print.c, B is very elementary, I daresay crude, for now; it indicates possible reasons for segfaults, such as data not fitting the page; its main redeeming feature is that it works :-)
Best Mark http://www.halloit.com Key ID 046B65CF gboolean nsgtk_on_source_print_activate( GtkMenuItem *widget, gpointer g) { /* correct printing */ struct nsgtk_source_window * nsg = (struct nsgtk_source_window *)g; struct content *tempcontent = content_create(nsg->url); unsigned int len = (unsigned int)strlen(nsg->data); const char * params[2] = {"encoding", "utf-8"}; textplain_create(tempcontent, params); textplain_process_data(tempcontent, nsg->data, len); content_to_print = tempcontent; nsgtk_temp_pango_print(g); return TRUE; } void nsgtk_temp_pango_print(gpointer g) { struct nsgtk_source_window * nsg = (struct nsgtk_source_window *)g; GtkPrintOperation *op; GtkPrintOperationResult res; GtkPrintSettings *settings; GtkPageSetup *pagesetup; op = gtk_print_operation_new(); settings = gtk_print_settings_new_from_file( print_options_file_location, NULL); if (settings != NULL) { gtk_print_operation_set_print_settings(op, settings); } pagesetup = gtk_print_run_page_setup_dialog(GTK_WINDOW(nsg->sourcewindow), NULL, NULL); gtk_print_operation_set_default_page_setup(op, pagesetup); gtk_print_operation_set_print_settings(op, settings); gtk_print_operation_set_n_pages(op, 1); gtk_print_operation_set_unit(op, GTK_UNIT_MM); g_signal_connect(op, "draw_page", G_CALLBACK(nsgtk_temp_draw_page), g); res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(nsg->sourcewindow), NULL); if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { settings = gtk_print_operation_get_print_settings(op); // save_print_settings(settings); } } static void nsgtk_temp_draw_page(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer g) { struct nsgtk_source_window *nsg = (struct nsgtk_source_window *)g; char * content; content = malloc (2 * strlen(nsg->data)); long additional = 0; long offset = -1; long len = strlen(nsg->data); int i = 0; int nl = 0; while ((offset < len) && (nl < 100)) { content[offset + additional] = nsg->data[offset]; printf("%c",nsg->data[offset]); i = (nsg->data[offset] == '\n') ? 0 : i+1; if (i == 0) nl++; if (i == 100) { printf("\n\n\n"); additional++; i = 0; nl++; content[offset + additional] = '\n'; } offset++; } content[offset + additional] = '\0'; printf("content:\n%s\n",content); cairo_t *cr = gtk_print_context_get_cairo_context (context); PangoLayout *layout = gtk_print_context_create_pango_layout(context); pango_layout_set_text(layout, content, -1); PangoFontDescription * fontdesc = pango_font_description_from_string("sans 10"); pango_layout_set_font_description(layout, fontdesc); pango_font_description_free(fontdesc); cairo_move_to(cr, 0, 0); pango_cairo_show_layout(cr, layout); }
