Commit 61f7422d31d4dd380d0efaa59f50070b2f0c6978
Exists in
master
and in
1 other branch
Merging updates to allow new Graphic APL chars.
Showing
1 changed file
with
100 additions
and
20 deletions
Show diff stats
src/terminal/drawing/draw.c
| ... | ... | @@ -205,6 +205,102 @@ void v3270_draw_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, |
| 205 | 205 | v3270_draw_text_at(cr,rect->x,rect->y,font,str); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | +static void draw_small_text(cairo_t *cr, const GdkRectangle *rect, v3270FontInfo *font, const char *str, int mode) | |
| 209 | +{ | |
| 210 | + cairo_status_t status; | |
| 211 | + cairo_glyph_t * glyphs = NULL; | |
| 212 | + int num_glyphs = 0; | |
| 213 | + cairo_text_cluster_t * clusters = NULL; | |
| 214 | + int num_clusters = 0; | |
| 215 | + double y = (double) rect->y; | |
| 216 | + | |
| 217 | + cairo_text_cluster_flags_t cluster_flags; | |
| 218 | + cairo_scaled_font_t * scaled_font = cairo_get_scaled_font(cr); | |
| 219 | + cairo_font_extents_t extents; | |
| 220 | + | |
| 221 | + cairo_save(cr); | |
| 222 | + | |
| 223 | + cairo_set_font_face(cr,font->face); | |
| 224 | + cairo_set_font_size(cr,font->size/ 1.6); | |
| 225 | + cairo_font_extents(cr,&extents); | |
| 226 | + | |
| 227 | + if(mode == 0) | |
| 228 | + { | |
| 229 | + y += ((double) extents.height); | |
| 230 | + } | |
| 231 | + else | |
| 232 | + { | |
| 233 | + y += font->height; | |
| 234 | + } | |
| 235 | + | |
| 236 | + status = cairo_scaled_font_text_to_glyphs( | |
| 237 | + scaled_font, | |
| 238 | + (double) rect->x, y, | |
| 239 | + str, 1, | |
| 240 | + &glyphs, &num_glyphs, | |
| 241 | + &clusters, &num_clusters, &cluster_flags ); | |
| 242 | + | |
| 243 | + if (status == CAIRO_STATUS_SUCCESS) { | |
| 244 | + cairo_show_text_glyphs(cr,str,1,glyphs, num_glyphs,clusters, num_clusters, cluster_flags); | |
| 245 | + } | |
| 246 | + | |
| 247 | + if(glyphs) | |
| 248 | + cairo_glyph_free(glyphs); | |
| 249 | + | |
| 250 | + if(clusters) | |
| 251 | + cairo_text_cluster_free(clusters); | |
| 252 | + | |
| 253 | + cairo_restore(cr); | |
| 254 | + | |
| 255 | +} | |
| 256 | + | |
| 257 | +static gboolean draw_cg(cairo_t *cr, unsigned char chr, v3270FontInfo *font, GdkRectangle *rect) | |
| 258 | +{ | |
| 259 | + static const struct CharList | |
| 260 | + { | |
| 261 | + unsigned char chr; | |
| 262 | + const gchar * utf; | |
| 263 | + } charlist[] = | |
| 264 | + { | |
| 265 | + { 0x8c, "≤" }, // CG 0xf7, less or equal "≤" | |
| 266 | + { 0xae, "≥" }, // CG 0xd9, greater or equal "≥" | |
| 267 | + { 0xbe, "≠" }, // CG 0x3e, not equal "≠" | |
| 268 | + { 0xad, "[" }, // "[" | |
| 269 | + { 0xbd, "]" }, // "]" | |
| 270 | + { 0xb8, "÷" }, // Division Sign ÷ | |
| 271 | + | |
| 272 | + }; | |
| 273 | + | |
| 274 | + size_t ix; | |
| 275 | + | |
| 276 | + if(chr >= 0xf0 && chr <= 0xf9) | |
| 277 | + { | |
| 278 | + char str[] = { '0' + (chr-0xF0), 0 }; | |
| 279 | + draw_small_text(cr, rect, font, str, 0); | |
| 280 | + return TRUE; | |
| 281 | + } | |
| 282 | + | |
| 283 | + if(chr >= 0xe1 && chr <= 0xe3) | |
| 284 | + { | |
| 285 | + char str[] = { '1' + (chr-0xe1), 0 }; | |
| 286 | + draw_small_text(cr, rect, font, str, 1); | |
| 287 | + return TRUE; | |
| 288 | + } | |
| 289 | + | |
| 290 | + for(ix = 0; ix < G_N_ELEMENTS(charlist); ix++) | |
| 291 | + { | |
| 292 | + if(chr == charlist[ix].chr) | |
| 293 | + { | |
| 294 | + v3270_draw_text(cr,rect,font,charlist[ix].utf); | |
| 295 | + return TRUE; | |
| 296 | + } | |
| 297 | + } | |
| 298 | + | |
| 299 | + debug("%s: Unknown char 0x%02x",__FUNCTION__,(int) chr); | |
| 300 | + | |
| 301 | + return FALSE; | |
| 302 | +} | |
| 303 | + | |
| 208 | 304 | void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *fg, GdkRGBA *bg) |
| 209 | 305 | { |
| 210 | 306 | // Clear element area |
| ... | ... | @@ -234,6 +330,7 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 |
| 234 | 330 | } |
| 235 | 331 | else if(attr & LIB3270_ATTR_CG) |
| 236 | 332 | { |
| 333 | + | |
| 237 | 334 | switch(chr) |
| 238 | 335 | { |
| 239 | 336 | case 0xd3: // CG 0xab, plus |
| ... | ... | @@ -305,28 +402,11 @@ void v3270_draw_char(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 |
| 305 | 402 | cairo_rel_line_to(cr,rect->width,0); |
| 306 | 403 | break; |
| 307 | 404 | |
| 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; | |
| 319 | - | |
| 320 | - case 0xad: // "[" | |
| 321 | - v3270_draw_text(cr,rect,font,"["); | |
| 322 | - break; | |
| 405 | + default: | |
| 323 | 406 | |
| 324 | - case 0xbd: // "]" | |
| 325 | - v3270_draw_text(cr,rect,font,"]"); | |
| 326 | - break; | |
| 407 | + if(!draw_cg(cr, chr, font, rect)) | |
| 408 | + cairo_rectangle(cr, rect->x+1, rect->y+1, rect->width-2, rect->height-2); | |
| 327 | 409 | |
| 328 | - default: | |
| 329 | - cairo_rectangle(cr, rect->x+1, rect->y+1, rect->width-2, rect->height-2); | |
| 330 | 410 | } |
| 331 | 411 | } |
| 332 | 412 | else if(chr) | ... | ... |