Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
postscript [2020/02/20 17:43]
christian [exception handling example]
postscript [2020/02/23 15:53] (current)
christian [Get the code]
Line 9: Line 9:
 ===== Get the code ===== ===== Get the code =====
  
-Load the package **[PostScript]** from the [[storeaccess|Cincom Public Store]] into your [[http://www.cincomsmalltalk.com/main/products/visualworks/|VisualWorks]] image. +Load the packages **[Values]** and **[PostScript]** from the [[storeaccess|Cincom Public Store]] into your [[http://www.cincomsmalltalk.com/main/products/visualworks/|VisualWorks]] image. 
-Tests are in package **[PostScript Testing]**.+Tests are in package **[PostScript Testing]**. The package can be used stand-alone without PDFtalk. It only depends on the **[Values]** package.
  
-The bundle **{PDFtalk}** now depends on this package and loads PostScript automatically.+The package is now part of the **{PDFtalk}** bundle.
  
 ===== Use it ===== ===== Use it =====
Line 46: Line 46:
 Ultimately I want to extract text from PDFs for which I need CMaps. Ultimately I want to extract text from PDFs for which I need CMaps.
  
-Also, I like PostScript. I used it quite a bit to write UIs with Display PostScript on a Sun Solaris NeWS workstation. The language allows for some nice programming patterns.+Also, I like PostScript. I used it quite a bit to write UIs with Display PostScript on a Sun NeWS(([[https://en.wikipedia.org/wiki/NeWS|NeWS]] Wikipedia article)) workstation. The language allows for some nice programming patterns.
 ===== PostScript programming introduction ===== ===== PostScript programming introduction =====
  
Line 75: Line 75:
 </code> </code>
 leaves 49 on the stack. leaves 49 on the stack.
- 
  
 At the start of a PostScript interpreter, the dictionary stack contains 3 dictionaries: At the start of a PostScript interpreter, the dictionary stack contains 3 dictionaries:
Line 81: Line 80:
   * **global dict** "globally accessible definitions. Initially empty"   * **global dict** "globally accessible definitions. Initially empty"
   * **system dict** "bottom of the stack. Read only with build-in operators"   * **system dict** "bottom of the stack. Read only with build-in operators"
 +
 +New definitions are put into the topmost dictionary of the stack. This allows programs to override system definitions. The NeWS system from Sun used this to implement an object oriented Display PostScript with the dictionaries as classes. Another view is to see the dictionaries as namespaces.
 +
 +The dictionaries can be named with an interesting trick: the dictionary itself is stored under a key which is interpreted as its name. The system dict for example is constructed like:
 +<code smalltalk>
 +| dict |
 +dict := PSDictionary new.
 +dict at: #systemdict put: dict.
 +^dict
 +</code>
 +
 +This creates a recursive structure which is not handled well by the standard Smalltalk dictionary, hence ''PSDictionary'' as my implementation of it.
 +
 +  Interestingly, Gemstone has exactly the same dictionaries implementing method lookup.
 +  Including the naming scheme for dictionaries!
  
 (more will be written on demand...) (more will be written on demand...)
Line 135: Line 149:
 </code> </code>
  
 +I think that both approaches are very elegant.
  
  • postscript.1582217011.txt.gz
  • Last modified: 2020/02/20 17:43
  • by christian