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