Skip to content

[212_6]Fix export as image for jpeg,tif#2955

Open
git-lakshy wants to merge 2 commits intoMoganLab:mainfrom
git-lakshy:myb6
Open

[212_6]Fix export as image for jpeg,tif#2955
git-lakshy wants to merge 2 commits intoMoganLab:mainfrom
git-lakshy:myb6

Conversation

@git-lakshy
Copy link
Contributor

@git-lakshy git-lakshy commented Mar 7, 2026

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
  • Also test .png and .pdf works as expected

(Tested on debian works)

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:

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:

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.

@git-lakshy git-lakshy marked this pull request as ready for review March 7, 2026 10:53
Copilot AI review requested due to automatic review settings March 7, 2026 10:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes “Export selection as image” for JPEG and TIFF when built with the MuPDF renderer by avoiding MuPDF’s PNG-only save_picture path and ensuring the PDF→raster converter pipeline (pdftocairo / ImageMagick) is correctly wired for TIFF.

Changes:

  • Gate print_snippet’s bitmap (direct raster) export path to PNG only when USE_MUPDF_RENDERER is enabled; route JPEG/TIFF through the PDF→converter pipeline instead.
  • Fix pdftocairo raster conversion flag selection by deriving the format from the destination suffix and mapping tiftiff for the CLI.
  • Register a pdf-file → tif-file converter via pdftocairo and add missing imports for get-raster-resolution.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Edit/Editor/edit_main.cpp Avoids MuPDF PNG-only raster saving for JPEG/TIFF by routing those exports through the converter pipeline.
TeXmacs/plugins/binary/progs/binary/pdftocairo.scm Uses format-from-suffix + tif→tiff mapping for correct pdftocairo flags; imports image-format for resolution.
TeXmacs/plugins/binary/progs/binary/convert.scm Imports image-format so get-raster-resolution is available for ImageMagick conversion.
TeXmacs/plugins/image/progs/image/pdf.scm Adds a pdftocairo-based pdf-file → tif-file converter to support TIFF without ImageMagick.
devel/212_6.md Developer documentation / test instructions for the fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants