gs_pfile.ps 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. % Copyright (C) 1994, 1995 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  6. % This software is distributed under license and may not be copied,
  7. % modified or distributed except as expressly authorized under the terms
  8. % of the license contained in the file LICENSE in this distribution.
  9. %
  10. % For more information about licensing, please refer to
  11. % http://www.ghostscript.com/licensing/. For information on
  12. % commercial licensing, go to http://www.artifex.com/licensing/ or
  13. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  14. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  15. % $Id: gs_pfile.ps,v 1.5 2003/08/08 18:45:05 ray Exp $
  16. % Runtime support for minimum-space fonts and packed files.
  17. % ****** NOTE: This file must be kept consistent with
  18. % ****** packfile.ps and wrfont.ps.
  19. % ---------------- Packed file support ---------------- %
  20. % A packed file is the concatenation of several file groups, each of which
  21. % is the result of compressing several files concatenated together.
  22. % The packed file begins with a procedure that creates an appropriate
  23. % decoding filter for each file group, as follows:
  24. % <group-subfile-filter> -proc- <group-decode-filter>
  25. % Thus, accessing an individual file requires 4 parameters:
  26. % the starting address and length of the outer compressed file,
  27. % and the starting address and length of the inner file.
  28. /.packedfilefilter % <file> <ostart> <olength> <istart> <ilength>
  29. % .packedfilefilter <filter>
  30. { 4 index systemdict begin token pop end 6 1 roll
  31. % Stack: fproc file ostart olength istart ilength
  32. 4 index 5 -1 roll setfileposition
  33. % Stack: fproc file olength istart ilength
  34. 4 -2 roll () /SubFileDecode filter
  35. % Stack: fproc istart ilength ofilter
  36. 4 -1 roll exec
  37. % Filters don't support setfileposition, so we must skip data
  38. % by reading it into a buffer. We rely on the fact that
  39. % save/restore don't affect file positions.
  40. % Stack: istart ilength dfilter
  41. save exch 64000 string
  42. % Stack: istart ilength save dfilter scratch
  43. 4 index 1 index length idiv { 2 copy readstring pop pop } repeat
  44. 2 copy 0 8 -1 roll 2 index length mod getinterval readstring pop pop pop
  45. % Stack: ilength save dfilter
  46. exch restore exch () /SubFileDecode filter
  47. } bind def
  48. % Run a packed library file.
  49. /.runpackedlibfile % <filename> <ostart> <olength> <istart> <ilength>
  50. % .runpackedlibfile
  51. { 5 -1 roll findlibfile
  52. { exch pop dup 6 2 roll .packedfilefilter
  53. currentobjectformat exch 1 setobjectformat run
  54. setobjectformat closefile
  55. }
  56. { 5 1 roll /findlibfile load /undefinedfilename signalerror
  57. }
  58. ifelse
  59. } bind def
  60. % ---------------- Compacted font support ---------------- %
  61. % Compacted fonts written by wrfont.ps depend on the existence and
  62. % specifications of the procedures and data in this section.
  63. /.compactfontdefault mark
  64. /PaintType 0
  65. /FontMatrix [0.001 0 0 0.001 0 0] readonly
  66. /FontType 1
  67. /Encoding StandardEncoding
  68. .dicttomark readonly def
  69. /.checkexistingfont % <fontname> <uid> <privatesize> <fontsize>
  70. % .checkexistingfont
  71. % {} (<font> on d-stack)
  72. % <fontname> <uid> <privatesize> <fontsize>
  73. % .checkexistingfont
  74. % -save- --restore-- (<font> on d-stack)
  75. { FontDirectory 4 index .knownget
  76. { dup /UniqueID .knownget
  77. { 4 index eq exch /FontType get 1 eq and }
  78. { pop false }
  79. ifelse
  80. }
  81. { false
  82. }
  83. ifelse
  84. { save /restore load 6 2 roll }
  85. { {} 5 1 roll }
  86. ifelse
  87. dict //.compactfontdefault exch .copydict begin
  88. dict /Private exch def
  89. Private begin
  90. /MinFeature {16 16} def
  91. /Password 5839 def
  92. /UniqueID 1 index def
  93. end
  94. /UniqueID exch def
  95. /FontName exch def
  96. } bind def
  97. /.knownEncodings [
  98. ISOLatin1Encoding
  99. StandardEncoding
  100. SymbolEncoding
  101. ] readonly def
  102. /.readCharStrings % <count> <encrypt> .readCharStrings <dict>
  103. { exch dup dict dup 3 -1 roll
  104. { currentfile token pop dup type /integertype eq
  105. { dup -8 bitshift //.knownEncodings exch get exch 255 and get } if
  106. currentfile token pop dup type /nametype eq
  107. { 2 index exch get
  108. }
  109. { % Stack: encrypt dict dict key value
  110. 4 index { 4330 exch dup .type1encrypt exch pop } if
  111. readonly
  112. }
  113. ifelse put dup
  114. }
  115. repeat pop exch pop
  116. } bind def