diff options
| author | Stephen Pegoraro | 2017-08-18 11:02:40 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-08-18 11:02:40 +0300 |
| commit | efb508bbb42a214966483c911f2cfc5a4eba73f5 (patch) | |
| tree | 615ec37fd2efa98741d47215406def2d4406e538 /src | |
| parent | 65d3c27fe13565bfacd4e5138cd217d6084c6ee9 (diff) | |
| download | emacs-efb508bbb42a214966483c911f2cfc5a4eba73f5.tar.gz emacs-efb508bbb42a214966483c911f2cfc5a4eba73f5.zip | |
Support HiDPI displays for wave style underlines
* src/xterm.c (x_draw_underwave): Compute height, length and thickness
based on scale factor.
(x_get_scale_factor): New function.
Copyright-paperwork-exempt: yes
Diffstat (limited to 'src')
| -rw-r--r-- | src/xterm.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/xterm.c b/src/xterm.c index a214cd81031..5c1b061566f 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -23,9 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 23 | #include <config.h> | 23 | #include <config.h> |
| 24 | #include <stdio.h> | 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
| 26 | #ifdef USE_CAIRO | ||
| 27 | #include <math.h> | 26 | #include <math.h> |
| 28 | #endif | ||
| 29 | 27 | ||
| 30 | #include "lisp.h" | 28 | #include "lisp.h" |
| 31 | #include "blockinput.h" | 29 | #include "blockinput.h" |
| @@ -3475,6 +3473,21 @@ x_draw_stretch_glyph_string (struct glyph_string *s) | |||
| 3475 | s->background_filled_p = true; | 3473 | s->background_filled_p = true; |
| 3476 | } | 3474 | } |
| 3477 | 3475 | ||
| 3476 | static void | ||
| 3477 | x_get_scale_factor(Display *disp, int *scale_x, int *scale_y) | ||
| 3478 | { | ||
| 3479 | const int base_res = 96; | ||
| 3480 | struct x_display_info * dpyinfo = x_display_info_for_display (disp); | ||
| 3481 | |||
| 3482 | *scale_x = *scale_y = 1; | ||
| 3483 | |||
| 3484 | if (dpyinfo) | ||
| 3485 | { | ||
| 3486 | *scale_x = floor (dpyinfo->resx / base_res); | ||
| 3487 | *scale_y = floor (dpyinfo->resy / base_res); | ||
| 3488 | } | ||
| 3489 | } | ||
| 3490 | |||
| 3478 | /* | 3491 | /* |
| 3479 | Draw a wavy line under S. The wave fills wave_height pixels from y0. | 3492 | Draw a wavy line under S. The wave fills wave_height pixels from y0. |
| 3480 | 3493 | ||
| @@ -3485,11 +3498,16 @@ x_draw_stretch_glyph_string (struct glyph_string *s) | |||
| 3485 | wave_height = 3 | * * * * | 3498 | wave_height = 3 | * * * * |
| 3486 | 3499 | ||
| 3487 | */ | 3500 | */ |
| 3488 | |||
| 3489 | static void | 3501 | static void |
| 3490 | x_draw_underwave (struct glyph_string *s) | 3502 | x_draw_underwave (struct glyph_string *s) |
| 3491 | { | 3503 | { |
| 3492 | int wave_height = 3, wave_length = 2; | 3504 | /* Adjust for scale/HiDPI. */ |
| 3505 | int scale_x, scale_y; | ||
| 3506 | |||
| 3507 | x_get_scale_factor (s->display, &scale_x, &scale_y); | ||
| 3508 | |||
| 3509 | int wave_height = 3 * scale_y, wave_length = 2 * scale_x, thickness = scale_y; | ||
| 3510 | |||
| 3493 | #ifdef USE_CAIRO | 3511 | #ifdef USE_CAIRO |
| 3494 | x_draw_horizontal_wave (s->f, s->gc, s->x, s->ybase - wave_height + 3, | 3512 | x_draw_horizontal_wave (s->f, s->gc, s->x, s->ybase - wave_height + 3, |
| 3495 | s->width, wave_height, wave_length); | 3513 | s->width, wave_height, wave_length); |
| @@ -3501,7 +3519,7 @@ x_draw_underwave (struct glyph_string *s) | |||
| 3501 | dx = wave_length; | 3519 | dx = wave_length; |
| 3502 | dy = wave_height - 1; | 3520 | dy = wave_height - 1; |
| 3503 | x0 = s->x; | 3521 | x0 = s->x; |
| 3504 | y0 = s->ybase - wave_height + 3; | 3522 | y0 = s->ybase + wave_height / 2; |
| 3505 | width = s->width; | 3523 | width = s->width; |
| 3506 | xmax = x0 + width; | 3524 | xmax = x0 + width; |
| 3507 | 3525 | ||
| @@ -3535,6 +3553,8 @@ x_draw_underwave (struct glyph_string *s) | |||
| 3535 | 3553 | ||
| 3536 | while (x1 <= xmax) | 3554 | while (x1 <= xmax) |
| 3537 | { | 3555 | { |
| 3556 | XSetLineAttributes (s->display, s->gc, thickness, LineSolid, CapButt, | ||
| 3557 | JoinRound); | ||
| 3538 | XDrawLine (s->display, FRAME_X_DRAWABLE (s->f), s->gc, x1, y1, x2, y2); | 3558 | XDrawLine (s->display, FRAME_X_DRAWABLE (s->f), s->gc, x1, y1, x2, y2); |
| 3539 | x1 = x2, y1 = y2; | 3559 | x1 = x2, y1 = y2; |
| 3540 | x2 += dx, y2 = y0 + odd*dy; | 3560 | x2 += dx, y2 = y0 + odd*dy; |