Imported Upstream version 1.23.0
[platform/upstream/groff.git] / tmac / pspic.tmac
1 .\" Define the PSPIC macro.
2 .\"
3 .\" When used with output devices other than ps, dvi, html, or xhtml,
4 .\" draw a box where the picture would go.
5 .\"
6 .\" Usage:
7 .\"
8 .\"   .PSPIC [-L|-R|-C|-I <indentation>] <file> [<width> [<height>]]
9 .
10 .do if d PSPIC .nx
11 .
12 .do nr *groff_pspic_tmac_C \n[.cp]
13 .cp 0
14 .
15 .\" This is called if the `psbb` request returned a bounding box of all
16 .\" zeroes.  It already issues a diagnostic; one can append `ab` to this
17 .\" macro if that should be a fatal error, or redefine it for some other
18 .\" purpose.
19 .de pspic*error-hook
20 ..
21 .
22 .de PSPIC
23 .  nr ps-offset-mode 0
24 .  \" left-aligned?
25 .  ie '\\$1'-L' \{\
26 .    nr ps-offset-mode 1
27 .    shift
28 .    HTML-DO-IMAGE \\$1 l
29 .  \}
30 .  el \{\
31 .    \" right-aligned?
32 .    ie '\\$1'-R' \{\
33 .      nr ps-offset-mode 2
34 .      shift
35 .      HTML-DO-IMAGE \\$1 r
36 .    \}
37 .    el \{\
38 .      \" indented?
39 .      ie '\\$1'-I' \{\
40 .        nr ps-offset-mode 3
41 .        nr ps-offset (m;\\$2)
42 .        shift 2
43 .        HTML-DO-IMAGE \\$1 i
44 .      \}
45 .      el \{\
46 .        \" centered is the default
47 .        if '\\$1'-C' \
48 .          shift
49 .        HTML-DO-IMAGE \\$1 c
50 .      \}
51 .    \}
52 .  \}
53 .
54 .  br
55 .
56 .  \" get bounding box
57 .  psbb \\$1
58 .  ie (\\n[llx] : \\n[lly] : \\n[urx] : \\n[ury]) \{\
59 .    nr ps-wid (\\n[urx] - \\n[llx])
60 .    nr ps-ht (\\n[ury] - \\n[lly])
61 .    if (\\n[ps-wid] < 0) \
62 .      nr ps-wid (-\\n[ps-wid])
63 .    if (\\n[ps-ht] < 0) \
64 .      nr ps-ht (-\\n[ps-ht])
65 .
66 .    \" if we have a <width> parameter, use it as the final
67 .    \" image width; otherwise we use the image's natural width
68 .    \" or the current line length, whatever is smaller
69 .    ie (\\n[.$] >= 2) \
70 .      nr ps-deswid (i;\\$2)
71 .    el \
72 .      nr ps-deswid ((\\n[.l] - \\n[.i]) <? \\n[ps-wid]p)
73 .
74 .    \" compute the final image height (with proper rounding),
75 .    \" based on the image's aspect
76 .    nr ps-desht (\\n[ps-deswid] * 1000 + (\\n[ps-wid] / 2) \
77                   / \\n[ps-wid] * \\n[ps-ht] \
78                   + 500 / 1000)
79 .
80 .    \" if we have a <height> parameter, use it as the final
81 .    \" image height in case it is smaller than the height
82 .    \" value we have just computed
83 .    if ((\\n[.$] >= 3) & (\\n[ps-desht] > (i;0\\$3))) \{\
84 .      nr ps-desht (i;\\$3)
85 .      \" recompute the final image width since we always
86 .      \" keep the correct image aspect
87 .      nr ps-deswid (\\n[ps-desht] * 1000 + (\\n[ps-ht] / 2) \
88                      / \\n[ps-ht] * \\n[ps-wid] \
89                      + 500 / 1000)
90 .    \}
91 .
92 .    \" reserve vertical space for image
93 .    ne (\\n[ps-desht]u + 1v)
94 .
95 .    \" compute image offset w.r.t. the current left margin
96 .    if (\\n[ps-offset-mode] == 0) \
97 .      nr ps-offset (\\n[.l] - \\n[.i] - \\n[ps-deswid] / 2)
98 .    if (\\n[ps-offset-mode] == 1) \
99 .      nr ps-offset 0
100 .    if (\\n[ps-offset-mode] == 2) \
101 .      nr ps-offset (\\n[.l] - \\n[.i] - \\n[ps-deswid])
102 .
103 .    ie '\*[.T]'dvi' \{\
104 .      \" prepare values for \special{psfile=...} as needed by dvips
105 .      ie (\\n[ps-wid]p == \\n[ps-deswid]) \{\
106 .        ds ps-scale \" empty
107 .        ds ps-hoffset hoffset=-\\n[llx]
108 .        ds ps-voffset voffset=-\\n[lly]
109 .      \}
110 .      el \{\
111 .        nr ps-scale (\\n[ps-deswid] * 100 / \\n[ps-wid]p)
112 .        nr ps-hoffset (-\\n[llx] * \\n[ps-scale] / 100)
113 .        nr ps-voffset (-\\n[lly] * \\n[ps-scale] / 100)
114 .        ds ps-scale hscale=\\n[ps-scale] vscale=\\n[ps-scale]
115 .        ds ps-hoffset hoffset=\\n[ps-hoffset]
116 .        ds ps-voffset voffset=\\n[ps-voffset]
117 .      \}
118 .
119 \h'\\n[ps-offset]u'\
120 \v'\\n[ps-desht]u'\
121 \X'psfile=\\$1 \\*[ps-hoffset] \\*[ps-voffset] \\*[ps-scale]'
122 .    \}
123 .    el \{\
124 .      ie '\*[.T]'ps' \{\
125 .        \" prepare values for grops; the 'ps-invis' and 'ps-endinvis'
126 .        \" escapes are for groff's -X switch to provide a PS preview
127 .        \" with xditview: it uses -Tps for formatting but xditview
128 .        \" can't handle EPS files, thus alternative code is enclosed
129 .        \" 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 .      \}
140 .
141 .      ie (\\n[.$] >= 3) \
142 .        ds ps-desht \\n[ps-desht]
143 .      el \
144 .        ds ps-desht \" empty
145 .
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
154 \# vertically);
155 \Z'\v'((\\n[ps-desht]u / 2u) \
156        + (\w'\\$1'u * 0) \
157        + ((\\n[rst]u + \\n[rsb]u) / 2u))'\h'1m'\\$1'\
158 \\*[ps-endinvis]\
159 \v'\\n[ps-desht]u'\
160 \\*[ps-import]
161 .    \}
162 .
163 .    br
164 .    sp \\n[ps-desht]u
165 .  \}
166 .  el \
167 .    pspic*error-hook \\$@
168 .  HTML-IMAGE-END
169 ..
170 .
171 .cp \n[*groff_pspic_tmac_C]
172 .do rr *groff_pspic_tmac_C
173 .
174 .\" Local Variables:
175 .\" mode: nroff
176 .\" fill-column: 72
177 .\" End:
178 .\" vim: set expandtab filetype=groff tabstop=2 textwidth=72: