Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TeXmacs/plugins/binary/progs/binary/convert.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
8 changes: 5 additions & 3 deletions TeXmacs/plugins/binary/progs/binary/pdftocairo.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand All @@ -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))))
Expand Down
6 changes: 6 additions & 0 deletions TeXmacs/plugins/image/progs/image/pdf.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
53 changes: 53 additions & 0 deletions devel/212_6.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 7 additions & 2 deletions src/Edit/Editor/edit_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading