fix some regressions in text bbox calculation in no cairo mode

This commit is contained in:
stefan schippers 2025-04-16 02:54:56 +02:00
parent 9a937ecd70
commit cf3fa993bd
4 changed files with 9 additions and 9 deletions

View File

@ -3487,7 +3487,7 @@ int text_bbox(const char *str, double xscale, double yscale,
cairo_text_extents_t ext;
cairo_font_extents_t fext;
double ww, hh, maxw;
/* if no cairo_ctx is available use text_bbox_nocairo().
* will not match exactly font metrics when doing ps/svg output, but better than nothing */
if(!has_x && !xctx->cairo_ctx) return text_bbox_nocairo(str, xscale, yscale, rot, flip, hcenter, vcenter, x1, y1,
@ -3584,9 +3584,9 @@ int text_bbox(const char *str,double xscale, double yscale,
if(length > w)
w = length;
}
w *= (FONTWIDTH+FONTWHITESPACE)*xscale* tclgetdoublevar("nocairo_font_xscale");
w *= (FONTWIDTH+FONTWHITESPACE)*xscale* tclgetdoublevar("nocairo_font_xscale") * cairo_font_scale;
*cairo_longest_line = w;
h *= (FONTHEIGHT+FONTDESCENT+FONTWHITESPACE)*yscale* tclgetdoublevar("nocairo_font_yscale");
h *= (FONTHEIGHT+FONTDESCENT+FONTWHITESPACE)*yscale* tclgetdoublevar("nocairo_font_yscale") * cairo_font_scale;
*rx1=x1;*ry1=y1;
if( rot==0) *ry1-=nocairo_vert_correct;
else if(rot==1) *rx1+=nocairo_vert_correct;

View File

@ -352,8 +352,6 @@ void draw_string(int layer, int what, const char *str, short rot, short flip, in
}
else {
char *estr = my_expand(str, tclgetintvar("tabstop"));
xscale*=tclgetdoublevar("nocairo_font_xscale") * cairo_font_scale;
yscale*=tclgetdoublevar("nocairo_font_yscale") * cairo_font_scale;
text_bbox(estr, xscale, yscale, rot, flip, hcenter, vcenter, x1,y1,
&textx1,&texty1,&textx2,&texty2, &no_of_lines, &longest_line);
if(!textclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,
@ -361,6 +359,8 @@ void draw_string(int layer, int what, const char *str, short rot, short flip, in
my_free(_ALLOC_ID_, &estr);
return;
}
xscale*=tclgetdoublevar("nocairo_font_xscale") * cairo_font_scale;
yscale*=tclgetdoublevar("nocairo_font_yscale") * cairo_font_scale;
x1=textx1;y1=texty1;
if(rot&1) {y1=texty2;rot=3;}
else rot=0;

View File

@ -808,8 +808,6 @@ static void old_ps_draw_string(int gctext, const char *str,
if(str==NULL) return;
estr = my_expand(str, tclgetintvar("tabstop"));
xscale*=tclgetdoublevar("nocairo_font_xscale") * cairo_font_scale;
yscale*=tclgetdoublevar("nocairo_font_yscale") * cairo_font_scale;
#if HAS_CAIRO==1
text_bbox_nocairo(estr, xscale, yscale, rot, flip, hcenter, vcenter,
x1,y1, &rx1,&ry1,&rx2,&ry2, &no_of_lines, &longest_line);
@ -822,6 +820,8 @@ static void old_ps_draw_string(int gctext, const char *str,
my_free(_ALLOC_ID_, &estr);
return;
}
xscale*=tclgetdoublevar("nocairo_font_xscale") * cairo_font_scale;
yscale*=tclgetdoublevar("nocairo_font_yscale") * cairo_font_scale;
set_ps_colors(gctext);
x1=rx1;y1=ry1;
if(rot&1) {y1=ry2;rot=3;}

View File

@ -437,8 +437,6 @@ static void old_svg_draw_string(int layer, const char *str,
if(str==NULL) return;
estr = my_expand(str, tclgetintvar("tabstop"));
xscale*=tclgetdoublevar("nocairo_font_xscale") * cairo_font_scale;
yscale*=tclgetdoublevar("nocairo_font_yscale") * cairo_font_scale;
#if HAS_CAIRO==1
text_bbox_nocairo(estr, xscale, yscale, rot, flip, hcenter, vcenter,
x,y, &rx1,&ry1,&rx2,&ry2, &no_of_lines, &longest_line);
@ -450,6 +448,8 @@ static void old_svg_draw_string(int layer, const char *str,
my_free(_ALLOC_ID_, &estr);
return;
}
xscale*=tclgetdoublevar("nocairo_font_xscale") * cairo_font_scale;
yscale*=tclgetdoublevar("nocairo_font_yscale") * cairo_font_scale;
x=rx1;y=ry1;
if(rot&1) {y=ry2;rot=3;}
else rot=0;