gs_dps1.ps 4.6 KB

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