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