Commit f89d68c2cad425f3c423a6ec417207d51782c31d
1 parent
28a85c77
Exists in
master
and in
5 other branches
Removendo uso da função cairo_show_text que, aparentemente, causa segfaults em windows.
Showing
4 changed files
with
85 additions
and
55 deletions
Show diff stats
pw3270.cbp
| ... | ... | @@ -440,6 +440,7 @@ |
| 440 | 440 | <Unit filename="src/pw3270/hostdialog.c"> |
| 441 | 441 | <Option compilerVar="CC" /> |
| 442 | 442 | </Unit> |
| 443 | + <Unit filename="src/pw3270/include/v3270.h" /> | |
| 443 | 444 | <Unit filename="src/pw3270/include/v3270ft.h" /> |
| 444 | 445 | <Unit filename="src/pw3270/main.c"> |
| 445 | 446 | <Option compilerVar="CC" /> | ... | ... |
src/pw3270/v3270/draw.c
| ... | ... | @@ -30,8 +30,11 @@ |
| 30 | 30 | #include <gtk/gtk.h> |
| 31 | 31 | #include <math.h> |
| 32 | 32 | #include <pw3270.h> |
| 33 | + #include <ctype.h> | |
| 33 | 34 | #include <lib3270.h> |
| 35 | + #include <lib3270/log.h> | |
| 34 | 36 | #include <lib3270/session.h> |
| 37 | + | |
| 35 | 38 | #include <v3270.h> |
| 36 | 39 | #include "private.h" |
| 37 | 40 | |
| ... | ... | @@ -142,8 +145,47 @@ void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H32 |
| 142 | 145 | |
| 143 | 146 | } |
| 144 | 147 | |
| 148 | +void v3270_draw_text_at(cairo_t *cr, int x, int y, v3270FontInfo *font, const char *str) { | |
| 149 | + | |
| 150 | + size_t szText = strlen(str); | |
| 151 | + | |
| 152 | + if(szText == 1 && isspace(*str)) { | |
| 153 | + return; | |
| 154 | + } | |
| 155 | + | |
| 156 | + // Tem string, desenha | |
| 157 | + cairo_status_t status; | |
| 158 | + cairo_glyph_t * glyphs = NULL; | |
| 159 | + int num_glyphs = 0; | |
| 160 | + cairo_text_cluster_t * clusters = NULL; | |
| 161 | + int num_clusters = 0; | |
| 162 | + cairo_text_cluster_flags_t cluster_flags; | |
| 163 | + cairo_scaled_font_t * scaled_font = cairo_get_scaled_font(cr); | |
| 164 | + | |
| 165 | + status = cairo_scaled_font_text_to_glyphs( | |
| 166 | + scaled_font, | |
| 167 | + (double) x, (double) (y+font->height), | |
| 168 | + str, szText, | |
| 169 | + &glyphs, &num_glyphs, | |
| 170 | + &clusters, &num_clusters, &cluster_flags ); | |
| 171 | + | |
| 172 | + if (status == CAIRO_STATUS_SUCCESS) { | |
| 173 | + cairo_show_text_glyphs(cr,str,szText,glyphs, num_glyphs,clusters, num_clusters, cluster_flags); | |
| 174 | + } | |
| 175 | + | |
| 176 | + if(glyphs) | |
| 177 | + cairo_glyph_free(glyphs); | |
| 178 | + | |
| 179 | + if(clusters) | |
| 180 | + cairo_text_cluster_free(clusters); | |
| 181 | + | |
| 182 | +} | |
| 183 | + | |
| 145 | 184 | void v3270_draw_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, const char *str) { |
| 146 | 185 | |
| 186 | + v3270_draw_text_at(cr,rect->x,rect->y,font,str); | |
| 187 | + | |
| 188 | +/* | |
| 147 | 189 | cairo_status_t status; |
| 148 | 190 | cairo_glyph_t * glyphs = NULL; |
| 149 | 191 | int num_glyphs = 0; |
| ... | ... | @@ -168,7 +210,7 @@ void v3270_draw_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, |
| 168 | 210 | |
| 169 | 211 | if(clusters) |
| 170 | 212 | cairo_text_cluster_free(clusters); |
| 171 | - | |
| 213 | +*/ | |
| 172 | 214 | } |
| 173 | 215 | |
| 174 | 216 | void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *fg, GdkRGBA *bg) |
| ... | ... | @@ -470,6 +512,7 @@ void v3270_update_cursor_rect(v3270 *widget, GdkRectangle *rect, unsigned char c |
| 470 | 512 | |
| 471 | 513 | void v3270_queue_draw_area(GtkWidget *widget, gint x, gint y, gint width, gint height) |
| 472 | 514 | { |
| 515 | + | |
| 473 | 516 | if(GTK_V3270(widget)->drawing && gtk_widget_get_realized(widget)) |
| 474 | 517 | { |
| 475 | 518 | gtk_widget_queue_draw_area(widget,x,y,width,height); | ... | ... |
src/pw3270/v3270/oia.c
| ... | ... | @@ -180,13 +180,8 @@ static void setup_luname_position(GdkRectangle *rect, v3270FontInfo *font, cairo |
| 180 | 180 | |
| 181 | 181 | if(luname) |
| 182 | 182 | { |
| 183 | -// cairo_move_to(cr,rect->x,rect->y+font->height); | |
| 184 | - | |
| 185 | 183 | gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_LUNAME); |
| 186 | 184 | v3270_draw_text(cr,rect,font,luname); |
| 187 | - | |
| 188 | -// cairo_show_text(cr,luname); | |
| 189 | -// cairo_stroke(cr); | |
| 190 | 185 | } |
| 191 | 186 | |
| 192 | 187 | cairo_restore(cr); |
| ... | ... | @@ -242,55 +237,41 @@ static void setup_double_char_position(GdkRectangle *rect, v3270FontInfo *metric |
| 242 | 237 | |
| 243 | 238 | } |
| 244 | 239 | |
| 240 | +static int draw_centered_char(cairo_t *cr, v3270FontInfo *metrics, int x, int y, const gchar chr) | |
| 241 | +{ | |
| 242 | + char str[2] = { chr, 0 }; | |
| 243 | +// cairo_text_extents_t extents; | |
| 244 | + | |
| 245 | + cairo_set_scaled_font(cr,metrics->scaled); | |
| 246 | +// cairo_text_extents(cr,str,&extents); | |
| 247 | + | |
| 248 | + v3270_draw_text_at(cr, x, y, metrics, str); | |
| 249 | + | |
| 250 | + return y+metrics->height+2; | |
| 251 | + | |
| 252 | +} | |
| 253 | + | |
| 245 | 254 | static void draw_undera(cairo_t *cr, H3270 *host, v3270FontInfo *metrics, GdkRGBA *color, GdkRectangle *rect) |
| 246 | 255 | { |
| 247 | -#ifdef DEBUG | |
| 248 | - cairo_set_source_rgb(cr,0.1,0.1,0.1); | |
| 249 | -#else | |
| 250 | 256 | gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); |
| 251 | -#endif | |
| 252 | 257 | |
| 253 | 258 | cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); |
| 254 | 259 | cairo_fill(cr); |
| 255 | 260 | |
| 256 | 261 | if(lib3270_get_undera(host)) |
| 257 | 262 | { |
| 258 | - const gchar *chr = lib3270_in_e(host) ? "B" : "A"; | |
| 259 | - cairo_text_extents_t extents; | |
| 260 | - int x,y; | |
| 261 | - | |
| 262 | - gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_BACKGROUND); | |
| 263 | - cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | |
| 264 | - cairo_fill(cr); | |
| 263 | + int y; | |
| 265 | 264 | |
| 266 | 265 | gdk_cairo_set_source_rgba(cr,color+V3270_COLOR_OIA_FOREGROUND); |
| 267 | 266 | |
| 268 | - cairo_text_extents(cr,chr,&extents); | |
| 269 | - | |
| 270 | - x = rect->x + ((rect->width/2) - ((extents.width+extents.x_bearing)/2)); | |
| 271 | - y = rect->y + extents.height+((rect->height/2) - (extents.height/2)); | |
| 272 | - | |
| 273 | - cairo_move_to(cr,x,y); | |
| 274 | - cairo_show_text(cr,chr); | |
| 275 | - | |
| 276 | - cairo_move_to(cr,x+extents.x_bearing,y+2); | |
| 277 | - cairo_rel_line_to(cr,extents.width,0); | |
| 267 | + y = draw_centered_char(cr, metrics,rect->x,rect->y, lib3270_in_e(host) ? 'B' : 'A'); | |
| 278 | 268 | |
| 269 | + cairo_move_to(cr,rect->x,y); | |
| 270 | + cairo_rel_line_to(cr,10,0); | |
| 279 | 271 | cairo_stroke(cr); |
| 280 | 272 | |
| 281 | 273 | } |
| 282 | - | |
| 283 | -} | |
| 284 | - | |
| 285 | -static void draw_centered_char(cairo_t *cr, v3270FontInfo *metrics, int x, int y, const gchar chr) | |
| 286 | -{ | |
| 287 | - char str[2] = { chr, 0 }; | |
| 288 | - | |
| 289 | - cairo_text_extents_t extents; | |
| 290 | - cairo_text_extents(cr,str,&extents); | |
| 291 | - | |
| 292 | - cairo_move_to(cr,x+(((metrics->width+2)/2)-(extents.width/2)),y+extents.height+( (metrics->spacing/2) - (extents.height/2))); | |
| 293 | - cairo_show_text(cr,str); | |
| 274 | + debug("%s",__FUNCTION__); | |
| 294 | 275 | |
| 295 | 276 | } |
| 296 | 277 | |
| ... | ... | @@ -706,10 +687,12 @@ void v3270_update_luname(GtkWidget *widget,const gchar *name) |
| 706 | 687 | |
| 707 | 688 | if(name) |
| 708 | 689 | { |
| 709 | - cairo_move_to(cr,rect->x,rect->y+terminal->font.height); | |
| 690 | +// cairo_move_to(cr,rect->x,rect->y+terminal->font.height); | |
| 691 | +// cairo_show_text(cr,name); | |
| 692 | +// cairo_stroke(cr); | |
| 710 | 693 | gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_LUNAME); |
| 711 | - cairo_show_text(cr,name); | |
| 712 | - cairo_stroke(cr); | |
| 694 | + v3270_draw_text_at(cr, rect->x, rect->y, &terminal->font, name); | |
| 695 | + | |
| 713 | 696 | } |
| 714 | 697 | |
| 715 | 698 | cairo_destroy(cr); |
| ... | ... | @@ -757,10 +740,7 @@ static void draw_cursor_position(cairo_t *cr, GdkRectangle *rect, v3270FontInfo |
| 757 | 740 | buffer[7] = 0; |
| 758 | 741 | |
| 759 | 742 | cairo_text_extents(cr,buffer,&extents); |
| 760 | - | |
| 761 | - cairo_move_to(cr,(rect->x+rect->width)-(extents.width+2),rect->y+metrics->height); | |
| 762 | - cairo_show_text(cr, buffer); | |
| 763 | - cairo_stroke(cr); | |
| 743 | + v3270_draw_text_at(cr,(rect->x+rect->width)-(extents.width+2),rect->y,metrics,buffer); | |
| 764 | 744 | } |
| 765 | 745 | |
| 766 | 746 | void v3270_update_cursor(H3270 *session, unsigned short row, unsigned short col, unsigned char c, unsigned short attr) |
| ... | ... | @@ -937,9 +917,10 @@ static void update_text_field(v3270 *terminal, gboolean flag, V3270_OIA_FIELD id |
| 937 | 917 | |
| 938 | 918 | if(flag) |
| 939 | 919 | { |
| 940 | - cairo_move_to(cr,0,terminal->font.height); | |
| 941 | - cairo_show_text(cr, text); | |
| 942 | - cairo_stroke(cr); | |
| 920 | + v3270_draw_text_at(cr,0,0,&terminal->font,text); | |
| 921 | +// cairo_move_to(cr,0,terminal->font.height); | |
| 922 | +// cairo_show_text(cr, text); | |
| 923 | +// cairo_stroke(cr); | |
| 943 | 924 | } |
| 944 | 925 | |
| 945 | 926 | cairo_destroy(cr); |
| ... | ... | @@ -1108,29 +1089,33 @@ void v3270_update_oia(H3270 *session, LIB3270_FLAG id, unsigned char on) |
| 1108 | 1089 | switch(id) |
| 1109 | 1090 | { |
| 1110 | 1091 | case LIB3270_FLAG_BOXSOLID: |
| 1111 | - debug("%s",__FUNCTION__); | |
| 1092 | + debug("%s LIB3270_FLAG_BOXSOLID",__FUNCTION__); | |
| 1112 | 1093 | cr = set_update_region(terminal,&r,V3270_OIA_CONNECTION); |
| 1113 | 1094 | v3270_draw_connection(cr,terminal->host,&terminal->font,terminal->color,r); |
| 1114 | - v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | |
| 1115 | 1095 | cairo_destroy(cr); |
| 1096 | + v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | |
| 1116 | 1097 | break; |
| 1117 | 1098 | |
| 1118 | 1099 | case LIB3270_FLAG_UNDERA: |
| 1119 | - debug("%s",__FUNCTION__); | |
| 1100 | + debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | |
| 1120 | 1101 | cr = set_update_region(terminal,&r,V3270_OIA_UNDERA); |
| 1102 | + debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | |
| 1121 | 1103 | draw_undera(cr,terminal->host,&terminal->font,terminal->color,r); |
| 1122 | - v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | |
| 1104 | + debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | |
| 1123 | 1105 | cairo_destroy(cr); |
| 1106 | + debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | |
| 1107 | + v3270_queue_draw_area(GTK_WIDGET(terminal),r->x,r->y,r->width,r->height); | |
| 1108 | + debug("%s LIB3270_FLAG_UNDERA",__FUNCTION__); | |
| 1124 | 1109 | break; |
| 1125 | 1110 | |
| 1126 | 1111 | case LIB3270_FLAG_TYPEAHEAD: |
| 1127 | - debug("%s",__FUNCTION__); | |
| 1112 | + debug("%s LIB3270_FLAG_TYPEAHEAD",__FUNCTION__); | |
| 1128 | 1113 | update_text_field(terminal,on,V3270_OIA_TYPEAHEAD,'T'); |
| 1129 | 1114 | break; |
| 1130 | 1115 | |
| 1131 | 1116 | #ifdef HAVE_PRINTER |
| 1132 | 1117 | case LIB3270_FLAG_PRINTER: |
| 1133 | - debug("%s",__FUNCTION__); | |
| 1118 | + debug("%s LIB3270_FLAG_PRINTER",__FUNCTION__); | |
| 1134 | 1119 | update_text_field(terminal,on,V3270_OIA_PRINTER,'P'); |
| 1135 | 1120 | break; |
| 1136 | 1121 | #endif // HAVE_PRINTER | ... | ... |
src/pw3270/v3270/private.h
| ... | ... | @@ -271,6 +271,7 @@ void v3270_register_io_handlers(v3270Class *cls); |
| 271 | 271 | |
| 272 | 272 | void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *fg, GdkRGBA *bg); |
| 273 | 273 | void v3270_draw_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, const char *str); |
| 274 | +void v3270_draw_text_at(cairo_t *cr, int x, int y, v3270FontInfo *font, const char *str); | |
| 274 | 275 | |
| 275 | 276 | void v3270_start_timer(GtkWidget *terminal); |
| 276 | 277 | void v3270_stop_timer(GtkWidget *terminal); | ... | ... |