gs_dps1.ps 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. % Copyright (C) 1997, 1999 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_dps1.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
  16. % Initialization file for most of the Display PostScript functions
  17. % that are also included in Level 2.
  18. level2dict begin
  19. % ------ Virtual memory ------ %
  20. /currentshared /.currentglobal load def
  21. /scheck /.gcheck load def
  22. %****** FOLLOWING IS WRONG ******
  23. /shareddict currentdict /globaldict .knownget not { 20 dict } if def
  24. % Global and LocalFontDirectory must remain in systemdict
  25. % even if we temporarily exit Level 2 mode.
  26. end % level2dict
  27. systemdict begin
  28. /SharedFontDirectory .FontDirectory .gcheck
  29. { .currentglobal false .setglobal
  30. /LocalFontDirectory .FontDirectory dup maxlength dict copy
  31. .forcedef % LocalFontDirectory is local, systemdict is global
  32. .setglobal .FontDirectory
  33. }
  34. { /LocalFontDirectory .FontDirectory
  35. .forcedef % LocalFontDirectory is local, systemdict is global
  36. 50 dict
  37. }
  38. ifelse def
  39. end % systemdict
  40. level2dict begin
  41. % setshared must rebind FontDirectory to the appropriate one of
  42. % Local or SharedFontDirectory.
  43. /.setglobal % <bool> .setglobal -
  44. { dup .setglobal
  45. //systemdict /FontDirectory .currentglobal
  46. { //SharedFontDirectory }
  47. { /LocalFontDirectory .systemvar } % can't embed ref to local VM
  48. ifelse .forceput pop % LocalFontDirectory is local, systemdict is global
  49. } .bind odef % must bind .forceput and .setglobal
  50. % even if NOBIND in effect
  51. % Don't just copy (load) the definition of .setglobal:
  52. % it gets redefined for LL3.
  53. /setshared { /.setglobal .systemvar exec } odef
  54. .currentglobal setshared
  55. % See below for changes in save and restore.
  56. % ------ Fonts ------ %
  57. /selectfont % <fontname> <size> selectfont -
  58. { 1 index findfont
  59. 1 index dup type /arraytype eq { makefont } { scalefont } ifelse
  60. setfont pop pop
  61. } odef
  62. % undefinefont has to take local/global VM into account.
  63. /undefinefont % <fontname> undefinefont -
  64. { .FontDirectory 1 index .undef
  65. .currentglobal
  66. { % Current mode is global; delete from local directory too.
  67. //systemdict /LocalFontDirectory .knownget
  68. { 1 index .undef }
  69. if
  70. }
  71. { % Current mode is local; if there was a shadowed global
  72. % definition, copy it into the local directory.
  73. //systemdict /SharedFontDirectory .knownget
  74. { 1 index .knownget
  75. { .FontDirectory 2 index 3 -1 roll put }
  76. if
  77. }
  78. if
  79. }
  80. ifelse pop
  81. } odef
  82. % If we load a font into global VM within an inner save, the restore
  83. % will delete it from FontDirectory but not from SharedFontDirectory.
  84. % We have to handle this by making restore copy missing entries from
  85. % SharedFontDirectory to FontDirectory. Since this could slow down restore
  86. % considerably, we define a new operator .dictcopynew for this purpose.
  87. % Furthermore, if FAKEFONTS is in effect, we want global real fonts to
  88. % override fake local ones. We handle this by brute force.
  89. /restore % <save> restore -
  90. { dup //restore % bind even if NOBIND
  91. /LocalFontDirectory .systemvar
  92. FAKEFONTS
  93. { mark
  94. % We want to delete a fake font from the local directory
  95. % iff the global directory now has no definition for it,
  96. % or a non-fake definition.
  97. 1 index dup
  98. { % Stack: lfd mark lfd key ... lfd key value
  99. length 1 gt
  100. { % This is a real local definition; don't do anything.
  101. pop
  102. }
  103. { % This is a fake local definition, check for global.
  104. //SharedFontDirectory 1 index .knownget
  105. { % A global definition exists, check for fake.
  106. length 1 eq { pop } { 1 index } ifelse
  107. }
  108. { % No global definition, delete the local one.
  109. 1 index
  110. }
  111. ifelse
  112. }
  113. ifelse
  114. } forall
  115. pop counttomark 2 idiv { .undef } repeat pop
  116. }
  117. if
  118. //SharedFontDirectory exch .dictcopynew pop
  119. .currentglobal .setglobal % Rebind FontDirectory according to current VM.
  120. pop
  121. } bind odef
  122. % ------ Miscellaneous ------ %
  123. /undef /.undef load def
  124. end % level2dict