Commit 462bca78e8fd8eaa363e0885f4500cf1c23f97e3

Authored by perry.werneck@gmail.com
1 parent fd3e7e30

Mudando tratamento da tabela de fontes durante a impressão

Showing 1 changed file with 42 additions and 34 deletions   Show diff stats
src/pw3270/print.c
@@ -60,13 +60,17 @@ @@ -60,13 +60,17 @@
60 int cols; /**< Max line width */ 60 int cols; /**< Max line width */
61 int pages; 61 int pages;
62 int lpp; /**< Lines per page */ 62 int lpp; /**< Lines per page */
63 - cairo_font_extents_t extents; 63 +
  64 + v3270FontInfo font;
  65 +
  66 +// cairo_font_extents_t extents;
  67 +// cairo_scaled_font_t * font_scaled;
  68 +// gchar * font; /**< Font name */
  69 +
64 double left; 70 double left;
65 double width; /**< Report width */ 71 double width; /**< Report width */
66 double height; /**< Report height (all pages) */ 72 double height; /**< Report height (all pages) */
67 - cairo_scaled_font_t * font_scaled;  
68 73
69 - gchar * font; /**< Font name */  
70 gchar **text; 74 gchar **text;
71 75
72 } PRINT_INFO; 76 } PRINT_INFO;
@@ -76,13 +80,14 @@ @@ -76,13 +80,14 @@
76 80
77 static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) 81 static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info)
78 { 82 {
  83 + cairo_font_extents_t extents;
  84 +
79 cairo_t * cr = gtk_print_context_get_cairo_context(context); 85 cairo_t * cr = gtk_print_context_get_cairo_context(context);
80 gchar * font = get_string_from_config("print",FONT_CONFIG,DEFAULT_FONT); 86 gchar * font = get_string_from_config("print",FONT_CONFIG,DEFAULT_FONT);
81 87
82 trace("%s: operation=%p context=%p font=\"%s\"",__FUNCTION__,prt,context,font); 88 trace("%s: operation=%p context=%p font=\"%s\"",__FUNCTION__,prt,context,font);
83 89
84 // Setup font 90 // Setup font
85 -  
86 if(*font) 91 if(*font)
87 { 92 {
88 PangoFontDescription * descr = pango_font_description_from_string(font); 93 PangoFontDescription * descr = pango_font_description_from_string(font);
@@ -102,7 +107,6 @@ @@ -102,7 +107,6 @@
102 #endif // GTK(3,0,0) 107 #endif // GTK(3,0,0)
103 double current = width / cols; 108 double current = width / cols;
104 double valid = current; 109 double valid = current;
105 - cairo_font_extents_t extents;  
106 110
107 do 111 do
108 { 112 {
@@ -124,12 +128,16 @@ @@ -124,12 +128,16 @@
124 } 128 }
125 g_free(font); 129 g_free(font);
126 130
127 - info->font_scaled = cairo_get_scaled_font(cr);  
128 - cairo_scaled_font_reference(info->font_scaled);  
129 - cairo_scaled_font_extents(info->font_scaled,&info->extents); 131 + info->font.scaled = cairo_get_scaled_font(cr);
  132 + cairo_scaled_font_reference(info->font.scaled);
  133 + cairo_scaled_font_extents(info->font.scaled,&extents);
130 134
131 - info->width = ((double) info->cols) * info->extents.max_x_advance;  
132 - info->height = ((double) info->rows) * (info->extents.height + info->extents.descent); 135 + info->font.height = extents.height;
  136 + info->font.descent = extents.descent;
  137 + info->font.width = extents.max_x_advance;
  138 +
  139 + info->width = ((double) info->cols) * extents.max_x_advance;
  140 + info->height = ((double) info->rows) * (extents.height + extents.descent);
133 141
134 // Center image 142 // Center image
135 info->left = (gtk_print_context_get_width(context)-info->width)/2; 143 info->left = (gtk_print_context_get_width(context)-info->width)/2;
@@ -137,7 +145,7 @@ @@ -137,7 +145,7 @@
137 info->left = 2; 145 info->left = 2;
138 146
139 // Setup page size 147 // Setup page size
140 - info->lpp = (gtk_print_context_get_height(context) / (info->extents.height + info->extents.descent)); 148 + info->lpp = (gtk_print_context_get_height(context) / (extents.height + extents.descent));
141 info->pages = (info->rows / info->lpp)+1; 149 info->pages = (info->rows / info->lpp)+1;
142 150
143 trace("%d lines per page, %d pages to print",info->lpp,info->pages); 151 trace("%d lines per page, %d pages to print",info->lpp,info->pages);
@@ -153,12 +161,12 @@ @@ -153,12 +161,12 @@
153 int baddr = info->baddr; 161 int baddr = info->baddr;
154 GdkRectangle rect; 162 GdkRectangle rect;
155 163
156 - cairo_set_scaled_font(cr,info->font_scaled); 164 + cairo_set_scaled_font(cr,info->font.scaled);
157 165
158 memset(&rect,0,sizeof(rect)); 166 memset(&rect,0,sizeof(rect));
159 rect.y = 2; 167 rect.y = 2;
160 - rect.height = (info->extents.height + info->extents.descent);  
161 - rect.width = info->extents.max_x_advance; 168 + rect.height = (info->font.height + info->font.descent);
  169 + rect.width = info->font.width;
162 170
163 // Clear page 171 // Clear page
164 gdk_cairo_set_source_rgba(cr,info->color+V3270_COLOR_BACKGROUND); 172 gdk_cairo_set_source_rgba(cr,info->color+V3270_COLOR_BACKGROUND);
@@ -181,7 +189,7 @@ @@ -181,7 +189,7 @@
181 { 189 {
182 if(!info->show_selection) 190 if(!info->show_selection)
183 attr &= ~LIB3270_ATTR_SELECTED; 191 attr &= ~LIB3270_ATTR_SELECTED;
184 - v3270_draw_element(cr,c,attr,info->session,info->extents.height,&rect,info->color); 192 + v3270_draw_element(cr,c,attr,info->session,info->font.height,&rect,info->color);
185 } 193 }
186 194
187 rect.x += (rect.width-1); 195 rect.x += (rect.width-1);
@@ -335,14 +343,14 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -335,14 +343,14 @@ static gchar * enum_to_string(GType type, guint enum_value)
335 343
336 } 344 }
337 345
338 - if(info->font_scaled)  
339 - cairo_scaled_font_destroy(info->font_scaled); 346 + if(info->font.scaled)
  347 + cairo_scaled_font_destroy(info->font.scaled);
340 348
341 if(info->text) 349 if(info->text)
342 g_strfreev(info->text); 350 g_strfreev(info->text);
343 351
344 - if(info->font)  
345 - g_free(info->font); 352 + if(info->font.family)
  353 + g_free(info->font.family);
346 354
347 g_free(info); 355 g_free(info);
348 } 356 }
@@ -376,10 +384,10 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -376,10 +384,10 @@ static gchar * enum_to_string(GType type, guint enum_value)
376 384
377 gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,0,&value); 385 gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,0,&value);
378 386
379 - if(info->font)  
380 - g_free(info->font); 387 + if(info->font.family)
  388 + g_free(info->font.family);
381 389
382 - info->font = g_value_dup_string(&value); 390 + info->font.family = g_value_dup_string(&value);
383 391
384 } 392 }
385 393
@@ -424,14 +432,14 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -424,14 +432,14 @@ static gchar * enum_to_string(GType type, guint enum_value)
424 gtk_table_attach(GTK_TABLE(container),label[f],0,1,f,f+1,GTK_FILL,GTK_FILL,0,0); 432 gtk_table_attach(GTK_TABLE(container),label[f],0,1,f,f+1,GTK_FILL,GTK_FILL,0,0);
425 } 433 }
426 434
427 - if(info->font)  
428 - g_free(info->font); 435 + if(info->font.family)
  436 + g_free(info->font.family);
429 437
430 - info->font = get_string_from_config("print",FONT_CONFIG,DEFAULT_FONT);  
431 - if(!*info->font) 438 + info->font.family = get_string_from_config("print",FONT_CONFIG,DEFAULT_FONT);
  439 + if(!*info->font.family)
432 { 440 {
433 - g_free(info->font);  
434 - info->font = g_strdup(DEFAULT_FONT); 441 + g_free(info->font.family);
  442 + info->font.family = g_strdup(DEFAULT_FONT);
435 } 443 }
436 444
437 // Font selection button 445 // Font selection button
@@ -460,7 +468,7 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -460,7 +468,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
460 gtk_list_store_append((GtkListStore *) model,&iter); 468 gtk_list_store_append((GtkListStore *) model,&iter);
461 gtk_list_store_set((GtkListStore *) model, &iter,0, name, -1); 469 gtk_list_store_set((GtkListStore *) model, &iter,0, name, -1);
462 470
463 - if(!g_ascii_strcasecmp(name,info->font)) 471 + if(!g_ascii_strcasecmp(name,info->font.family))
464 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); 472 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter);
465 } 473 }
466 } 474 }
@@ -525,8 +533,8 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -525,8 +533,8 @@ static gchar * enum_to_string(GType type, guint enum_value)
525 533
526 trace("%s starts combo=%p clr=%p widget=%p",__FUNCTION__,combo,clr,widget); 534 trace("%s starts combo=%p clr=%p widget=%p",__FUNCTION__,combo,clr,widget);
527 535
528 - if(info->font)  
529 - set_string_to_config("print",FONT_CONFIG,info->font); 536 + if(info->font.family)
  537 + set_string_to_config("print",FONT_CONFIG,info->font.family);
530 538
531 if(clr) 539 if(clr)
532 { 540 {
@@ -805,12 +813,12 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -805,12 +813,12 @@ static gchar * enum_to_string(GType type, guint enum_value)
805 int row = pg*info->lpp; 813 int row = pg*info->lpp;
806 int l; 814 int l;
807 815
808 - cairo_set_scaled_font(cr,info->font_scaled); 816 + cairo_set_scaled_font(cr,info->font.scaled);
809 817
810 memset(&rect,0,sizeof(rect)); 818 memset(&rect,0,sizeof(rect));
811 rect.y = 2; 819 rect.y = 2;
812 - rect.height = (info->extents.height + info->extents.descent)+1;  
813 - rect.width = info->extents.max_x_advance+1; 820 + rect.height = (info->font.height + info->font.descent)+1;
  821 + rect.width = info->font.width+1;
814 822
815 for(l=0;l<info->lpp && row < info->rows;l++) 823 for(l=0;l<info->lpp && row < info->rows;l++)
816 { 824 {