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