![]() |
Images in documents | ![]() |
An image is included with
<image|file|width|height|x-offset|y-offset> |
(see graphics primitives for the user level description). It is typeset by concater_rep::typeset_image in
Typeset/Concat/concat_active.cpp
, which requires exactly five arguments and proceeds as follows.
If the first argument is a tuple (tuple (raw-data bytes) name), the image is embedded in the document. It is then designated by a ramdisc URL (url_ramdisc,
System/Classes/url.cpp
) whose root holds the bytes themselves, followed by the file name image.name, so that the suffix of the original file determines the format. The file functions (load_string, exists, …) recognize such URLs, and the converters which need a real file materialize them into temporary files.
Typeset/Boxes/Basic/basic_boxes.cpp
) creates an image_box_rep, which holds a scalable obtained from load_scalable_image (u, w, h, "", pixel) and the current opacity. Its extents are those of the scalable image, and its display method calls ren->draw_scalable. Nothing is loaded or rasterized at typesetting time: only the size of the file is needed. The animation boxes (
Typeset/Boxes/Animate/animate_boxes.cpp
) use image_box too.
Other ways of including images in a document, which are not covered here, are the images inside pictures of the graphics editor (see the graphics editor), and images used as backgrounds (next section).
The background of a box, a page or a table cell may be a pattern, a tree (pattern url width height [effect]) stored in a pattern brush. Patterns are drawn by renderer_rep::clear_pattern (
Graphics/Renderer/renderer.cpp
):
the original size of the image is computed with image_size, at 600 dots per inch;
the size of one tile is the original size when the width or height is empty, an integer number of logical units, a percentage of the area to be filled, or, with the @ suffix, a percentage of the other dimension multiplied or divided by the aspect ratio of the image; it is rounded up to whole pixels;
a scalable image of the tile size, with the effect of the pattern, is created, and every tile which meets both the area and the clipping rectangle is drawn with draw_scalable.
The Scheme side of patterns (the pattern and gradient selectors of the format menus) is in
generic/pattern-selector.scm
and
generic/pattern-tools.scm
. The PDF renderer does not use clear_pattern: it turns patterns into PDF tiling patterns (see images in PDF output).
The Insert\(\rightarrow\)Image menu (
generic/insert-menu.scm
) offers Link image and Insert image, which call make-link-image and make-inline-image (
generic/generic-edit.scm
) through the file chooser. Both call the editor routine edit_text_rep::make_image (file, link, w, h, x, y) (
Edit/Modify/edit_text.cpp
), with the name made relative to the current buffer:
The image tag contains the file name. Local absolute names are rerooted to file:, and the name is converted to Cork encoding.
The file is read into memory and the tag contains (tuple (raw-data bytes) name), where name is the last component of the file name. A missing file or a file without suffix is refused with a message in the footer.
The width and height proposed by the file chooser come from qt_pretty_image_size. When files are dropped on a document, the image names of the dropped content are made relative to the document if possible (relativize in
Edit/Interface/edit_mouse.cpp
).
The editor can typeset a fragment and save it as an image: edit_main_rep::print_snippet produces EPS or PDF through a printer renderer, or a bitmap through a picture renderer (see renderers at work, section “printing and export”). Its Scheme wrapper is print-snippet, which returns the extents and the baseline of the typeset fragment.
$TEXMACS_PATH/progs/convert/images/tmimage.scm uses it for two commands:
Export the selection to a file whose format is given by its suffix, or by the preference texmacs->image:format when the name has none (SVG if a PDF to SVG converter exists, PDF otherwise). The selection is wrapped in a minimal table or a document-at so that the image has the width of the material and, for single lines, a known baseline; mathematics keeps its inline or display style. For SVG, the TeXmacs source of the selection is embedded in the image so that it can be edited again from Inkscape (refactor-svg); for PDF, it is attached as a TeXmacs document (embbed-tm-selection-in-pdf, see PDF attachments).
Export the selection to a temporary file in the preferred format and put it on the clipboard (Qt only).
In renderer_rep::clear_pattern (
Graphics/Renderer/renderer.cpp:408
), the height of a tile is set to the image height when pattern[1] (the width) is empty, instead of testing pattern[2]. A pattern with an empty height and an explicit width gets the height of the whole area, and a pattern with an empty width and an explicit height ignores that height.
When the format requested in export-selection-as-graphics has no converter, the code falls back on PDF by rebuilding the file name from (substring surl (- sl sufl) sl), which is the suffix of the name rather than the part before it (
tmimage.scm:259
). Exporting a/b.png without a PDF to PNG converter therefore writes a file called pngpdf in the current directory.
typeset_gr_effect and typeset_gr_transform (
Typeset/Concat/concat_graphics.cpp:199
, 211) call typeset_error on a wrong number of arguments but do not return, and then read the missing arguments.
An embedded image is stored with its whole file name, and the ramdisc URL is image.name, for instance image.photo.png. Only the last suffix matters, so this works, but code which inspects these names must not assume that the part after image. is a suffix.
The image size is taken from the size cache. If an image file is replaced by a file with another aspect ratio, the image is drawn with the old proportions until the document is typeset again.