Adjust font hights so underscores are not cut off

This commit is contained in:
Ray Chason
2026-08-19 09:37:41 +03:00
committed by Pasi Kallinen
parent b8dc070d07
commit 6dc9ac1c31
6 changed files with 15 additions and 16 deletions
+4
View File
@@ -11,6 +11,9 @@
#ifdef USE_XFT #ifdef USE_XFT
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
typedef XftFont X11_Font;
#else
typedef XFontStruct X11_Font;
#endif #endif
#ifndef COLOR_H #ifndef COLOR_H
@@ -529,6 +532,7 @@ extern void X11_set_attrs(Widget, unsigned);
extern void X11_set_highlight(Widget, boolean); extern void X11_set_highlight(Widget, boolean);
extern void X11_set_percent(Widget, unsigned, Pixel); extern void X11_set_percent(Widget, unsigned, Pixel);
extern void X11_blink_labels(void); extern void X11_blink_labels(void);
extern int X11_font_height(X11_Font *);
/* /*
* These are for widgets that use the enhanced label services only for text * These are for widgets that use the enhanced label services only for text
+1 -1
View File
@@ -794,7 +794,7 @@ nhFontHeight(Widget w, int win_type)
#ifdef USE_XFT #ifdef USE_XFT
XftFont *font = X11_new_font(w, 0, win_type); XftFont *font = X11_new_font(w, 0, win_type);
Dimension height = font->height; Dimension height = X11_font_height(font);
X11_release_font(w, font); X11_release_font(w, font);
return height; return height;
+4 -10
View File
@@ -19,13 +19,7 @@
#include "winX.h" #include "winX.h"
/* Declarations depending on Xft support or none */ /* Declarations depending on Xft support or none */
#ifdef USE_XFT
typedef XftFont X11_Font;
#else
typedef XFontStruct X11_Font;
#endif
static int X11_text_width(Display *, X11_Font *, const char *, size_t); static int X11_text_width(Display *, X11_Font *, const char *, size_t);
static int X11_font_height(X11_Font *);
/* Data attached to a wrapped widget */ /* Data attached to a wrapped widget */
typedef struct WidgetData { typedef struct WidgetData {
@@ -383,7 +377,7 @@ update_label(Widget w, WidgetData *data)
/* Render the line */ /* Render the line */
#ifdef USE_XFT #ifdef USE_XFT
XftDrawRect(draw, &bgcolor, x, y - font->ascent, lwidth, font->height); XftDrawRect(draw, &bgcolor, x, y - font->ascent, lwidth, X11_font_height(font));
XftDrawString8(draw, &fgcolor, font, x, y, XftDrawString8(draw, &fgcolor, font, x, y,
(const FcChar8 *) (label + i), line2); (const FcChar8 *) (label + i), line2);
#else #else
@@ -507,10 +501,10 @@ X11_text_width(Display *display, X11_Font *font, const char *text, size_t length
return extents.width - extents.x; return extents.width - extents.x;
} }
static int int
X11_font_height(X11_Font *font) X11_font_height(X11_Font *font)
{ {
return font->height; return max(font->height, font->ascent + font->descent);
} }
#else /* !USE_XFT */ #else /* !USE_XFT */
static int static int
@@ -520,7 +514,7 @@ X11_text_width(Display *display, X11_Font *font, const char *text, size_t length
return XTextWidth(font, text, length); return XTextWidth(font, text, length);
} }
static int int
X11_font_height(X11_Font *font) X11_font_height(X11_Font *font)
{ {
return font->ascent + font->descent; return font->ascent + font->descent;
+2 -2
View File
@@ -1048,7 +1048,7 @@ get_char_info(struct xwindow *wp)
struct text_map_info_t *text_map = &map_info->text_map; struct text_map_info_t *text_map = &map_info->text_map;
XftFont *font = X11_new_font(wp->w, 0, NHW_MAP); XftFont *font = X11_new_font(wp->w, 0, NHW_MAP);
text_map->square_width = font->max_advance_width; text_map->square_width = font->max_advance_width;
text_map->square_height = font->height; text_map->square_height = X11_font_height(font);
text_map->square_ascent = 0; text_map->square_ascent = 0;
text_map->square_lbearing = 0; text_map->square_lbearing = 0;
X11_release_font(wp->w, font); X11_release_font(wp->w, font);
@@ -1546,7 +1546,7 @@ X11_draw_image_string(
{ {
XftDrawRect(draw, bgcolor, x, y, XftDrawRect(draw, bgcolor, x, y,
length * font->max_advance_width, length * font->max_advance_width,
font->height); X11_font_height(font));
int xt = x; int xt = x;
int yt = y + font->ascent; int yt = y + font->ascent;
+1 -1
View File
@@ -158,7 +158,7 @@ create_message_window(struct xwindow *wp, /* window pointer */
XftFont *font = X11_new_font(wp->w, 0, NHW_MESSAGE); XftFont *font = X11_new_font(wp->w, 0, NHW_MESSAGE);
XGlyphInfo extents; XGlyphInfo extents;
mesg_info->char_width = font->max_advance_width; mesg_info->char_width = font->max_advance_width;
mesg_info->char_height = font->height; mesg_info->char_height = X11_font_height(font);
mesg_info->char_ascent = font->ascent; mesg_info->char_ascent = font->ascent;
mesg_info->char_lbearing = 0; mesg_info->char_lbearing = 0;
/* Xft seems to offer no direct way to distinguish proportional from /* Xft seems to offer no direct way to distinguish proportional from
+3 -2
View File
@@ -785,6 +785,7 @@ tty_render_text(Widget w, const XRectangle *clip, int x, int y,
/* Get the font */ /* Get the font */
XftFont *font = X11_new_font(w, attr, NHW_STATUS); XftFont *font = X11_new_font(w, attr, NHW_STATUS);
int height = X11_font_height(font);
/* Get the drawing resources */ /* Get the drawing resources */
Display *display = XtDisplay(w); Display *display = XtDisplay(w);
@@ -827,7 +828,7 @@ tty_render_text(Widget w, const XRectangle *clip, int x, int y,
goldwidth = extents.width - extents.x; goldwidth = extents.width - extents.x;
/* Render the gold symbol */ /* Render the gold symbol */
XftDrawRect(draw, &bgcolor, x, y, goldwidth, font->height); XftDrawRect(draw, &bgcolor, x, y, goldwidth, height);
#ifdef ENHANCED_SYMBOLS #ifdef ENHANCED_SYMBOLS
XftDrawString32(draw, &fgcolor, font, x, y + font->ascent, &goldch, 1); XftDrawString32(draw, &fgcolor, font, x, y + font->ascent, &goldch, 1);
#else /* !ENHANCED_SYMBOLS */ #else /* !ENHANCED_SYMBOLS */
@@ -857,7 +858,7 @@ tty_render_text(Widget w, const XRectangle *clip, int x, int y,
} }
/* Render the string */ /* Render the string */
XftDrawRect(draw, &bgcolor, x + goldwidth, y, width, font->height); XftDrawRect(draw, &bgcolor, x + goldwidth, y, width, height);
XftDrawString8(draw, &fgcolor, font, XftDrawString8(draw, &fgcolor, font,
x + goldwidth, y + font->ascent, x + goldwidth, y + font->ascent,
(const FcChar8 *) text, strlen(text)); (const FcChar8 *) text, strlen(text));