2 % This file is part of the LibreOffice project.
4 % This Source Code Form is subject to the terms of the Mozilla Public
5 % License, v. 2.0. If a copy of the MPL was not distributed with this
6 % file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 % This file incorporates work covered by the following license notice:
10 % Licensed to the Apache Software Foundation (ASF) under one or more
11 % contributor license agreements. See the NOTICE file distributed
12 % with this work for additional information regarding copyright
13 % ownership. The ASF licenses this file to you under the Apache
14 % License, Version 2.0 (the "License"); you may not use this file
15 % except in compliance with the License. You may obtain a copy of
16 % the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 % This is an "unobsfucated version of postscript header" in printerjob.cxx. It
20 % was propably kept separate for the comments, but it is not used in it self
21 % and propably was not kept in sync with the actual header.
27 % The intention of readpath is to save disk space since the vcl clip region routines
28 % produce a huge amount of lineto/moveto commands
30 % The principal idea is to maintain the current point on stack and to provide only deltas
31 % in the command. These deltas are added to the current point. The new point is used for
32 % the lineto and moveto command and saved on stack for the next command.
34 % pathdict implements binary/hex representation of lineto and moveto commands.
35 % The command consists of a 1byte opcode to switch between lineto and moveto and the size
36 % of the following delta-x and delta-y values. The opcode is read with /rcmd, the two
37 % coordinates are read with /rhex. The whole command is executed with /xcmd
41 /pathdict dup 8 dict def load
44 % the command is of the bit format cxxyy
45 % with c=0 meaning lineto
47 % xx is a 2bit value for the number of bytes for x position
48 % yy is the same for y, values are off by one: 00 means 1; 11 means 4 !
49 % the command has been added to 'A' to be always in the ascii character
50 % range. the command is followed by 2*xx + 2*yy hexchars.
51 % '~' denotes the special case of EOD
54 currentfile 1 string readstring % s bool
57 % --- check whether s[0] is CR, LF ...
58 dup 32 gt % s > ' ' ? then read on
65 dup 126 eq { pop exit } if % -- Exit loop if cmd is '~'
68 dup 16#3 and 1 add % cmd yy
71 dup 16#C and -2 bitshift
72 16#3 and 1 add exch % yy xx cmd
73 % -- Separate command bit
74 16#10 and 16#10 eq % yy xx bool
75 3 1 roll exch % bool xx yy
78 % length rhex -- reads a signed hex value of given length
79 % the left most bit of char 0 is considered as the sign (0 means '+', 1 means '-')
80 % the rest of the bits is considered to be the abs value. Please note that this
81 % does not match the C binary representation of integers
83 dup 1 sub exch % l-1 l
84 currentfile exch string readhexstring % l-1 substring[l] bool
86 dup 0 get dup % l-1 s s[0] s[0]
88 16#80 and 16#80 eq dup % l-1 s s[0] sign=- sign=-
89 % -- Mask out the sign bit and put value back
90 3 1 roll % l-1 s sign=- s[0] sign=-
91 { 16#7f and } if % l-1 s sign=- +s[0]
92 2 index 0 % l-1 s sign=- +s[0] s 0
93 3 -1 roll put % l-1 s sign=- s 0 +s[0]
94 % -- Read loop: add to prev sum, mul with 256
95 3 1 roll 0 % sign=- l-1 s Sum=0
96 0 1 5 -1 roll % sign=- s Sum=0 0 1 l-1
98 2 index exch % sign=- s Sum s idx
99 get % sign=- s Sum s[idx]
100 add 256 mul % sign=- s Sum=(s[idx]+Sum)*256
103 % -- mul was once too often, weave in the sign
104 256 div % sign=- s Sum/256
105 exch pop % sign=- Sum/256
106 exch { neg } if % (sign=- ? -Sum : Sum)
109 % execute a single command, the former x and y position is already on stack
110 % only offsets are read from cmdstring
112 rcmd % x y bool wx wy
113 exch rhex % x y bool wy Dx
114 exch rhex % x y bool Dx Dy
115 exch 5 -1 roll % y bool Dy Dx x
116 add exch % y bool X Dy
117 4 -1 roll add % bool X Y
118 1 index 1 index % bool X Y X Y
119 5 -1 roll % X Y X Y bool
128 0 0 % push initial-x initial-y
132 pop pop % pop final-x final-y
137 % if languagelevel is not in the systemdict then its level 1 interpreter:
138 % provide compatibility routines
142 systemdict /languagelevel known not
144 % string numarray xxshow -
145 % does only work for single byte fonts
148 length 0 1 % a s l(s) 1 1
149 3 -1 roll 1 sub % a s 0 1 l(s)-1
152 % -- extract the delta offset
153 3 index exch get % a s idx a[idx]
154 % -- extract the character
155 exch % a s a[idx] idx
156 2 index exch get % a s a[idx] s[idx]
157 % -- create a tmp string for show
158 1 string dup 0 % a s a[idx] s[idx] s1 s1 0
159 4 -1 roll % a s a[idx] s1 s1 0 s[idx]
161 % -- store the current point
162 currentpoint 3 -1 roll % a s a[idx] x y s1
163 % -- draw the character
164 show % a s a[idx] x y
165 % -- move to the offset
166 moveto 0 rmoveto % a s
172 % x y width height rectfill
173 % x y width height rectshow
174 % in contrast to the languagelevel 2 operator
175 % they use and change the currentpath
177 4 -2 roll % width height x y
178 moveto % width height
179 1 index 0 rlineto % width height % rmoveto(width, 0)
180 0 exch rlineto % width % rmoveto(0, height)
181 neg 0 rlineto % - % rmoveto(-width, 0)
185 /rectfill { rectangle fill } def
186 /rectstroke { rectangle stroke } def
190 % -- small test program
191 % 75 75 moveto /Times-Roman findfont 12 scalefont setfont
192 % <292a2b2c2d2e2f30313233343536373839>
193 % [5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 5] xshow <21>[0] xshow
198 % shortcuts for image header with compression
203 currentfile /ASCII85Decode filter /LZWDecode filter
206 currentfile /ASCII85Decode filter
209 psp_lzwfilter 1024 string readstring
212 psp_ascii85filter 1024 string readstring
215 /psp_bitspercomponent {
222 [ [0 1 0 1 0 1] [0 255] [0 1] [0 255] ] exch get
227 /Width 7 -1 roll put dup
228 /Height 5 index put dup
229 /BitsPerComponent 4 index
230 psp_bitspercomponent put dup
232 psp_decodearray put dup
233 /ImageMatrix [1 0 0 1 0 0] dup
234 5 8 -1 roll put put dup
235 /DataSource 4 -1 roll
238 { psp_ascii85filter }
245 % font encoding and reencoding
250 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
251 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
252 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
253 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
254 /space /exclam /quotedbl /numbersign /dollar /percent /ampersand /quotesingle
255 /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash
256 /zero /one /two /three /four /five /six /seven
257 /eight /nine /colon /semicolon /less /equal /greater /question
258 /at /A /B /C /D /E /F /G
259 /H /I /J /K /L /M /N /O
260 /P /Q /R /S /T /U /V /W
261 /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore
262 /grave /a /b /c /d /e /f /g
263 /h /i /j /k /l /m /n /o
264 /p /q /r /s /t /u /v /w
265 /x /y /z /braceleft /bar /braceright /asciitilde /unused
266 /Euro /unused /quotesinglbase /florin /quotedblbase /ellipsis /dagger /daggerdbl
267 /circumflex /perthousand /Scaron /guilsinglleft /OE /unused /Zcaron /unused
268 /unused /quoteleft /quoteright /quotedblleft /quotedblright /bullet /endash /emdash
269 /tilde /trademark /scaron /guilsinglright /oe /unused /zcaron /Ydieresis
270 /space /exclamdown /cent /sterling /currency /yen /brokenbar /section
271 /dieresis /copyright /ordfeminine /guillemotleft /logicalnot /hyphen /registered /macron
272 /degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph /periodcentered
273 /cedilla /onesuperior /ordmasculine /guillemotright /onequarter /onehalf /threequarters /questiondown
274 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla
275 /Egrave /Eacute /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis
276 /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply
277 /Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls
278 /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla
279 /egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis
280 /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /divide
281 /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis
284 % /fontname /encoding psp_findfont
286 exch dup % encoding fontname fontname
287 findfont % encoding fontname
296 /Encoding 3 -1 roll def
299 /psp_reencodedfont exch definefont
302 % bshow shows a text in artificial bold
303 % this is achieved by first showing the text
304 % then stroking its outline over it with
305 % the linewidth set to the second parameter
306 % usage: (string) num bshow
309 currentlinewidth % save current linewidth
310 3 1 roll % move it to the last stack position
311 currentpoint % save the current point
312 3 index % copy the string to show
314 moveto % move to the original coordinates again
315 setlinewidth % set the linewidth
316 false charpath % create the outline path of the shown string
317 stroke % and stroke it
318 setlinewidth % reset the stored linewidth
321 % bxshow shows a text with a delta array in artificial bold
322 % that is it does what bshow does for show
323 % usage: (string) [deltaarray] num bxshow
326 currentlinewidth % save linewidth
327 4 1 roll % move it to the last stack position
328 setlinewidth % set the new linewidth
329 exch % exchange string and delta array
331 length % get length of string
332 1 sub % prepare parameters for {} for
336 1 string % create a string object length 1
337 2 index % get the text
338 2 index % get charpos (for index variable)
339 get % have char value at charpos
340 1 index % prepare string for put
344 put % put into string of length 1
345 dup % duplicate the it
346 currentpoint % save current position
347 3 -1 roll % prepare show
348 show % show the character
349 moveto % move back to beginning
350 currentpoint % save current position
351 3 -1 roll % prepare outline path of character
355 % now move to next point
356 2 index % get advance array
358 get % get advance element
359 0 rmoveto % advance current position
361 pop pop % remove string and delta array
362 setlinewidth % restore linewidth