diff options
| author | Eli Zaretskii | 2021-12-02 19:44:46 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2021-12-02 19:44:46 +0200 |
| commit | 608267c71e11da9c757c269a5e22e62ef04d0bfe (patch) | |
| tree | 49f0e60b2a4b7b175252ef31ceb1842005002812 /src | |
| parent | a8bfdf2efc41479efecee4dff71fe8a341cb5729 (diff) | |
| download | emacs-608267c71e11da9c757c269a5e22e62ef04d0bfe.tar.gz emacs-608267c71e11da9c757c269a5e22e62ef04d0bfe.zip | |
Support display of non-ASCII characters with aligned columns
* src/xdisp.c (get_normal_width): New function.
(gui_produce_glyphs): Use 'get_normal_width' to widen on display
characters whose width is not an integral multiple of the
"standard" width.
(syms_of_xdisp) <align-columns-display>: New boolean variable.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index 9f93799783d..fdcf6a611e6 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -28812,6 +28812,21 @@ normal_char_height (struct font *font, int c) | |||
| 28812 | return ascent + descent; | 28812 | return ascent + descent; |
| 28813 | } | 28813 | } |
| 28814 | 28814 | ||
| 28815 | /* Return the "standard" pixel width of a character from FACE's font, | ||
| 28816 | if the font is fixed-pitch, zero otherwise. */ | ||
| 28817 | static int | ||
| 28818 | get_normal_width (struct face *face) | ||
| 28819 | { | ||
| 28820 | struct font *ascii_font = face->ascii_face->font; | ||
| 28821 | /* Heuristics: fixed-pitch fonts have the value of MAX-WIDTH not | ||
| 28822 | much larger than AVERAGE-WIDTH. */ | ||
| 28823 | bool fixed_pitch = | ||
| 28824 | ascii_font->average_width == ascii_font->space_width | ||
| 28825 | && ascii_font->average_width != 0 | ||
| 28826 | && ascii_font->max_width < 3 * ascii_font->average_width; | ||
| 28827 | return fixed_pitch ? ascii_font->space_width : 0; | ||
| 28828 | } | ||
| 28829 | |||
| 28815 | /* EXPORT for RIF: | 28830 | /* EXPORT for RIF: |
| 28816 | Set *LEFT and *RIGHT to the left and right overhang of GLYPH on | 28831 | Set *LEFT and *RIGHT to the left and right overhang of GLYPH on |
| 28817 | frame F. Overhangs of glyphs other than type CHAR_GLYPH are | 28832 | frame F. Overhangs of glyphs other than type CHAR_GLYPH are |
| @@ -30909,6 +30924,17 @@ gui_produce_glyphs (struct it *it) | |||
| 30909 | it->phys_ascent = pcm->ascent + boff; | 30924 | it->phys_ascent = pcm->ascent + boff; |
| 30910 | it->phys_descent = pcm->descent - boff; | 30925 | it->phys_descent = pcm->descent - boff; |
| 30911 | it->pixel_width = pcm->width; | 30926 | it->pixel_width = pcm->width; |
| 30927 | if (align_columns_display) | ||
| 30928 | { | ||
| 30929 | int unit_width = get_normal_width (face); | ||
| 30930 | if (unit_width > 0) | ||
| 30931 | { | ||
| 30932 | int ncolumns = | ||
| 30933 | (it->pixel_width - 1 + unit_width) / unit_width; | ||
| 30934 | |||
| 30935 | it->pixel_width = ncolumns * unit_width; | ||
| 30936 | } | ||
| 30937 | } | ||
| 30912 | /* Don't use font-global values for ascent and descent | 30938 | /* Don't use font-global values for ascent and descent |
| 30913 | if they result in an exceedingly large line height. */ | 30939 | if they result in an exceedingly large line height. */ |
| 30914 | if (it->override_ascent < 0) | 30940 | if (it->override_ascent < 0) |
| @@ -31486,6 +31512,17 @@ gui_produce_glyphs (struct it *it) | |||
| 31486 | it->glyph_row->contains_overlapping_glyphs_p = true; | 31512 | it->glyph_row->contains_overlapping_glyphs_p = true; |
| 31487 | 31513 | ||
| 31488 | it->pixel_width = cmp->pixel_width; | 31514 | it->pixel_width = cmp->pixel_width; |
| 31515 | if (align_columns_display) | ||
| 31516 | { | ||
| 31517 | int unit_width = get_normal_width (face); | ||
| 31518 | if (unit_width > 0) | ||
| 31519 | { | ||
| 31520 | int ncolumns = | ||
| 31521 | (it->pixel_width - 1 + unit_width) / unit_width; | ||
| 31522 | |||
| 31523 | it->pixel_width = ncolumns * unit_width; | ||
| 31524 | } | ||
| 31525 | } | ||
| 31489 | it->ascent = it->phys_ascent = cmp->ascent; | 31526 | it->ascent = it->phys_ascent = cmp->ascent; |
| 31490 | it->descent = it->phys_descent = cmp->descent; | 31527 | it->descent = it->phys_descent = cmp->descent; |
| 31491 | IT_APPLY_FACE_BOX(it, face); | 31528 | IT_APPLY_FACE_BOX(it, face); |
| @@ -31531,6 +31568,17 @@ gui_produce_glyphs (struct it *it) | |||
| 31531 | it->glyph_row->contains_overlapping_glyphs_p = true; | 31568 | it->glyph_row->contains_overlapping_glyphs_p = true; |
| 31532 | it->ascent = it->phys_ascent = metrics.ascent; | 31569 | it->ascent = it->phys_ascent = metrics.ascent; |
| 31533 | it->descent = it->phys_descent = metrics.descent; | 31570 | it->descent = it->phys_descent = metrics.descent; |
| 31571 | if (align_columns_display) | ||
| 31572 | { | ||
| 31573 | int unit_width = get_normal_width (face); | ||
| 31574 | if (unit_width > 0) | ||
| 31575 | { | ||
| 31576 | int ncolumns = | ||
| 31577 | (it->pixel_width - 1 + unit_width) / unit_width; | ||
| 31578 | |||
| 31579 | it->pixel_width = ncolumns * unit_width; | ||
| 31580 | } | ||
| 31581 | } | ||
| 31534 | } | 31582 | } |
| 31535 | IT_APPLY_FACE_BOX(it, face); | 31583 | IT_APPLY_FACE_BOX(it, face); |
| 31536 | 31584 | ||
| @@ -35607,6 +35655,14 @@ variable are ignored and the default 0.25 is used instead. */); | |||
| 35607 | Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */); | 35655 | Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */); |
| 35608 | Vdisplay_pixels_per_inch = make_float (72.0); | 35656 | Vdisplay_pixels_per_inch = make_float (72.0); |
| 35609 | 35657 | ||
| 35658 | DEFVAR_BOOL ("align-columns-display", align_columns_display, | ||
| 35659 | doc: /* Whether to align columns on GUI frames. | ||
| 35660 | If this is non-nil characters displayed on GUI frames will be | ||
| 35661 | aligned to produce straight columns. This is achieved by | ||
| 35662 | enlarging the pixel width of characters to an integral | ||
| 35663 | multiple of pixels taken by ASCII characters of the same face. */); | ||
| 35664 | align_columns_display = false; | ||
| 35665 | |||
| 35610 | #ifdef GLYPH_DEBUG | 35666 | #ifdef GLYPH_DEBUG |
| 35611 | DEFVAR_INT ("debug-end-pos", debug_end_pos, doc: /* Don't ask. */); | 35667 | DEFVAR_INT ("debug-end-pos", debug_end_pos, doc: /* Don't ask. */); |
| 35612 | #endif | 35668 | #endif |