* src/preproc/html/pre-html.cpp (usage): Don't describe options but
[s-roff.git] / tmac / pspic.tmac
blobedaa2ec8686153799db440e85a9a60edab08d484
1 .\" pspic.tmac
2 .\"
3 .\" Define the PSPIC macro.
4 .\"
5 .\" When used other than with -Tps, -Tdvi, -Thtml, or -Txhtml it draws a box
6 .\" around where the picture would go.
7 .\"
8 .\" Usage:
9 .\"
10 .\"   .PSPIC [-L|-R|-I <indent>] <file> [<width> [<height>]]
12 .do if d PSPIC .nx
14 .nr _C \n(.C
15 .cp 0
17 .de PSPIC
18 .  nr ps-offset-mode 0
19 .  \" left-aligned?
20 .  ie '\\$1'-L' \{\
21 .    nr ps-offset-mode 1
22 .    shift
23 .    HTML-DO-IMAGE \\$1 l
24 .  \}
25 .  el \{\
26 .    \" right-aligned?
27 .    ie '\\$1'-R' \{\
28 .      nr ps-offset-mode 2
29 .      shift
30 .      HTML-DO-IMAGE \\$1 r
31 .    \}
32 .    el \{\
33 .      \" indented?
34 .      ie '\\$1'-I' \{\
35 .        nr ps-offset-mode 3
36 .        nr ps-offset (m;\\$2)
37 .        shift 2
38 .        HTML-DO-IMAGE \\$1 i
39 .      \}
40 .      el \
41 .        HTML-DO-IMAGE \\$1 c
42 .    \}
43 .  \}
45 .  br
47 .  \" get bounding box
48 .  psbb \\$1
49 .  if (\\n[llx] : \\n[lly] : \\n[urx] : \\n[ury]) \{\
50 .    nr ps-wid (\\n[urx] - \\n[llx])
51 .    nr ps-ht (\\n[ury] - \\n[lly])
52 .    if (\\n[ps-wid] < 0) \
53 .      nr ps-wid (-\\n[ps-wid])
54 .    if (\\n[ps-ht] < 0) \
55 .      nr ps-ht (-\\n[ps-ht])
57 .    \" if we have a <width> parameter, use it as the final
58 .    \" image width; otherwise we use the image's natural width
59 .    \" or the current line length, whatever is smaller
60 .    ie (\\n[.$] >= 2) \
61 .      nr ps-deswid (i;\\$2)
62 .    el \
63 .      nr ps-deswid ((\\n[.l] - \\n[.i]) <? \\n[ps-wid]p)
65 .    \" compute the final image height (with proper rounding),
66 .    \" based on the image's aspect
67 .    nr ps-desht (\\n[ps-deswid] * 1000 + (\\n[ps-wid] / 2) \
68                   / \\n[ps-wid] * \\n[ps-ht] \
69                   + 500 / 1000)
71 .    \" if we have a <height> parameter, use it as the final
72 .    \" image height in case it is smaller than the height
73 .    \" value we have just computed
74 .    if ((\\n[.$] >= 3) & (\\n[ps-desht] > (i;0\\$3))) \{\
75 .      nr ps-desht (i;\\$3)
76 .      \" recompute the final image width since we always
77 .      \" keep the correct image aspect
78 .      nr ps-deswid (\\n[ps-desht] * 1000 + (\\n[ps-ht] / 2) \
79                      / \\n[ps-ht] * \\n[ps-wid] \
80                      + 500 / 1000)
81 .    \}
83 .    \" reserve vertical space for image
84 .    ne (\\n[ps-desht]u + 1v)
86 .    \" compute image offset w.r.t. the current left margin
87 .    if (\\n[ps-offset-mode] == 0) \
88 .      nr ps-offset (\\n[.l] - \\n[.i] - \\n[ps-deswid] / 2)
89 .    if (\\n[ps-offset-mode] == 1) \
90 .      nr ps-offset 0
91 .    if (\\n[ps-offset-mode] == 2) \
92 .      nr ps-offset (\\n[.l] - \\n[.i] - \\n[ps-deswid])
94 .    ie '\*[.T]'dvi' \{\
95 .      \" prepare values for \special{psfile=...} as needed by dvips
96 .      ie (\\n[ps-wid]p == \\n[ps-deswid]) \{\
97 .        ds ps-scale \" empty
98 .        ds ps-hoffset hoffset=-\\n[llx]
99 .        ds ps-voffset voffset=-\\n[lly]
100 .      \}
101 .      el \{\
102 .        nr ps-scale (\\n[ps-deswid] * 100 / \\n[ps-wid]p)
103 .        nr ps-hoffset (-\\n[llx] * \\n[ps-scale] / 100)
104 .        nr ps-voffset (-\\n[lly] * \\n[ps-scale] / 100)
105 .        ds ps-scale hscale=\\n[ps-scale] vscale=\\n[ps-scale]
106 .        ds ps-hoffset hoffset=\\n[ps-hoffset]
107 .        ds ps-voffset voffset=\\n[ps-voffset]
108 .      \}
110 \h'\\n[ps-offset]u'\
111 \v'\\n[ps-desht]u'\
112 \X'psfile=\\$1 \\*[ps-hoffset] \\*[ps-voffset] \\*[ps-scale]'
113 .    \}
114 .    el \{\
115 .      ie '\*[.T]'ps' \{\
116 .        \" prepare values for grops; the `ps-invis' and `ps-endinvis' escapes
117 .        \" are for groff's -X switch to provide a PS preview with xditview:
118 .        \" it uses -Tps for formatting but xditview can't handle EPS files,
119 .        \" thus alternative code is enclosed between those two escapes
120 .        ds ps-invis \X'ps: invis'
121 .        ds ps-endinvis \X'ps: endinvis'
122 .        ds ps-import \X'ps: import \E$1 \En[llx] \En[lly] \En[urx] \En[ury] \
123                                     \En[ps-deswid] \E*[ps-desht]'
124 .      \}
125 .      el \{\
126 .        ds ps-invis
127 .        ds ps-endinvis
128 .        ds ps-import
129 .      \}
131 .      ie (\\n[.$] >= 3) \
132 .        ds ps-desht \\n[ps-desht]
133 .      el \
134 .        ds ps-desht \" empty
136 \h'\\n[ps-offset]u'\
137 \\*[ps-invis]\
138 \# horizontally, the rectangle is slightly smaller than the image
139 \# to compensate the line thickness (especially needed for TTY devices)
140 \Z'\D'p 0 \\n[ps-desht]u \
141         (\\n[ps-deswid]u - \\n[.H]u) 0 \
142         0 -\\n[ps-desht]u''\
143 \# for convenience we also display the image file name (centered vertically);
144 \Z'\v'((\\n[ps-desht]u / 2u) \
145        + (\w'\\$1'u * 0) \
146        + ((\\n[rst]u + \\n[rsb]u) / 2u))'\h'1m'\\$1'\
147 \\*[ps-endinvis]\
148 \v'\\n[ps-desht]u'\
149 \\*[ps-import]
150 .    \}
152 .    br
153 .    sp \\n[ps-desht]u
154 .  \}
155 .  HTML-IMAGE-END
158 .cp \n[_C]
160 .\" end of pspic.tmac