groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bitmaps in groff documents


From: G. Branden Robinson
Subject: Re: bitmaps in groff documents
Date: Sun, 4 Jun 2023 09:15:09 -0500

Hi Doug,

At 2023-06-04T06:59:55-0400, Douglas McIlroy wrote:
> >> Does anyone have a recipe for including a bitmap image in a groff
> >> document? I wish to assure that on a raster-printing device the
> >> bitmap is appropriately aligned with that of the device.
> 
> > There is a PSPIC macro which is part of the MM macros (groff_mm)
> > which I use to pull in a picture.
> 
> I use PSPIC regularly.  It is capable of scaling images, but this is
> not the same as aligning bitmaps. I  would like to assure that a
> 1000x1000 bitmap, say, occupies exactly 1000x1000 pixels on the
> display, regardless of the physical size of a pixel. A misaligned
> bitmap produces unwanted artifacts such as. Moiré patterns.
> 
> Of course, on a very high resolution device 1000x1000 pixels may be an
> extreme eye test, but I can deal with that if necessary.

There doesn't appear to be a troff drawing command for this purpose, and
no groff device control command tag for it, either.  Maybe it would be a
nice thing to have.

According to this:

https://stackoverflow.com/questions/15167454/how-include-img-in-postscript

My guess is that you can wrap the guidance above into GNU troff's "ps:
exec" device control command to get what you want.

grops(1) says:

  Device control commands
    grops recognizes device control commands produced by the \X escape
    sequence, but interprets only those that begin with a "ps:" tag.

    \X'ps: exec code'
        Execute the arbitrary PostScript commands code.  The PostScript
        currentpoint is set to the groff drawing position when the \X
        escape sequence is interpreted before executing code.  The
        origin is at the top left corner of the page; x coordinates
        increase to the right, and y coordinates down the page.  A
        procedure u is defined that converts groff basic units to the
        coordinate system in effect (provided the user doesn't change
        the scale).  For example,
            .nr x 1i
            \X'ps: exec \nx u 0 rlineto stroke'
        draws a horizontal line one inch long.
[...]

Since PostScript has machinery for this purpose, I would guess PDF does
too.

TeX DVI reportedly does not.[1]

Maybe someone on this list with experience embedding PostScript commands
into GNU troff documents can advise further; I don't have such yet.

It might be convenient to expose a new device control command extension
for this purpose; we could name its tag 'raster:', maybe.  Possibly it
would take an argument identifying the image format to follow.  The
easiest thing to do at first would be to support only "native", say, and
require the user to pass only the format that the device expects.

I suspect we could finagle such a raster graphics extension into the X11
devices, if someone wanted to go to the trouble (I imagine just dumping
the meaty part of an XPM file into GNU troff output, albeit with each
line prefixed with '+' as described in groff_out(5)).

I don't have any idea about the lbp or lj4 devices.  (I don't know if I
mentioned this to the list, but about a year ago I was able to
test groff Git HEAD on a laser printer that accepts a
LaserJet 4 input stream (HP PCL/PDL, I suppose), and it worked fine.)

The most interesting possibility for my own nefarious plans would be to
support this on terminal devices by converting images to Sixel
graphics[2] in the output driver.

Regards,
Branden

[1] 
https://tex.stackexchange.com/questions/547408/how-to-put-a-picture-inside-a-dvi-file
[2] https://en.wikipedia.org/wiki/Sixel

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]