├── COPYING
├── README.md
├── examples
├── manual
│ └── p106.ps
├── news
│ ├── events.ps
│ ├── p105.ps
│ └── p87.ps
└── wps
│ ├── bowtie.ps
│ ├── clock2.ps
│ ├── fill.ps
│ ├── heart.ps
│ ├── rect.ps
│ ├── smile.ps
│ ├── squares.ps
│ ├── squares2.ps
│ ├── star.ps
│ ├── tiger.eps
│ └── triangles.ps
├── executive
├── index.html
└── index.ts
├── index.org
├── lib
├── canvas.ts
├── context-transform.ts
├── corelib.ts
├── coroutine.ts
├── html5canvas.d.ts
├── index.ts
├── oop.ps
├── ps0.ts
├── stdlib.ps
└── util.ts
├── package.json
├── test
├── basic.spec.ts
├── entry.js
├── examples.spec.ts
└── index.html
├── tsconfig.json
├── typings.json
└── webpack.config.js
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | See the [Executive page](http://dev.rsnous.com/dewdrop/executive/).
2 |
--------------------------------------------------------------------------------
/examples/manual/p106.ps:
--------------------------------------------------------------------------------
1 | % Can't run automatically, since it doesn't terminate:
2 | % should print an event every 12 seconds.
3 |
4 | {
5 | createevent dup begin
6 | /Name /Hello def
7 | end expressinterest
8 | {
9 | awaitevent ==
10 | createevent dup begin
11 | /Name /Hello def
12 | /TimeStamp currenttime 0.2 add def
13 | end sendevent
14 | } loop
15 | } fork
16 |
17 | createevent dup begin
18 | /Name /Hello def
19 | end sendevent
20 |
21 | waitprocess
22 |
--------------------------------------------------------------------------------
/examples/news/events.ps:
--------------------------------------------------------------------------------
1 | { % Start defining a listener process.
2 | createevent dup begin
3 | /Name /Hello def
4 | end expressinterest
5 | { (awaiting) == awaitevent (awaited) == == } loop
6 | } fork % Fork the listener process.
7 |
8 | createevent dup begin
9 | /Name /Hello def
10 | /Action /Mumble def
11 | end sendevent % Send the /Hello event. The listener process will wake up and print it.
12 |
13 | createevent dup begin
14 | /Name /Goodbye def
15 | /Action /Mumble def
16 | end sendevent
17 |
18 | % Kill off the listener process --
19 | % its process object has been on the stack all this time.
20 | killprocess
21 |
--------------------------------------------------------------------------------
/examples/news/p105.ps:
--------------------------------------------------------------------------------
1 | /cv framebuffer newcanvas
2 | def
3 | framebuffer setcanvas
4 | 130 130 translate % Changed to fit in bounds of report canvas.
5 | 0 0 100 0 360 arc
6 | cv reshapecanvas
7 | cv /Mapped true put
8 | cv setcanvas
9 | erasepage
10 | {
11 | createevent dup begin
12 | /Canvas cv def
13 | /Name /LeftMouseButton def
14 | /Action /UpTransition def
15 | end expressinterest
16 | {
17 | awaitevent begin
18 | 0 0 moveto
19 | XLocation YLocation lineto stroke
20 | end
21 | } loop
22 | } fork
23 |
--------------------------------------------------------------------------------
/examples/news/p87.ps:
--------------------------------------------------------------------------------
1 | /cv framebuffer newcanvas def
2 | framebuffer setcanvas
3 | 130 130 translate % Changed to fit in bounds of report canvas.
4 | 0 0 100 0 360 arc
5 | cv reshapecanvas
6 | cv /Mapped true put
7 | cv setcanvas
8 | erasepage
9 | 0 0 moveto 100 100 lineto stroke
10 |
--------------------------------------------------------------------------------
/examples/wps/bowtie.ps:
--------------------------------------------------------------------------------
1 | % based on the JavaScript example from
2 | % https://developer.mozilla.org/en/drawing_graphics_with_canvas#section_6
3 |
4 | 0 0 180 180 .gbox
5 |
6 | /bowtie { % fillStyle --
7 | 200 200 200 0.3 .rgba .setFillStyle
8 | -30 -30 60 60 rectfill
9 | .setFillStyle 1.0 .setGlobalAlpha
10 | newpath
11 | 25 25 moveto
12 | -25 -25 lineto
13 | 25 -25 lineto
14 | -25 25 lineto
15 | closepath
16 | fill
17 | } bind def
18 |
19 | /bowtieDot { % --
20 | 0 0 0 setrgbcolor
21 | -2 -2 4 4 rectfill
22 | } bind def
23 |
24 | /bowtie1 { % fillStyle angle x y --
25 | gsave
26 | translate
27 | rotate
28 | bowtie
29 | bowtieDot
30 | grestore
31 | } bind def
32 |
33 | 45 45 translate
34 | (red) 0 0 0 bowtie1
35 | (green) 45 85 0 bowtie1
36 | (blue) 135 0 85 bowtie1
37 | (yellow) 90 85 85 bowtie1
38 |
--------------------------------------------------------------------------------
/examples/wps/clock2.ps:
--------------------------------------------------------------------------------
1 | % based on the PostScript example from
2 | % http://oreilly.com/openbook/cgi/ch06_02.html
3 |
4 | 0 0 150 150 .gbox
5 | 0 150 translate
6 | 1 -1 scale
7 |
8 | /max 150 def
9 | /width 1.5 def
10 | /marker 5 def
11 | /origin {0 0} def
12 | /center {max 2 div} bind def
13 | /radius /center load def
14 | /hsegment 0.50 radius mul def
15 | /msegment 0.80 radius mul def
16 | /ssegment 0.90 radius mul def
17 |
18 | /yellow {1 1 0 setrgbcolor} bind def
19 | /red {1 0 0 setrgbcolor} bind def
20 | /green {0 1 0 setrgbcolor} bind def
21 | /blue {0 0 1 setrgbcolor} bind def
22 | /black {0 0 0 setrgbcolor} bind def
23 |
24 | /hangle {/$h load 60 mul /$m load add 2 div neg .deg2rad} bind def
25 | /mangle {/$m load 6 mul neg .deg2rad} bind def
26 | /sangle {/$s load 6 mul neg .deg2rad} bind def
27 |
28 | /hand { % segment angle color width --
29 | origin moveto
30 | width mul setlinewidth
31 | load exec
32 | 2 copy cos mul
33 | 3 1 roll sin mul
34 | lineto stroke
35 | } bind def
36 |
37 | /draw {
38 | /$h .date (getHours) 0 .call def
39 | /$m .date (getMinutes) 0 .call def
40 | /$s .date (getSeconds) 0 .call def
41 | gsave
42 | width setlinewidth
43 | black clippath fill % background
44 | center dup translate
45 | 90 rotate
46 | gsave % markers
47 | 12 {
48 | radius marker sub 0 moveto
49 | marker 0 rlineto red stroke
50 | 360 12 div rotate
51 | } repeat
52 | grestore
53 | newpath origin radius 0 360 arc blue stroke % circle
54 | hsegment hangle /green 2 hand % hour
55 | msegment mangle /green 1 hand % minute
56 | ssegment sangle /yellow 0.5 hand % second
57 | origin width 2 mul 0 360 arc red fill % dot
58 | grestore
59 | } bind def
60 |
61 | draw
62 |
63 | /timer false def
64 | /go {{draw} .callback 1000 .setInterval /timer exch def} bind def
65 | /halt {/timer load .clearTimeout /timer false def} bind def
66 | /callback {/timer load type (booleantype) eq {go} {halt} ifelse} bind def
67 |
68 | .gcanvas (onclick) /callback load .callback .hook
69 |
--------------------------------------------------------------------------------
/examples/wps/fill.ps:
--------------------------------------------------------------------------------
1 | % based on the JavaScript example from
2 | % https://developer.mozilla.org/samples/canvas-tutorial/4_1_canvas_fillstyle.html
3 |
4 | /n 5 def
5 | /w 25 def
6 |
7 | 0 0 n w mul dup .gbox
8 |
9 | 4 dict begin
10 | 0 1 n {
11 | /i exch def
12 | /ii 1 1 n div i mul sub def
13 | 0 1 n {
14 | /j exch def
15 | /jj 1 1 n div j mul sub def
16 | ii jj 0 setrgbcolor
17 | w j mul w i mul w w rectfill
18 | } for
19 | } for
20 | end
21 |
--------------------------------------------------------------------------------
/examples/wps/heart.ps:
--------------------------------------------------------------------------------
1 | % based on the JavaScript example from
2 | % https://developer.mozilla.org/samples/canvas-tutorial/2_6_canvas_beziercurveto.html
3 |
4 | 0 0 150 150 .gbox
5 |
6 | q
7 | 75 40 m
8 | 75 37 70 25 50 25 c
9 | 20 25 20 62.5 20 62.5 c
10 | 20 80 40 102 75 120 c
11 | 110 102 130 80 130 62.5 c
12 | 130 62.5 130 25 100 25 c
13 | 85 25 75 37 75 40 c
14 | f
15 | Q
16 |
--------------------------------------------------------------------------------
/examples/wps/rect.ps:
--------------------------------------------------------------------------------
1 | 0 0 170 170 .gbox
2 |
3 | 1 0 0 1 80 80 cm
4 | 0 72 m
5 | 72 0 l
6 | 0 -72 l
7 | -72 0 l
8 | 4 w
9 | h S
10 |
--------------------------------------------------------------------------------
/examples/wps/smile.ps:
--------------------------------------------------------------------------------
1 | % based on the JavaScript example from
2 | % http://developer.mozilla.org/samples/canvas-tutorial/2_2_canvas_moveto.html
3 |
4 | 0 0 150 150 .gbox
5 |
6 | %0 0 m % TODO m op meaning?
7 | newpath
8 | 75 75 50 0 360 arc % TODO pdf way to draw arc?
9 | S
10 | 110 75 m
11 | 75 75 35 0 180 arcn
12 | S
13 | 65 65 m
14 | 60 65 5 0 360 arc
15 | S
16 | 95 65 m
17 | 90 65 5 0 360 arc
18 | S
19 |
--------------------------------------------------------------------------------
/examples/wps/squares.ps:
--------------------------------------------------------------------------------
1 | % based on the JavaScript example from
2 | % https://developer.mozilla.org/samples/canvas-tutorial/5_1_canvas_savestate.html
3 |
4 | 0 0 150 150 .gbox
5 |
6 | q
7 | 0 0 m 0 0 150 150 re f
8 | q
9 | 0 0.4 1 rg
10 | 0 0 m 15 15 120 120 re f
11 | q
12 | 1 1 1 rg
13 | 0.5 .setGlobalAlpha
14 | 0 0 m 30 30 90 90 re f
15 | Q
16 | 0 0 m 45 45 60 60 re f
17 | Q
18 | 0 0 m 60 60 30 30 re f
19 | Q
20 |
--------------------------------------------------------------------------------
/examples/wps/squares2.ps:
--------------------------------------------------------------------------------
1 | % based on the JavaScript example from
2 | % https://developer.mozilla.org/en/drawing_graphics_with_canvas
3 |
4 | 0 0 100 100 .gbox
5 |
6 | q
7 | 0.8 0 0 rg
8 | 0 0 m
9 | 10 10 55 50 re
10 | f
11 | 0 0 0.8 rg
12 | 0.5 .setGlobalAlpha
13 | 0 0 m
14 | 30 30 55 50 re
15 | f
16 | Q
17 |
--------------------------------------------------------------------------------
/examples/wps/star.ps:
--------------------------------------------------------------------------------
1 | % based on the PDF example from
2 | % http://www.adobe.com/technology/pdfs/presentations/KingPDFTutorial.pdf
3 |
4 | 0 0 100 100 .gbox
5 | 1 0 0 -1 0 100 cm
6 |
7 | q
8 | 0 0 1 rg
9 | 4 0 0 4 50 50 cm
10 | 0 5.5 m
11 | -4 -5.5 l
12 | 6 1 l
13 | -6 1 l
14 | 4 -5.5 l
15 | f
16 | Q
17 |
--------------------------------------------------------------------------------
/examples/wps/triangles.ps:
--------------------------------------------------------------------------------
1 | % based on the PDF example from
2 | % https://developer.mozilla.org/samples/canvas-tutorial/2_3_canvas_lineto.html
3 |
4 | 0 0 150 150 .gbox
5 |
6 | 25 25 m
7 | 105 25 l
8 | 25 105 l
9 | f
10 |
11 | 125 125 m
12 | 125 45 l
13 | 45 125 l
14 | h
15 | S
16 |
--------------------------------------------------------------------------------
/executive/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
27 | Dewdrop executive
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
Samples
38 |
39 |
Basic computation
40 |
> 2 3 add ==
41 | 5
42 | > (hello world) (putting stuff on stack) stack
43 | hello world,putting stuff on stack
44 | > exch stack
45 | putting stuff on stack,hello world
46 |
47 |
48 |
Round window which draws line on each click (from The NeWS Book)
102 | PostScript is the future of words on paper.
103 |
104 |
105 |
106 |
107 | Dewdrop is a work-in-progress reimplementation of Sun's
108 |
109 | NeWS
110 | (Network/extensible Window System) version 1.1,
111 | by Omar Rizwan.
112 | Its PostScript interpreter and standard library are based on
113 | Tom Hlavaty's WPS.
114 | It's licensed under the GPLv3.
115 | Source is on GitHub.
116 |
117 |
118 |
119 | NeWS is a window system and UI/graphics API based on a superset of Adobe's
120 | PostScript
121 | (a stack-based programming language made for printable graphics). NeWS adds interaction support, a UI
122 | toolkit, cooperative multitasking, and OOP on top of Adobe PostScript and its graphics model.
123 |
140 | NeWS was architecturally similar to what is now called AJAX, except that NeWS:
141 |
142 |
used PostScript code instead of JavaScript for programming.
143 |
used PostScript graphics instead of DHTML/CSS for rendering.
144 |
used PostScript data instead of XML/JSON for data representation.
145 |
146 |
147 |
148 |
Aside
149 |
150 |
151 | Curiously, NeWS got to the same place as the modern Web,
152 | but took a very different path, decades earlier.
153 | The argument the NeWS Book makes for the NeWS architecture is basically
154 | a *compression* argument.
155 |
156 |
157 |
158 | Suppose we have two computers: one is a 'server', where logic runs, and one
159 | is a 'client' which sits on our desk. How can we build a window system where
160 | a graphical app runs remotely on the server,
161 | but we interact with it from our desk?
162 |
163 |
164 |
165 | One approach would be to stream full video of the screen from the server to
166 | our desk. Steam can do this. But that's bandwidth-intensive and hard to pull off
167 | if you're back in the 1980s.
168 |
169 |
170 |
171 | Another approach, which is taken (in theory) by the X Window System when you
172 | do `ssh -X`, is to come up with a basic set of objects, like buttons and
173 | text boxes, and have the server stream a display list of all the objects to the client.
174 | If you do this, however, then your objects are frozen in stone and
175 | might not be what applications want to use -- what if they want to have a custom UI,
176 | or what if your system button style just looks ugly? -- and if an application
177 | draws its own stuff, you end up streaming that custom stuff pixel by pixel
178 | anyway.
179 |
180 |
181 |
182 | NeWS asks: why do we need to send flat lists at all,
183 | whether of pixels or of higher-level display
184 | objects? Our client is a full-fledged computer. Why not send a small *program*
185 | from the server to the client, and let that program draw whatever it wants on the client?
186 |
187 |
188 |
189 | In fact, Adobe built PostScript to solve a very similar problem:
190 | your Mac could send your LaserWriter printer a compact PostScript program describing the pages to print,
191 | and the LaserWriter would interpret the program on its own CPU.
192 | (A faster CPU
193 | than the original Mac's CPU, by the way.)
194 |
9 | #+end_html
10 |
11 | Welcome to WPS, a PostScript and PDF interpreter for HTML 5 canvas.
12 |
13 | Note that to see and run the examples, JavaScript must be enabled and
14 | your browser must support HTML 5 canvas (latest Firefox, Opera and
15 | Chrome should work).
16 |
17 | This document allows you to try simple PostScript programs in the WPS
18 | sandbox. A few examples are presented here accompanied by a brief
19 | description of the interpreter and listing some implementation notes
20 | for my future reference.
21 |
22 | #+begin_html
23 |
27 | #+end_html
28 |
29 | #+html:
69 |
72 | code from sandbox.
73 | #+end_html
74 |
75 | * PostScript interpreter
76 |
77 | A few initial ideas and questions:
78 |
79 | - Learn and implement a Forth like language. PostScript seems like a
80 | good choice:
81 | - It has the right syntax and stack based evaluation.
82 | - It is practical and widely used.
83 | - It has long sucessful history in print and publishing (and more).
84 | - It is a predecessor of PDF.
85 | - Almost everything (e.g. editors, pictures, documentation) can be
86 | reused to a great extent.
87 | - It is ideal for HTML 5 canvas experiments because from the
88 | PostScript point of view, canvas is just another low level device.
89 | - Flexibility and simplicity first.
90 | - Optimize for fast code change, not for raw running speed. Keep
91 | the code small and regular if possible.
92 | - Can JavaScript be used as a portable assembler for the Web? Is
93 | building scripting languages on top of JavaScript feasible and
94 | efficient enough for real-world use? If not, why? Find the
95 | limits.
96 | - Keep the language/environment specific core as small as possible.
97 | - Allow to port the interpreter to other languages on both
98 | client and server side.
99 | - Be open for the possibility of running "the same code" on both the
100 | client and server side.
101 | - Can PDF documents be displayed in web browsers without server-side
102 | image rendering?
103 | - Implement a canvas based version of PDF page contents in [[../ondoc/index.org][OnDoc]].
104 | - It might be possible to implement different backend devices to be
105 | used instead of HTML 5 canvas, for example an SVG device.
106 | - Investigate the possibility of implementing a Lisp interpreter
107 | suitable for production use in web applications.
108 |
109 | There are several things WPS is about:
110 |
111 | - stack(s)
112 | - function (operator) dictionary
113 | - reader
114 | - interpreter/evaluator
115 | - data types
116 | - native bindings (JavaScript FFI)
117 | - PostScript and PDF API
118 |
119 | [[http://en.wikipedia.org/wiki/PostScript][PostScript]] can be seen as a crossover between [[http://en.wikipedia.org/wiki/Forth_(programming_language)][Forth]] and [[http://en.wikipedia.org/wiki/LISP][Lisp]]
120 | programming languages. It is (roughly) a programming language with
121 | [[http://en.wikipedia.org/wiki/Reverse_Polish_notation][RPN]], complex data types, garbage collection and specialized
122 | drawing operators.
123 |
124 | ** Trivial example
125 |
126 | The core essence of a RPN calculator is captured in the JavaScript
127 | code bellow.
128 |
129 | #+html:
147 | #+begin_html
148 |
154 |
155 | "1 2 = 3 + ="
156 | #+end_html
157 |
158 | =Os= stands for Operand Stack, which holds arguments for operators.
159 | =Sd= is a System Dictionary which contains definitions of operators
160 | (JavaScript functions in this case).
161 |
162 | ** Example with PostScript reader
163 |
164 | PostScript has simple but non-trivial syntax so a reader which reads
165 | text and creates internal PostScript objects is necessary. The reader
166 | and evaluator is called =Ps0= (an empty PostScript interpreter) in the
167 | JavaScript code bellow.
168 |
169 | #+html:
170 | #+begin_src js2
171 | function example2(T) {
172 | var Os = [];
173 | var Sd = {};
174 | var Ds = [Sd];
175 | var Es = [];
176 | Sd[new Symbol("+")] = function() {Os.push(Os.pop() + Os.pop());};
177 | Sd[new Symbol("dup")] = function() {var X = Os.pop(); Os.push(X); Os.push(X);};
178 | Sd[new Symbol("=")] = function() {alert(Os.pop());};
179 | (new Ps0(Os, Ds, Es)).parse(T); // read and interpret code T
180 | }
181 | #+end_src
182 | #+html:
183 | #+begin_html
184 |
190 |
191 | "12 34 + dup = 56 + ="
192 | #+end_html
193 |
194 | =Ds= is a Dictionary Stack allowing users to redefine existing
195 | operators and revert back to the original ones. =Es= is an Execution
196 | Stack which is used to implement a tail recursive evaluator.
197 |
198 | ** Example with recursion
199 |
200 | It is possible to write recursive code in PostScript. The following
201 | PostScript code is from the [[http://www.math.ubc.ca/~cass/graphics/manual/pdf/ch9.pdf][Recursion in PostScript PDF document]].
202 |
203 | #+html:
204 | #+begin_src ps
205 | /factorial1 {
206 | 1 dict begin
207 | /n exch def
208 | n 0 eq {1}{n n 1 sub factorial1 mul} ifelse
209 | end
210 | } def
211 |
212 | 5 factorial1 =
213 |
214 | /factorial2 {
215 | dup 0 eq {pop 1}{dup 1 sub factorial2 mul} ifelse
216 | } def
217 |
218 | 5 factorial2 =
219 |
220 | % based on the PostScript example from
221 | % http://partners.adobe.com/public/developer/en/ps/sdk/sample/BlueBook.zip
222 |
223 | /factorial3 {
224 | dup 1 gt {dup 1 sub factorial3 mul} if
225 | } def
226 |
227 | 5 factorial3 =
228 | #+end_src
229 | #+html:
230 | #+begin_html
231 |
234 | the example.
235 | #+end_html
236 |
237 | ** Execution stack
238 |
239 | The interpreter manages its Execution Stack explicitly.
240 |
241 | Most operators simply:
242 |
243 | 1. get their arguments from the Operand Stack
244 | 2. perform some computation and/or side effects
245 | 3. push results to the Operand Stack
246 |
247 | Some operators are more complex and involve some kind of control flow,
248 | e.g. {{{ps(if)}}}, {{{ps(repeat)}}}, {{{ps(for)}}}, {{{ps(loop)}}}
249 | operators. Such operators:
250 |
251 | 1. get their arguments from the Operand Stack
252 | 2. perform single step of some computation and/or side effects
253 | 3. push the continuation (code and arguments to be executed next) to
254 | the Execution Stack
255 |
256 | [[http://en.wikipedia.org/wiki/Tail_call][Tail Call Optimisation]] is implemented using [[http://logand.com/picoWiki/trampoline][trampoline]]. The evaluator
257 | runs in a loop getting the next [[http://en.wikipedia.org/wiki/Continuation][continuation]] from the Execution Stack.
258 | Operators that want to "continue" their execution (i.e. use the
259 | interpreter to run other operators, including themselves) must perform
260 | only one step at a time and save the remaining steps (continuation) on
261 | the Execution Stack.
262 |
263 | For example, the {{{ps(if)}}} operator saves the "then" or "else" code
264 | branch to the Execution Stack depending on the value of the "test"
265 | argument. It does not "evaluate" the chosen branch directly
266 | (recursively) but leaves the control to the evaluator loop.
267 |
268 | The whole process of interpreting is fed from JavaScript strings which
269 | are obtained from the content of HTML elements (sometimes hidden from
270 | this document).
271 |
272 | ** PostScript data types
273 |
274 | PostScript has quite rich set of data types.
275 | See [[http://www.adobe.com/devnet/postscript/pdfs/PLRM.pdf][PostScript Language Reference PDF document]] for more details.
276 |
277 | | category | type | executable | example | spec |
278 | |-----------+-------------+------------+------------------------+--------------------|
279 | | simple | boolean | | true false | |
280 | | | fontID | | | |
281 | | | integer | | 42 -123 0 | |
282 | | | mark | | | |
283 | | | name | Y | draw /draw | |
284 | | | null | | null | |
285 | | | operator | Y | | |
286 | | | real | | 3.14 1e-10 | |
287 | | | save | | | |
288 | | composite | array | Y | [1 /hi 3.14] {1 2 add} | |
289 | | | condition | | | Display PostScript |
290 | | | dictionary | | <> | |
291 | | | file | | | |
292 | | | gstate | | | Level 2 |
293 | | | lock | | | Display PostScript |
294 | | | packedarray | | | Level 2 |
295 | | | string | Y | (hi) | |
296 |
297 | The following data types are implemented in WPS:
298 |
299 | | category | type | direct | literal | executable |
300 | |-----------+------------+--------+---------+------------|
301 | | simple | boolean | Y | Y | - |
302 | | | number | Y | Y | - |
303 | | | mark | - | Y | - |
304 | | | name | - | Y | Y |
305 | | | null | Y | Y | - |
306 | | | operator | Y | - | Y |
307 | | composite | array | Y | Y | - |
308 | | | proc | - | - | Y |
309 | | | dictionary | Y | Y | - |
310 | | | string | Y | Y | - |
311 |
312 | All the above types are represented directly in JavaScript except:
313 |
314 | | type | representation |
315 | |-----------------+-----------------|
316 | | mark | unique object |
317 | | literal name | quoted symbol |
318 | | executable name | unquoted symbol |
319 | | operator | function |
320 | | proc | quoted array |
321 |
322 | The interpreter needs to understand when to evaluate an argument. The
323 | distinction between a "literal" and "executable" is the key. For the
324 | "proc" type, its origin from the Execution Stack is also important.
325 |
326 | ** Quoting and execution
327 |
328 | There are two important operators to control evaluation at the
329 | PostScript language level.
330 |
331 | The {{{ps(exec)}}} operator usually leaves the argument as is except:
332 |
333 | | type | result |
334 | |-----------------+-------------------|
335 | | executable name | exec value |
336 | | operator | apply operator |
337 | | proc | exec each element |
338 |
339 | The {{{ps(cvx)}}} operator makes the argument "executable". Usually
340 | leaves the argument as is except:
341 |
342 | | from | to | how |
343 | |--------------+-----------------+---------|
344 | | literal name | executable name | unquote |
345 | | array | proc | quote |
346 | | string | proc | ~ parse |
347 |
348 | The ~ (tilde) character in the above table means that the
349 | functionality has not been implemented yet.
350 |
351 | * Drawing with PostScript
352 |
353 | As a convention, operators beginning with dot are non-standard, low
354 | level operators which are subject to change.
355 |
356 | There is a difference in how HTML 5 canvas, PostScript and PDF measure
357 | angles:
358 |
359 | | language/device | unit |
360 | |-----------------+------|
361 | | canvas | rad |
362 | | PostScript | deg |
363 | | PDF | rad |
364 |
365 | Many of the examples below set up their bounding box using the
366 | =.gbox= operator, e.g.
367 |
368 | #+begin_src ps
369 | 0 0 180 180 .gbox
370 | #+end_src
371 |
372 | Only the width and height of the canvas clipping rectangle are taken
373 | into account so far. The width and height is related to the drawing
374 | units rather than to the size of the canvas element.
375 |
376 | Both PostScript and PDF documents have the origin of the coordinate
377 | system in the bottom left corner while HTML 5 canvas in the top left
378 | corner. Thus, some of the following pictures are displayed upside
379 | down unless an explicit coordinate transformation was added. This
380 | discrepancy between the origin of the coordinate system is a problem
381 | when drawing text because a simple coordinate transformation on its
382 | own would draw the text upside-down.
383 |
384 | ** Bowtie example
385 |
386 | See the [[https://developer.mozilla.org/en/drawing_graphics_with_canvas#section_6][original example]] in JavaScript.
387 |
388 | #+html:
389 | #+html:
390 | #+include "bowtie.wps" src ps
391 | #+html:
392 | #+html:
393 |
394 | ** Analog clock example
395 |
396 | See the [[http://oreilly.com/openbook/cgi/ch06_02.html][original example]].
397 |
398 | Click on the clock to start/stop it. (If using Chrome, you might need
399 | to reload the page for this to work. Not sure why?)
400 |
401 | #+html:
402 |
403 | #+html:
404 | #+include "clock2.wps" src ps
405 | #+html:
406 | #+html:
407 |
408 | Running the clock keeps the CPU noticeably busy. Chrome is best with
409 | very little overhead. Firefox and Opera perform significantly worse.
410 | WPS seems to be fast enough for one-off drawings, but its usability
411 | depends on the efficiency of the host JavaScript interpreter when
412 | running the interpreter in a tight loop.
413 |
414 | ** Fill example
415 |
416 | See the [[https://developer.mozilla.org/samples/canvas-tutorial/4_1_canvas_fillstyle.html][original example]] in JavaScript.
417 |
418 | #+html:
419 | #+html:
420 | #+include "fill.wps" src ps
421 | #+html:
422 | #+html:
423 |
424 | ** Tiger example
425 |
426 | The [[http://svn.ghostscript.com/viewvc/trunk/gs/examples/tiger.eps?view=co][original example]] is included with [[http://ghostscript.com/][Ghostscript]].
427 |
428 | #+begin_html
429 |
431 |
Drawing took -- seconds.
432 | #+end_html
433 |
434 | #+html:
435 | #+include "tiger.eps" src text
436 | #+html:
447 | /time2 .date (getTime) 0 .call def
448 | (msg) .getElementById (textContent) time2 time1 sub 1000 div put
449 |
450 |
451 |
454 | the tiger (be patient).
455 | #+end_html
456 |
457 | Is this an interesting JavaScript and canvas benchmark?
458 |
459 | #+plot: title:"tiger.eps drawing times" ind:1 deps:(2 3 4) type:2d with:histograms set:"yrange [0:]" set:"xlabel 'browser'" set:"ylabel 'time [s]'" set:"style histogram gap 3" file:"tiger.png" set:"term png size 600, 300"
460 | | browser | WPS time [s] | WPS time (no bind) [s] | PostCanvas time [s] |
461 | |-------------+--------------+------------------------+---------------------|
462 | | Chrome | 2.7 | 4.1 | 1.6 |
463 | | Opera | 17.9 | 12.3 | 0 |
464 | | Firefox 3.0 | 21.0 | 19.0 | 7.0 |
465 | | Firefox 3.5 | 13.0 | 9.5 | 3.3 |
466 | | Safari | 2.9 | 0 | 0 |
467 |
468 | The above times were on Vaio T7200 Core 2 2GHz 2GB running Ubuntu.
469 |
470 | [[http://www.feiri.de/pcan/][PostCanvas]] runs this [[http://www.feiri.de/pcan/example1.html][example]] about 1.5 times (Chrome) to 3 times
471 | (Firefox) faster. I am actually surprised that WPS runs only about
472 | 1.5 times slower in Chrome even though it interprets almost everything
473 | with minimal number of operators coded directly in JavaScript
474 | (compared to PostCanvas which implements all operators directly in
475 | JavaScript). Time for Safari was reported by Will King and even
476 | though it was not run on the same machine as the other tests, it shows
477 | that the speed is comparable to Chrome.
478 |
479 | Another surprise to me is that I expected more significant speed up
480 | after implementing the {{{ps(bind)}}} operator. Why does Opera and
481 | Firefox get slower in this case?
482 |
483 | It should be fairly easy to speed WPS up by coding more operators
484 | directly in JavaScript. The speed of PostCanvas could probably be
485 | taken as the best case that could be achieved by optimizing WPS.
486 |
487 | file:tiger.png
488 |
489 | Note by Dave Chapman:
490 |
491 | #+begin_quote
492 |
493 | I've found that reducing the number of function calls in complex
494 | scripts has by far the biggest gains in speed - but I guess you
495 | already know this. For instance, when I run the Tiger demo it takes
496 | about 19sec on my machine (FF3.0, dual core, 4gb ram) but according to
497 | the firebug profiler it's making nearly 4 million function calls (as a
498 | comparison PostCanvas is *only* making about 220,000 calls).
499 |
500 | #+end_quote
501 |
502 | Note by Ray Johnson:
503 |
504 | #+begin_quote
505 |
506 | Tested Safari 4.0.4 (Win) and Firefox 3.5.5 (Win):
507 |
508 | - Safari 4.0.4 Tiger drawing time = 1.76
509 | - Firefox 3.5.5 Tiger drawing time = 6.945
510 |
511 | I’m on a Dell T7400 Xeon Quad Core 3.0 GHz with 4GB Ram and Vista SP2 32 Bit-and
512 |
513 | #+end_quote
514 |
515 | Firefox throws error about linecap and linejoin not being supported so
516 | these were not used here. Opera throws an error when running the
517 | PostCanvas example. The tiger does not look the same as rendered by
518 | [[http://projects.gnome.org/evince/][Evince]] ([[http://poppler.freedesktop.org/][poppler]]/[[http://cairographics.org/][cairo]]) so maybe the linecap and linejoin are
519 | really needed to get proper image as intended.
520 |
521 | It is also interesting to observe that PDF operators and their names
522 | probably came up from shortening/compressing common "user-space"
523 | PostScript operators in PostScript files. The tiger.eps file was
524 | created in 1990 and contains some "shortcuts" that match PDF operators
525 | standardised later.
526 |
527 | * Drawing with PDF
528 |
529 | PDF is rather complex format. WPS aims to implement only drawing
530 | operators that can be present in PDF content streams. The number of
531 | these operators is fixed and limited. Even though the full PostScript
532 | language is not required, it can be convenient to implement them in
533 | PostScript.
534 |
535 | However, some aspects (e.g. colors) are handled differently in PDF
536 | compared to PostScript and these differences are not addressed by WPS.
537 | I imagine that a supporting server-side solution like [[../ondoc/index.org][OnDoc]] would
538 | provide necessary data (e.g. decomposing PDF into pages and objects,
539 | providing HTML 5 web fonts and font metrics) and WPS would only draw
540 | preprocessed page content.
541 |
542 | Quoting from [[http://www.adobe.com/print/features/psvspdf/index.html][Adobe]]:
543 |
544 | #+begin_quote
545 | A PDF file is actually a PostScript file which has already been
546 | interpreted by a RIP and made into clearly defined objects.
547 | #+end_quote
548 |
549 | ** Heart example
550 |
551 | See also the [[https://developer.mozilla.org/samples/canvas-tutorial/2_6_canvas_beziercurveto.html][original example]] in JavaScript.
552 |
553 | #+html:
554 | #+html:
555 | #+include "heart.wps" src ps
556 | #+html:
557 | #+html:
558 |
559 | ** Rectangle example
560 |
561 | TODO find the original example
562 |
563 | #+html:
564 | #+html:
565 | #+include "rect.wps" src ps
566 | #+html:
567 | #+html:
568 |
569 | ** Triangles example
570 |
571 | See also the [[https://developer.mozilla.org/samples/canvas-tutorial/2_3_canvas_lineto.html][original example]] in JavaScript.
572 |
573 | #+html:
574 | #+html:
577 | #+html:
578 |
579 | ** Smile example
580 |
581 | See also the [[http://developer.mozilla.org/samples/canvas-tutorial/2_2_canvas_moveto.html][original example]] in JavaScript.
582 |
583 | #+html:
584 | #+html:
585 | #+include "smile.wps" src ps
586 | #+html:
587 | #+html:
588 |
589 | ** Star example
590 |
591 | See also the [[http://www.adobe.com/technology/pdfs/presentations/KingPDFTutorial.pdf][original PDF document]] where this example is presented.
592 |
593 | #+html:
594 | #+html:
595 | #+include "star.wps" src ps
596 | #+html:
597 | #+html:
598 |
599 | ** Squares example
600 |
601 | See also the [[https://developer.mozilla.org/samples/canvas-tutorial/5_1_canvas_savestate.html][original example]] in JavaScript.
602 |
603 | #+html:
604 | #+html:
607 | #+html:
608 |
609 | ** Two squares example
610 |
611 | See also the [[https://developer.mozilla.org/en/drawing_graphics_with_canvas][original example]] in JavaScript.
612 |
613 | #+html:
614 | #+html: