Skip to content

Commit c303fe9

Browse files
committed
Fix the case where psimage had imported another PS file.
In that case, do not try to touch any further BoundingBox found.
1 parent 7941eeb commit c303fe9

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

src/psconvert.c

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,63 +2367,47 @@ EXTERN_MSC int GMT_psconvert (void *V_API, int mode, void *args) {
23672367
"Very likely this won't work as you wish inside GE.\n");
23682368
}
23692369
}
2370-
else if (!strncmp (line, "%GMTBoundingBox:", 16)) {
2371-
sscanf (&line[16], "%s %s %s %s",c1,c2,c3,c4);
2372-
gmtBB_x0 = atof (c1); gmtBB_y0 = atof (c2);
2373-
gmtBB_width = atof (c3); gmtBB_height = atof (c4);
2370+
else if (!strncmp(line, "%GMTBoundingBox:", 16)) {
2371+
sscanf(&line[16], "%s %s %s %s",c1,c2,c3,c4);
2372+
gmtBB_x0 = atof(c1); gmtBB_y0 = atof(c2);
2373+
gmtBB_width = atof(c3); gmtBB_height = atof(c4);
23742374
continue;
23752375
}
23762376

2377-
if (!strncmp (line, "%%BoundingBox:", 14)) {
2377+
if (!strncmp(line, "%%BoundingBox:", 14)) {
23782378
double w_t, h_t;
23792379
w_t = w; h_t = h;
23802380
if (Ctrl->I.resize) { /* Here the BB is the new size itself */
23812381
w_t = Ctrl->I.new_size[0]; h_t = Ctrl->I.new_size[1];
23822382
}
23832383

2384-
if (Ctrl->O.active) {
2385-
fseek(fp, (off_t)-(strlen(line)+1), SEEK_CUR); /* Seek back to start of line */
2386-
if (got_BB && !Ctrl->A.round)
2387-
sprintf(line, "%%%%BoundingBox: 0 0 %ld %ld", lrint (psconvert_smart_ceil(w_t)), lrint (psconvert_smart_ceil(h_t)));
2388-
else if (got_BB && Ctrl->A.round) /* Go against Adobe Law and round HRBB instead of ceil */
2389-
sprintf(line, "%%%%BoundingBox: 0 0 %ld %ld", lrint(w_t), lrint(h_t));
2390-
fprintf(fp, "%s\n", line);
2391-
fflush(fp);
2392-
}
2384+
if (Ctrl->O.active)
2385+
continue; /* Because with -! we already parsed the code where we put the BB. This one must be from a psimage import. */
23932386
else {
23942387
if (got_BB && !Ctrl->A.round)
2395-
fprintf (fpo, "%%%%BoundingBox: 0 0 %ld %ld\n", lrint (psconvert_smart_ceil(w_t)), lrint (psconvert_smart_ceil(h_t)));
2388+
fprintf(fpo, "%%%%BoundingBox: 0 0 %ld %ld\n", lrint(psconvert_smart_ceil(w_t)), lrint(psconvert_smart_ceil(h_t)));
23962389
else if (got_BB && Ctrl->A.round) /* Go against Adobe Law and round HRBB instead of ceil */
2397-
fprintf (fpo, "%%%%BoundingBox: 0 0 %ld %ld\n", lrint (w_t), lrint (h_t));
2390+
fprintf(fpo, "%%%%BoundingBox: 0 0 %ld %ld\n", lrint(w_t), lrint(h_t));
23982391
}
23992392

24002393
got_BB = false;
24012394
if (file_has_HRBB)
24022395
continue; /* High-res BB will be put elsewhere */
24032396
if (got_HRBB) { /* TO DELETE?. This is silly, if we 'continue' above we can never come here. */
2404-
if (Ctrl->O.active) {
2405-
fseek(fp, (off_t)-(strlen(line)+1), SEEK_CUR); /* Seek back to start of line */
2406-
fprintf(fp, "%%%%HiResBoundingBox: 0 0 %.4f %.4f", w_t, h_t);
2407-
fflush(fp);
2408-
}
2409-
else
2410-
fprintf(fpo, "%%%%HiResBoundingBox: 0 0 %.4f %.4f\n", w_t, h_t);
2397+
fprintf(fpo, "%%%%HiResBoundingBox: 0 0 %.4f %.4f\n", w_t, h_t);
24112398
}
24122399
got_HRBB = false;
24132400
continue;
24142401
}
2415-
else if (!strncmp (line, "%%HiResBoundingBox:", 19)) {
2402+
else if (!strncmp(line, "%%HiResBoundingBox:", 19)) {
24162403
double w_t, h_t;
24172404
w_t = w; h_t = h;
24182405
if (Ctrl->I.resize) { /* Here the BB is the new size itself */
24192406
w_t = Ctrl->I.new_size[0]; h_t = Ctrl->I.new_size[1];
24202407
}
24212408
if (got_HRBB) {
2422-
if (Ctrl->O.active) {
2423-
fseek(fp, (off_t)-(strlen(line)+1), SEEK_CUR); /* Seek back to start of line */
2424-
fprintf(fp, "%%%%HiResBoundingBox: 0 0 %.4f %.4f", w_t, h_t); /* No '\n' here because orig line already has it */
2425-
fflush(fp);
2426-
}
2409+
if (Ctrl->O.active)
2410+
continue; /* As explained above, this one must be from a psimage PS import. */
24272411
else
24282412
fprintf(fpo, "%%%%HiResBoundingBox: 0 0 %.4f %.4f\n", w_t, h_t);
24292413
}

0 commit comments

Comments
 (0)