gs_pfile.ps 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. % Copyright (C) 1994, 1995 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of AFPL Ghostscript.
  4. %
  5. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  6. % distributor accepts any responsibility for the consequences of using it, or
  7. % for whether it serves any particular purpose or works at all, unless he or
  8. % she says so in writing. Refer to the Aladdin Free Public License (the
  9. % "License") for full details.
  10. %
  11. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  12. % in a plain ASCII text file named PUBLIC. The License grants you the right
  13. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14. % conditions described in the License. Among other things, the License
  15. % requires that the copyright notice and this notice be preserved on all
  16. % copies.
  17. % $Id: gs_pfile.ps,v 1.2 2000/09/19 18:29:11 lpd Exp $
  18. % Runtime support for minimum-space fonts and packed files.
  19. % ****** NOTE: This file must be kept consistent with
  20. % ****** packfile.ps and wrfont.ps.
  21. % ---------------- Packed file support ---------------- %
  22. % A packed file is the concatenation of several file groups, each of which
  23. % is the result of compressing several files concatenated together.
  24. % The packed file begins with a procedure that creates an appropriate
  25. % decoding filter for each file group, as follows:
  26. % <group-subfile-filter> -proc- <group-decode-filter>
  27. % Thus, accessing an individual file requires 4 parameters:
  28. % the starting address and length of the outer compressed file,
  29. % and the starting address and length of the inner file.
  30. /.packedfilefilter % <file> <ostart> <olength> <istart> <ilength>
  31. % .packedfilefilter <filter>
  32. { 4 index systemdict begin token pop end 6 1 roll
  33. % Stack: fproc file ostart olength istart ilength
  34. 4 index 5 -1 roll setfileposition
  35. % Stack: fproc file olength istart ilength
  36. 4 -2 roll () /SubFileDecode filter
  37. % Stack: fproc istart ilength ofilter
  38. 4 -1 roll exec
  39. % Filters don't support setfileposition, so we must skip data
  40. % by reading it into a buffer. We rely on the fact that
  41. % save/restore don't affect file positions.
  42. % Stack: istart ilength dfilter
  43. save exch 1000 string
  44. % Stack: istart ilength save dfilter scratch
  45. 4 index 1 index length idiv { 2 copy readstring pop pop } repeat
  46. 2 copy 0 8 -1 roll 2 index length mod getinterval readstring pop pop pop
  47. % Stack: ilength save dfilter
  48. exch restore exch () /SubFileDecode filter
  49. } bind def
  50. % Run a packed library file.
  51. /.runpackedlibfile % <filename> <ostart> <olength> <istart> <ilength>
  52. % .runpackedlibfile
  53. { 5 -1 roll findlibfile
  54. { exch pop dup 6 2 roll .packedfilefilter
  55. currentobjectformat exch 1 setobjectformat run
  56. setobjectformat closefile
  57. }
  58. { 5 1 roll /findlibfile load /undefinedfilename signalerror
  59. }
  60. ifelse
  61. } bind def
  62. % ---------------- Compacted font support ---------------- %
  63. % Compacted fonts written by wrfont.ps depend on the existence and
  64. % specifications of the procedures and data in this section.
  65. /.compactfontdefault mark
  66. /PaintType 0
  67. /FontMatrix [0.001 0 0 0.001 0 0] readonly
  68. /FontType 1
  69. /Encoding StandardEncoding
  70. .dicttomark readonly def
  71. /.checkexistingfont % <fontname> <uid> <privatesize> <fontsize>
  72. % .checkexistingfont
  73. % {} (<font> on d-stack)
  74. % <fontname> <uid> <privatesize> <fontsize>
  75. % .checkexistingfont
  76. % -save- --restore-- (<font> on d-stack)
  77. { FontDirectory 4 index .knownget
  78. { dup /UniqueID .knownget
  79. { 4 index eq exch /FontType get 1 eq and }
  80. { pop false }
  81. ifelse
  82. }
  83. { false
  84. }
  85. ifelse
  86. { save /restore load 6 2 roll }
  87. { {} 5 1 roll }
  88. ifelse
  89. dict //.compactfontdefault exch .copydict begin
  90. dict /Private exch def
  91. Private begin
  92. /MinFeature {16 16} def
  93. /Password 5839 def
  94. /UniqueID 1 index def
  95. end
  96. /UniqueID exch def
  97. /FontName exch def
  98. } bind def
  99. /.knownEncodings [
  100. ISOLatin1Encoding
  101. StandardEncoding
  102. SymbolEncoding
  103. ] readonly def
  104. /.readCharStrings % <count> <encrypt> .readCharStrings <dict>
  105. { exch dup dict dup 3 -1 roll
  106. { currentfile token pop dup type /integertype eq
  107. { dup -8 bitshift //.knownEncodings exch get exch 255 and get } if
  108. currentfile token pop dup type /nametype eq
  109. { 2 index exch get
  110. }
  111. { % Stack: encrypt dict dict key value
  112. 4 index { 4330 exch dup .type1encrypt exch pop } if
  113. readonly
  114. }
  115. ifelse put dup
  116. }
  117. repeat pop exch pop
  118. } bind def