Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
6455 fschmid 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
 
11
%%% this file also contains a section taken from GPL Ghostscript 8.50 "traceimg.ps", see below
12
 
13
% this PostScript code writes a file with the structure below.
14
% # # # # l		(x0 y0 x1 y1) line
15
% # # # # # # # #c	(x0 y0 x1 y1 x2 y2 x3 y3) curve
16
% # w			(width) width
17
% # # # # # co		(c m y k a) color
18
% n			new list
19
% f			list is a filled polygon
20
% s			list is a group
21
% cl			list is a clip list (clip with old clip list and use it)
22
% gs			save current clip list and width to top of stack
23
% gr			use last clip list (on top of stack) and width
24
% # # # # # # # # # #	(x y a b c d e f text font) text
25
%
26
% Adapted for Scribus by Franz Schmid 15.05.2004
27
% Also removed the hardcoded Output Filename
28
% and changed it in a way the -sOutputFile Option of Ghostscript can be used
29
% Speeded up the flattening of Text by removing unneeded calculations.
30
% Changed the Output slightly to ease parsing
31
% m                 moveto
32
% l # # # #         (x0 y0 x1 y1) line
33
% c # # # # # # # # (x0 y0 x1 y1 x2 y2 x3 y3) curve
34
% w #               (width) Linewidth
35
% co # # # # #      (c m y k a) color
36
% n                 new list
37
% f                 list is a filled polygon
38
% s                 list is a stroke path
39
% cp                close current subpath
40
% ci                list is a clip list (clip with old clip list and use it)
41
% sp                end of page
42
% lj #              linejoin
43
% lc #              linecap
44
% ld # # #n         linedash count offset d1, d2, dx
45
% im #              image <name>
46
% pat # #           makepattern params tmpfilename
47
% mask				imagemask, followed by b/w image
48
% fill-evenodd		set fill rule
49
% fill-winding		- " -
50
% 15.05.2004 Added the Glyphshow Operator.
51
% 17.05.2004 Made clipping working.
52
% 20.05.2004 kshow is working now.
53
% 22.02.2006 added image and colorimage ops -- av
54
% 02.03.2006 added code to divide reported coordinates by (device resolution/72) -- av
55
% 23.03.2006 added code to trace PDF commands
56
 
57
% some hacks to get access to PDF operators, needs -sDELAYBIND
58
 
59
currentglobal true setglobal
60
GS_PDF_ProcSet begin
61
currentdict /setshowstate
62
{
63
	dup WordSpacing 0 32 TextSpacing 0 6 -1 roll awidthshow
64
	//setshowstate exec
65
} .forceput
66
currentdict /endpage {
67
	(sp\n) print
68
	//endpage exec
69
} .forceput
70
currentdict /doimage known not {
71
	currentdict /doimage { } .forceput
72
} if
73
currentdict /doimage {
74
	currentdict i_image
75
	//doimage exec
76
} .forceput
77
end
78
setglobal
79
.bindnow
80
 
81
/cfile TraceFile (w) file def
82
/print { cfile exch writestring } bind def
83
 
84
 
85
/==write  % any ==write -
86
{
87
	dup type dup /arraytype eq exch /packedarraytype eq or
88
	{
89
		i_file ([) writestring
90
			{ ==write i_file ( ) writestring } forall
91
		i_file (]) writestring
92
	} {
93
	dup type /nametype eq
94
	{
95
		i_file (/) writestring i_file exch i_str cvs writestring
96
	} {
97
	dup type /stringtype eq
98
	{
99
		true 1 index { 32 ge and } forall
100
		{
101
			i_file (\() writestring i_file exch writestring i_file (\)) writestring
102
		}
103
		{
104
			i_file (<) writestring
105
			i_file /ASCIIHexEncode filter dup
106
			3 -1 roll
107
			writestring closefile % close filter
108
			i_file (\n) writestring
109
		} ifelse
110
	} {
111
	dup type /dicttype eq
112
	{
113
		i_file (<<) writestring
114
		{ ==write ( ) =write ==write (\n) =write } forall
115
		i_file (>>) writestring
116
	} {
117
		i_file exch i_str cvs
118
		dup dup length 1 sub get (-) 0 get eq { pop (null) } if
119
		writestring
120
	} ifelse } ifelse } ifelse } ifelse
121
} def
122
 
123
/=write  % any =write -
124
{
125
	dup type dup /arraytype eq exch /packedarraytype eq or
126
	{
127
			{ =write i_file ( ) writestring } forall
128
	} {
129
	dup type /nametype eq
130
	{
131
		i_file exch i_str cvs writestring
132
	} {
133
	dup type /stringtype eq
134
	{
135
		i_file exch writestring
136
	} {
137
	dup type /dicttype eq
138
	{
139
		i_file (<<) writestring
140
		{ =write ( ) =write =write (\n) =write } forall
141
		i_file (>>) writestring
142
	} {
143
		i_file exch i_str cvs writestring
144
	} ifelse } ifelse } ifelse } ifelse
145
} def
146
 
147
 
148
% flag to deactivate our substitutions
149
/i_shortcut false def
150
 
151
% defines an overloaded function     name proc i_shortcutOverload -
152
% equvalent to /name { i_shortcut { //name } { proc } ifelse } bind def
153
/i_shortcutOverload
154
{
155
	[ /i_shortcut /load load [ 5 index load ] cvx 4 index /ifelse load ] cvx
156
	exch pop
157
	bind def
158
} def
159
 
160
% whether we have to flatten the text
161
/flattenText 1 def
162
 
163
% is a Clipping there
164
/clipCnt 0 def
165
 
166
% remember the current point
167
/currentX 0 def
168
/currentY 0 def
169
 
170
% 1st point of path to close the path
171
/beginX 0 def
172
/beginY 0 def
173
 
174
% dummy for converting strings
175
/i_str 50 string def
176
 
177
% 0 = mirror at
178
/mirror 0 def
179
 
180
% mirror a at 0
181
/mir
182
{
183
	mirror 0 ne
184
	{	0 exch sub
185
	}if
186
} bind def
187
 
188
% scale
189
 
190
currentpagedevice /HWResolution get aload pop
191
72 div /i_vscale exch def
192
72 div /i_hscale exch def
193
 
194
/m_a 1 def
195
/m_b 0 def
196
/m_c 0 def
197
/m_d 1 def
198
/m_x 0 def
199
/m_y 0 def
200
/matrix_x	% x y
201
{
202
	% ax + cy + tx
203
	m_c mul exch m_a mul add m_x add i_hscale div
204
} bind def
205
/matrix_y	% x y
206
{
207
	% bx + dy + ty
208
	m_d mul exch m_b mul add m_y add i_vscale div
209
} bind def
210
 
211
 
212
/concatenate   % str1 str2 concatenate str12
213
{
214
	dup length 2 index length add string
215
	dup 3 index length 3 index putinterval
216
	dup 0 4 index putinterval
217
	exch pop exch pop
218
} bind def
219
 
220
% this is like search but returns the last match in string
221
/rsearch	% string seek  rsearch  post match pre true // string false
222
{
223
	2 copy search	% string seek post1 match1 pre1 true
224
	{
225
		2 index 4 index rsearch		% string seek post1 match1 pre1 post2 match2 pre2 true
226
		{
227
			6 -1 roll pop			% string seek match1 pre1 post2 match2 pre2
228
			% combine (pre1 match1 pre2) into one string
229
			5 -1 roll exch concatenate	% string seek pre1 post2 match2 (match1+pre2)
230
			4 -1 roll exch concatenate	% string seek post2 match2 (pre1+match1+pre2)
231
		} {		% string seek post1 match1 pre1 post1
232
			pop
233
		} ifelse
234
		% string seek post match pre
235
		5 -2 roll pop pop
236
		true
237
	} {		% string seek string
238
		pop pop false
239
	} ifelse
240
} bind def
241
 
242
 
243
% returns a unique filename for the given extension
244
/i_exportfilename   % string i_exportfilename string
245
{
246
	/ExportFiles where { /ExportFiles get (.) rsearch { exch pop exch pop } if } { (imagefile) } ifelse
247
	    (-) concatenate dup /i_basename exch def i_filecount 9 string cvs concatenate
248
		{
249
			i_filecount 1 add /i_filecount exch store
250
			dup 2 index concatenate status not { exit } if
251
			pop pop pop pop pop
252
			i_basename i_filecount 9 string cvs concatenate
253
		} loop
254
	exch pop
255
} bind def
256
 
257
/makepattern { % dict matrix  makepattern patterndict
258
%/makepattern =
259
	% we will do some real painting here:
260
	/i_shortcut true store
261
	% params:
262
	/i_m exch def
263
	/i_dict exch def
264
	% define export filename
265
	/i_basename (.png) i_exportfilename (.png) concatenate def
266
	i_dict /BBox get
267
		dup 0 get /i_x exch def
268
		dup 1 get /i_y exch def
269
		dup 2 get i_x sub /i_w exch def
270
		3 get i_y sub /i_h exch def
271
	% we want those in devspace:
272
		i_x i_y i_m itransform matrix currentmatrix transform
273
			i_vscale div /i_y exch def i_hscale div /i_x exch def
274
		i_w i_h i_m idtransform matrix currentmatrix dtransform
275
			i_vscale div /i_h exch def i_hscale div /i_w exch def
276
		% i_h < 0 ?
277
		i_h 0 le
278
		{
279
			/i_y i_h i_y add def
280
			/i_h i_h neg def
281
		} if
282
		% i_w < 0 ?
283
		i_w 0 le
284
		{
285
			/i_x i_w i_x add def
286
			/i_w i_w neg def
287
		} if
288
	% now we can use the current matrix as pattern matrix, but with (0,0) origin
289
	i_m ==
290
	i_x i_y matrix currentmatrix translate /i_m exch def
291
	i_m ==
292
	i_dict /BBox [ 0 0 i_w i_h ] put
293
	(w x h =) = i_w = i_h =
294
	% paint pattern to png file
295
	gsave
296
	currentcolor currentcolorspace
297
	<<
298
		/OutputFile i_basename
299
		/OutputDevice (pngalpha)
300
		/TextAlphaBits 4
301
		/GraphicsAlphaBits 4
302
%		/BackgroundColor 16777215
303
%		/BackgroundColor 0
304
		/PageUsesTransparency true
305
		/HWResolution [ 72 72 ]
306
		/ProcessColorModel /DeviceRGB
307
		/PageSize [i_w i_h]
308
	/pngalpha finddevice putdeviceprops setdevice
309
	setcolorspace setcolor
310
%	matrix currentmatrix ==
311
%	0 0 transform exch = =
312
%	1 1 transform exch = =
313
	i_dict i_w i_h matrix identmatrix scale
314
			%matrix identmatrix
315
			//makepattern setpattern
316
 
317
	showpage
318
	grestore
319
	% create pattern with our extensions:
320
	i_dict dup /ExportFile i_basename put
321
	dup /Origin [ 0 0 transform ] put
322
	i_m //makepattern
323
	/i_shortcut false store
324
%/makepatternE =
325
} i_shortcutOverload
326
 
327
/writecurrentpattern
328
{
329
	currentcolor
330
	(pat ) print
331
	dup /Origin get
332
	dup 0 get i_hscale div i_str cvs print ( ) print
333
	    1 get i_vscale div i_str cvs print ( ) print
334
	/ExportFile get print
335
	(\n) print
336
} bind def
337
 
338
/writecurrentcmykcolor
339
{
340
	currentcmykcolor	% -> c m y k
341
	(co )print
342
	3 index i_str cvs print
343
	( ) print
344
	2 index i_str cvs print
345
	( ) print
346
	1 index i_str cvs print
347
	( ) print
348
	i_str cvs print
349
	( ) print
350
	pop pop pop
351
	.currentopacityalpha	% a
352
	i_str cvs print
353
	(\n) print
354
} bind def
355
 
356
 
357
/writecurrentrgbcolor
358
{
359
	currentrgbcolor	% -> r g b
360
	(corgb )print
361
	2 index i_str cvs print
362
	( ) print
363
	1 index i_str cvs print
364
	( ) print
365
	i_str cvs print
366
	( ) print
367
	pop pop
368
	.currentopacityalpha	% a
369
	i_str cvs print
370
	(\n) print
371
} bind def
372
 
373
 
374
/writecurrentcolor
375
{
376
	currentcolorspace 0 get
377
 
378
	% try to find a base colorspace first
379
	dup	/Indexed eq
380
	{
381
		pop
382
		currentcolorspace 1 get
383
		dup type /arraytype eq { 0 get } if
384
	} if
385
 
386
	dup dup /DeviceN eq exch /Separation eq or
387
	{
388
		pop
389
		currentcolorspace 2 get
390
		dup type /arraytype eq { 0 get } if
391
	} if
392
 
393
	% now write values
394
	dup /CIEBasedABC eq
395
	{ % this must be a hack....
396
		gsave
397
		currentcolor setrgbcolor
398
		writecurrentrgbcolor
399
		grestore
400
	} {
401
 	dup /DeviceRGB eq
402
	{
403
		writecurrentrgbcolor
404
	} {
405
	dup dup /DeviceCMYK eq exch /DeviceGray eq or
406
	{
407
		writecurrentcmykcolor
408
	} {
409
	dup /Pattern eq
410
	{
411
		writecurrentpattern
412
	} {
413
		% TODO: other CIE
414
		writecurrentrgbcolor % will always be 0
415
	}
416
	ifelse } ifelse } ifelse } ifelse
417
	pop
418
} bind def
419
 
420
/writecurrentlinecap
421
{
422
	(lc ) print
423
	currentlinecap i_str cvs print
424
	(\n) print
425
} bind def
426
 
427
/writecurrentlinejoin
428
{
429
	(lj ) print
430
	currentlinejoin i_str cvs print
431
	(\n) print
432
} bind def
433
 
434
/writecurrentdash
435
{
436
	(ld ) print
437
	currentdash 1 index length i_str cvs print ( ) print i_str cvs print ( ) print
438
 
439
	{
440
		1 index exch get i_str cvs print ( ) print
441
	} for
442
	pop
443
	(\n) print
444
} bind def
445
 
446
/writecurrentlinewidth
447
{
448
	userdict begin
449
	currentlinewidth	% w
450
	storeMatrix
451
 
452
	% (wb + wd + wa + wc) / 2
453
%??
454
	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
455
	i_hscale div
456
	% transform (w,w) and take length
457
%av-test:	dup dtransform i_vscale div dup mul exch i_hscale div dup mul add sqrt
458
	(w ) print
459
	i_str cvs print
460
	(\n) print
461
	end
462
} bind def
463
 
464
/i_move	% x y
465
{
466
	userdict begin
467
	(m\n) print
468
	/currentY exch def
469
	/currentX exch def
470
	/beginX currentX def
471
	/beginY currentY def
472
	end
473
} bind def
474
 
475
/i_line
476
{
477
	userdict begin
478
	/y1 exch def
479
	/x1 exch def
480
 
481
	% x x1 ne y y1 ne or
482
	currentX x1 sub abs 0.001 gt  currentY y1 sub abs 0.001 gt or
483
	{
484
		(l ) print
485
		currentX currentY matrix_x i_str cvs print
486
		( ) print
487
		currentX currentY matrix_y i_str cvs print
488
		( ) print
489
 
490
		x1 y1 matrix_x i_str cvs print
491
		( ) print
492
		x1 y1 matrix_y i_str cvs print
493
		(\n) print
494
		/currentX x1 def
495
		/currentY y1 def
496
	}if
497
	end
498
} bind def
499
 
500
/i_curve
501
{
502
	userdict begin
503
	% x1 y1 x2 y2 x3 y3
504
	(c ) print
505
	currentX currentY matrix_x i_str cvs print
506
	( ) print
507
	currentX currentY matrix_y i_str cvs print
508
	( ) print
509
	5 index 5 index matrix_x i_str cvs print
510
	( ) print
511
	5 index 5 index matrix_y i_str cvs print
512
	( ) print
513
	3 index 3 index matrix_x i_str cvs print
514
	( ) print
515
	3 index 3 index matrix_y i_str cvs print
516
	( ) print
517
 
518
	/currentY exch def
519
	/currentX exch def
520
 
521
	currentX currentY matrix_x i_str cvs print
522
	( ) print
523
	currentX currentY matrix_y i_str cvs print
524
	(\n)print
525
	pop pop pop pop
526
	end
527
} bind def
528
 
529
% modified: 18.10.96
530
/i_close
531
{
532
	(cp\n) print
533
	beginX beginY i_line
534
} bind def
535
 
536
/storeMatrix
537
{
538
	userdict begin
539
	matrix currentmatrix
540
	dup 0 get /m_a exch def
541
	dup 1 get /m_b exch def
542
	dup 2 get /m_c exch def
543
	dup 3 get /m_d exch def
544
	dup 4 get /m_x exch def
545
	5 get /m_y exch def
546
	end
547
} bind def
548
 
549
/pathClipAndClose % this is not nice: closes all open paths & flattens the path :-(
550
{
551
	clipsave
552
	clip				% combine clippath and path
553
	newpath clippath	% copy (closed) clippath to path
554
	cliprestore
555
} bind def
556
 
557
 
558
% find out if the point is within the clipping area
559
/i_in_clip					% x y  i_in_clip  bool
560
{
561
	gsave
562
	newpath clippath
563
	infill
564
	grestore
565
} bind def
566
 
567
 
568
% find out if two points are within the clipping area
569
/i_in_clip2					% x1 y1 x2 y2 i_in_clip  bool1 bool2
570
{
571
	gsave
572
	newpath clippath
573
	infill					% x1 y1 bool2
574
	3 1 roll				% bool2 x1 y1
575
	infill					% bool2 bool1
576
	exch
577
	grestore
578
} bind def
579
 
580
 
581
/i_clip_move
582
{
583
	/beginY exch store
584
	/beginX exch store
585
	/currentX beginX store
586
	/currentY beginY store
587
	% test if within cliparea
588
	currentX currentY i_in_clip
589
	{
590
		currentX currentY /moveto load
591
	} if
592
} bind def
593
 
594
 
595
% find intersection with line x1,y1 -> x2,y2 with clip path.
596
% x1,y2 is outside the clip area, x2, y2, x3, y3 inside
597
 
598
/i_find_clip_intersect		% x1 y1 x2 y2  i_find_clip_intersect  x3 y3
599
{
600
	3 index 2 index sub		% x1 y1 x2 y2 dx
601
	3 index 2 index sub		% x1 y1 x2 y2 dx dy
602
	gsave
603
	newpath clippath
604
	{
605
		2 div exch 2 div exch				% half interval
606
		2 copy abs 0.01 lt exch abs 0.01 lt and
607
			{ exit } if						% done
608
		2 copy 4 index add exch				% x1 y1 x2 y2 dx dy (y2+dy) dx
609
		       5 index add exch				% x1 y1 x2 y2 dx dy (x2+dx) (y2+dy)
610
%		/Intersect = 7 index = 6 index = 5 index = 4 index = 3 index = 2 index = 1 index = 0 index =
611
		2 copy infill
612
		{									% replace x2,y2
613
			6 -2 roll pop pop
614
			4 2 roll
615
		} {
616
			8 -2 roll pop pop				% replace x1,y1
617
			6 2 roll
618
		} ifelse
619
	} loop
620
	grestore
621
	6 -2 roll								% return x2,y2
622
	4 { pop } repeat
623
} bind def
624
 
625
/i_clip_line
626
{
627
	/endY exch store
628
	/endX exch store
629
	currentX currentY endX endY i_in_clip2
630
	{ % end in
631
		{
632
			% both in. just draw it. FIXME check if line leaves cliparea
633
			endX endY /lineto load
634
		} {
635
			% current not in
636
			% find new current point
637
			currentX currentY endX endY i_find_clip_intersect
638
			/moveto load
639
			endX endY /lineto load
640
		} ifelse
641
	} { % end not in
642
		{   % current in
643
			% find new endpoint
644
			endX endY currentX currentY i_find_clip_intersect
645
			/lineto load
646
		} {
647
			% both not in
648
			% try to find a point within cliparea
649
			currentX currentY endX endY i_find_clip_intersect
650
			2 copy i_in_clip
651
			{
652
				% yeah
653
				/moveto load
654
				% now find point from other end
655
				endX endY currentX currentY i_find_clip_intersect
656
				/lineto load
657
			} {
658
				pop pop
659
			} ifelse
660
		} ifelse
661
	} ifelse
662
	/currentX endX store
663
	/currentY endY store
664
} bind def
665
 
666
 
667
/pathClipForStroke
668
{
669
	% only lines
670
	flattenpath
671
	% create a userpath from currentpath
672
	userdict begin
673
	/beginX 0 def /beginY 0 def
674
	/currentX 0 def /currentY 0 def
675
	/endX 0 def /endY 0 def
676
	systemdict begin							% some EPS redefine moveto & Co :-(
677
	[
678
			{ i_clip_move }						% remember last move
679
			{ i_clip_line }						% clip lines individually
680
			{ 6 {pop} repeat /OOPS = }			% won't happen
681
			{ beginX beginY i_clip_line }		% close with line
682
		pathforall
683
	] cvx
684
%	dup ==
685
	newpath % uappend % userpaths SUCK!
686
	end end
687
	exec
688
} bind def
689
 
690
/rectfill
691
{
692
	userdict begin
693
	(n\n)print			% start polygon
694
	writecurrentcolor
695
	writecurrentlinewidth
696
	writecurrentlinecap
697
	writecurrentlinejoin
698
	writecurrentdash
699
	storeMatrix
700
 
701
	% x y width height
702
	dup type /arraytype ne
703
	{
704
		/hr exch def
705
		/wr exch def
706
		/yr exch def
707
		/xr exch def
708
		xr yr i_move
709
		xr wr add yr i_line
710
		xr wr add yr hr add i_line
711
		xr yr hr add i_line
712
		xr yr i_line
713
	}
714
	% numarray
715
	% numstring
716
	{
717
		/ar exch def
718
 
719
		{
720
			/n exch def
721
			ar n get /xr exch def
722
			ar n 1 add get /yr exch def
723
			ar n 2 add get /wr exch def
724
			ar n 3 add get /hr exch def
725
			xr yr i_move
726
			xr wr add yr i_line
727
			xr wr add yr hr add i_line
728
			xr yr hr add i_line
729
			xr yr i_line
730
		} for
731
	}ifelse
732
 
733
	(f\n)print			% close polygon
734
	end
735
} i_shortcutOverload
736
 
737
/rectstroke
738
{
739
	userdict begin
740
	(n\n)print			% start rect
741
	writecurrentcolor
742
	writecurrentlinewidth
743
	writecurrentlinecap
744
	writecurrentlinejoin
745
	writecurrentdash
746
	storeMatrix
747
 
748
	% x y width height
749
	dup type dup /arraytype ne exch /stringtype ne and
750
	{
751
		/hr exch def
752
		/wr exch def
753
		/yr exch def
754
		/xr exch def
755
		xr yr i_move
756
		xr wr add yr i_line
757
		xr wr add yr hr add i_line
758
		xr yr hr add i_line
759
		xr yr i_line
760
	}
761
	% numarray
762
	% numstring
763
	{
764
		/ar exch def
765
 
766
		{
767
			/n exch def
768
			ar n get /xr exch def
769
			ar n 1 add get /yr exch def
770
			ar n 2 add get /wr exch def
771
			ar n 3 add get /hr exch def
772
			xr yr i_move
773
			xr wr add yr i_line
774
			xr wr add yr hr add i_line
775
			xr yr hr add i_line
776
			xr yr i_line
777
		} for
778
	}ifelse
779
	(n\n)print			% stroke rect
780
	end
781
} i_shortcutOverload
782
 
783
/stroke
784
{
785
	(n\n) print
786
	writecurrentcolor
787
	writecurrentlinewidth
788
	writecurrentlinecap
789
	writecurrentlinejoin
790
	writecurrentdash
791
	clipCnt 1 eq
792
		{ pathClipForStroke } if
793
	storeMatrix
794
 
795
	{i_move} {i_line} {i_curve} {i_close} pathforall
796
	(s\n)print			% stroke path
797
	newpath
798
} i_shortcutOverload
799
 
800
/eofill
801
{
802
	(n\n) print			% start polygon
803
	writecurrentcolor	% write color
804
	writecurrentlinewidth
805
	writecurrentlinecap
806
	writecurrentlinejoin
807
	writecurrentdash
808
	clipCnt 1 eq
809
		{ pathClipAndClose } if
810
	storeMatrix			% take transformation, scaling, rotation from PostScript
811
	{i_move} {i_line} {i_curve} {i_close} pathforall
812
	(f\n)print			% close polygon
813
 
814
	newpath				% clear stack
815
} i_shortcutOverload
816
 
817
/fill
818
{
819
	(fill-winding\n) print
820
	eofill
821
	(fill-evenodd\n) print
822
} i_shortcutOverload
823
 
824
/clip
825
{
826
	userdict begin
827
	(n\n)print			% start clip polygon
828
 
829
% FIXME: pathClipAndClose first?
830
 
831
	storeMatrix			% take transformation, scaling, rotation from PostScript
832
	{i_move} {i_line} {i_curve} {i_close} pathforall
833
 
834
	(ci\n)print			% close clip polygon begin path
835
						% we have to close the path!!
836
	clip
837
	/clipCnt 1 def
838
	newpath				% clear stack
839
	end
840
} i_shortcutOverload
841
 
842
% we don't clip
843
% because this doesn't work for flattening text (show, charpath) with NeXT PostScript Code
844
/rectclip
845
{
846
	% let Scribus decide what to do with ci; was: pop pop pop pop
847
	userdict begin
848
	(n\n)print			% start clip polygon
849
 
850
	storeMatrix			% take transformation, scaling, rotation from PostScript
851
	dup type dup /arraytype ne exch /stringtype ne and
852
	{
853
		4 copy
854
		/i_h exch def
855
		/i_w exch def
856
		/i_y exch def
857
		/i_x exch def
858
		i_x i_y i_move
859
		i_x i_w add i_y i_line
860
		i_x i_w add i_y i_h add i_line
861
		i_x i_y i_h add i_line
862
	} {
863
		% array or string
864
 
865
		{
866
			1 index 1 index get /i_x exch def
867
			1 add
868
			1 index 1 index get /i_y exch def
869
			1 add
870
			1 index 1 index get /i_w exch def
871
			1 add
872
			1 index 1 index get /i_y exch def
873
			i_x i_y i_move
874
			i_x i_w add i_y i_line
875
			i_x i_w add i_y i_h add i_line
876
			i_x i_y i_h add i_line
877
		} for
878
	} ifelse
879
 
880
	(ci\n)print			% close clip polygon begin path
881
						% we have to close the path!!
882
	rectclip
883
	/clipCnt 1 def
884
	newpath				% clear stack
885
	end
886
} i_shortcutOverload
887
 
888
 
889
%    Copyright (C) 1994 Aladdin Enterprises.  All rights reserved.
890
%
891
% This software is provided AS-IS with no warranty, either express or
892
% implied.
893
%
894
% This software is distributed under license and may not be copied,
895
% modified or distributed except as expressly authorized under the terms
896
% of the license contained in the file LICENSE in this distribution.
897
%
898
% For more information about licensing, please refer to
899
% http://www.ghostscript.com/licensing/. For information on
900
% commercial licensing, go to http://www.artifex.com/licensing/ or
901
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
902
% San Rafael, CA  94903, U.S.A., +1(415)492-9861.
903
 
904
% $Id: import_la.prolog 6455 2006-09-25 08:57:20Z fschmid $
905
% traceimg.ps
906
% Trace the data supplied to the 'image' operator.
907
 
908
% This code currently handles only the (Level 2) dictionary form of image,
909
% with a single data source and 8-bit pixels.
910
 
911
% changed for Scribus image import by Andreas Vox, 2006-2-21
912
% added support for colorimage and other image variant
913
 
914
/i_image			% <dict> i_image -
915
{
916
/i_image =
917
	begin
918
		/i_left Width Height mul Decode length 2 idiv mul BitsPerComponent mul 8 idiv dup /i_size exch store store
919
		/i_dict currentdict store
920
		/i_nsources 1 store
921
		/i_source 0 store
922
		/i_datasource currentdict /DataSource get store
923
		currentdict /MultipleDataSources known not
924
			{ /MultipleDataSources false def } if
925
		MultipleDataSources
926
		{
927
			/i_nsources  DataSource length store
928
			/i_datasource DataSource 0 get store
929
		} if
930
	end
931
	storeMatrix
932
	i_dict /ImageMatrix get matrix invertmatrix matrix currentmatrix matrix concatmatrix /i_m exch def
933
	i_dict /Width get  0 i_m dtransform dup mul exch dup mul add sqrt /i_w exch def
934
 
935
 
936
	i_dict /Width get i_dict /Height get i_m transform
937
	/i_hflip -1 def /i_vflip 1 def
938
	dup i_y le { /i_y exch def } { pop /i_vflip -1 def } ifelse
939
	dup i_x le { /i_x exch def } { pop /i_hflip  1 def } ifelse
940
 
941
	/i_angle exch def
942
	(.dat) i_exportfilename
943
		(im ) print												% im x y w h angle ...
944
		i_x i_hscale div i_str cvs print ( ) print
945
		i_y i_vscale div i_str cvs print ( ) print
946
		i_w i_hscale div i_str cvs print ( ) print
947
		i_h i_vscale div i_str cvs print ( ) print
948
		i_angle i_str cvs print ( ) print
949
		i_dict /Width get  i_str cvs print ( ) print			% ... hpix vpix ...
950
		i_dict /Height get i_str cvs print ( ) print
951
		currentcolorspace 0 get /DeviceRGB eq
952
			{ (tiff24nc ) print }
953
		{ currentcolorspace 0 get /DeviceCMYK eq
954
			{ (psdcmyk ) print }
955
		{ currentcolorspace 0 get /DeviceGray eq
956
			{ (tiffgray ) print }
957
			{ (tiff32nc ) print }
958
		ifelse } ifelse } ifelse
959
        dup  (.tif) concatenate print (\n) print flush			% ... dev filename
960
		(.dat) concatenate (w) file /i_file exch store			% temp file
961
	currentcolorspace ==write ( setcolorspace\n) =write
962
	(<<\n) =write
963
	i_dict { exch
964
		  dup /DataSource eq
965
			{ pop pop (/DataSource currentfile\n) =write }
966
		  {
967
			dup /ImageMatrix eq
968
				{ pop pop (/ImageMatrix [) =write
969
					i_hflip ==write ( 0 0 ) =write i_vflip ==write
970
					( ) =write
971
					i_hflip 0 lt { i_dict /Width get } { 0 } ifelse ==write
972
					( ) =write
973
					i_vflip 0 lt { i_dict /Height get} { 0 } ifelse ==write
974
					(]\n) =write }
975
				{ ==write ( ) =write ==write (\n) =write }
976
			ifelse
977
		  } ifelse
978
		} forall
979
	(>>\nimage\n) =write i_file flushfile
980
 
981
    { %loop
982
      i_left 0 le
983
      {
984
		i_source 1 add /i_source exch def
985
        i_source i_nsources ge { exit } if
986
        i_dict /DataSource get i_source get /i_datasource exch def
987
		/i_left i_size def
988
      } if
989
      /i_datasource load exec
990
      dup type /filetype eq
991
       { i_buf 0 i_left 32 .min getinterval readstring pop
992
       } if
993
      dup i_file exch writestring
994
      i_left exch length sub /i_left exch def
995
    } loop
996
    i_file flushfile
997
/i_imageE =
998
 } bind def
999
 
1000
/colorimage
1001
{
1002
/colorimage =
1003
	% width height bits/sample matrix datasource0..n-1 multi ncomp
1004
	/tmpN exch def
1005
	/tmpMulti exch def
1006
	tmpMulti
1007
	{
1008
		/tmpN load array astore
1009
	} if
1010
	/tmpN load 6 add dict
1011
	dup 7 -1 roll /Width exch put
1012
	dup 6 -1 roll /Height exch put
1013
	dup 5 -1 roll /BitsPerComponent exch put
1014
	dup 4 -1 roll /ImageMatrix exch put
1015
	dup 3 -1 roll /DataSource exch put
1016
	tmpMulti
1017
	{
1018
		dup /MultipleDataSources true put
1019
	} if
1020
	dup /ImageType 1 put
1021
	gsave
1022
	/tmpN load
1023
		dup 1 eq
1024
		{
1025
			1 index /Decode [0 1] /Decode put
1026
            /DeviceGray setcolorspace
1027
		} if
1028
		dup 3 eq
1029
		{
1030
			1 index /Decode [0 1 0 1 0 1] put
1031
			/DeviceRGB setcolorspace
1032
		} if
1033
		dup 4 eq
1034
		{
1035
			1 index /Decode [0 1 0 1 0 1 0 1]  put
1036
			/DeviceCMYK setcolorspace
1037
		} if
1038
	pop
1039
	i_image
1040
	grestore
1041
/colorimageE =
1042
} i_shortcutOverload
1043
 
1044
/image {
1045
/image =
1046
	gsave
1047
	dup type /dicttype ne
1048
	{
1049
		% width height bits/sample matrix datasource
1050
		7 dict
1051
		dup 7 -1 roll /Width exch put
1052
		dup 6 -1 roll /Height exch put
1053
		dup 5 -1 roll /BitsPerComponent  exch put
1054
		dup 4 -1 roll /ImageMatrix exch put
1055
		dup 3 -1 roll /DataSource exch put
1056
		dup 1 /ImageType exch put
1057
		dup [0 1] /Decode exch put
1058
		/DeviceGray setcolorspace
1059
	} if
1060
	i_image
1061
	grestore
1062
/imageE =
1063
} i_shortcutOverload
1064
 
1065
/imagemask
1066
{
1067
/imagemask =
1068
	writecurrentcolor
1069
	(mask\n) print
1070
	gsave
1071
	dup type /dicttype ne
1072
	{
1073
		% width height pol matrix datasource
1074
		7 dict
1075
		dup 7 -1 roll /Width exch put
1076
		dup 6 -1 roll /Height exch put
1077
		dup 5 -1 roll { [0 1] } { [1 0] } ifelse /Decode exch put
1078
		dup 4 -1 roll /ImageMatrix exch put
1079
		dup 3 -1 roll /DataSource exch put
1080
	} if
1081
	dup 1 /ImageType exch put
1082
	dup 1 /BitsPerComponent exch put
1083
	/DeviceGray setcolorspace
1084
	i_image
1085
	grestore
1086
/imagemaskE =
1087
} i_shortcutOverload
1088
 
1089
 
1090
% declare some global vars
1091
 
1092
/i_left 0 def
1093
/i_size 0 def
1094
/i_dict null def
1095
/i_buf 32 string def
1096
/i_nsources 1 def
1097
/i_source 0 def
1098
/i_datasource { (x) } def
1099
/i_file null def
1100
/i_filecount 1 def
1101
 
1102
%%%% End of traceimage code
1103
 
1104
 
1105
/stateArray 500 array def
1106
/stateTop 0 def
1107
/gsave
1108
{
1109
	userdict begin
1110
%	(gs\n) print
1111
	stateArray stateTop gstate currentgstate put
1112
	/stateTop stateTop 1 add def
1113
	end
1114
} i_shortcutOverload
1115
 
1116
/grestore
1117
{
1118
	userdict begin
1119
	stateTop 1 lt
1120
	{
1121
	}
1122
	{
1123
%		(gr\n) print
1124
		stateArray stateTop 1 sub get setgstate
1125
		/stateTop stateTop 1 sub def
1126
		stateArray stateTop 0 put
1127
	}ifelse
1128
	end
1129
} i_shortcutOverload
1130
 
1131
% a bind def of the show operator doesn't work,
1132
% so this is our way to get a charpath entry for flattening text
1133
/root_charpath
1134
{
1135
	charpath
1136
} bind def
1137
 
1138
/i_kerningI
1139
{
1140
	exch 1 getinterval stringwidth
1141
} bind def
1142
 
1143
% find kerning value
1144
/i_kerningII		% index string   i_kerning   dx dy
1145
{
1146
	% stringwidth( [n..n+1] ) - stringwidth( [n+1] )
1147
	/i_pstring exch def
1148
	/i_pindex exch def
1149
	i_pstring i_pindex 2 getinterval stringwidth exch	% y2 x2
1150
	i_pstring i_pindex 1 add 1 getinterval stringwidth		% y2 x2 x1 y1
1151
	4 1 roll sub											% y1 y2 (x2-x1)
1152
	3 1 roll exch sub										% (x2-x1) (y2-y1)
1153
} bind def
1154
 
1155
 
1156
/i_kerningIII		% index string   i_kerning   dx dy
1157
{
1158
	% stringwidth( [n..n+1] ) - stringwidth( [n+1] )
1159
	/i_pstring exch def
1160
	/i_pindex exch def
1161
	i_pstring i_pindex 2 getinterval (l) exch concatenate stringwidth exch	% y2 x2
1162
	i_pstring i_pindex 1 add 1 getinterval (l) exch concatenate stringwidth		% y2 x2 x1 y1
1163
	4 1 roll sub											% y1 y2 (x2-x1)
1164
	3 1 roll exch sub										% (x2-x1) (y2-y1)
1165
} bind def
1166
 
1167
/i_kerning /i_kerningII load def
1168
 
1169
/show % string show -
1170
{
1171
	userdict begin
1172
	storeMatrix
1173
	currentfont /FontName known
1174
	% stack: string
1175
	{
1176
		currentpoint /ycur exch def /xcur exch def
1177
		currentpoint	% x y
1178
		newpath
1179
		/clipCnt 0 def
1180
		moveto
1181
		/completeString exch def
1182
		% we process each char separately to get smaller paths
1183
 
1184
		{
1185
			(n\n)print			% start polygon
1186
			writecurrentcolor	% write color
1187
			storeMatrix
1188
			dup completeString length 1 sub eq
1189
			{ dup completeString exch 1 getinterval stringwidth }
1190
			{ dup completeString i_kerning } ifelse
1191
			/curwidthy exch def /curwidthx exch def
1192
			completeString exch 1 getinterval dup /curstr exch def
1193
			false root_charpath
1194
			{i_move} {i_line} {i_curve} {i_close} pathforall
1195
			(f\n)print			% close polygon
1196
			newpath
1197
			curwidthx xcur add curwidthy ycur add moveto
1198
			currentpoint /ycur exch def /xcur exch def
1199
			newpath			% clear graphic stack
1200
			xcur ycur moveto
1201
		} for
1202
		currentpoint	% x y
1203
		newpath				% clear graphic stack (and current point)
1204
		moveto
1205
	} {
1206
		pop		% string
1207
	} ifelse
1208
	end
1209
} i_shortcutOverload
1210
 
1211
/ashow
1212
{
1213
	% ax ay string
1214
	exch /ydist exch def
1215
	exch /xdist exch def
1216
	userdict begin
1217
	storeMatrix
1218
	currentfont /FontName known
1219
	% stack: string
1220
	{
1221
		currentpoint /ycur exch def /xcur exch def
1222
		currentpoint	% x y
1223
		newpath
1224
		/clipCnt 0 def
1225
		moveto
1226
		/completeString exch def
1227
		% we process each char separately to get smaller paths
1228
 
1229
		{
1230
			(n\n)print			% start polygon
1231
			writecurrentcolor	% write color
1232
			storeMatrix
1233
			dup completeString length 1 sub eq
1234
			{ dup completeString exch 1 getinterval stringwidth }
1235
			{ dup completeString i_kerning } ifelse
1236
			/curwidthy exch def /curwidthx exch def
1237
			completeString exch 1 getinterval dup /curstr exch def
1238
			false root_charpath
1239
			{i_move} {i_line} {i_curve} {i_close} pathforall
1240
			(f\n)print			% close polygon
1241
			newpath
1242
			curwidthx xcur add curwidthy ycur add
1243
			exch xdist add exch ydist add moveto
1244
			currentpoint /ycur exch def /xcur exch def
1245
			newpath			% clear graphic stack
1246
			xcur ycur moveto
1247
		} for
1248
		currentpoint	% x y
1249
		newpath				% clear graphic stack (and current point)
1250
		moveto
1251
	} {
1252
		pop
1253
	} ifelse
1254
	end
1255
} i_shortcutOverload
1256
 
1257
/awidthshow		% cx cy char ax ay string
1258
{
1259
	% ax ay string
1260
	exch /ydist exch def
1261
	exch /xdist exch def
1262
	% cx cy char string
1263
	exch /char exch def
1264
	exch /cydist exch def
1265
	exch /cxdist exch def
1266
	userdict begin
1267
	storeMatrix
1268
	currentfont /FontName known
1269
	% stack: string
1270
	{
1271
		currentpoint /ycur exch def /xcur exch def
1272
		currentpoint	% x y
1273
		newpath
1274
		/clipCnt 0 def
1275
		moveto
1276
		/completeString exch def
1277
		% we process each char separately to get smaller paths
1278
 
1279
		{
1280
			(n\n)print			% start polygon
1281
			writecurrentcolor	% write color
1282
			storeMatrix
1283
			dup completeString length 1 sub eq
1284
			{ dup completeString exch 1 getinterval stringwidth }
1285
			{ dup completeString i_kerning } ifelse
1286
			/curwidthy exch def /curwidthx exch def
1287
			completeString exch 1 getinterval dup /curstr exch def
1288
			false root_charpath
1289
			{i_move} {i_line} {i_curve} {i_close} pathforall
1290
			(f\n)print			% close polygon
1291
			newpath
1292
			curwidthx xcur add curwidthy ycur add
1293
			exch xdist add exch ydist add moveto
1294
			curstr 0 get char eq
1295
			{
1296
				currentpoint exch cxdist add exch cydist add moveto
1297
			} if
1298
			currentpoint /ycur exch def /xcur exch def
1299
			newpath			% clear graphic stack
1300
			xcur ycur moveto
1301
		} for
1302
		currentpoint	% x y
1303
		newpath				% clear graphic stack (and current point)
1304
		moveto
1305
	} {
1306
		pop
1307
	} ifelse
1308
	end
1309
} i_shortcutOverload
1310
 
1311
/widthshow	% cx cy char string
1312
{
1313
 
1314
 
1315
	awidthshow
1316
} bind def
1317
 
1318
/cshow	% proc string
1319
{
1320
	exch pop
1321
	show
1322
} i_shortcutOverload
1323
 
1324
/kshow	% proc string
1325
{
1326
	dup length 1 sub
1327
	dup 0 ne
1328
	{
1329
		1 index 0 1 getinterval
1330
		show
1331
		1 sub
1332
		dup 0 ne
1333
		{
1334
			1 add
1335
			1 exch 1 exch
1336
			{
1337
				dup 1 sub
1338
				2 index exch get
1339
				2 index 2 index get
1340
				4 index exec
1341
				1 index exch 1 getinterval
1342
				show
1343
			} for
1344
		} if
1345
	}
1346
	{
1347
		pop dup show
1348
	} ifelse
1349
	pop pop
1350
} i_shortcutOverload
1351
 
1352
/xshow	% string array
1353
{
1354
	pop %FIXME
1355
	show
1356
} i_shortcutOverload
1357
 
1358
/xyshow	% string array
1359
{
1360
	pop %FIXME
1361
	show
1362
} i_shortcutOverload
1363
 
1364
/yshow	% string array
1365
{
1366
	pop %FIXME
1367
	show
1368
} i_shortcutOverload
1369
 
1370
/i_reencode % newfontname reencodevector origfontdict -> i_reencode -> newfontdict
1371
{
1372
	userdict begin
1373
 dup begin dup maxlength dict begin
1374
  { 1 index /FID ne {def} {pop pop} ifelse
1375
  } forall
1376
  /Encoding exch def
1377
  currentdict
1378
  end end
1379
  definefont
1380
	end
1381
} bind def
1382
 
1383
/glyphshow {
1384
    save % So can reclaim VM from reencoding
1385
    currentfont /Encoding get dup length array copy dup 0 5 -1 roll put
1386
    /GlyphShowTempFont exch currentfont i_reencode
1387
    setfont
1388
    (\000) show
1389
	currentpoint 3 -1 roll % curx cury -save-
1390
	restore
1391
	newpath
1392
	moveto
1393
} i_shortcutOverload
1394
 
1395
/showpage
1396
{
1397
	(sp\n) print
1398
} i_shortcutOverload
1399