From d44efc5047498f25c544b5e01bcacb7253ac260e Mon Sep 17 00:00:00 2001 From: Dmitry Karasik Date: Sat, 7 Dec 2024 15:50:10 +0100 Subject: [PATCH] calculate eventual accel text overhangs for core fonts --- include/unix/guts.h | 3 +++ unix/corefont.c | 16 ++++++++++++++++ unix/menu.c | 8 ++++++++ unix/text.c | 12 +----------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/include/unix/guts.h b/include/unix/guts.h index 728c9ab80..50032c1ff 100644 --- a/include/unix/guts.h +++ b/include/unix/guts.h @@ -1280,6 +1280,9 @@ prima_corefont_pp2font( char * ppFontNameSize, PFont font); extern PCachedFont prima_corefont_match(PFont match, Bool by_size, PCachedFont kf); +extern Point +prima_corefont_get_text_overhangs( XFontStruct *fs, const char *text, int len, int flags); + extern Bool prima_corefont_encoding( char * encoding); diff --git a/unix/corefont.c b/unix/corefont.c index ee5794c6a..76fbd525a 100644 --- a/unix/corefont.c +++ b/unix/corefont.c @@ -1692,6 +1692,22 @@ prima_char_struct( XFontStruct * xs, void * c, Bool wide) return cs; } +Point +prima_corefont_get_text_overhangs( XFontStruct *fs, const char *text, int len, int flags) +{ + Point ret; + if ( len > 0) { + XCharStruct * cs; + cs = prima_char_struct( fs, (void*) text, flags & (toUTF8 | toGlyphs)); + ret. x = ( cs-> lbearing < 0) ? - cs-> lbearing : 0; + text += (len - 1) * ((flags & (toUTF8 | toGlyphs)) ? 2 : 1); + cs = prima_char_struct( fs, (void*) text, flags & (toUTF8 | toGlyphs)); + ret. y = (( cs-> width - cs-> rbearing) < 0) ? cs-> rbearing - cs-> width : 0; + } else + ret. x = ret. y = 0; + return ret; +} + Byte* prima_corefont_get_glyph_bitmap( Handle self, uint16_t index, Bool mono, PPoint offset, PPoint size, int *advance) { diff --git a/unix/menu.c b/unix/menu.c index 7065faa9b..58fe6c994 100644 --- a/unix/menu.c +++ b/unix/menu.c @@ -190,10 +190,18 @@ get_text_width( PCachedFont font, const char * text, int byte_length, Bool utf8, XChar2b * xc = prima_alloc_utf8_to_wchar( text, char_len); if ( xc) { ret = XTextWidth16( font-> fs, xc, char_len); + if ( for_right_align ) { + Point ovx = prima_corefont_get_text_overhangs( font->fs, text, char_len, toUTF8); + ret += ovx.y; + } free( xc); } } else { ret = XTextWidth( font-> fs, text, byte_length); + if ( for_right_align ) { + Point ovx = prima_corefont_get_text_overhangs( font->fs, text, char_len, 0); + ret += ovx.y; + } } return ret; } diff --git a/unix/text.c b/unix/text.c index bba692a01..c3c3205d4 100644 --- a/unix/text.c +++ b/unix/text.c @@ -88,17 +88,7 @@ static Point gp_get_text_overhangs( Handle self, const char *text, int len, int flags) { DEFXX; - Point ret; - if ( len > 0) { - XCharStruct * cs; - cs = prima_char_struct( XX-> font-> fs, (void*) text, flags & (toUTF8 | toGlyphs)); - ret. x = ( cs-> lbearing < 0) ? - cs-> lbearing : 0; - text += (len - 1) * ((flags & (toUTF8 | toGlyphs)) ? 2 : 1); - cs = prima_char_struct( XX-> font-> fs, (void*) text, flags & (toUTF8 | toGlyphs)); - ret. y = (( cs-> width - cs-> rbearing) < 0) ? cs-> rbearing - cs-> width : 0; - } else - ret. x = ret. y = 0; - return ret; + return prima_corefont_get_text_overhangs( XX->font->fs, text, len, flags); } static int