Commit 86d3732f5f2a8647494559049223070276aba83b

Authored by perry.werneck@gmail.com
1 parent 0a3c7900

Implementando funções de impressão

src/gtk/print.c
... ... @@ -39,11 +39,15 @@
39 39 GdkColor color[V3270_COLOR_COUNT];
40 40 H3270 * session;
41 41 gchar * font;
  42 + guint fontsize;
  43 + cairo_font_weight_t fontweight;
42 44 gchar * colorname;
43 45 int rows;
44 46 int cols;
45 47 int pages;
46 48 cairo_font_extents_t extents;
  49 + double width;
  50 + double height;
47 51 cairo_scaled_font_t * font_scaled;
48 52  
49 53 } PRINT_INFO;
... ... @@ -52,12 +56,15 @@
52 56  
53 57 static void setup_font(cairo_t *cr, PRINT_INFO *info)
54 58 {
55   - cairo_select_font_face(cr, info->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  59 + cairo_select_font_face(cr, info->font, CAIRO_FONT_SLANT_NORMAL, info->fontweight);
56 60  
57 61 info->font_scaled = cairo_get_scaled_font(cr);
58 62 cairo_scaled_font_reference(info->font_scaled);
59 63 cairo_scaled_font_extents(info->font_scaled,&info->extents);
60 64  
  65 + info->width = ((double) info->cols) * info->extents.max_x_advance;
  66 + info->height = ((double) info->rows) * (info->extents.height + info->extents.descent);
  67 +
61 68 }
62 69  
63 70 static void begin_print_all(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info)
... ... @@ -72,14 +79,47 @@
72 79  
73 80 static void draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info)
74 81 {
75   - cairo_t *cr = gtk_print_context_get_cairo_context(context);
  82 + int row;
  83 + int col;
  84 + cairo_t * cr = gtk_print_context_get_cairo_context(context);
  85 + int baddr = 0;
  86 + GdkRectangle rect;
76 87  
77 88 cairo_set_scaled_font(cr,info->font_scaled);
78 89  
79   - cairo_move_to(cr,0,0);
80   - cairo_show_text(cr, "Teste");
  90 + memset(&rect,0,sizeof(rect));
  91 +
  92 + rect.x = 0;
  93 + rect.y = 0;
  94 + rect.height = (info->extents.height + info->extents.descent);
  95 + rect.width = info->extents.max_x_advance;
81 96  
  97 +/*
  98 + gdk_cairo_set_source_color(cr,info->color+V3270_COLOR_BACKGROUND);
  99 + cairo_rectangle(cr, 0, 0, rect.width*info->cols, rect.height*info->rows);
  100 + cairo_fill(cr);
82 101 cairo_stroke(cr);
  102 +*/
  103 +
  104 + rect.width++;
  105 + rect.height++;
  106 +
  107 + for(row = 0; row < info->rows; row++)
  108 + {
  109 + rect.x = 0;
  110 + for(col = 0; col < info->cols; col++)
  111 + {
  112 + unsigned char c;
  113 + unsigned short attr;
  114 +
  115 + if(!lib3270_get_element(info->session,baddr++,&c,&attr))
  116 + v3270_draw_element(cr,c,attr,info->session,info->extents.height,&rect,info->color);
  117 +
  118 + rect.x += (rect.width-1);
  119 + }
  120 + rect.y += (rect.height-1);
  121 +
  122 + }
83 123 }
84 124  
85 125 static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info)
... ... @@ -107,12 +147,33 @@
107 147  
108 148 static void font_set(GtkFontButton *widget, PRINT_INFO *info)
109 149 {
  150 + const gchar *name = gtk_font_button_get_font_name(widget);
  151 +
110 152 if(info->font)
111 153 g_free(info->font);
112 154  
113   - info->font = g_strdup(gtk_font_button_get_font_name(widget));
114   - set_string_to_config("print","font","%s",info->font);
115   - trace("Font set to \"%s\"",info->font);
  155 +#if GTK_CHECK_VERSION(3,2,0)
  156 +
  157 + info->font = g_strdup(name);
  158 + info->fontsize = gtk_font_chooser_get_font_size((GtkFontChooser *) widget);
  159 +
  160 +#else
  161 + {
  162 + PangoFontDescription *descr = pango_font_description_from_string(name);
  163 +
  164 + info->font = g_strdup(pango_font_description_get_family(descr));
  165 + info->fontsize = pango_font_description_get_size(descr);
  166 + info->fontweight = CAIRO_FONT_WEIGHT_NORMAL;
  167 +
  168 + if(pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD)
  169 + info->fontweight = CAIRO_FONT_WEIGHT_BOLD;
  170 +
  171 + pango_font_description_free(descr);
  172 + }
  173 +#endif // GTK(3,2,0)
  174 +
  175 + set_string_to_config("print","font",name);
  176 + trace("Font set to \"%s\" with size %d",info->font,info->fontsize);
116 177 }
117 178  
118 179 static void color_scheme_changed(GtkComboBox *widget,PRINT_INFO *info)
... ... @@ -139,12 +200,13 @@
139 200 if(!info->colorname)
140 201 return;
141 202  
142   - trace("%s: %s->%s",__FUNCTION__,info->colorname,new_colors);
  203 +// trace("%s: %s->%s",__FUNCTION__,info->colorname,new_colors);
143 204  
144 205 if(*info->colorname)
145 206 g_free(info->colorname);
146 207  
147 208 info->colorname = new_colors;
  209 +
148 210 }
149 211  
150 212 static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info)
... ... @@ -201,6 +263,7 @@
201 263  
202 264 info->font = get_string_from_config("print","font","Courier 10");
203 265 gtk_font_button_set_font_name((GtkFontButton *) widget,info->font);
  266 + font_set((GtkFontButton *) widget,info);
204 267 g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info);
205 268  
206 269 // Color scheme dropdown
... ... @@ -222,9 +285,11 @@
222 285 return G_OBJECT(container);
223 286 }
224 287  
225   - static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *font_dialog, gpointer user_data)
  288 + static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget, PRINT_INFO *info)
226 289 {
227 290 trace("%s",__FUNCTION__);
  291 + set_string_to_config("print","colors",info->colorname);
  292 + v3270_set_color_table(info->color,info->colorname);
228 293 }
229 294  
230 295 static GtkPrintOperation * begin_print_operation(GtkAction *action, GtkWidget *widget, PRINT_INFO **info)
... ... @@ -236,6 +301,7 @@
236 301  
237 302 *info = g_new0(PRINT_INFO,1);
238 303 (*info)->session = v3270_get_session(widget);
  304 + (*info)->fontweight = CAIRO_FONT_WEIGHT_NORMAL;
239 305  
240 306 // Basic setup
241 307 gtk_print_operation_set_allow_async(print,TRUE);
... ...
src/gtk/uiparser/menuitem.c
... ... @@ -108,7 +108,6 @@
108 108 }
109 109 }
110 110  
111   -
112 111 return G_OBJECT(widget);
113 112 }
114 113  
... ...
src/gtk/uiparser/parsefile.c
... ... @@ -115,6 +115,7 @@
115 115 const gchar * name = NULL;
116 116 gchar * key;
117 117  
  118 +trace("%s ----",__FUNCTION__);
118 119 if(action)
119 120 name = gtk_action_get_name(action);
120 121  
... ... @@ -133,7 +134,6 @@
133 134 g_object_ref(G_OBJECT(widget));
134 135 g_hash_table_insert(info->element_list[id],key,widget);
135 136  
136   -// trace("%s - %s",__FUNCTION__,name);
137 137 return widget;
138 138 }
139 139  
... ...
src/gtk/v3270/draw.c
... ... @@ -93,7 +93,7 @@ gboolean v3270_expose(GtkWidget *widget, GdkEventExpose *event)
93 93 #endif // GTk3
94 94  
95 95  
96   -void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, const struct v3270_metrics *metrics, GdkRectangle *rect, GdkColor *color)
  96 +void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color)
97 97 {
98 98 GdkColor *fg;
99 99 GdkColor *bg;
... ... @@ -113,10 +113,10 @@ void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, con
113 113 bg = color+(attr & 0x000F);
114 114 }
115 115  
116   - v3270_draw_char(cr,chr,attr,metrics,rect,fg,bg);
  116 + v3270_draw_char(cr,chr,attr,session,height,rect,fg,bg);
117 117 }
118 118  
119   -void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, const struct v3270_metrics *metrics, GdkRectangle *rect, GdkColor *fg, GdkColor *bg)
  119 +void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *fg, GdkColor *bg)
120 120 {
121 121 // Clear element area
122 122 gdk_cairo_set_source_color(cr,fg);
... ... @@ -201,27 +201,27 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, const
201 201 break;
202 202  
203 203 case 0x8c: // CG 0xf7, less or equal "≤"
204   - cairo_move_to(cr,rect->x,rect->y+metrics->height);
  204 + cairo_move_to(cr,rect->x,rect->y+height);
205 205 cairo_show_text(cr, "≤");
206 206 break;
207 207  
208 208 case 0xae: // CG 0xd9, greater or equal "≥"
209   - cairo_move_to(cr,rect->x,rect->y+metrics->height);
  209 + cairo_move_to(cr,rect->x,rect->y+height);
210 210 cairo_show_text(cr, "≥");
211 211 break;
212 212  
213 213 case 0xbe: // CG 0x3e, not equal "≠"
214   - cairo_move_to(cr,rect->x,rect->y+metrics->height);
  214 + cairo_move_to(cr,rect->x,rect->y+height);
215 215 cairo_show_text(cr, "≠");
216 216 break;
217 217  
218 218 case 0xad: // "["
219   - cairo_move_to(cr,rect->x,rect->y+metrics->height);
  219 + cairo_move_to(cr,rect->x,rect->y+height);
220 220 cairo_show_text(cr, "[");
221 221 break;
222 222  
223 223 case 0xbd: // "]"
224   - cairo_move_to(cr,rect->x,rect->y+metrics->height);
  224 + cairo_move_to(cr,rect->x,rect->y+height);
225 225 cairo_show_text(cr, "]");
226 226 break;
227 227  
... ... @@ -231,11 +231,11 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, const
231 231 }
232 232 else if(chr)
233 233 {
234   - gchar *utf = g_convert((char *) &chr, 1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
  234 + gchar *utf = g_convert((char *) &chr, 1, "UTF-8", lib3270_get_charset(session), NULL, NULL, NULL);
235 235  
236 236 if(utf)
237 237 {
238   - cairo_move_to(cr,rect->x,rect->y+metrics->height);
  238 + cairo_move_to(cr,rect->x,rect->y+height);
239 239 cairo_show_text(cr, utf);
240 240 g_free(utf);
241 241 }
... ... @@ -304,7 +304,7 @@ void v3270_reload(GtkWidget *widget)
304 304 if(addr == cursor)
305 305 v3270_update_cursor_rect(terminal,&rect,chr,attr);
306 306  
307   - v3270_draw_element(cr,chr,attr,&terminal->metrics,&rect,terminal->color);
  307 + v3270_draw_element(cr,chr,attr,terminal->host,terminal->metrics.height,&rect,terminal->color);
308 308  
309 309 addr++;
310 310 rect.x += rect.width;
... ... @@ -349,7 +349,7 @@ void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned sho
349 349  
350 350 cr = cairo_create(terminal->surface);
351 351 cairo_set_scaled_font(cr,terminal->font_scaled);
352   - v3270_draw_element(cr, chr, attr, &terminal->metrics, &rect,terminal->color);
  352 + v3270_draw_element(cr, chr, attr, terminal->host, terminal->metrics.height, &rect,terminal->color);
353 353 cairo_destroy(cr);
354 354  
355 355 if(cursor)
... ... @@ -386,7 +386,7 @@ void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short
386 386  
387 387 rect.x = 0;
388 388 rect.y = 0;
389   - v3270_draw_char(cr,chr,attr,&widget->metrics,&rect,bg,fg);
  389 + v3270_draw_char(cr,chr,attr,widget->host,widget->metrics.height,&rect,bg,fg);
390 390  
391 391 cairo_destroy(cr);
392 392 }
... ...
src/gtk/v3270/private.h
... ... @@ -103,8 +103,7 @@ void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned sho
103 103  
104 104 void v3270_register_io_handlers(v3270Class *cls);
105 105  
106   -void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, const struct v3270_metrics *metrics, GdkRectangle *rect, GdkColor *color);
107   -void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, const struct v3270_metrics *metrics, GdkRectangle *rect, GdkColor *fg, GdkColor *bg);
  106 +void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *fg, GdkColor *bg);
108 107  
109 108 void v3270_start_timer(GtkWidget *terminal);
110 109 void v3270_stop_timer(GtkWidget *terminal);
... ...
src/gtk/v3270/v3270.h
... ... @@ -214,6 +214,7 @@
214 214 void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name);
215 215 int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name);
216 216 void v3270_set_color_table(GdkColor *table, const gchar *colors);
  217 + void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color);
217 218  
218 219 G_END_DECLS
219 220  
... ...