GNU TeXmacsUser manualReferenceAboutEnglish
Images, pictures and PDF output

1.Introduction

TeXmacs documents may contain images in many formats: bitmaps (PNG, JPEG, GIF, …), vector images (PDF, PostScript, EPS, SVG) and formats which can only be read by external programs (Xfig, Geogebra, …). An image is inserted with the image primitive, it may also serve as a background pattern, and graphical effects (blur, shadows, color transformations, …) can be applied to images and to typeset content. The same images must be shown on the screen, at any zoom factor, and written into PDF and PostScript files, preferably without rasterizing vector images.

This chapter describes the machinery which makes this possible:

The renderer interface itself (draw_picture, draw_scalable, shadow, picture renderers) and the general organization of the PDF renderer are described in the renderer interface, in particular in the renderer API and implementations, new renderers and pitfalls; they are not repeated here. The user level description of the image primitive is in graphics primitives, and the typesetting of gr-effect in the graphics editor: typesetting pictures.

All file names below are relative to

src/src/

unless stated otherwise.

2.Overview

The following diagram shows what happens to an image from the document to the output devices. Each arrow is a function call; the names on the right are the main classes or caches involved.

<image|photo.png|5cm|||>
  |
  concater_rep::typeset_image                    resolves the url
    |-- image_size                             size in pt, cache img_box
    |-- image_box --> load_scalable_image        scalable_image_rep
  |
  image_box_rep::display --> renderer::draw_scalable
    |
    |-- screen: scalable_image_rep::draw
    |       --> cached_load_picture             picture_cache
    |            --> load_picture (Qt)       qt_pic_cache
    |                    --> QImage, resvg, or image_to_png
    |       --> renderer::draw_picture
    |
    |-- PDF:    pdf_hummus_renderer_rep::image       image_pool
    |       --> pdf_image_rep::flush             embed pdf/jpg/png,
    |                                       or image_to_pdf
    |
    |-- PS:     printer_rep::draw_scalable
            --> ps_load --> image_to_psdoc --> image_to_eps

Three ideas run through the whole subsystem:

Sizes in points

The original size of an image file is always expressed in points (1/72 inch) and is cached per file in a table of

image_files.cpp

, because the typesetter asks for it very often.

One place for conversions

All conversions go through the functions of

image_files.cpp

, which try the available tools in a fixed order of preference and fall back on placeholder images ($TEXMACS_PATH/misc/pixmaps/unknown.*) when everything fails. The comment at the top of that file asks other modules not to call external tools directly.

Rasterize late

An image stays a scalable until a renderer draws it. Screen renderers rasterize it at the current resolution; printers embed the original file when they can, and rasterize only for effects and for formats they cannot embed.

3.Source files

Graphics/Pictures/picture.hpp
,
picture.cpp

The abstract class picture_rep, the composition modes, the list of picture operations, the cache of loaded pictures (cached_load_picture and friends), load_xpm for builds without Qt, and picture_as_eps.

Graphics/Pictures/raster.hpp
,
raster_operators.hpp
,
raster_picture.hpp
,
raster_picture.cpp
,
raster_random.cpp

Portable pixel arrays (raster<C>), the pixel operators used to compose them, the picture class which wraps them, and the implementation of all picture operations (including random noise).

Graphics/Pictures/effect.hpp
,
effect.cpp

Effects and build_effect, the parser of effect trees.

Graphics/Pictures/scalable.hpp
,
scalable.cpp

Scalable images and scalable_image_rep.

System/Files/image_files.hpp
,
image_files.cpp

Image sizes, the size cache, the conversions image_to_png, image_to_eps, image_to_pdf, image_to_psdoc, the calls to Scheme converters and to ImageMagick, xpm_load and ps_load.

Plugins/Qt/qt_picture.cpp
,
qt_utilities.cpp

The Qt pictures, the loading of image files into QImages with their own cache, icons, effects applied to files, and the Qt based size determination and conversions (qt_supports, qt_image_size, qt_convert_image, qt_image_to_pdf).

Plugins/Qt6/

contains a copy of these files for Qt 6.

Plugins/Resvg/resvg.cpp

Size determination and rendering of SVG files with the resvg library (USE_RESVG).

Plugins/Ghostscript/gs_utilities.cpp
,
ghostscript.cpp

Calls to the Ghostscript executable for PostScript and PDF files (USE_GS), and, for the X11 port, the rendering of PostScript into pixmaps.

Plugins/Imlib2/imlib2.cpp

Optional dynamically loaded Imlib2 support for the X11 port.

Plugins/MacOS/mac_images.mm

Image sizes and conversion to PNG with the macOS frameworks, used only when TeXmacs is not built with Qt 6.

Plugins/Pdf/pdf_hummus_renderer.cpp

The image related parts of the PDF renderer: pdf_image_rep, image and pattern pools, hummus_pdf_image_size.

Plugins/Pdf/pdf_hummus_make_attachment.cpp
,
pdf_hummus_extract_attachment.cpp

Embedding files into PDF files and extracting them again.

Plugins/Cairo/

A Cairo renderer, only compiled with USE_CAIRO, which the CMake build does not set.

Typeset/Concat/concat_active.cpp
,
Typeset/Boxes/Basic/basic_boxes.cpp

The typesetting of the image primitive and the image box.

Graphics/Renderer/renderer.cpp
,
printer.cpp

Background patterns (renderer_rep::clear_pattern) and the PostScript inclusion of images.

Edit/Modify/edit_text.cpp

The insertion of images (edit_text_rep::make_image).

$TEXMACS_PATH/progs/convert/images/init-images.scm

The image formats and the converters between them which call external programs.

$TEXMACS_PATH/progs/convert/images/tmimage.scm

Export of the selection as an image and copy of the selection to the clipboard as an image.

4.Contents of this chapter

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".