Commit 86d3732f5f2a8647494559049223070276aba83b
1 parent
0a3c7900
Exists in
master
and in
5 other branches
Implementando funções de impressão
Showing
6 changed files
with
91 additions
and
26 deletions
Show diff stats
src/gtk/print.c
@@ -39,11 +39,15 @@ | @@ -39,11 +39,15 @@ | ||
39 | GdkColor color[V3270_COLOR_COUNT]; | 39 | GdkColor color[V3270_COLOR_COUNT]; |
40 | H3270 * session; | 40 | H3270 * session; |
41 | gchar * font; | 41 | gchar * font; |
42 | + guint fontsize; | ||
43 | + cairo_font_weight_t fontweight; | ||
42 | gchar * colorname; | 44 | gchar * colorname; |
43 | int rows; | 45 | int rows; |
44 | int cols; | 46 | int cols; |
45 | int pages; | 47 | int pages; |
46 | cairo_font_extents_t extents; | 48 | cairo_font_extents_t extents; |
49 | + double width; | ||
50 | + double height; | ||
47 | cairo_scaled_font_t * font_scaled; | 51 | cairo_scaled_font_t * font_scaled; |
48 | 52 | ||
49 | } PRINT_INFO; | 53 | } PRINT_INFO; |
@@ -52,12 +56,15 @@ | @@ -52,12 +56,15 @@ | ||
52 | 56 | ||
53 | static void setup_font(cairo_t *cr, PRINT_INFO *info) | 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 | info->font_scaled = cairo_get_scaled_font(cr); | 61 | info->font_scaled = cairo_get_scaled_font(cr); |
58 | cairo_scaled_font_reference(info->font_scaled); | 62 | cairo_scaled_font_reference(info->font_scaled); |
59 | cairo_scaled_font_extents(info->font_scaled,&info->extents); | 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 | static void begin_print_all(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) | 70 | static void begin_print_all(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) |
@@ -72,14 +79,47 @@ | @@ -72,14 +79,47 @@ | ||
72 | 79 | ||
73 | static void draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) | 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 | cairo_set_scaled_font(cr,info->font_scaled); | 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 | cairo_stroke(cr); | 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 | static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info) | 125 | static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info) |
@@ -107,12 +147,33 @@ | @@ -107,12 +147,33 @@ | ||
107 | 147 | ||
108 | static void font_set(GtkFontButton *widget, PRINT_INFO *info) | 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 | if(info->font) | 152 | if(info->font) |
111 | g_free(info->font); | 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 | static void color_scheme_changed(GtkComboBox *widget,PRINT_INFO *info) | 179 | static void color_scheme_changed(GtkComboBox *widget,PRINT_INFO *info) |
@@ -139,12 +200,13 @@ | @@ -139,12 +200,13 @@ | ||
139 | if(!info->colorname) | 200 | if(!info->colorname) |
140 | return; | 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 | if(*info->colorname) | 205 | if(*info->colorname) |
145 | g_free(info->colorname); | 206 | g_free(info->colorname); |
146 | 207 | ||
147 | info->colorname = new_colors; | 208 | info->colorname = new_colors; |
209 | + | ||
148 | } | 210 | } |
149 | 211 | ||
150 | static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) | 212 | static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) |
@@ -201,6 +263,7 @@ | @@ -201,6 +263,7 @@ | ||
201 | 263 | ||
202 | info->font = get_string_from_config("print","font","Courier 10"); | 264 | info->font = get_string_from_config("print","font","Courier 10"); |
203 | gtk_font_button_set_font_name((GtkFontButton *) widget,info->font); | 265 | gtk_font_button_set_font_name((GtkFontButton *) widget,info->font); |
266 | + font_set((GtkFontButton *) widget,info); | ||
204 | g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); | 267 | g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); |
205 | 268 | ||
206 | // Color scheme dropdown | 269 | // Color scheme dropdown |
@@ -222,9 +285,11 @@ | @@ -222,9 +285,11 @@ | ||
222 | return G_OBJECT(container); | 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 | trace("%s",__FUNCTION__); | 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 | static GtkPrintOperation * begin_print_operation(GtkAction *action, GtkWidget *widget, PRINT_INFO **info) | 295 | static GtkPrintOperation * begin_print_operation(GtkAction *action, GtkWidget *widget, PRINT_INFO **info) |
@@ -236,6 +301,7 @@ | @@ -236,6 +301,7 @@ | ||
236 | 301 | ||
237 | *info = g_new0(PRINT_INFO,1); | 302 | *info = g_new0(PRINT_INFO,1); |
238 | (*info)->session = v3270_get_session(widget); | 303 | (*info)->session = v3270_get_session(widget); |
304 | + (*info)->fontweight = CAIRO_FONT_WEIGHT_NORMAL; | ||
239 | 305 | ||
240 | // Basic setup | 306 | // Basic setup |
241 | gtk_print_operation_set_allow_async(print,TRUE); | 307 | gtk_print_operation_set_allow_async(print,TRUE); |
src/gtk/uiparser/menuitem.c
src/gtk/uiparser/parsefile.c
@@ -115,6 +115,7 @@ | @@ -115,6 +115,7 @@ | ||
115 | const gchar * name = NULL; | 115 | const gchar * name = NULL; |
116 | gchar * key; | 116 | gchar * key; |
117 | 117 | ||
118 | +trace("%s ----",__FUNCTION__); | ||
118 | if(action) | 119 | if(action) |
119 | name = gtk_action_get_name(action); | 120 | name = gtk_action_get_name(action); |
120 | 121 | ||
@@ -133,7 +134,6 @@ | @@ -133,7 +134,6 @@ | ||
133 | g_object_ref(G_OBJECT(widget)); | 134 | g_object_ref(G_OBJECT(widget)); |
134 | g_hash_table_insert(info->element_list[id],key,widget); | 135 | g_hash_table_insert(info->element_list[id],key,widget); |
135 | 136 | ||
136 | -// trace("%s - %s",__FUNCTION__,name); | ||
137 | return widget; | 137 | return widget; |
138 | } | 138 | } |
139 | 139 |
src/gtk/v3270/draw.c
@@ -93,7 +93,7 @@ gboolean v3270_expose(GtkWidget *widget, GdkEventExpose *event) | @@ -93,7 +93,7 @@ gboolean v3270_expose(GtkWidget *widget, GdkEventExpose *event) | ||
93 | #endif // GTk3 | 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 | GdkColor *fg; | 98 | GdkColor *fg; |
99 | GdkColor *bg; | 99 | GdkColor *bg; |
@@ -113,10 +113,10 @@ void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, con | @@ -113,10 +113,10 @@ void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, con | ||
113 | bg = color+(attr & 0x000F); | 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 | // Clear element area | 121 | // Clear element area |
122 | gdk_cairo_set_source_color(cr,fg); | 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,27 +201,27 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, const | ||
201 | break; | 201 | break; |
202 | 202 | ||
203 | case 0x8c: // CG 0xf7, less or equal "≤" | 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 | cairo_show_text(cr, "≤"); | 205 | cairo_show_text(cr, "≤"); |
206 | break; | 206 | break; |
207 | 207 | ||
208 | case 0xae: // CG 0xd9, greater or equal "≥" | 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 | cairo_show_text(cr, "≥"); | 210 | cairo_show_text(cr, "≥"); |
211 | break; | 211 | break; |
212 | 212 | ||
213 | case 0xbe: // CG 0x3e, not equal "≠" | 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 | cairo_show_text(cr, "≠"); | 215 | cairo_show_text(cr, "≠"); |
216 | break; | 216 | break; |
217 | 217 | ||
218 | case 0xad: // "[" | 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 | cairo_show_text(cr, "["); | 220 | cairo_show_text(cr, "["); |
221 | break; | 221 | break; |
222 | 222 | ||
223 | case 0xbd: // "]" | 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 | cairo_show_text(cr, "]"); | 225 | cairo_show_text(cr, "]"); |
226 | break; | 226 | break; |
227 | 227 | ||
@@ -231,11 +231,11 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, const | @@ -231,11 +231,11 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, const | ||
231 | } | 231 | } |
232 | else if(chr) | 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 | if(utf) | 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 | cairo_show_text(cr, utf); | 239 | cairo_show_text(cr, utf); |
240 | g_free(utf); | 240 | g_free(utf); |
241 | } | 241 | } |
@@ -304,7 +304,7 @@ void v3270_reload(GtkWidget *widget) | @@ -304,7 +304,7 @@ void v3270_reload(GtkWidget *widget) | ||
304 | if(addr == cursor) | 304 | if(addr == cursor) |
305 | v3270_update_cursor_rect(terminal,&rect,chr,attr); | 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 | addr++; | 309 | addr++; |
310 | rect.x += rect.width; | 310 | rect.x += rect.width; |
@@ -349,7 +349,7 @@ void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned sho | @@ -349,7 +349,7 @@ void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned sho | ||
349 | 349 | ||
350 | cr = cairo_create(terminal->surface); | 350 | cr = cairo_create(terminal->surface); |
351 | cairo_set_scaled_font(cr,terminal->font_scaled); | 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 | cairo_destroy(cr); | 353 | cairo_destroy(cr); |
354 | 354 | ||
355 | if(cursor) | 355 | if(cursor) |
@@ -386,7 +386,7 @@ void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short | @@ -386,7 +386,7 @@ void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned short | ||
386 | 386 | ||
387 | rect.x = 0; | 387 | rect.x = 0; |
388 | rect.y = 0; | 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 | cairo_destroy(cr); | 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,8 +103,7 @@ void v3270_update_cursor_surface(v3270 *widget,unsigned char chr,unsigned sho | ||
103 | 103 | ||
104 | void v3270_register_io_handlers(v3270Class *cls); | 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 | void v3270_start_timer(GtkWidget *terminal); | 108 | void v3270_start_timer(GtkWidget *terminal); |
110 | void v3270_stop_timer(GtkWidget *terminal); | 109 | void v3270_stop_timer(GtkWidget *terminal); |
src/gtk/v3270/v3270.h
@@ -214,6 +214,7 @@ | @@ -214,6 +214,7 @@ | ||
214 | void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name); | 214 | void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name); |
215 | int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name); | 215 | int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name); |
216 | void v3270_set_color_table(GdkColor *table, const gchar *colors); | 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 | G_END_DECLS | 219 | G_END_DECLS |
219 | 220 |