3 # Creates Postscript encoding vector for given encoding
6 proc ::tk::CreatePostscriptEncoding {encoding} {
7 # now check for known. Even if it is known, it can be other
8 # than we need. GhostScript seems to be happy with such approach
9 set result
"/CurrentEncoding \[\n"
10 for {set i
0} {$i<256} {incr i
8} {
11 for {set j
0} {$j<8} {incr j
} {
12 set enc
[encoding convertfrom
$encoding [format %c
[expr {$i+$j}]]]
13 if {[catch {format %04X
[scan $enc %c
]} hexcode
]} {set hexcode
{}}
14 if [info exists
::tk::psglyphs($hexcode)] {
15 append result
"/$::tk::psglyphs($hexcode)"
17 append result
"/space"
22 append result
"\] def\n"
26 # List of adobe glyph names. Converted from glyphlist.txt, downloaded
393 0390 iotadieresistonos
424 03B0 upsilondieresistonos
727 207D parenleftsuperior
728 207E parenrightsuperior
740 208D parenleftinferior
741 208E parenrightinferior
933 F6DE threequartersemdash
959 F6F8 Hungarumlautsmall
1008 F7A1 exclamdownsmall
1014 F7BF questiondownsmall
1017 F7E2 Acircumflexsmall
1025 F7EA Ecircumflexsmall
1029 F7EE Icircumflexsmall
1035 F7F4 Ocircumflexsmall
1041 F7FB Ucircumflexsmall
1084 # precalculate entire prolog when this file is loaded
1085 # (to speed things up)
1086 set ps_preamable
"%%BeginProlog\n"
1087 append ps_preamable
[CreatePostscriptEncoding
[encoding system
]]
1088 append ps_preamable
{
1090 % This is a standard prolog
for Postscript generated by Tk's
canvas
1092 % RCS
: @(#) $Id: mkpsenc.tcl,v 1.3 2002/07/19 14:37:21 drh Exp $
1094 % The definitions below just define all of the variables used in
1095 % any of the procedures here. This is needed
for obscure reasons
1096 % explained on p.
716 of the Postscript manual
(Section H
.2.7,
1097 % "Initializing Variables," in the section on Encapsulated Postscript
).
1114 dup type
/stringtype eq
1115 { show
} { glyphshow
}
1126 dup type
/stringtype eq
1128 currentfont
/Encoding get exch
1 exch put
(\001) stringwidth
1131 exch
3 1 roll add
3 1 roll add exch
1136 % font ISOEncode
font
1137 % This procedure changes the
encoding of a
font from the
default
1138 % Postscript
encoding to current system
encoding. It's typically invoked just
1139 % before invoking
"setfont". The body of this procedure comes from
1140 % Section
5.6.1 of the Postscript book.
1143 dup length dict begin
1144 {1 index
/FID ne
{def
} {pop pop
} ifelse
} forall
1145 /Encoding CurrentEncoding def
1149 % I'm not sure why it's necessary to use
"definefont" on this new
1150 % font, but it seems to be important
; just use the name
"Temporary"
1153 /Temporary exch definefont
1158 % This procedure converts the current path into a clip area under
1159 % the assumption of stroking. It's a bit tricky because some Postscript
1160 % interpreters get errors during strokepath
for dashed lines. If
1161 % this happens then turn off dashes and try again.
1164 {strokepath
} stopped
{
1165 (This Postscript printer
gets limitcheck overflows when
) =
1166 (stippling dashed lines
; lines will be printed solid instead.
) =
1167 [] 0 setdash strokepath
} if
1171 % desiredSize EvenPixels closestSize
1173 % The procedure below is used
for stippling. Given the optimal size
1174 % of a dot in a stipple pattern in the current user coordinate system
,
1175 % compute the closest size that is an exact multiple of the device's
1176 % pixel size. This allows stipple patterns to be displayed without
1180 % Compute exact number of device pixels per stipple dot.
1181 dup
0 matrix currentmatrix dtransform
1182 dup mul exch dup mul add sqrt
1184 % Round to an integer
, make sure the number is at least
1, and compute
1185 % user coord distance corresponding to this.
1186 dup round dup
1 lt
{pop
1} if
1190 % width height
string StippleFill
--
1192 % Given a path already
set up and a clipping region generated from
1193 % it
, this procedure will fill the clipping region with a stipple
1194 % pattern.
"String" contains a proper
image description of the
1195 % stipple pattern and
"width" and
"height" give its dimensions. Each
1196 % stipple dot is assumed to be about one unit across in the current
1197 % user coordinate system. This procedure trashes the graphics state.
1200 % The following code is needed to work around a NeWSprint bug.
1202 /tmpstip
1 index def
1204 % Change the scaling so that one user unit in user coordinates
1205 % corresponds to the size of one stipple dot.
1206 1 EvenPixels dup
scale
1208 % Compute the bounding box occupied by the path
(which is now
1209 % the clipping region
), and round the
lower coordinates down
1210 % to the nearest starting point
for the stipple pattern. Be
1211 % careful about negative numbers
, since the rounding works
1212 % differently on them.
1216 5 index div dup
0 lt
{1 sub
} if cvi
5 index mul
4 1 roll
1217 6 index div dup
0 lt
{1 sub
} if cvi
6 index mul
3 2 roll
1219 % Stack now
: width height
string y1 y2 x1 x2
1220 % Below is a doubly-nested
for loop to iterate across this area
1221 % in units of the stipple pattern size
, going up columns then
1222 % across rows
, blasting out a stipple-pattern-sized rectangle at
1226 2 index
5 index
3 index
{
1227 % Stack now
: width height
string y1 y2 x y
1230 1 index exch translate
1231 5 index
5 index true matrix tmpstip imagemask
1240 % Given a color value already
set for output by the caller
, adjusts
1241 % that value to a grayscale or mono value
if requested by the CL
1248 .5 lt
{0} {1} ifelse
1254 % x y strings spacing xoffset yoffset justify stipple DrawText
--
1255 % This procedure does all of the real work of drawing
text. The
1256 % color and
font must already have been
set by the caller
, and the
1257 % following arguments must be on the stack
:
1259 % x
, y
- Coordinates at which to draw
text.
1260 % strings
- An
array of strings
, one
for each line of the
text item
,
1261 % in order from top to bottom.
1262 % spacing
- Spacing between lines.
1263 % xoffset
- Horizontal offset
for text bbox relative to x and y
: 0 for
1264 % nw
/w
/sw anchor
, -0.5
for n
/center
/s
, and
-1.0
for ne
/e
/se.
1265 % yoffset
- Vertical offset
for text bbox relative to x and y
: 0 for
1266 % nw
/n
/ne anchor
, +0.5 for w
/center
/e
, and
+1.0 for sw
/s
/se.
1267 % justify
- 0 for left justification
, 0.5 for center
, 1 for right justify.
1268 % stipple
- Boolean value indicating whether or not
text is to be
1269 % drawn in stippled fashion. If
text is stippled
,
1270 % procedure StippleText must have been defined to call
1271 % StippleFill in the right way.
1273 % Also
, when this procedure is invoked
, the color and
font must already
1274 % have been
set for the
text.
1284 % First
scan through all of the
text to find the widest line.
1289 dup lineLength gt
{/lineLength exch def
} {pop
} ifelse
1293 % Compute the baseline offset and the actual
font height.
1295 0 0 moveto
(TXygqPZ
) false charpath
1296 pathbbox dup
/baseline exch def
1297 exch pop exch sub
/height exch def pop
1300 % Translate coordinates first so that the origin is at the upper-left
1301 % corner of the
text's bounding box. Remember that x and y
for
1302 % positioning are still on the stack.
1305 lineLength xoffset mul
1306 strings length
1 sub spacing mul height add yoffset mul translate
1308 % Now use the baseline and justification information to translate so
1309 % that the origin is at the baseline and positioning point
for the
1310 % first line of
text.
1312 justify lineLength mul baseline neg translate
1314 % Iterate over each of the lines to output it. For each line
,
1315 % compute its width again so it can be properly justified
, then
1319 dup cstringwidth pop
1320 justify neg mul
0 moveto
1324 % The
text is stippled
, so turn it into a path and print
1325 % by calling StippledText
, which in turn calls StippleFill.
1326 % Unfortunately
, many Postscript interpreters will get
1327 % overflow errors
if we try to do the whole
string at
1328 % once
, so do it a character at a
time.
1333 dup type
/stringtype eq
{
1334 % This segment is a
string.
1336 char
0 3 -1 roll put
1339 char true charpath clip StippleText
1341 char stringwidth translate
1345 % This segment is glyph name
1346 % Temporary override
1347 currentfont
/Encoding get exch
1 exch put
1349 gsave
(\001) true charpath clip StippleText
1351 (\001) stringwidth translate
1356 } {cstringshow
} ifelse
1357 0 spacing neg translate
1366 proc tk::ensure_psenc_is_loaded {} {