Skip to content

Commit

Permalink
[41_7] gs: embedded eps to png and pdf (#1730)
Browse files Browse the repository at this point in the history
<!-- Thank you for your contribution! -->
## What
+ Fix embedded eps->png
+ Fix embedded eps->pdf

## Why
We need to `url-sys-concretize` the ramdisc url first and then convert
it.

## How to test your changes?
Test it via view 41_eps.tm and export 41_eps.tm to PDF.
  • Loading branch information
da-liii committed Mar 14, 2024
1 parent 553a073 commit 6542aa1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
14 changes: 7 additions & 7 deletions TeXmacs/plugins/binary/progs/binary/gs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
" -dBATCH "
" -dSAFER "
" -sDEVICE=bbox "
(url->system u))))
(url-sys-concretize u))))
(l (filter (lambda (x) (string-starts? x "%%BoundingBox: "))
(string-split out #\newline)))
(box (and (> (length l) 0)
Expand Down Expand Up @@ -80,7 +80,7 @@
" -dCompatibilityLevel=1.4 "
(string-append " -sOutputFile=" (url->system to) " ")
(string-append " -c " (string-quote gs-inline))
(string-append " -f " (url->system from) " ")
(string-append " -f " (url-sys-concretize from) " ")
(string-append " -c " (string-quote " grestore ")))))
(debug-message "io" (string-append "call: " cmd "\n"))
(system cmd)))
Expand All @@ -95,12 +95,12 @@
(width (if (and opt_w (!= opt_w 0)) opt_w box_w))
(height (if (and opt_h (!= opt_h 0)) opt_h box_w))
(page_size_in_px (string-append " -g" (number->string width) "x" (number->string height)))
(resolution_in_px (string-append " -r" (number->string (/ (* width 72.0) box_w)) "x"
(number->string (/ (* height 72.0) box_h)) " "))
(resolution_in_px (string-append " -r" (number->string (round (/ (* width 72.0) box_w))) "x"
(number->string (round (/ (* height 72.0) box_h))) " "))
(offset-x (number->string (- (first box))))
(offset-y (number->string (- (second box))))
(gs-inline
(string-append offset-x " " offset-y " translate gsave "))
(string-append " " offset-x " " offset-y " translate gsave "))
(cmd (string-append
(string-append
(url->system (find-binary-gs))
Expand All @@ -111,11 +111,11 @@
" -sDEVICE=pngalpha "
" -dGraphicsAlphaBits=4 "
" -dTextAlphaBits=4 ";
(string-append " -sOutputFile=" (url->system to) " ")
page_size_in_px
(string-append " -sOutputFile=" (url->system to) " ")
resolution_in_px
(string-append " -c " (string-quote gs-inline))
(string-append " -f " (url->system from) " ")
(string-append " -f " (url-sys-concretize from) " ")
(string-append " -c " (string-quote " grestore "))))))
(debug-message "io" (string-append cmd "\n"))
(system cmd)))
Expand Down
6 changes: 5 additions & 1 deletion TeXmacs/tests/tm/41_eps.tm

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Plugins/Ghostscript/gs_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ gs_image_size (url image, int& w_pt, int& h_pt) {
else {
if (DEBUG_CONVERT) debug_convert << "gs eps image size :" << LF;
int x1, y1, x2, y2;
string buf;
ok= !load_string (image, buf, false);
string buf= ps_load (image, false);
ok = (N (buf) > 0);
if (ok) {
// try finding Bounding box in file:
ok= ps_read_bbox (buf, x1, y1, x2, y2);
Expand Down
2 changes: 1 addition & 1 deletion src/System/Files/image_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ string
ps_load (url image, bool conv) {
if (DEBUG_CONVERT) debug_convert << "ps_load " << image << LF;

url name= resolve (image);
url name= sys_concretize (image);
if (is_none (name)) name= "$TEXMACS_PATH/misc/pixmaps/unknown.png";

if (is_ramdisc (name)) name= get_from_ramdisc (name);
Expand Down

0 comments on commit 6542aa1

Please sign in to comment.