From 6542aa1f48e21acf91d6ff0481e7524a46f10e15 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Thu, 14 Mar 2024 23:21:43 +0800 Subject: [PATCH] [41_7] gs: embedded eps to png and pdf (#1730) ## 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. --- TeXmacs/plugins/binary/progs/binary/gs.scm | 14 +++++++------- TeXmacs/tests/tm/41_eps.tm | 6 +++++- src/Plugins/Ghostscript/gs_utilities.cpp | 4 ++-- src/System/Files/image_files.cpp | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/TeXmacs/plugins/binary/progs/binary/gs.scm b/TeXmacs/plugins/binary/progs/binary/gs.scm index 3b077a5f6e..c6d8c7d3ed 100644 --- a/TeXmacs/plugins/binary/progs/binary/gs.scm +++ b/TeXmacs/plugins/binary/progs/binary/gs.scm @@ -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) @@ -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))) @@ -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)) @@ -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))) diff --git a/TeXmacs/tests/tm/41_eps.tm b/TeXmacs/tests/tm/41_eps.tm index 3e2079deaf..f3ef209017 100644 --- a/TeXmacs/tests/tm/41_eps.tm +++ b/TeXmacs/tests/tm/41_eps.tm @@ -14,11 +14,15 @@ After the small ps image + + Here is the embeded ps image: + + |41_7.eps>|0.7par|||> <\initial> <\collection> - + \ No newline at end of file diff --git a/src/Plugins/Ghostscript/gs_utilities.cpp b/src/Plugins/Ghostscript/gs_utilities.cpp index a0a121566f..40fb0be27d 100644 --- a/src/Plugins/Ghostscript/gs_utilities.cpp +++ b/src/Plugins/Ghostscript/gs_utilities.cpp @@ -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); diff --git a/src/System/Files/image_files.cpp b/src/System/Files/image_files.cpp index 2f500fbe04..0dd2fdcaf2 100644 --- a/src/System/Files/image_files.cpp +++ b/src/System/Files/image_files.cpp @@ -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);