More ifdefs; use Xft font to split messages
This commit is contained in:
committed by
Pasi Kallinen
parent
cada45a786
commit
3f8e704231
+50
-18
@@ -37,7 +37,7 @@
|
||||
|
||||
static struct line_element *get_previous(struct line_element *);
|
||||
static void set_circle_buf(struct mesg_info_t *, int);
|
||||
static char *split(char *, XFontStruct *, Dimension);
|
||||
static char *split(char *, struct xwindow *, Dimension);
|
||||
static void add_line(struct mesg_info_t *, const char *);
|
||||
static void redraw_message_window(struct xwindow *);
|
||||
static void mesg_check_size_change(struct xwindow *);
|
||||
@@ -83,7 +83,9 @@ create_message_window(struct xwindow *wp, /* window pointer */
|
||||
wp->mesg_information = mesg_info =
|
||||
(struct mesg_info_t *) alloc(sizeof (struct mesg_info_t));
|
||||
|
||||
#ifndef USE_XFT
|
||||
mesg_info->fs = 0;
|
||||
#endif
|
||||
mesg_info->num_lines = 0;
|
||||
mesg_info->head = mesg_info->line_here = mesg_info->last_pause =
|
||||
mesg_info->last_pause_head = (struct line_element *) 0;
|
||||
@@ -151,26 +153,37 @@ create_message_window(struct xwindow *wp, /* window pointer */
|
||||
* is appResources.message_lines high and DEFAULT_MESSAGE_WIDTH wide.
|
||||
*/
|
||||
|
||||
/* Save character information for fast use later. */
|
||||
#ifdef USE_XFT
|
||||
XftFont *font = X11_new_font(wp->w, 0, NHW_MESSAGE);
|
||||
XGlyphInfo extents;
|
||||
mesg_info->char_width = font->max_advance_width;
|
||||
mesg_info->char_height = font->height;
|
||||
mesg_info->char_ascent = font->ascent;
|
||||
mesg_info->char_lbearing = 0;
|
||||
/* Xft seems to offer no direct way to distinguish proportional from
|
||||
monospaced fonts. Assume that "!" will be narrower than maximum. */
|
||||
XftTextExtents8(XtDisplay(wp->w), font, (const FcChar8*) "!", 1, &extents);
|
||||
int min_width = extents.width - extents.x;
|
||||
/* "Maximum" is likely to include things like Chinese characters that
|
||||
* display at double width. Use the width of "M". */
|
||||
XftTextExtents8(XtDisplay(wp->w), font, (const FcChar8*) "M", 1, &extents);
|
||||
int max_width = extents.width - extents.x;
|
||||
X11_release_font(wp->w, font);
|
||||
#else
|
||||
/* Get the font information. */
|
||||
num_args = 0;
|
||||
XtSetArg(args[num_args], XtNfont, &mesg_info->fs);
|
||||
num_args++;
|
||||
XtGetValues(wp->w, args, num_args);
|
||||
|
||||
/* Save character information for fast use later. */
|
||||
#ifdef USE_XFT
|
||||
XftFont *font = X11_new_font(wp->w, 0, NHW_MESSAGE);
|
||||
mesg_info->char_width = font->max_advance_width;
|
||||
mesg_info->char_height = font->height;
|
||||
mesg_info->char_ascent = font->ascent;
|
||||
mesg_info->char_lbearing = 0;
|
||||
X11_release_font(wp->w, font);
|
||||
#else
|
||||
mesg_info->char_width = mesg_info->fs->max_bounds.width;
|
||||
mesg_info->char_height =
|
||||
mesg_info->fs->max_bounds.ascent + mesg_info->fs->max_bounds.descent;
|
||||
mesg_info->char_ascent = mesg_info->fs->max_bounds.ascent;
|
||||
mesg_info->char_lbearing = -mesg_info->fs->min_bounds.lbearing;
|
||||
int min_width = mesg_info->fs->min_bounds.width;
|
||||
int max_width = mesg_info->fs->max_bounds.width;
|
||||
#endif
|
||||
|
||||
get_gc(wp->w, mesg_info);
|
||||
@@ -178,12 +191,11 @@ create_message_window(struct xwindow *wp, /* window pointer */
|
||||
wp->pixel_height = ((int) iflags.msg_history) * mesg_info->char_height;
|
||||
|
||||
/* If a variable spaced font, only use 2/3 of the default size */
|
||||
if (mesg_info->fs->min_bounds.width != mesg_info->fs->max_bounds.width) {
|
||||
if (min_width != max_width) {
|
||||
wp->pixel_width = ((2 * DEFAULT_MESSAGE_WIDTH) / 3)
|
||||
* mesg_info->fs->max_bounds.width;
|
||||
* max_width;
|
||||
} else
|
||||
wp->pixel_width =
|
||||
(DEFAULT_MESSAGE_WIDTH * mesg_info->fs->max_bounds.width);
|
||||
wp->pixel_width = (DEFAULT_MESSAGE_WIDTH * max_width);
|
||||
|
||||
/* Set the new width and height. */
|
||||
num_args = 0;
|
||||
@@ -259,7 +271,7 @@ append_message(struct xwindow *wp, const char *str)
|
||||
remainder = buf;
|
||||
do {
|
||||
mark = remainder;
|
||||
remainder = split(mark, wp->mesg_information->fs, wp->pixel_width);
|
||||
remainder = split(mark, wp, wp->pixel_width);
|
||||
add_line(wp->mesg_information, mark);
|
||||
} while (remainder);
|
||||
}
|
||||
@@ -366,10 +378,16 @@ set_circle_buf(struct mesg_info_t *mesg_info, int count)
|
||||
* not, back up from the end by words until we find a place to split.
|
||||
*/
|
||||
static char *
|
||||
split(char *s,
|
||||
XFontStruct *fs, /* Font for the window. */
|
||||
split(
|
||||
char *s,
|
||||
struct xwindow *wp,
|
||||
Dimension pixel_width)
|
||||
{
|
||||
#ifdef USE_XFT
|
||||
XftFont *font = X11_new_font(wp->w, 0, NHW_MESSAGE);
|
||||
#else
|
||||
XFontStruct *fs = wp->mesg_information->fs; /* Font for the window. */
|
||||
#endif
|
||||
char save, *end, *remainder;
|
||||
|
||||
save = '\0';
|
||||
@@ -377,7 +395,18 @@ split(char *s,
|
||||
end = eos(s); /* point to null at end of string */
|
||||
|
||||
/* assume that if end == s, XXXXXX returns 0) */
|
||||
while ((Dimension) XTextWidth(fs, s, (int) strlen(s)) > pixel_width) {
|
||||
while (TRUE) {
|
||||
#ifdef USE_XFT
|
||||
XGlyphInfo extents;
|
||||
XftTextExtents8(XtDisplay(wp->w), font, (const FcChar8*) s, strlen(s), &extents);
|
||||
if (extents.width - extents.x < pixel_width) {
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if ((Dimension) XTextWidth(fs, s, (int) strlen(s)) < pixel_width) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
*end-- = save;
|
||||
while (*end != ' ') {
|
||||
if (end == s)
|
||||
@@ -388,6 +417,9 @@ split(char *s,
|
||||
*end = '\0';
|
||||
remainder = end + 1;
|
||||
}
|
||||
#ifdef USE_XFT
|
||||
X11_release_font(wp->w, font);
|
||||
#endif
|
||||
return remainder;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user