Commit 0bd2c878f4008e218a872a9aeae079c68fda37ec

Authored by perry.werneck@gmail.com
1 parent 4e81c711

Remodelando ajustes de fonte durante a impressao

Showing 1 changed file with 49 additions and 14 deletions   Show diff stats
src/pw3270/print.c
@@ -42,9 +42,11 @@ @@ -42,9 +42,11 @@
42 PW3270_SRC src; 42 PW3270_SRC src;
43 43
44 H3270 * session; 44 H3270 * session;
  45 +/*
45 gchar * font; 46 gchar * font;
46 guint fontsize; 47 guint fontsize;
47 cairo_font_weight_t fontweight; 48 cairo_font_weight_t fontweight;
  49 +*/
48 int baddr; 50 int baddr;
49 int rows; 51 int rows;
50 int cols; 52 int cols;
@@ -62,6 +64,7 @@ @@ -62,6 +64,7 @@
62 64
63 /*--[ Implement ]------------------------------------------------------------------------------------*/ 65 /*--[ Implement ]------------------------------------------------------------------------------------*/
64 66
  67 +/*
65 static void setup_font(GtkPrintContext * context, PRINT_INFO *info) 68 static void setup_font(GtkPrintContext * context, PRINT_INFO *info)
66 { 69 {
67 cairo_t *cr = gtk_print_context_get_cairo_context(context); 70 cairo_t *cr = gtk_print_context_get_cairo_context(context);
@@ -83,11 +86,43 @@ @@ -83,11 +86,43 @@
83 86
84 87
85 } 88 }
86 - 89 +*/
87 static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) 90 static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info)
88 { 91 {
89 - setup_font(context,info); 92 + cairo_t * cr = gtk_print_context_get_cairo_context(context);
  93 + gchar * font = get_string_from_config("print","font","Courier New 10");
  94 +
  95 + // Setup font
  96 +
  97 + if(font)
  98 + {
  99 + PangoFontDescription * descr = pango_font_description_from_string(font);
  100 + if(descr)
  101 + {
  102 + cairo_select_font_face(cr, pango_font_description_get_family(descr),
  103 + CAIRO_FONT_SLANT_NORMAL,
  104 + pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
  105 +
  106 + cairo_set_font_size(cr,gtk_print_context_get_width(context)/80);
  107 +
  108 + pango_font_description_free(descr);
  109 + }
  110 + g_free(font);
  111 + }
  112 +
  113 + info->font_scaled = cairo_get_scaled_font(cr);
  114 + cairo_scaled_font_reference(info->font_scaled);
  115 + cairo_scaled_font_extents(info->font_scaled,&info->extents);
90 116
  117 + info->width = ((double) info->cols) * info->extents.max_x_advance;
  118 + info->height = ((double) info->rows) * (info->extents.height + info->extents.descent);
  119 +
  120 + // Center image
  121 + info->left = (gtk_print_context_get_width(context)-info->width)/2;
  122 + if(info->left < 2)
  123 + info->left = 2;
  124 +
  125 + // Setup page size
91 info->lpp = (gtk_print_context_get_height(context) / (info->extents.height + info->extents.descent)); 126 info->lpp = (gtk_print_context_get_height(context) / (info->extents.height + info->extents.descent));
92 info->pages = (info->rows / info->lpp)+1; 127 info->pages = (info->rows / info->lpp)+1;
93 128
@@ -252,8 +287,10 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -252,8 +287,10 @@ static gchar * enum_to_string(GType type, guint enum_value)
252 if(info->font_scaled) 287 if(info->font_scaled)
253 cairo_scaled_font_destroy(info->font_scaled); 288 cairo_scaled_font_destroy(info->font_scaled);
254 289
  290 +/*
255 if(info->font) 291 if(info->font)
256 g_free(info->font); 292 g_free(info->font);
  293 +*/
257 294
258 if(info->text) 295 if(info->text)
259 g_strfreev(info->text); 296 g_strfreev(info->text);
@@ -270,7 +307,8 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -270,7 +307,8 @@ static gchar * enum_to_string(GType type, guint enum_value)
270 307
271 static void font_set(GtkFontButton *widget, PRINT_INFO *info) 308 static void font_set(GtkFontButton *widget, PRINT_INFO *info)
272 { 309 {
273 - const gchar * name = gtk_font_button_get_font_name(widget); 310 + set_string_to_config("print","font",gtk_font_button_get_font_name(widget));
  311 +/*
274 PangoFontDescription * descr = pango_font_description_from_string(name); 312 PangoFontDescription * descr = pango_font_description_from_string(name);
275 313
276 if(!descr) 314 if(!descr)
@@ -288,11 +326,8 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -288,11 +326,8 @@ static gchar * enum_to_string(GType type, guint enum_value)
288 326
289 pango_font_description_free(descr); 327 pango_font_description_free(descr);
290 328
291 - set_string_to_config("print","font",name);  
292 - set_integer_to_config("print","fontsize",info->fontsize);  
293 - set_integer_to_config("print","fontweight",info->fontweight);  
294 -  
295 trace("Font set to \"%s\" with size %d",info->font,info->fontsize); 329 trace("Font set to \"%s\" with size %d",info->font,info->fontsize);
  330 +*/
296 } 331 }
297 332
298 static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info) 333 static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info)
@@ -306,14 +341,11 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -306,14 +341,11 @@ static gchar * enum_to_string(GType type, guint enum_value)
306 { 341 {
307 gchar *ptr = get_string_from_config("print","colors",""); 342 gchar *ptr = get_string_from_config("print","colors","");
308 343
309 - info->font = get_string_from_config("print","font","Courier New 10");  
310 - info->fontsize = get_integer_from_config("print","fontsize",10240);  
311 - info->fontweight = get_integer_from_config("print","fontweight",0);  
312 -  
313 if(*ptr) 344 if(*ptr)
314 v3270_set_color_table(info->color,ptr); 345 v3270_set_color_table(info->color,ptr);
315 else 346 else
316 v3270_set_mono_color_table(info->color,"black","white"); 347 v3270_set_mono_color_table(info->color,"black","white");
  348 +
317 g_free(ptr); 349 g_free(ptr);
318 } 350 }
319 351
@@ -324,6 +356,7 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -324,6 +356,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
324 GtkWidget * label[G_N_ELEMENTS(text)]; 356 GtkWidget * label[G_N_ELEMENTS(text)];
325 GtkWidget * widget; 357 GtkWidget * widget;
326 int f; 358 int f;
  359 + gchar * font;
327 360
328 trace("%s starts",__FUNCTION__); 361 trace("%s starts",__FUNCTION__);
329 362
@@ -344,8 +377,11 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -344,8 +377,11 @@ static gchar * enum_to_string(GType type, guint enum_value)
344 gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); 377 gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);
345 378
346 load_settings(info); 379 load_settings(info);
347 - gtk_font_button_set_font_name((GtkFontButton *) widget,info->font);  
348 - font_set((GtkFontButton *) widget,info); 380 +
  381 + font = get_string_from_config("print","font","Courier New 10");
  382 + gtk_font_button_set_font_name((GtkFontButton *) widget, font);
  383 + g_free(font);
  384 +
349 g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); 385 g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info);
350 386
351 widget = color_scheme_new(info->color); 387 widget = color_scheme_new(info->color);
@@ -414,7 +450,6 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -414,7 +450,6 @@ static gchar * enum_to_string(GType type, guint enum_value)
414 450
415 *info = g_new0(PRINT_INFO,1); 451 *info = g_new0(PRINT_INFO,1);
416 (*info)->session = v3270_get_session(widget); 452 (*info)->session = v3270_get_session(widget);
417 - (*info)->fontweight = CAIRO_FONT_WEIGHT_NORMAL;  
418 453
419 // Basic setup 454 // Basic setup
420 gtk_print_operation_set_allow_async(print,TRUE); 455 gtk_print_operation_set_allow_async(print,TRUE);