3 .\" Define the PDFPIC macro.
5 .\" When used other than with gropdf, the image is converted to .eps
6 .\" and processing passed over to PSPIC.
10 .\" .PDFPIC [-L|-R|-C|-I <indent>] <file> [<width> [<height>]]
12 .\" Requires the poppler-utils package (for pdfinfo and pdftops).
13 .\" Requires running groff in unsafe mode.
21 . ab [PDFPIC]: \\$* Aborting.
25 . @abort Use of \\$0 requires giving groff the -U option.
28 . if !'\\*[.T]'pdf' .nr convert-pdf 1
30 . nr pdf-offset-mode 0
34 . nr pdf-offset-mode 1
35 . if \\n[convert-pdf] .ds pspic-args \\$1 \"
41 . nr pdf-offset-mode 2
42 . if \\n[convert-pdf] .ds pspic-args \\$1 \"
48 . nr pdf-offset-mode 3
49 . nr pdf-offset (m;\\$2)
50 . if \\n[convert-pdf] .ds pspic-args \\$1 \\$2 \"
54 . \" centered is the default
56 . if \\n[convert-pdf] .ds pspic-args \\$1 \"
59 . el .nr pdf-offset-mode 0
67 . if !'\\*[is-pdf]'pdf' \
68 . @abort \\$1 at line \\n[.c] is not a PDF file, or lacks a .pdf extension.
70 .\" if driver is not gropdf, convert image to .eps
71 . if \\n[convert-pdf] \{\
73 . substring img-file 0 -5
75 . sy pdftops -eps \\$1
78 . as pspic-args \\*[img-file].eps \\$*
80 . PSPIC \\*[pspic-args]
84 .\" get image dimensions
88 sed -e 's/Page *size: *\\([[:digit:].]*\\) *x *\\([[:digit:].]*\\).*$/\
89 .nr pdf-wid (p;\\1)\\n\
90 .nr pdf-ht (p;\\2)/' \
92 . so /tmp/pdfpic\n[$$]
93 . sy rm /tmp/pdfpic\n[$$]
96 . \" if we have a <width> parameter, use it as the final
97 . \" image width; otherwise we use the image's natural width
98 . \" or the current line length, whatever is smaller
100 . nr pdf-deswid (i;\\$2)
102 . nr pdf-deswid ((\\n[.l] - \\n[.i]) <? \\n[pdf-wid])
104 . \" compute the final image height (with proper rounding),
105 . \" based on the image's aspect
106 . nr pdf-desht (\\n[pdf-deswid] * 1000 + (\\n[pdf-wid] / 2) \
107 / \\n[pdf-wid] * \\n[pdf-ht] \
110 . \" if we have a <height> parameter, use it as the final
111 . \" image height in case it is smaller than the height
112 . \" value we have just computed
113 . if ((\\n[.$] >= 3) & (\\n[pdf-desht] > (i;0\\$3))) \{\
114 . nr pdf-desht (i;\\$3)
115 . \" recompute the final image width since we always
116 . \" keep the correct image aspect
117 . nr pdf-deswid (\\n[pdf-desht] * 1000 + (\\n[pdf-ht] / 2) \
118 / \\n[pdf-ht] * \\n[pdf-wid] \
122 . \" reserve vertical space for image
123 . ne (\\n[pdf-desht]u + 1v)
125 . \" compute image offset w.r.t. the current left margin
126 . if (\\n[pdf-offset-mode] == 0) \
127 . nr pdf-offset (\\n[.l] - \\n[.i] - \\n[pdf-deswid] / 2)
128 . if (\\n[pdf-offset-mode] == 1) \
130 . if (\\n[pdf-offset-mode] == 2) \
131 . nr pdf-offset (\\n[.l] - \\n[.i] - \\n[pdf-deswid])
133 \h'\\n[pdf-offset]u'\
134 \X'pdf: pdfpic \\$1 -L \\n[pdf-deswid]z \\n[pdf-desht]z'
135 . if !r PDFPIC_NOSPACE \{\
136 . sy echo ".nr PDFPIC_NOSPACE 0$GROFF_PDFPIC_NOSPACE" > /tmp/x\n[$$]
140 . if \\n[PDFPIC_NOSPACE]==0 \{\
148 .\" end of pdfpic.tmac