svg and ps/pdf export: do not include data for offscreen graphs or images to reduce file size

This commit is contained in:
stefan schippers 2024-09-24 11:10:30 +02:00
parent 2372828c22
commit bb1a1557bc
5 changed files with 80 additions and 51 deletions

View File

@ -1,4 +1,6 @@
3.4.6:
- svgdraw and psprint: draw text after images as done in screen draw. Correct postscript / pdf
image zoom factor to match scaling with other xschem elements.
- do not reset xctx->netlist_name after doing `Netlist` from gui (xschem netlist -erc)
- process tcleval(....) (if present) in symbol `name` argument
- let symbol name entry box in component edit property dialog box expand in X direction

View File

@ -4504,6 +4504,15 @@ void svg_embedded_graph(FILE *fd, xRect *r, double rx1, double ry1, double rx2,
const double max_size = 3000.0;
if(!has_x) return;
/* screen position */
x1=X_TO_SCREEN(rx1);
y1=Y_TO_SCREEN(ry1);
x2=X_TO_SCREEN(rx2);
y2=Y_TO_SCREEN(ry2);
if(RECT_OUTSIDE(x1, y1, x2, y2,
xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2)) return;
rw = fabs(rx2 -rx1);
rh = fabs(ry2 - ry1);
scale = 3.0;
@ -4567,10 +4576,6 @@ void svg_embedded_graph(FILE *fd, xRect *r, double rx1, double ry1, double rx2,
save_restore_zoom(0, &zi);
resetwin(1, 1, 1, xctx->xrect[0].width, xctx->xrect[0].height);
x1=X_TO_SVG(rx1);
y1=Y_TO_SVG(ry1);
x2=X_TO_SVG(rx2);
y2=Y_TO_SVG(ry2);
h = fabs(y2 - y1);
w = fabs(x2 - x1);

View File

@ -77,7 +77,7 @@ static Ps_color *ps_colors;
static char ps_font_name[80] = "Helvetica"; /* Courier Times Helvetica Symbol */
static char ps_font_family[80] = "Helvetica"; /* Courier Times Helvetica Symbol */
int ps_embedded_image(xRect* r, double x1, double y1, double x2, double y2, int rot, int flip)
static int ps_embedded_image(xRect* r, double x1, double y1, double x2, double y2, int rot, int flip)
{
#if defined(HAS_LIBJPEG) && HAS_CAIRO==1
int i, jpg;
@ -94,6 +94,15 @@ int ps_embedded_image(xRect* r, double x1, double y1, double x2, double y2, int
const char *quality_attr;
size_t oLength, attr_len;
cairo_t *ct;
double sx1, sy1, sx2, sy2;
/* screen position */
sx1=X_TO_SCREEN(x1);
sy1=Y_TO_SCREEN(y1);
sx2=X_TO_SCREEN(x2);
sy2=Y_TO_SCREEN(y2);
if(RECT_OUTSIDE(sx1, sy1, sx2, sy2,
xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2)) return 0;
invertImage = !strboolcmp(get_tok_value(r->prop_ptr, "InvertOnExport", 0), "true");
if(!invertImage)
@ -229,7 +238,7 @@ int ps_embedded_image(xRect* r, double x1, double y1, double x2, double y2, int
return 1;
}
void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2)
static int ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2)
{
#if defined(HAS_LIBJPEG) && HAS_CAIRO==1
Zoom_info zi;
@ -249,6 +258,15 @@ void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2)
const char *quality_attr;
size_t oLength;
int i;
double sx1, sy1, sx2, sy2;
/* screen position */
sx1=X_TO_SCREEN(rx1);
sy1=Y_TO_SCREEN(ry1);
sx2=X_TO_SCREEN(rx2);
sy2=Y_TO_SCREEN(ry2);
if(RECT_OUTSIDE(sx1, sy1, sx2, sy2,
xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2)) return 0;
quality_attr = get_tok_value(r->prop_ptr, "jpeg_quality", 0);
if(quality_attr[0]) quality = atoi(quality_attr);
@ -257,7 +275,8 @@ void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2)
if(quality_attr[0]) quality = atoi(quality_attr);
}
if(quality_attr[0]) quality = atoi(quality_attr);
if (!has_x) return;
if (!has_x) return 0;
rw = fabs(rx2 - rx1);
rh = fabs(ry2 - ry1);
scale = 3.0;
@ -371,6 +390,7 @@ void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2)
my_free(_ALLOC_ID_, &ascii85EncodedJpeg);
#endif
return 1;
}
static void set_lw(void)
{

View File

@ -111,8 +111,8 @@ static void svg_drawbezier(double *x, double *y, int points)
for(t = 0; t <= 1.0; t += bez_steps) {
xp = (1 - t) * (1 - t) * x0 + 2 * (1 - t) * t * x1 + t * t * x2;
yp = (1 - t) * (1 - t) * y0 + 2 * (1 - t) * t * y1 + t * t * y2;
if(i==0) fprintf(fd, "M%g %g", X_TO_SVG(xp), Y_TO_SVG(yp));
else fprintf(fd, "L%g %g", X_TO_SVG(xp), Y_TO_SVG(yp));
if(i==0) fprintf(fd, "M%g %g", X_TO_SCREEN(xp), Y_TO_SCREEN(yp));
else fprintf(fd, "L%g %g", X_TO_SCREEN(xp), Y_TO_SCREEN(yp));
i++;
}
}
@ -124,10 +124,10 @@ static void svg_drawpolygon(int c, int what, double *x, double *y, int points, i
double xx, yy;
int bezier, i;
polygon_bbox(x, y, points, &x1,&y1,&x2,&y2);
x1=X_TO_SVG(x1);
y1=Y_TO_SVG(y1);
x2=X_TO_SVG(x2);
y2=Y_TO_SVG(y2);
x1=X_TO_SCREEN(x1);
y1=Y_TO_SCREEN(y1);
x2=X_TO_SCREEN(x2);
y2=Y_TO_SCREEN(y2);
if( !rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) ) {
return;
}
@ -144,8 +144,8 @@ static void svg_drawpolygon(int c, int what, double *x, double *y, int points, i
} else {
fprintf(fd, "d=\"");
for(i=0;i<points; ++i) {
xx = X_TO_SVG(x[i]);
yy = Y_TO_SVG(y[i]);
xx = X_TO_SCREEN(x[i]);
yy = Y_TO_SCREEN(y[i]);
if(i==0) fprintf(fd, "M%g %g", xx, yy);
else fprintf(fd, "L%g %g", xx, yy);
}
@ -158,10 +158,10 @@ static void svg_filledrect(int gc, double rectx1,double recty1,double rectx2,dou
{
double x1,y1,x2,y2;
x1=X_TO_SVG(rectx1);
y1=Y_TO_SVG(recty1);
x2=X_TO_SVG(rectx2);
y2=Y_TO_SVG(recty2);
x1=X_TO_SCREEN(rectx1);
y1=Y_TO_SCREEN(recty1);
x2=X_TO_SCREEN(rectx2);
y2=Y_TO_SCREEN(recty2);
if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) )
{
svg_xfillrectangle(gc, x1,y1,x2,y2, dash, fill);
@ -173,14 +173,14 @@ static void svg_drawcircle(int gc, int fillarc, double x,double y,double r,doubl
double xx,yy,rr;
double x1, y1, x2, y2;
xx=X_TO_SVG(x);
yy=Y_TO_SVG(y);
xx=X_TO_SCREEN(x);
yy=Y_TO_SCREEN(y);
rr=r*xctx->mooz;
arc_bbox(x, y, r, a, b, &x1,&y1,&x2,&y2);
x1=X_TO_SVG(x1);
y1=Y_TO_SVG(y1);
x2=X_TO_SVG(x2);
y2=Y_TO_SVG(y2);
x1=X_TO_SCREEN(x1);
y1=Y_TO_SCREEN(y1);
x2=X_TO_SCREEN(x2);
y2=Y_TO_SCREEN(y2);
if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) )
{
@ -195,14 +195,14 @@ static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a
double xx1, yy1, xx2, yy2;
int fs, fa;
xx=X_TO_SVG(x);
yy=Y_TO_SVG(y);
xx=X_TO_SCREEN(x);
yy=Y_TO_SCREEN(y);
rr=r*xctx->mooz;
arc_bbox(x, y, r, a, b, &x1,&y1,&x2,&y2);
x1=X_TO_SVG(x1);
y1=Y_TO_SVG(y1);
x2=X_TO_SVG(x2);
y2=Y_TO_SVG(y2);
x1=X_TO_SCREEN(x1);
y1=Y_TO_SCREEN(y1);
x2=X_TO_SCREEN(x2);
y2=Y_TO_SCREEN(y2);
if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) )
{
@ -240,10 +240,10 @@ static void svg_drawline(int gc, int bus, double linex1,double liney1,double lin
{
double x1,y1,x2,y2;
x1=X_TO_SVG(linex1);
y1=Y_TO_SVG(liney1);
x2=X_TO_SVG(linex2);
y2=Y_TO_SVG(liney2);
x1=X_TO_SCREEN(linex1);
y1=Y_TO_SCREEN(liney1);
x2=X_TO_SCREEN(linex2);
y2=Y_TO_SCREEN(liney2);
if( clip(&x1,&y1,&x2,&y2) )
{
svg_xdrawline(gc, bus, x1, y1, x2, y2, dash);
@ -272,8 +272,8 @@ static void svg_draw_string_line(int layer, char *s, double x, double y, double
line_delta = lineno*fontheight;
lines = (no_of_lines-1)*fontheight;
ix=X_TO_SVG(x);
iy=Y_TO_SVG(y);
ix=X_TO_SCREEN(x);
iy=Y_TO_SCREEN(y);
if(rot&1) {
rot1=3;
} else rot1=0;
@ -476,10 +476,16 @@ static int svg_embedded_image(xRect *r, double rx1, double ry1, double rx2, doub
char transform[150];
double alpha = 1.0;
x1=X_TO_SVG(rx1);
y1=Y_TO_SVG(ry1);
x2=X_TO_SVG(rx2);
y2=Y_TO_SVG(ry2);
x1=X_TO_SCREEN(rx1);
y1=Y_TO_SCREEN(ry1);
x2=X_TO_SCREEN(rx2);
y2=Y_TO_SCREEN(ry2);
/* screen position */
if(RECT_OUTSIDE(x1, y1, x2, y2,
xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2)) return 0;
if(rot == 1 || rot == 3) {
w = fabs(y2 - y1);
h = fabs(x2 - x1);
@ -541,10 +547,10 @@ static void svg_draw_symbol(int c, int n,int layer,short tmp_flip, short rot,
}
if(layer==0) {
x1=X_TO_SVG(xctx->inst[n].x1);
x2=X_TO_SVG(xctx->inst[n].x2);
y1=Y_TO_SVG(xctx->inst[n].y1);
y2=Y_TO_SVG(xctx->inst[n].y2);
x1=X_TO_SCREEN(xctx->inst[n].x1);
x2=X_TO_SCREEN(xctx->inst[n].x2);
y1=Y_TO_SCREEN(xctx->inst[n].y1);
y2=Y_TO_SCREEN(xctx->inst[n].y2);
if(RECT_OUTSIDE(x1,y1,x2,y2,xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2)) {
xctx->inst[n].flags|=1;
return;
@ -864,9 +870,9 @@ void svg_draw(void)
/* do first graphs as these require draw() which clobbers xctx->inst[n].flags bit 0 */
for(c=0;c<cadlayers; ++c)
{
for(i=0;i<xctx->rects[c]; ++i)
if(c == GRIDLAYER) for(i=0;i<xctx->rects[c]; ++i)
{
if(c == GRIDLAYER && (xctx->rect[c][i].flags & 1) ) { /* graph */
if(xctx->rect[c][i].flags & 1) { /* graph */
xRect *r = &xctx->rect[c][i];
svg_embedded_graph(fd, r, r->x1, r->y1, r->x2, r->y2);
}

View File

@ -385,10 +385,6 @@ extern char win_temp_dir[PATH_MAX];
#define X_TO_XSCHEM(x) ( (x) * xctx->zoom - xctx->xorigin )
#define Y_TO_XSCHEM(y) ( (y) * xctx->zoom - xctx->yorigin )
#define X_TO_SVG(x) ( (x+xctx->xorigin)* xctx->mooz )
#define Y_TO_SVG(y) ( (y+xctx->yorigin)* xctx->mooz )
/* coordinate transformations graph to xschem */
#define W_X(x) (gr->cx * (x) + gr->dx)
#define W_Y(y) (gr->cy * (y) + gr->dy)