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