Commit dfefe3cf21415cc63fc6484ac12289d094e983ba
1 parent
c312bb7f
Exists in
master
and in
1 other branch
Adjustments on CG character drawing.
Showing
1 changed file
with
76 additions
and
20 deletions
Show diff stats
src/terminal/drawing/draw.c
| @@ -205,6 +205,78 @@ void v3270_draw_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, | @@ -205,6 +205,78 @@ void v3270_draw_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, | ||
| 205 | v3270_draw_text_at(cr,rect->x,rect->y,font,str); | 205 | v3270_draw_text_at(cr,rect->x,rect->y,font,str); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | +static gboolean draw_cg(cairo_t *cr, unsigned char chr, v3270FontInfo *font, GdkRectangle *rect) | ||
| 209 | +{ | ||
| 210 | + static const struct CharList | ||
| 211 | + { | ||
| 212 | + unsigned char chr; | ||
| 213 | + const gchar * utf; | ||
| 214 | + } charlist[] = | ||
| 215 | + { | ||
| 216 | + { 0x8c, "≤" }, // CG 0xf7, less or equal "≤" | ||
| 217 | + { 0xae, "≥" }, // CG 0xd9, greater or equal "≥" | ||
| 218 | + { 0xbe, "≠" }, // CG 0x3e, not equal "≠" | ||
| 219 | + { 0xad, "[" }, // "[" | ||
| 220 | + { 0xbd, "]" }, // "]" | ||
| 221 | + }; | ||
| 222 | + | ||
| 223 | + size_t ix; | ||
| 224 | + | ||
| 225 | + if(chr >= 0xf0 && chr <= 0xf9) | ||
| 226 | + { | ||
| 227 | + char str[] = { '0' + (chr-0xF0), 0 }; | ||
| 228 | + | ||
| 229 | + cairo_status_t status; | ||
| 230 | + cairo_glyph_t * glyphs = NULL; | ||
| 231 | + int num_glyphs = 0; | ||
| 232 | + cairo_text_cluster_t * clusters = NULL; | ||
| 233 | + int num_clusters = 0; | ||
| 234 | + cairo_text_cluster_flags_t cluster_flags; | ||
| 235 | + cairo_scaled_font_t * scaled_font = cairo_get_scaled_font(cr); | ||
| 236 | + cairo_font_extents_t extents; | ||
| 237 | + | ||
| 238 | + cairo_save(cr); | ||
| 239 | + | ||
| 240 | + cairo_set_font_face(cr,font->face); | ||
| 241 | + cairo_set_font_size(cr,font->size/1.3); | ||
| 242 | + cairo_font_extents(cr,&extents); | ||
| 243 | + | ||
| 244 | + status = cairo_scaled_font_text_to_glyphs( | ||
| 245 | + scaled_font, | ||
| 246 | + (double) rect->x, (double) (rect->y+extents.height), | ||
| 247 | + str, 1, | ||
| 248 | + &glyphs, &num_glyphs, | ||
| 249 | + &clusters, &num_clusters, &cluster_flags ); | ||
| 250 | + | ||
| 251 | + if (status == CAIRO_STATUS_SUCCESS) { | ||
| 252 | + cairo_show_text_glyphs(cr,str,1,glyphs, num_glyphs,clusters, num_clusters, cluster_flags); | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + if(glyphs) | ||
| 256 | + cairo_glyph_free(glyphs); | ||
| 257 | + | ||
| 258 | + if(clusters) | ||
| 259 | + cairo_text_cluster_free(clusters); | ||
| 260 | + | ||
| 261 | + cairo_restore(cr); | ||
| 262 | + | ||
| 263 | + return TRUE; | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + for(ix = 0; ix < G_N_ELEMENTS(charlist); ix++) | ||
| 267 | + { | ||
| 268 | + if(chr == charlist[ix].chr) | ||
| 269 | + { | ||
| 270 | + v3270_draw_text(cr,rect,font,charlist[ix].utf); | ||
| 271 | + return TRUE; | ||
| 272 | + } | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + debug("%s: Unknown char 0x%02x",__FUNCTION__,(int) chr); | ||
| 276 | + | ||
| 277 | + return FALSE; | ||
| 278 | +} | ||
| 279 | + | ||
| 208 | void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *fg, GdkRGBA *bg) | 280 | void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *fg, GdkRGBA *bg) |
| 209 | { | 281 | { |
| 210 | // Clear element area | 282 | // Clear element area |
| @@ -234,6 +306,7 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 | @@ -234,6 +306,7 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 | ||
| 234 | } | 306 | } |
| 235 | else if(attr & LIB3270_ATTR_CG) | 307 | else if(attr & LIB3270_ATTR_CG) |
| 236 | { | 308 | { |
| 309 | + | ||
| 237 | switch(chr) | 310 | switch(chr) |
| 238 | { | 311 | { |
| 239 | case 0xd3: // CG 0xab, plus | 312 | case 0xd3: // CG 0xab, plus |
| @@ -305,28 +378,11 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 | @@ -305,28 +378,11 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 | ||
| 305 | cairo_rel_line_to(cr,rect->width,0); | 378 | cairo_rel_line_to(cr,rect->width,0); |
| 306 | break; | 379 | break; |
| 307 | 380 | ||
| 308 | - case 0x8c: // CG 0xf7, less or equal "≤" | ||
| 309 | - v3270_draw_text(cr,rect,font,"≤"); | ||
| 310 | - break; | ||
| 311 | - | ||
| 312 | - case 0xae: // CG 0xd9, greater or equal "≥" | ||
| 313 | - v3270_draw_text(cr,rect,font,"≥"); | ||
| 314 | - break; | ||
| 315 | - | ||
| 316 | - case 0xbe: // CG 0x3e, not equal "≠" | ||
| 317 | - v3270_draw_text(cr,rect,font,"≠"); | ||
| 318 | - break; | 381 | + default: |
| 319 | 382 | ||
| 320 | - case 0xad: // "[" | ||
| 321 | - v3270_draw_text(cr,rect,font,"["); | ||
| 322 | - break; | 383 | + if(!draw_cg(cr, chr, font, rect)) |
| 384 | + cairo_rectangle(cr, rect->x+1, rect->y+1, rect->width-2, rect->height-2); | ||
| 323 | 385 | ||
| 324 | - case 0xbd: // "]" | ||
| 325 | - v3270_draw_text(cr,rect,font,"]"); | ||
| 326 | - break; | ||
| 327 | - | ||
| 328 | - default: | ||
| 329 | - cairo_rectangle(cr, rect->x+1, rect->y+1, rect->width-2, rect->height-2); | ||
| 330 | } | 386 | } |
| 331 | } | 387 | } |
| 332 | else if(chr) | 388 | else if(chr) |