fix regression in psprint.c

This commit is contained in:
stefan schippers 2025-02-13 20:43:39 +01:00
parent ed3190c9b1
commit b0d740757a
1 changed files with 66 additions and 72 deletions

View File

@ -301,7 +301,6 @@ static int ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, doubl
rwi = (int)(rw * scale + 1.0);
rhi = (int)(rh * scale + 1.0);
dbg(1, "graph size: %dx%d\n", rwi, rhi);
dbg(1, "ps_embedded_graph: saving zoom\n");
save_restore_zoom(1, &zi);
set_viewport_size(rwi, rhi, xctx->lw);
@ -354,7 +353,6 @@ static int ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, doubl
cairo_surface_destroy(png_sfc);
xctx->draw_pixmap = 1;
tclsetboolvar("draw_grid", save_draw_grid);
dbg(1, "ps_embedded_graph: restoring zoom\n");
save_restore_zoom(0, &zi);
resetwin(1, 1, 1, 0, 0);
change_linewidth(xctx->lw);
@ -1192,83 +1190,78 @@ void create_ps(char **psfile, int what, int fullzoom, int eps)
old_grid=tclgetboolvar("draw_grid");
tclsetvar("draw_grid", "0");
/* xschem window aspect ratio decides if portrait or landscape */
boundbox.x1 = xctx->areax1;
boundbox.x2 = xctx->areax2;
boundbox.y1 = xctx->areay1;
boundbox.y2 = xctx->areay2;
dx=boundbox.x2-boundbox.x1;
dy=boundbox.y2-boundbox.y1;
/* xschem drawing bbox decides if portrait or landscape */
if(fullzoom == 1) {
calc_drawing_bbox(&boundbox, 0);
dx=boundbox.x2-boundbox.x1;
dy=boundbox.y2-boundbox.y1;
}
if(dx >= dy) {
landscape = 1;
} else {
landscape = 0;
}
dbg(1, "dx=%g, dy=%g\n", dx, dy);
if(!(what & 4)) {
/* xschem window aspect ratio decides if portrait or landscape */
if(fullzoom == 1) {
/* save size and zoom factor */
save_restore_zoom(1, &zi);
/* this zoom only done to reset lw */
zoom_full(0, 0, 1 + 2 * tclgetboolvar("zoom_full_center"), 0.97);
/* adjust aspect ratio to paper size */
if(landscape)
xctx->xrect[0].height = (short unsigned int) (xctx->xrect[0].width * pagey / pagex);
else
xctx->xrect[0].width = (short unsigned int) (xctx->xrect[0].height * pagey / pagex);
dbg(1, "xrect.width=%d, xrect.height=%d\n", xctx->xrect[0].width, xctx->xrect[0].height);
xctx->areax1 = -2*INT_WIDTH(xctx->lw);
xctx->areay1 = -2*INT_WIDTH(xctx->lw);
xctx->areax2 = xctx->xrect[0].width+2*INT_WIDTH(xctx->lw);
xctx->areay2 = xctx->xrect[0].height+2*INT_WIDTH(xctx->lw);
xctx->areaw = xctx->areax2-xctx->areax1;
xctx->areah = xctx->areay2 - xctx->areay1;
dbg(1, "dx=%g, dy=%g\n", dx, dy);
/* fit schematic into adjusted size */
zoom_full(0, 0, 0 + 2 * tclgetboolvar("zoom_full_center"), 0.97);
boundbox.x1 = xctx->areax1;
boundbox.x2 = xctx->areax2;
boundbox.y1 = xctx->areay1;
boundbox.y2 = xctx->areay2;
dx=boundbox.x2-boundbox.x1;
dy=boundbox.y2-boundbox.y1;
/* xschem drawing bbox decides if portrait or landscape */
if(fullzoom == 1) {
calc_drawing_bbox(&boundbox, 0);
dx=boundbox.x2-boundbox.x1;
dy=boundbox.y2-boundbox.y1;
}
if(dx >= dy) {
landscape = 1;
}
if(!landscape) { /* decide paper orientation for best schematic fit */
double tmp;
tmp = pagex;
pagex = pagey;
pagey = tmp;
}
if(fullzoom == 2) { /* set media size to bbox */
double sc;
my_strncpy(papername, "bbox", S(papername));
pagex = xctx->xrect[0].width;
pagey = xctx->xrect[0].height;
if(pagex > pagey) {
sc = 842. / pagex;
pagex = my_round(pagex * sc);
pagey = my_round(pagey * sc);
} else {
landscape = 0;
sc = 842. / pagey;
pagex = my_round(pagex * sc);
pagey = my_round(pagey * sc);
}
dbg(1, "dx=%g, dy=%g\n", dx, dy);
if(fullzoom == 1) {
/* save size and zoom factor */
dbg(1, "create_ps: saving zoom\n");
save_restore_zoom(1, &zi);
/* this zoom only done to reset lw */
zoom_full(0, 0, 1 + 2 * tclgetboolvar("zoom_full_center"), 0.97);
/* adjust aspect ratio to paper size */
if(landscape)
xctx->xrect[0].height = (short unsigned int) (xctx->xrect[0].width * pagey / pagex);
else
xctx->xrect[0].width = (short unsigned int) (xctx->xrect[0].height * pagey / pagex);
dbg(1, "xrect.width=%d, xrect.height=%d\n", xctx->xrect[0].width, xctx->xrect[0].height);
xctx->areax1 = -2*INT_WIDTH(xctx->lw);
xctx->areay1 = -2*INT_WIDTH(xctx->lw);
xctx->areax2 = xctx->xrect[0].width+2*INT_WIDTH(xctx->lw);
xctx->areay2 = xctx->xrect[0].height+2*INT_WIDTH(xctx->lw);
xctx->areaw = xctx->areax2-xctx->areax1;
xctx->areah = xctx->areay2 - xctx->areay1;
dbg(1, "dx=%g, dy=%g\n", dx, dy);
/* fit schematic into adjusted size */
zoom_full(0, 0, 0 + 2 * tclgetboolvar("zoom_full_center"), 0.97);
boundbox.x1 = xctx->areax1;
boundbox.x2 = xctx->areax2;
boundbox.y1 = xctx->areay1;
boundbox.y2 = xctx->areay2;
dx=boundbox.x2-boundbox.x1;
dy=boundbox.y2-boundbox.y1;
}
if(!landscape) { /* decide paper orientation for best schematic fit */
double tmp;
tmp = pagex;
pagex = pagey;
pagey = tmp;
}
if(fullzoom == 2) { /* set media size to bbox */
double sc;
my_strncpy(papername, "bbox", S(papername));
pagex = xctx->xrect[0].width;
pagey = xctx->xrect[0].height;
if(pagex > pagey) {
sc = 842. / pagex;
pagex = my_round(pagex * sc);
pagey = my_round(pagey * sc);
} else {
sc = 842. / pagey;
pagex = my_round(pagex * sc);
pagey = my_round(pagey * sc);
}
margin = 0.0;
}
} /* if(!(what & 4)) */
margin = 0.0;
}
if(what & 1) {/* prolog */
dbg(1, "ps_draw(): bbox: x1=%g y1=%g x2=%g y2=%g\n", boundbox.x1, boundbox.y1, boundbox.x2, boundbox.y2);
@ -1341,6 +1334,7 @@ void create_ps(char **psfile, int what, int fullzoom, int eps)
fprintf(fd, "%%%%EndProlog\n");
}
if(what & 2) { /* page */
++numpages;
@ -1497,7 +1491,7 @@ void create_ps(char **psfile, int what, int fullzoom, int eps)
dbg(1, "ps_draw(): INT_WIDTH(lw)=%d plotfile=%s\n",INT_WIDTH(xctx->lw), xctx->plotfile);
fprintf(fd, "showpage\n\n");
} /* if(what & 2) */
}
if(what & 4) { /* trailer */
fprintf(fd, "%%%%trailer\n");
fprintf(fd, "%%%%Pages: %d\n", numpages);
@ -1515,10 +1509,10 @@ void create_ps(char **psfile, int what, int fullzoom, int eps)
/* restore original size and zoom factor */
if(!(what & 4) && fullzoom == 1) {
dbg(1, "create_ps: restoring zoom\n");
if(fullzoom == 1) {
save_restore_zoom(0, &zi);
}
}
int ps_draw(int what, int fullzoom, int eps)