comparison src/gui.c @ 4053:29f29e86602e v7.3.781

updated for version 7.3.781 Problem: Drawing with 'guifontwide' can be slow. Solution: Draw multiple characters at a time. (Taro Muraoka)
author Bram Moolenaar <bram@vim.org>
date Wed, 23 Jan 2013 17:43:57 +0100
parents 6a76846b84eb
children 0de969850c06
comparison
equal deleted inserted replaced
4052:7457c0105747 4053:29f29e86602e
2378 int i; /* index of current char */ 2378 int i; /* index of current char */
2379 int c; /* current char value */ 2379 int c; /* current char value */
2380 int cl; /* byte length of current char */ 2380 int cl; /* byte length of current char */
2381 int comping; /* current char is composing */ 2381 int comping; /* current char is composing */
2382 int scol = col; /* screen column */ 2382 int scol = col; /* screen column */
2383 int dowide; /* use 'guifontwide' */ 2383 int curr_wide; /* use 'guifontwide' */
2384 int prev_wide = FALSE;
2385 int wide_changed;
2384 2386
2385 /* Break the string at a composing character, it has to be drawn on 2387 /* Break the string at a composing character, it has to be drawn on
2386 * top of the previous character. */ 2388 * top of the previous character. */
2387 start = 0; 2389 start = 0;
2388 cells = 0; 2390 cells = 0;
2393 if (cn > 1 2395 if (cn > 1
2394 # ifdef FEAT_XFONTSET 2396 # ifdef FEAT_XFONTSET
2395 && fontset == NOFONTSET 2397 && fontset == NOFONTSET
2396 # endif 2398 # endif
2397 && gui.wide_font != NOFONT) 2399 && gui.wide_font != NOFONT)
2398 dowide = TRUE; 2400 curr_wide = TRUE;
2399 else 2401 else
2400 dowide = FALSE; 2402 curr_wide = FALSE;
2401 comping = utf_iscomposing(c); 2403 comping = utf_iscomposing(c);
2402 if (!comping) /* count cells from non-composing chars */ 2404 if (!comping) /* count cells from non-composing chars */
2403 cells += cn; 2405 cells += cn;
2404 cl = utf_ptr2len(s + i); 2406 cl = utf_ptr2len(s + i);
2405 if (cl == 0) /* hit end of string */ 2407 if (cl == 0) /* hit end of string */
2406 len = i + cl; /* len must be wrong "cannot happen" */ 2408 len = i + cl; /* len must be wrong "cannot happen" */
2407 2409
2408 /* print the string so far if it's the last character or there is 2410 wide_changed = curr_wide != prev_wide;
2411
2412 /* Print the string so far if it's the last character or there is
2409 * a composing character. */ 2413 * a composing character. */
2410 if (i + cl >= len || (comping && i > start) || dowide 2414 if (i + cl >= len || (comping && i > start) || wide_changed
2411 # if defined(FEAT_GUI_X11) 2415 # if defined(FEAT_GUI_X11)
2412 || (cn > 1 2416 || (cn > 1
2413 # ifdef FEAT_XFONTSET 2417 # ifdef FEAT_XFONTSET
2414 /* No fontset: At least draw char after wide char at 2418 /* No fontset: At least draw char after wide char at
2415 * right position. */ 2419 * right position. */
2417 # endif 2421 # endif
2418 ) 2422 )
2419 # endif 2423 # endif
2420 ) 2424 )
2421 { 2425 {
2422 if (comping || dowide) 2426 if (comping || wide_changed)
2423 thislen = i - start; 2427 thislen = i - start;
2424 else 2428 else
2425 thislen = i - start + cl; 2429 thislen = i - start + cl;
2426 if (thislen > 0) 2430 if (thislen > 0)
2427 { 2431 {
2432 if (prev_wide)
2433 gui_mch_set_font(gui.wide_font);
2428 gui_mch_draw_string(gui.row, scol, s + start, thislen, 2434 gui_mch_draw_string(gui.row, scol, s + start, thislen,
2429 draw_flags); 2435 draw_flags);
2436 if (prev_wide)
2437 gui_mch_set_font(font);
2430 start += thislen; 2438 start += thislen;
2431 } 2439 }
2432 scol += cells; 2440 scol += cells;
2433 cells = 0; 2441 cells = 0;
2434 if (dowide) 2442 /* Adjust to not draw a character which width is changed
2443 * against with last one. */
2444 if (wide_changed && !comping)
2435 { 2445 {
2436 gui_mch_set_font(gui.wide_font); 2446 scol -= cn;
2437 gui_mch_draw_string(gui.row, scol - cn, 2447 cl = 0;
2438 s + start, cl, draw_flags);
2439 gui_mch_set_font(font);
2440 start += cl;
2441 } 2448 }
2442 2449
2443 # if defined(FEAT_GUI_X11) 2450 # if defined(FEAT_GUI_X11)
2444 /* No fontset: draw a space to fill the gap after a wide char 2451 /* No fontset: draw a space to fill the gap after a wide char
2445 * */ 2452 * */
2446 if (cn > 1 && (draw_flags & DRAW_TRANSP) == 0 2453 if (cn > 1 && (draw_flags & DRAW_TRANSP) == 0
2447 # ifdef FEAT_XFONTSET 2454 # ifdef FEAT_XFONTSET
2448 && fontset == NOFONTSET 2455 && fontset == NOFONTSET
2449 # endif 2456 # endif
2450 && !dowide) 2457 && !wide_changed)
2451 gui_mch_draw_string(gui.row, scol - 1, (char_u *)" ", 2458 gui_mch_draw_string(gui.row, scol - 1, (char_u *)" ",
2452 1, draw_flags); 2459 1, draw_flags);
2453 # endif 2460 # endif
2454 } 2461 }
2455 /* Draw a composing char on top of the previous char. */ 2462 /* Draw a composing char on top of the previous char. */
2463 gui_mch_draw_string(gui.row, scol - cn, s + i, cl, 2470 gui_mch_draw_string(gui.row, scol - cn, s + i, cl,
2464 draw_flags | DRAW_TRANSP); 2471 draw_flags | DRAW_TRANSP);
2465 # endif 2472 # endif
2466 start = i + cl; 2473 start = i + cl;
2467 } 2474 }
2475 prev_wide = curr_wide;
2468 } 2476 }
2469 /* The stuff below assumes "len" is the length in screen columns. */ 2477 /* The stuff below assumes "len" is the length in screen columns. */
2470 len = scol - col; 2478 len = scol - col;
2471 } 2479 }
2472 else 2480 else