Commit f20576591a10e99378de90653e4cc8479188689c

Authored by perry.werneck@gmail.com
1 parent 91fd639b

Melhorando dialogo de selecao de fontes para impressao

Showing 1 changed file with 77 additions and 28 deletions   Show diff stats
src/pw3270/print.c
@@ -33,6 +33,8 @@ @@ -33,6 +33,8 @@
33 #include <pw3270/v3270.h> 33 #include <pw3270/v3270.h>
34 #include <lib3270/selection.h> 34 #include <lib3270/selection.h>
35 35
  36 + #define AUTO_FONT_SIZE 1
  37 +
36 /*--[ Structs ]--------------------------------------------------------------------------------------*/ 38 /*--[ Structs ]--------------------------------------------------------------------------------------*/
37 39
38 typedef struct _print_info 40 typedef struct _print_info
@@ -54,6 +56,7 @@ @@ -54,6 +56,7 @@
54 double height; /**< Report height (all pages) */ 56 double height; /**< Report height (all pages) */
55 cairo_scaled_font_t * font_scaled; 57 cairo_scaled_font_t * font_scaled;
56 58
  59 + gchar * font; /**< Font name */
57 gchar **text; 60 gchar **text;
58 61
59 } PRINT_INFO; 62 } PRINT_INFO;
@@ -76,7 +79,9 @@ @@ -76,7 +79,9 @@
76 CAIRO_FONT_SLANT_NORMAL, 79 CAIRO_FONT_SLANT_NORMAL,
77 pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); 80 pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
78 81
  82 +#ifdef AUTO_FONT_SIZE
79 cairo_set_font_size(cr,gtk_print_context_get_width(context)/info->cols); 83 cairo_set_font_size(cr,gtk_print_context_get_width(context)/info->cols);
  84 +#endif // AUTO_FONT_SIZE
80 85
81 pango_font_description_free(descr); 86 pango_font_description_free(descr);
82 } 87 }
@@ -260,17 +265,17 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -260,17 +265,17 @@ static gchar * enum_to_string(GType type, guint enum_value)
260 if(info->font_scaled) 265 if(info->font_scaled)
261 cairo_scaled_font_destroy(info->font_scaled); 266 cairo_scaled_font_destroy(info->font_scaled);
262 267
263 -/*  
264 - if(info->font)  
265 - g_free(info->font);  
266 -*/  
267 -  
268 if(info->text) 268 if(info->text)
269 g_strfreev(info->text); 269 g_strfreev(info->text);
270 270
  271 + if(info->font)
  272 + g_free(info->font);
  273 +
271 g_free(info); 274 g_free(info);
272 } 275 }
273 276
  277 +#ifndef AUTO_FONT_SIZE
  278 +
274 #if GTK_CHECK_VERSION(3,2,0) 279 #if GTK_CHECK_VERSION(3,2,0)
275 static gboolean filter_monospaced(const PangoFontFamily *family,const PangoFontFace *face,gpointer data) 280 static gboolean filter_monospaced(const PangoFontFamily *family,const PangoFontFace *face,gpointer data)
276 { 281 {
@@ -280,29 +285,32 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -280,29 +285,32 @@ static gchar * enum_to_string(GType type, guint enum_value)
280 285
281 static void font_set(GtkFontButton *widget, PRINT_INFO *info) 286 static void font_set(GtkFontButton *widget, PRINT_INFO *info)
282 { 287 {
283 - set_string_to_config("print","font",gtk_font_button_get_font_name(widget));  
284 -/*  
285 - PangoFontDescription * descr = pango_font_description_from_string(name); 288 + if(info->font)
  289 + g_free(info->font)
  290 + info->font = g_strdup(gtk_font_button_get_font_name(widget));
  291 + }
286 292
287 - if(!descr)  
288 - return; 293 +#else
289 294
290 - if(info->font)  
291 - g_free(info->font); 295 + static void font_name_changed(GtkComboBox *combo, PRINT_INFO *info)
  296 + {
  297 + GValue value = { 0, };
  298 + GtkTreeIter iter;
292 299
293 - info->font = g_strdup(pango_font_description_get_family(descr));  
294 - info->fontsize = pango_font_description_get_size(descr);  
295 - info->fontweight = CAIRO_FONT_WEIGHT_NORMAL; 300 + if(!gtk_combo_box_get_active_iter(combo,&iter))
  301 + return;
296 302
297 - if(pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD)  
298 - info->fontweight = CAIRO_FONT_WEIGHT_BOLD; 303 + gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,0,&value);
299 304
300 - pango_font_description_free(descr); 305 + if(info->font)
  306 + g_free(info->font);
  307 +
  308 + info->font = g_value_dup_string(&value);
301 309
302 - trace("Font set to \"%s\" with size %d",info->font,info->fontsize);  
303 -*/  
304 } 310 }
305 311
  312 +#endif // !AUTO_FONT_SIZE
  313 +
306 static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info) 314 static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info)
307 { 315 {
308 gboolean active = gtk_toggle_button_get_active(togglebutton); 316 gboolean active = gtk_toggle_button_get_active(togglebutton);
@@ -339,25 +347,64 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -339,25 +347,64 @@ static gchar * enum_to_string(GType type, guint enum_value)
339 gtk_table_attach(GTK_TABLE(container),label[f],0,1,f,f+1,GTK_FILL,GTK_FILL,0,0); 347 gtk_table_attach(GTK_TABLE(container),label[f],0,1,f,f+1,GTK_FILL,GTK_FILL,0,0);
340 } 348 }
341 349
  350 + if(info->font)
  351 + g_free(info->font);
  352 +
  353 + info->font = get_string_from_config("print","font","Courier New");
  354 +
342 // Font selection button 355 // Font selection button
  356 +#ifdef AUTO_FONT_SIZE
343 { 357 {
344 - gchar * font = get_string_from_config("print","font","Courier New 10");  
345 - widget = gtk_font_button_new_with_font(font); 358 + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(1,G_TYPE_STRING);
  359 + GtkCellRenderer * renderer = gtk_cell_renderer_text_new();
  360 + PangoFontFamily **families;
  361 + gint n_families, i;
  362 + GtkTreeIter iter;
  363 +
  364 + widget = gtk_combo_box_new_with_model(model);
  365 +
  366 + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
  367 + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL);
  368 +
  369 + g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(font_name_changed),info);
  370 +
  371 + pango_context_list_families(gtk_widget_get_pango_context(container),&families, &n_families);
  372 +
  373 + for(i=0; i<n_families; i++)
  374 + {
  375 + if(pango_font_family_is_monospace(families[i]))
  376 + {
  377 + const gchar *name = pango_font_family_get_name (families[i]);
  378 + gtk_list_store_append((GtkListStore *) model,&iter);
  379 + gtk_list_store_set((GtkListStore *) model, &iter,0, name, -1);
  380 +
  381 + if(!g_strcasecmp(name,info->font))
  382 + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter);
  383 + }
  384 + }
  385 +
  386 + g_free(families);
  387 + }
  388 +#else
  389 + {
  390 + widget = gtk_font_button_new_with_font(info->font);
346 gtk_font_button_set_show_size((GtkFontButton *) widget,FALSE); 391 gtk_font_button_set_show_size((GtkFontButton *) widget,FALSE);
347 gtk_font_button_set_use_font((GtkFontButton *) widget,TRUE); 392 gtk_font_button_set_use_font((GtkFontButton *) widget,TRUE);
348 gtk_label_set_mnemonic_widget(GTK_LABEL(label[0]),widget); 393 gtk_label_set_mnemonic_widget(GTK_LABEL(label[0]),widget);
349 g_free(font); 394 g_free(font);
350 - }  
351 395
352 #if GTK_CHECK_VERSION(3,2,0) 396 #if GTK_CHECK_VERSION(3,2,0)
353 - gtk_font_chooser_set_filter_func((GtkFontChooser *) widget,filter_monospaced,NULL,NULL); 397 + gtk_font_chooser_set_filter_func((GtkFontChooser *) widget,filter_monospaced,NULL,NULL);
354 #endif // GTK(3,2,0) 398 #endif // GTK(3,2,0)
355 - gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);  
356 399
357 - load_settings(info); 400 + g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info);
  401 +
  402 + }
  403 +#endif
358 404
  405 + gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);
359 406
360 - g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); 407 + load_settings(info);
361 408
362 widget = color_scheme_new(info->color); 409 widget = color_scheme_new(info->color);
363 gtk_label_set_mnemonic_widget(GTK_LABEL(label[1]),widget); 410 gtk_label_set_mnemonic_widget(GTK_LABEL(label[1]),widget);
@@ -393,6 +440,9 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -393,6 +440,9 @@ static gchar * enum_to_string(GType type, guint enum_value)
393 GtkWidget * combo = g_object_get_data(G_OBJECT(widget),"combo"); 440 GtkWidget * combo = g_object_get_data(G_OBJECT(widget),"combo");
394 GdkColor * clr = g_object_get_data(G_OBJECT(combo),"selected"); 441 GdkColor * clr = g_object_get_data(G_OBJECT(combo),"selected");
395 442
  443 + if(info->font)
  444 + set_string_to_config("print","font",info->font);
  445 +
396 if(clr) 446 if(clr)
397 { 447 {
398 int f; 448 int f;
@@ -478,7 +528,6 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -478,7 +528,6 @@ static gchar * enum_to_string(GType type, guint enum_value)
478 RegCloseKey(hKey); 528 RegCloseKey(hKey);
479 } 529 }
480 530
481 -  
482 #warning Work in progress 531 #warning Work in progress
483 RegCloseKey(registry); 532 RegCloseKey(registry);
484 } 533 }