Commit 0965d449fb01f6c55a75b8847676e0a3a2631dfb

Authored by perry.werneck@gmail.com
1 parent 29388aa5

Ampliando largura de fonte na impressão

Showing 1 changed file with 48 additions and 4 deletions   Show diff stats
src/pw3270/print.c
@@ -68,6 +68,8 @@ @@ -68,6 +68,8 @@
68 cairo_t * cr = gtk_print_context_get_cairo_context(context); 68 cairo_t * cr = gtk_print_context_get_cairo_context(context);
69 gchar * font = get_string_from_config("print","font","Courier New 10"); 69 gchar * font = get_string_from_config("print","font","Courier New 10");
70 70
  71 + trace("%s: operation=%p context=%p font=\"%s\"",__FUNCTION__,prt,context,font);
  72 +
71 // Setup font 73 // Setup font
72 74
73 if(*font) 75 if(*font)
@@ -80,7 +82,27 @@ @@ -80,7 +82,27 @@
80 pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); 82 pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
81 83
82 #ifdef AUTO_FONT_SIZE 84 #ifdef AUTO_FONT_SIZE
83 - cairo_set_font_size(cr,gtk_print_context_get_width(context)/info->cols); 85 + {
  86 + double width = gtk_print_context_get_width(context);
  87 + double cols = (double)info->cols;
  88 + double current = width / cols;
  89 + double valid = current;
  90 + cairo_font_extents_t extents;
  91 +
  92 + do
  93 + {
  94 + valid = current;
  95 + current = valid +1.0;
  96 + cairo_set_font_size(cr,current);
  97 + cairo_font_extents(cr,&extents);
  98 + trace("Valid: %d",(int) valid);
  99 + } while( (cols * extents.max_x_advance) < width );
  100 +
  101 + trace("Font size: %d",(int) valid);
  102 + cairo_set_font_size(cr,valid);
  103 +
  104 +
  105 + }
84 #endif // AUTO_FONT_SIZE 106 #endif // AUTO_FONT_SIZE
85 107
86 pango_font_description_free(descr); 108 pango_font_description_free(descr);
@@ -479,7 +501,7 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -479,7 +501,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
479 (*info)->cols = 80; 501 (*info)->cols = 80;
480 502
481 // Basic setup 503 // Basic setup
482 - gtk_print_operation_set_allow_async(print,TRUE); 504 + gtk_print_operation_set_allow_async(print,get_boolean_from_config("print","allow_async",TRUE));
483 505
484 if(obj) 506 if(obj)
485 { 507 {
@@ -603,9 +625,10 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -603,9 +625,10 @@ static gchar * enum_to_string(GType type, guint enum_value)
603 625
604 LIB3270_EXPORT int pw3270_print(GtkWidget *widget, GObject *action, GtkPrintOperationAction oper, PW3270_SRC src) 626 LIB3270_EXPORT int pw3270_print(GtkWidget *widget, GObject *action, GtkPrintOperationAction oper, PW3270_SRC src)
605 { 627 {
606 - PRINT_INFO * info = NULL; 628 + PRINT_INFO * info = NULL;
607 GtkPrintOperation * print; 629 GtkPrintOperation * print;
608 const gchar * text; 630 const gchar * text;
  631 + GError * err = NULL;
609 632
610 #ifdef X3270_TRACE 633 #ifdef X3270_TRACE
611 if(action) 634 if(action)
@@ -657,7 +680,28 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -657,7 +680,28 @@ static gchar * enum_to_string(GType type, guint enum_value)
657 } 680 }
658 681
659 // Run Print dialog 682 // Run Print dialog
660 - gtk_print_operation_run(print,oper,GTK_WINDOW(gtk_widget_get_toplevel(widget)),NULL); 683 + gtk_print_operation_run(print,oper,GTK_WINDOW(gtk_widget_get_toplevel(widget)),&err);
  684 +
  685 + if(err)
  686 + {
  687 + GtkWidget *dialog;
  688 +
  689 + g_warning(err->message);
  690 +
  691 + dialog = gtk_message_dialog_new_with_markup( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  692 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  693 + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,
  694 + "%s",_( "Print operation failed" ));
  695 +
  696 + gtk_window_set_title(GTK_WINDOW(dialog),_("Error"));
  697 +
  698 + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",err->message);
  699 + g_error_free(err);
  700 +
  701 + gtk_dialog_run(GTK_DIALOG(dialog));
  702 + gtk_widget_destroy(dialog);
  703 + }
  704 +
661 g_object_unref(print); 705 g_object_unref(print);
662 706
663 return 0; 707 return 0;