diff --git a/TeXmacs/plugins/binary/progs/binary/convert.scm b/TeXmacs/plugins/binary/progs/binary/convert.scm index b18523bacb..5f7d403f7a 100644 --- a/TeXmacs/plugins/binary/progs/binary/convert.scm +++ b/TeXmacs/plugins/binary/progs/binary/convert.scm @@ -12,7 +12,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (texmacs-module (binary convert) - (:use (binary common))) + (:use (binary common) + (convert images image-format))) (define (convert-binary-candidates) (cond ((os-macos?) diff --git a/TeXmacs/plugins/binary/progs/binary/pdftocairo.scm b/TeXmacs/plugins/binary/progs/binary/pdftocairo.scm index 7aaa8fdbe0..81e97173d0 100644 --- a/TeXmacs/plugins/binary/progs/binary/pdftocairo.scm +++ b/TeXmacs/plugins/binary/progs/binary/pdftocairo.scm @@ -12,7 +12,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (texmacs-module (binary pdftocairo) - (:use (binary common))) + (:use (binary common) + (convert images image-format))) (define (pdftocairo-binary-candidates) (cond ((os-macos?) @@ -36,9 +37,10 @@ (tm-define (pdf-file->pdftocairo-raster x opts) (let* ((dest (assoc-ref opts 'dest)) (fullname (url-concretize dest)) - (fm (url-format fullname)) - (transp (if (== fm "png") "-transp " "")) (suffix (url-suffix fullname)) + (fm* (format-from-suffix suffix)) + (fm (if (== fm* "tif") "tiff" fm*)) + (transp (if (== fm "png") "-transp " "")) (name (string-drop-right fullname (+ 1 (string-length suffix)))) (res (get-raster-resolution opts)) (cmd (url->system (find-binary-pdftocairo)))) diff --git a/TeXmacs/plugins/image/progs/image/pdf.scm b/TeXmacs/plugins/image/progs/image/pdf.scm index bb54e62ac6..c9dded7ea9 100644 --- a/TeXmacs/plugins/image/progs/image/pdf.scm +++ b/TeXmacs/plugins/image/progs/image/pdf.scm @@ -36,6 +36,12 @@ ;;(:option "texmacs->image:raster-resolution" "300") ) +(converter pdf-file tif-file + (:require (has-binary-pdftocairo?)) + (:function-with-options pdf-file->pdftocairo-raster) + ;;(:option "texmacs->image:raster-resolution" "300") + ) + ;;(converter pdf-file postscript-document ;; (:require (has-pdftocairo?)) ;; (:shell "pdftocairo" "-eps" from to)) diff --git a/devel/212_6.md b/devel/212_6.md new file mode 100644 index 0000000000..f5a6c303fc --- /dev/null +++ b/devel/212_6.md @@ -0,0 +1,53 @@ +# 212_6: Fix export selection as image for jpeg, tiff + +## How to Test +- Select text in a document +- File → Export selection as image → save as `.jpg` → verify file is created and contains the selection +- Repeat for `.tif` and `.tiff` +- `png` exports have issue (when using mupdf render), trailing lines/words are trimmed. + +## Issue #2728 +JPEG and TIFF formats could not be exported via "Export Selected Area as Image".PNG and PDF export worked. + +## What + +### 1. `src/Edit/Editor/edit_main.cpp` +The root cause. `print_snippet` routed jpeg/tiff through `make_raster_image`, but mupdf's `save_picture` only supports PNG (hardcoded `fz_write_pixmap_as_png`). The fix gates the bitmap path by renderer: + +```cpp +// BEFORE +bool bitmap = (s == "png" || s == "jpg" || s == "jpeg" || s == "tif" || s == "tiff"); + +// AFTER +bool bitmap= false; +#ifdef USE_MUPDF_RENDERER + bitmap = (s == "png"); +#else + bitmap = (s == "png" || s == "jpg" || s == "jpeg" || s == "tif" || s == "tiff"); +#endif +``` + +With mupdf, jpeg/tiff now go through the PDF→Scheme converter pipeline instead. + +### 2. `TeXmacs/plugins/binary/progs/binary/pdftocairo.scm` +`url-format` returned format names (via C++ glue) that didn't match pdftocairo CLI flags. Replaced with `format-from-suffix` (proper Scheme API) plus a `tif→tiff` fix because pdftocairo accepts `-tiff` but not `-tif`: + +```scheme +;; BEFORE +(fm (url-format fullname)) + +;; AFTER +(fm* (format-from-suffix suffix)) +(fm (if (== fm* "tif") "tiff" fm*)) +``` + +Also added `(convert images image-format)` import for `get-raster-resolution`. + +### 3. `TeXmacs/plugins/binary/progs/binary/convert.scm` +Added missing `(convert images image-format)` import. Without it, `get-raster-resolution` was unbound when ImageMagick converter was invoked, causing a crash. + +### 4. `TeXmacs/plugins/image/progs/image/pdf.scm` +Registered `pdf-file → tif-file` converter via pdftocairo. Previously only ImageMagick had a TIFF converter, so systems without ImageMagick could not export TIFF. + +## Why +mupdf's `save_picture` only supports PNG output. The old code unconditionally treated jpeg/tiff as bitmap formats, sending them through a rendering path that silently failed. The converter pipeline (pdftocairo/ImageMagick) also had bugs: missing imports, missing converter registrations, and incorrect CLI flag generation. diff --git a/src/Edit/Editor/edit_main.cpp b/src/Edit/Editor/edit_main.cpp index 967d706af2..90e42baf24 100644 --- a/src/Edit/Editor/edit_main.cpp +++ b/src/Edit/Editor/edit_main.cpp @@ -335,9 +335,14 @@ edit_main_rep::print_snippet (url name, tree t, bool conserve_preamble) { temp_root << 0; assign (subtree (et, temp_root), copy (t)); - string s= suffix (name); - bool bitmap= + string s = suffix (name); + bool bitmap= false; +#ifdef USE_MUPDF_RENDERER + bitmap= (s == "png"); +#else + bitmap= (s == "png" || s == "jpg" || s == "jpeg" || s == "tif" || s == "tiff"); +#endif #ifndef QTTEXMACS bitmap= false; #endif