Skip to content

Commit

Permalink
fix text rendering of overstrike,understrike, and background on x11
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Dec 11, 2023
1 parent 10d40d6 commit 4e4208f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 8 additions & 4 deletions unix/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ gp_text_out_rotated(

if ( PDrawable( self)-> font. style & (fsUnderlined|fsStruckOut)) {
int lw = 1;
int tw = gp_get_text_width( self, text, len, flags | toAddOverhangs) - 1;
int tw = gp_get_text_width( self, text, len, flags);
int d = PDrawable(self)-> font.underlinePosition;
int t = PDrawable(self)-> font.underlineThickness;
Point ovx = gp_get_text_overhangs( self, text, len, flags);
Expand All @@ -266,7 +266,8 @@ gp_text_out_rotated(
if ( lw != t) {
XGCValues gcv;
lw = gcv.line_width = t;
XChangeGC( DISP, XX-> gc, GCLineWidth, &gcv);
gcv.cap_style = CapNotLast;
XChangeGC( DISP, XX-> gc, GCLineWidth | GCCapStyle, &gcv);
}

if ( PDrawable( self)-> font. style & fsUnderlined) {
Expand All @@ -278,6 +279,7 @@ gp_text_out_rotated(
tw += ovx.y;
rx. l = tw * r-> matrix[0]. l + ay * r-> matrix[2]. l + 0.5;
ry. l = tw * r-> matrix[1]. l + ay * r-> matrix[3]. l + 0.5;
tw -= ovx.y;
x2 = x + rx. i. i;
y2 = y + ry. i. i;
XDrawLine( DISP, XX-> gdrawable, XX-> gc, x1, REVERT( y1), x2, REVERT( y2));
Expand All @@ -293,6 +295,7 @@ gp_text_out_rotated(
tw += ovx.y;
rx. l = tw * r-> matrix[0]. l + ay * r-> matrix[2]. l + 0.5;
ry. l = tw * r-> matrix[1]. l + ay * r-> matrix[3]. l + 0.5;
tw -= ovx.y;
x2 = x + rx. i. i;
y2 = y + ry. i. i;
XDrawLine( DISP, XX-> gdrawable, XX-> gc, x1, REVERT( y1), x2, REVERT( y2));
Expand Down Expand Up @@ -350,14 +353,15 @@ draw_text_underline(Handle self, const char * text, int x, int y, int len, int f
{
DEFXX;
int lw = 1;
int tw = gp_get_text_width( self, text, len, flags | toAddOverhangs);
int tw = gp_get_text_width( self, text, len, flags);
int d = PDrawable(self)-> font.underlinePosition;
int t = PDrawable(self)-> font.underlineThickness;
Point ovx = gp_get_text_overhangs( self, text, len, flags);
if ( lw != t ) {
XGCValues gcv;
lw = gcv.line_width = t;
XChangeGC( DISP, XX-> gc, GCLineWidth, &gcv);
gcv.cap_style = CapNotLast;
XChangeGC( DISP, XX-> gc, GCLineWidth | GCCapStyle, &gcv);
}
if ( !XX-> flags. base_line)
y += XX-> font-> font. descent;
Expand Down
15 changes: 7 additions & 8 deletions unix/xft.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ prima_xft_get_text_box( Handle self, const char * text, int len, int flags)
{
DEFXX;
Point ovx;
return prima_get_text_box(self, &ovx,
return prima_get_text_box(self, &ovx,
prima_xft_get_text_width( XX-> font, text, len, flags, XX-> fc_map8, &ovx)
);
}
Expand Down Expand Up @@ -895,12 +895,13 @@ overstrike( Handle self, int x, int y, Point *ovx, int advance)
if ( lw != t ) {
XGCValues gcv;
lw = gcv.line_width = t;
XChangeGC( DISP, XX-> gc, GCLineWidth, &gcv);
gcv.cap_style = CapNotLast;
XChangeGC( DISP, XX-> gc, GCLineWidth | GCCapStyle, &gcv);
}

if ( PDrawable( self)-> font. style & fsUnderlined) {
x1 = ovx->x;
x2 = advance;
x2 = advance + 1;
y2 = d;
y1 = -y2;
prima_matrix_apply_int_to_int( XX->fc_font_matrix, &x1, &y1);
Expand All @@ -914,7 +915,7 @@ overstrike( Handle self, int x, int y, Point *ovx, int advance)

if ( PDrawable( self)-> font. style & fsStruckOut) {
x1 = ovx->x;
x2 = advance;
x2 = advance + 1;
y2 = (XX-> font-> font.ascent - XX-> font-> font.internalLeading)/3;
y1 = -y2;
prima_matrix_apply_int_to_int( XX->fc_font_matrix, &x1, &y1);
Expand Down Expand Up @@ -1108,10 +1109,8 @@ prima_xft_text_out( Handle self, const char * text, int x, int y, int len, int f

if ( PDrawable( self)-> font. style & (fsUnderlined|fsStruckOut)) {
Point ovx;
overstrike(self, x, y, &ovx, prima_xft_get_text_width(
XX-> font, text, len, flags | toAddOverhangs,
X(self)-> fc_map8, &ovx) - 1
);
int l = prima_xft_get_text_width( XX-> font, text, len, flags | toAddOverhangs, X(self)-> fc_map8, &ovx);
overstrike(self, x, y, &ovx, l - ovx.x - ovx.y - 1);
}
XFLUSH;

Expand Down

0 comments on commit 4e4208f

Please sign in to comment.