Subversion Repositories Scribus

Rev

Rev 292 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
290 Franz 1
%
2
% psi.prolog
3
%
4
% Copyright (C) 1996-2000 by vhf computer GmbH + vhf interservice GmbH
5
% Author:   Georg Fleischmann
6
%
7
% created:  2000-09-09
8
% modified:
9
%
10
% this PostScript code writes a file with the structure below.
11
% # # # # l		(x0 y0 x1 y1) line
12
% # # # # # # # #c	(x0 y0 x1 y1 x2 y2 x3 y3) curve
13
% # w			(width) width
14
% # # # # # co		(c m y k a) color
15
% n			new list
16
% f			list is a filled polygon
17
% s			list is a group
18
% cl			list is a clip list (clip with old clip list and use it)
19
% gs			save current clip list and width to top of stack
20
% gr			use last clip list (on top of stack) and width
21
% # # # # # # # # # #	(x y a b c d e f text font) text
22
%
23
% Adapted for Scribus by Franz Schmid 15.05.2004
24
% Also removed the hardcoded Output Filename
25
% and changed it in a way the -sOutputFile Option of Ghostscript can be used
26
% Speeded up the flattening of Text by removing unneeded calculations.
27
% Changed the Output slightly to ease parsing
28
% m                 moveto
29
% l # # # #         (x0 y0 x1 y1) line
30
% c # # # # # # # # (x0 y0 x1 y1 x2 y2 x3 y3) curve
31
% w #               (width) Linewidth
32
% co # # # # #      (c m y k a) color
33
% n                 new list
34
% f                 list is a filled polygon
35
% s                 list is a stroke path
36
% cp                close current subpath
37
% ci                list is a clip list (clip with old clip list and use it)
38
%
39
% 15.05.2004 Added the Glyphshow Operator.
40
% 17.05.2004 Made clipping working.
41
% 20.05.2004 kshow is working now.
42
 
43
/cfile OutputFile (w) file def
44
/print { cfile exch writestring } bind def
45
 
46
% whether we have to flatten the text
47
/flattenText 1 def
48
 
49
% is a Clipping there
50
/clipCnt 0 def
51
 
52
% remember the current point
53
/currentX 0 def
54
/currentY 0 def
55
 
56
% 1st point of path to close the path
57
/beginX 0 def
58
/beginY 0 def
59
 
60
% dummy for converting strings
61
/str 50 string def
62
 
63
% 0 = mirror at
64
/mirror 0 def
65
 
66
% mirror a at 0
67
/mir
68
{
69
	mirror 0 ne
70
	{	0 exch sub
71
	}if
72
} bind def
73
 
74
% scale
75
/m_a 1 def
76
/m_b 0 def
77
/m_c 0 def
78
/m_d 1 def
79
/m_x 0 def
80
/m_y 0 def
81
/matrix_x	% x y
82
{
83
	% ax + cy + tx
84
	m_c mul exch m_a mul add m_x add
85
} bind def
86
/matrix_y	% x y
87
{
88
	% bx + dy + ty
89
	m_d mul exch m_b mul add m_y add
90
} bind def
91
 
92
/writecurrentcolor
93
{
94
	currentcolorspace 0 get /CIEBasedABC eq
95
	{	currentcolor setrgbcolor
96
	} if
97
 
98
	currentcmykcolor	% -> c m y k
99
	(co )print
100
	3 index str cvs print
101
	( ) print
102
	2 index str cvs print
103
	( ) print
104
	1 index str cvs print
105
	( ) print
106
	str cvs print
107
	( ) print
108
	pop pop pop
109
	.currentopacityalpha	% a
110
	str cvs print
111
	(\n) print
112
} bind def
113
 
114
/writecurrentlinewidth
115
{
116
	userdict begin
117
	currentlinewidth	% w
118
	storeMatrix
119
 
120
	% (wb + wd + wa + wc) / 2
121
	dup dup dup m_b abs mul exch m_d abs mul add  exch m_a abs mul add  exch m_c abs mul add  2 div  abs
122
	(w ) print
123
	str cvs print
124
	(\n) print
125
	end
126
} bind def
127
 
128
/_move	% x y
129
{
130
	userdict begin
131
	(m\n) print
132
	/currentY exch def
133
	/currentX exch def
134
	/beginX currentX def
135
	/beginY currentY def
136
	end
137
} bind def
138
 
139
/_line
140
{
141
	userdict begin
142
	/y1 exch def
143
	/x1 exch def
144
 
145
	% x x1 ne y y1 ne or
146
	currentX x1 sub abs 0.001 gt  currentY y1 sub abs 0.001 gt or
147
	{
148
		(l ) print
149
		currentX currentY matrix_x str cvs print
150
		( ) print
151
		currentX currentY matrix_y str cvs print
152
		( ) print
153
 
154
		x1 y1 matrix_x str cvs print
155
		( ) print
156
		x1 y1 matrix_y str cvs print
157
		(\n) print
158
		/currentX x1 def
159
		/currentY y1 def
160
	}if
161
	end
162
} bind def
163
 
164
/_curve
165
{
166
	userdict begin
167
	% x1 y1 x2 y2 x3 y3
168
	(c ) print
169
	currentX currentY matrix_x str cvs print
170
	( ) print
171
	currentX currentY matrix_y str cvs print
172
	( ) print
173
	5 index 5 index matrix_x str cvs print
174
	( ) print
175
	5 index 5 index matrix_y str cvs print
176
	( ) print
177
	3 index 3 index matrix_x str cvs print
178
	( ) print
179
	3 index 3 index matrix_y str cvs print
180
	( ) print
181
 
182
	/currentY exch def
183
	/currentX exch def
184
 
185
	currentX currentY matrix_x str cvs print
186
	( ) print
187
	currentX currentY matrix_y str cvs print
188
	(\n)print
189
	pop pop pop pop
190
	end
191
} bind def
192
 
193
% modified: 18.10.96
194
/_close
195
{
196
	(cp\n) print
197
	beginX beginY _line
198
} bind def
199
 
200
/storeMatrix
201
{
202
	userdict begin
203
	matrix currentmatrix
204
 
205
	matrix currentmatrix
206
	1 get /m_b exch def
207
	matrix currentmatrix
208
	2 get /m_c exch def
209
	matrix currentmatrix
210
	3 get /m_d exch def
211
	matrix currentmatrix
212
	4 get /m_x exch def
213
	matrix currentmatrix
214
	5 get /m_y exch def
215
	end
216
} bind def
217
 
218
/rectfill
219
{
220
	userdict begin
221
	(n\n)print			% start polygon
222
	writecurrentcolor
223
	writecurrentlinewidth
224
	storeMatrix
225
 
226
	% x y width height
227
	dup type /arraytype ne
228
	{
229
		/hr exch def
230
		/wr exch def
231
		/yr exch def
232
		/xr exch def
233
		xr yr _move
234
		xr wr add yr _line
235
		xr wr add yr hr add _line
236
		xr yr hr add _line
237
		xr yr _line
238
	}
239
	% numarray
240
	% numstring
241
	{
242
		/ar exch def
243
 
244
		{
245
			/n exch def
246
			ar n get /xr exch def
247
			ar n 1 add get /yr exch def
248
			ar n 2 add get /wr exch def
249
			ar n 3 add get /hr exch def
250
			xr yr _move
251
			xr wr add yr _line
252
			xr wr add yr hr add _line
253
			xr yr hr add _line
254
			xr yr _line
255
		} for
256
	}ifelse
257
 
258
	(f\n)print			% close polygon
259
	end
260
} bind def
261
 
262
/rectstroke
263
{
264
	userdict begin
265
	(n\n)print			% start rect
266
	writecurrentcolor
267
	writecurrentlinewidth
268
	storeMatrix
269
 
270
	% x y width height
271
	dup type /arraytype ne
272
	{
273
		/hr exch def
274
		/wr exch def
275
		/yr exch def
276
		/xr exch def
277
		xr yr _move
278
		xr wr add yr _line
279
		xr wr add yr hr add _line
280
		xr yr hr add _line
281
		xr yr _line
282
	}
283
	% numarray
284
	% numstring
285
	{
286
		/ar exch def
287
 
288
		{
289
			/n exch def
290
			ar n get /xr exch def
291
			ar n 1 add get /yr exch def
292
			ar n 2 add get /wr exch def
293
			ar n 3 add get /hr exch def
294
			xr yr _move
295
			xr wr add yr _line
296
			xr wr add yr hr add _line
297
			xr yr hr add _line
298
			xr yr _line
299
		} for
300
	}ifelse
301
	(n\n)print			% stroke rect
302
	end
303
} bind def
304
 
305
/stroke
306
{
307
	(n\n) print
308
	writecurrentcolor
309
	writecurrentlinewidth
310
	clipCnt 1 eq
311
		{ clipsave clip newpath clippath cliprestore } if
312
	storeMatrix
313
	{_move} {_line} {_curve} {_close} pathforall
314
	(s\n)print			% stroke path
315
	newpath
316
} bind def
317
 
318
/eofill
319
{
320
	(n\n) print			% start polygon
321
	writecurrentcolor	% write color
322
	writecurrentlinewidth
323
	clipCnt 1 eq
324
		{ clipsave clip newpath clippath cliprestore } if
325
	storeMatrix			% take transformation, scaling, rotation from PostScript
326
	{_move} {_line} {_curve} {_close} pathforall
327
	(f\n)print			% close polygon
328
 
329
	newpath				% clear stack
330
} bind def
331
 
332
/fill
333
{
334
	eofill
335
} bind def
336
 
337
/clip
338
{
339
	userdict begin
340
	(n\n)print			% start clip polygon
341
 
342
	storeMatrix			% take transformation, scaling, rotation from PostScript
343
	{_move} {_line} {_curve} {_close} pathforall
344
 
345
	(ci\n)print			% close clip polygon begin path
346
						% we have to close the path!!
347
	clip
348
	/clipCnt 1 def
349
	newpath				% clear stack
350
	end
351
} bind def
352
 
353
% we don't clip
354
% because this doesn't work for flattening text (show, charpath) with NeXT PostScript Code
355
/rectclip
356
{
357
	pop pop pop pop
358
} bind def
359
 
360
/stateArray 500 array def
361
/stateTop 0 def
362
/gsave
363
{
364
	userdict begin
365
%	(gs\n) print
366
	stateArray stateTop gstate currentgstate put
367
	/stateTop stateTop 1 add def
368
	end
369
} bind def
370
 
371
/grestore
372
{
373
	userdict begin
374
	stateTop 1 lt
375
	{
376
	}
377
	{
378
%		(gr\n) print
379
		stateArray stateTop 1 sub get setgstate
380
		/stateTop stateTop 1 sub def
381
		stateArray stateTop 0 put
382
	}ifelse
383
	end
384
} bind def
385
 
386
% a bind def of the show operator doesn't work,
387
% so this is our way to get a charpath entry for flattening text
388
/root_charpath
389
{
390
	charpath
391
} bind def
392
 
393
/show
394
{
395
	userdict begin
396
	storeMatrix
397
	currentfont /FontName known
398
	% stack: string
399
	{
400
		currentpoint	% x y
401
		newpath
402
		/clipCnt 0 def
403
		moveto
404
		% we process each char separately to get smaller paths
405
 
406
		{
407
			(n\n)print			% start polygon
408
			writecurrentcolor	% write color
409
			storeMatrix
410
			currentpoint	% x y
411
			newpath			% clear graphic stack
412
			moveto
413
			1 index exch 1 getinterval false root_charpath
414
			{_move} {_line} {_curve} {_close} pathforall
415
			(f\n)print			% close polygon
416
		} for
417
		currentpoint	% x y
418
		newpath				% clear graphic stack (and current point)
419
		moveto
420
	} if
421
	pop
422
	end
423
} def
424
 
425
/ashow
426
{
427
	% ax ay string
428
	exch pop
429
	exch pop
430
	show
431
} bind def
432
 
433
/widthshow	% cx cy char string
434
{
435
	exch pop
436
	exch pop
437
	exch pop
438
	show
439
} bind def
440
 
441
/awidthshow		% cx cy char ax ay string
442
{
443
	exch pop
444
	exch pop
445
	exch pop
446
	exch pop
447
	exch pop
448
	show
449
} bind def
450
 
451
/cshow	% proc string
452
{
453
	exch pop
454
	show
455
} bind def
456
 
457
/kshow	% proc string
458
{
459
	dup length 1 sub
460
	dup 0 ne
461
	{
462
		1 index 0 1 getinterval
463
		show
464
		1 sub
465
		dup 0 ne
466
		{
467
			1 add
468
			1 exch 1 exch
469
			{
470
				dup 1 sub
471
				2 index exch get
472
				2 index 2 index get
473
				4 index exec
474
				1 index exch 1 getinterval
475
				show
476
			} for
477
		} if
478
	}
479
	{
480
		pop dup show
481
	} ifelse
482
	pop pop
483
} bind def
484
 
485
/xshow	% string array
486
{
487
	pop
488
	show
489
} bind def
490
 
491
/xyshow	% string array
492
{
493
	pop
494
	show
495
} bind def
496
 
497
/yshow	% string array
498
{
499
	pop
500
	show
501
} bind def
502
 
503
/ReEnc % newfontname reencodevector origfontdict -> ReEncode -> newfontdict
504
{
505
	userdict begin
506
 dup begin dup maxlength dict begin
507
  { 1 index /FID ne {def} {pop pop} ifelse
508
  } forall
509
  /Encoding exch def
510
  currentdict
511
  end end
512
  definefont
513
	end
514
} bind def
515
 
516
/glyphshow {
517
    save % So can reclaim VM from reencoding
518
    currentfont /Encoding get dup length array copy dup 0 5 -1 roll put
519
    /GlyphShowTempFont exch currentfont ReEnc
520
    setfont
521
    (\000) show
522
	restore
523
} bind def
524