home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / postscri / 6086 < prev    next >
Encoding:
Text File  |  1992-12-23  |  4.9 KB  |  98 lines

  1. Newsgroups: comp.lang.postscript
  2. Path: sparky!uunet!spool.mu.edu!agate!dog.ee.lbl.gov!hellgate.utah.edu!csn!raven!rcd
  3. From: rcd@raven.eklektix.com (Dick Dunn)
  4. Subject: Re: Justifying strings, how??
  5. Message-ID: <1992Dec23.082549@eklektix.com>
  6. Organization: eklektix - Boulder, Colorado
  7. References: <1992Dec17.011125.8658@trilithon.mpk.ca.us> <zisk-181292180203@macne003.boston.us.adobe.com> <id.4D0W.BNH@ferranti.com>
  8. Date: Wed, 23 Dec 1992 08:25:49 GMT
  9. Lines: 87
  10.  
  11. peter@ferranti.com (peter da silva) writes:
  12. >zisk@adobe.com (Stephen Zisk) writes:
  13. >(justification on the printer...)
  14. >> This works well, but puts the load onto the PostScript interpreter.
  15. >
  16. ><stringwidth> seems to be a cheap operator. 
  17.  
  18. Actually, stringwidth is moderately expensive, and can be quite expensive.
  19. The one factor that saves you is the font cache.  Let's take a look under
  20. the hood...
  21.  
  22. A host program, using .afm files and fairly obvious C code, gets the widths
  23. and runs down the string with a for loop, picking up widths and accumulating
  24. them.  The cost is a handful of machine instructions per character.
  25.  
  26. A PostScript program gets into the stringwidth operator and runs down the
  27. string with a for loop, picking up characters and adding their widths.  The
  28. cost is similar *except* for what it takes to get the widths.  Let's look
  29. another level down...
  30.  
  31. If the character is not in the cache, we're in trouble.  We've got a char-
  32. acter code, which is an index into the encoding vector, which gives a name,
  33. which must be hashed to get into the CharStrings dictionary, which gives us
  34. this funky object that must be interpreted.  Now, we only need the width,
  35. which must appear near the beginning (assuming the normal case of a Type 1
  36. font) in an sbw or hsbw operation...but by the time we get to that point,
  37. we're about two orders of magnitude higher in operations-per-character than
  38. the host case.  What saves us is this:  (a) the character has probably
  39. already been rendered once, so it's probably in the cache and we don't go
  40. down this path, or (b) if we get here, the interpreter may go ahead and
  41. render the character into the cache, so that we pay the cost here but not
  42. in the "show" operation which almost certainly follows.
  43.  
  44. That is, it may appear that stringwidth is cheap under normal circumstances,
  45. but if you didn't do corresponding show's afterward, it might look more
  46. expensive.
  47.  
  48. If the character is in the cache, we'll do a hash based on the character
  49. code and the current font/matrix combination, drag out the width and
  50. accumulate it.  The overhead isn't bad, but it's probably several times the
  51. cost of a direct host-based loop.
  52.  
  53. >> For tests, short jobs, and personal use, this is fine, but if you
  54. >> are writing a driver with performance in mind, you should at least
  55. >> consider doing the job on the host.
  56. >
  57. >I don't know about that. I've used text-to-Postscript preprocessors, and
  58. >even on printers with a cheesy 68000 I've got better results in terms of
  59. >page speed letting the printer do this sort of thing...
  60.  
  61. It's easy for the simple case, hard for the semi-sophisticated case, and
  62. damned-near-impossible for the general case.
  63.  
  64. >It seems that parsing
  65. >Postscript (breaking up numbers, words, etc) is relatively expensive
  66. >compared to executing the Postscript code...
  67.  
  68. Is the cost of parsing and managing it separated from the cost of trans-
  69. mitting it?  But even if the transmission time is not a major issue, yes,
  70. there is this per-character overhead that can dominate.  Get down to bound
  71. code, and the picture changes somewhat.
  72.  
  73. >Personally, I would prefer it if programs made decisions like this as late
  74. >as possible, so I can print a document with a different font (say, my printer
  75. >doesn't handle Palatino and the company is too cheap to buy a softfont)
  76. >without screwing things up too badly.
  77.  
  78. This would be nice, and it works for simple documents, but how far can you
  79. carry it?  My experience is that it works for *very* simple stuff, but you
  80. hit the wall before you get all you want.  Here's where it goes:  If you
  81. chnage the font, you change the line breaking, which requires hyphenation
  82. on the printer side.  You also change page breaks, which changes the
  83. ToC.  This ends up requiring the file-inclusion (diagrams, EPS stuff) on
  84. the printer side, which means that it has to know how to get files.  There
  85. is a large, uncomfortable middle ground...for example, I can see running
  86. troff on a host machine and shipping PostScript across, or I can see
  87. shipping troff source to a capable printer which knows how to snag the
  88. files it needs, but I don't see much in between.
  89.  
  90. Formatters written in PostScript (been there, done that!) tend to have
  91. this unfortunate characteristic of "simple things are simple; difficult
  92. things are impossible" and the curve in between has a very uncomfortable
  93. shape.  If anyone sees how to make the middle ground passable, I'd love to
  94. hear how.
  95. -- 
  96. Dick Dunn    rcd@eklektix.com   -or-   raven!rcd    Boulder, Colorado USA
  97.    ...Mr. Natural says, "Use the right tool for the job."
  98.