Subversion Repositories Scribus

Rev

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