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 .
23 % The intention of readpath is to save disk space since the vcl clip region routines
24 % produce a huge amount of lineto/moveto commands
26 % The principal idea is to maintain the current point on stack and to provide only deltas
27 % in the command. These deltas are added to the current point. The new point is used for
28 % the lineto and moveto command and saved on stack for the next command.
30 % pathdict implements binary/hex representation of lineto and moveto commands.
31 % The command consists of a 1byte opcode to switch between lineto and moveto and the size
32 % of the following delta-x and delta-y values. The opcode is read with /rcmd, the two
33 % coordinates are read with /rhex. The whole command is executed with /xcmd
37 /pathdict dup 8 dict def load
40 % the command is of the bit format cxxyy
41 % with c=0 meaning lineto
43 % xx is a 2bit value for the number of bytes for x position
44 % yy is the same for y, values are off by one: 00 means 1; 11 means 4 !
45 % the command has been added to 'A' to be always in the ascii character
46 % range. the command is followed by 2*xx + 2*yy hexchars.
47 % '~' denotes the special case of EOD
50 currentfile 1 string readstring % s bool
53 % --- check wether s[0] is CR, LF ...
54 dup 32 gt % s > ' ' ? then read on
61 dup 126 eq { pop exit } if % -- Exit loop if cmd is '~'
64 dup 16#3 and 1 add % cmd yy
67 dup 16#C and -2 bitshift
68 16#3 and 1 add exch % yy xx cmd
69 % -- Separate command bit
70 16#10 and 16#10 eq % yy xx bool
71 3 1 roll exch % bool xx yy
74 % length rhex -- reads a signed hex value of given length
75 % the left most bit of char 0 is considered as the sign (0 means '+', 1 means '-')
76 % the rest of the bits is considered to be the abs value. Please note that this
77 % does not match the C binary representation of integers
79 dup 1 sub exch % l-1 l
80 currentfile exch string readhexstring % l-1 substring[l] bool
82 dup 0 get dup % l-1 s s[0] s[0]
84 16#80 and 16#80 eq dup % l-1 s s[0] sign=- sign=-
85 % -- Mask out the sign bit and put value back
86 3 1 roll % l-1 s sign=- s[0] sign=-
87 { 16#7f and } if % l-1 s sign=- +s[0]
88 2 index 0 % l-1 s sign=- +s[0] s 0
89 3 -1 roll put % l-1 s sign=- s 0 +s[0]
90 % -- Read loop: add to prev sum, mul with 256
91 3 1 roll 0 % sign=- l-1 s Sum=0
92 0 1 5 -1 roll % sign=- s Sum=0 0 1 l-1
94 2 index exch % sign=- s Sum s idx
95 get % sign=- s Sum s[idx]
96 add 256 mul % sign=- s Sum=(s[idx]+Sum)*256
99 % -- mul was once too often, weave in the sign
100 256 div % sign=- s Sum/256
101 exch pop % sign=- Sum/256
102 exch { neg } if % (sign=- ? -Sum : Sum)
105 % execute a single command, the former x and y position is already on stack
106 % only offsets are read from cmdstring
108 rcmd % x y bool wx wy
109 exch rhex % x y bool wy Dx
110 exch rhex % x y bool Dx Dy
111 exch 5 -1 roll % y bool Dy Dx x
112 add exch % y bool X Dy
113 4 -1 roll add % bool X Y
114 1 index 1 index % bool X Y X Y
115 5 -1 roll % X Y X Y bool
124 0 0 % push initial-x initial-y
128 pop pop % pop final-x final-y
133 % if languagelevel is not in the systemdict then its level 1 interpreter:
134 % provide compatibility routines
138 systemdict /languagelevel known not
140 % string numarray xxshow -
141 % does only work for single byte fonts
144 length 0 1 % a s l(s) 1 1
145 3 -1 roll 1 sub % a s 0 1 l(s)-1
148 % -- extract the delta offset
149 3 index exch get % a s idx a[idx]
150 % -- extract the character
151 exch % a s a[idx] idx
152 2 index exch get % a s a[idx] s[idx]
153 % -- create a tmp string for show
154 1 string dup 0 % a s a[idx] s[idx] s1 s1 0
155 4 -1 roll % a s a[idx] s1 s1 0 s[idx]
157 % -- store the current point
158 currentpoint 3 -1 roll % a s a[idx] x y s1
159 % -- draw the character
160 show % a s a[idx] x y
161 % -- move to the offset
162 moveto 0 rmoveto % a s
168 % x y width height rectfill
169 % x y width height rectshow
170 % in contrast to the languagelevel 2 operator
171 % they use and change the currentpath
173 4 -2 roll % width height x y
174 moveto % width height
175 1 index 0 rlineto % width height % rmoveto(width, 0)
176 0 exch rlineto % width % rmoveto(0, height)
177 neg 0 rlineto % - % rmoveto(-width, 0)
181 /rectfill { rectangle fill } def
182 /rectstroke { rectangle stroke } def
186 % -- small test program
187 % 75 75 moveto /Times-Roman findfont 12 scalefont setfont
188 % <292a2b2c2d2e2f30313233343536373839>
189 % [5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 5] xshow <21>[0] xshow
194 % shortcuts for image header with compression
199 currentfile /ASCII85Decode filter /LZWDecode filter
202 currentfile /ASCII85Decode filter
205 psp_lzwfilter 1024 string readstring
208 psp_ascii85filter 1024 string readstring
211 /psp_bitspercomponent {
218 [ [0 1 0 1 0 1] [0 255] [0 1] [0 255] ] exch get
223 /Width 7 -1 roll put dup
224 /Height 5 index put dup
225 /BitsPerComponent 4 index
226 psp_bitspercomponent put dup
228 psp_decodearray put dup
229 /ImageMatrix [1 0 0 1 0 0] dup
230 5 8 -1 roll put put dup
231 /DataSource 4 -1 roll
234 { psp_ascii85filter }
241 % font encoding and reencoding
246 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
247 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
248 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
249 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
250 /space /exclam /quotedbl /numbersign /dollar /percent /ampersand /quotesingle
251 /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash
252 /zero /one /two /three /four /five /six /seven
253 /eight /nine /colon /semicolon /less /equal /greater /question
254 /at /A /B /C /D /E /F /G
255 /H /I /J /K /L /M /N /O
256 /P /Q /R /S /T /U /V /W
257 /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore
258 /grave /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 /braceleft /bar /braceright /asciitilde /unused
262 /Euro /unused /quotesinglbase /florin /quotedblbase /ellipsis /dagger /daggerdbl
263 /circumflex /perthousand /Scaron /guilsinglleft /OE /unused /Zcaron /unused
264 /unused /quoteleft /quoteright /quotedblleft /quotedblright /bullet /endash /emdash
265 /tilde /trademark /scaron /guilsinglright /oe /unused /zcaron /Ydieresis
266 /space /exclamdown /cent /sterling /currency /yen /brokenbar /section
267 /dieresis /copyright /ordfeminine /guillemotleft /logicalnot /hyphen /registered /macron
268 /degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph /periodcentered
269 /cedilla /onesuperior /ordmasculine /guillemotright /onequarter /onehalf /threequarters /questiondown
270 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla
271 /Egrave /Eacute /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis
272 /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply
273 /Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls
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 /divide
277 /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis
280 % /fontname /encoding psp_findfont
282 exch dup % encoding fontname fontname
283 findfont % encoding fontname
292 /Encoding 3 -1 roll def
295 /psp_reencodedfont exch definefont
298 % bshow shows a text in artificial bold
299 % this is achieved by first showing the text
300 % then stroking its outline over it with
301 % the linewidth set to the second parameter
302 % usage: (string) num bshow
305 currentlinewidth % save current linewidth
306 3 1 roll % move it to the last stack position
307 currentpoint % save the current point
308 3 index % copy the string to show
310 moveto % move to the original coordinates again
311 setlinewidth % set the linewidth
312 false charpath % create the outline path of the shown string
313 stroke % and stroke it
314 setlinewidth % reset the stored linewidth
317 % bxshow shows a text with a delta array in artificial bold
318 % that is it does what bshow does for show
319 % usage: (string) [deltaarray] num bxshow
322 currentlinewidth % save linewidth
323 4 1 roll % move it to the last stack position
324 setlinewidth % set the new linewidth
325 exch % exchange string and delta array
327 length % get length of string
328 1 sub % prepare parameters for {} for
332 1 string % create a string object length 1
333 2 index % get the text
334 2 index % get charpos (for index variable)
335 get % have char value at charpos
336 1 index % prepare string for put
340 put % put into string of length 1
341 dup % duplicate the it
342 currentpoint % save current position
343 3 -1 roll % prepare show
344 show % show the character
345 moveto % move back to beginning
346 currentpoint % save current position
347 3 -1 roll % prepare outline path of character
351 % now move to next point
352 2 index % get advance array
354 get % get advance element
355 0 rmoveto % advance current position
357 pop pop % remove string and delta array
358 setlinewidth % restore linewidth