diff --git a/include/unix/guts.h b/include/unix/guts.h index 728c9ab8..50032c1f 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 ee5794c6..76fbd525 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 7065faa9..58fe6c99 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 bba692a0..c3c3205d 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