You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.6 KiB

1 month ago
  1. % Copyright (C) 2001-2023 Artifex Software, Inc.
  2. % All Rights Reserved.
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  7. % This software is distributed under license and may not be copied,
  8. % modified or distributed except as expressly authorized under the terms
  9. % of the license contained in the file LICENSE in this distribution.
  10. %
  11. % Refer to licensing information at http://www.artifex.com or contact
  12. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  13. % CA 94129, USA, for further information.
  14. %
  15. % Initialization file for most of the Display PostScript functions
  16. % that are also included in Level 2.
  17. level2dict begin
  18. % ------ Virtual memory ------ %
  19. /currentshared /.currentglobal load def
  20. /scheck {.gcheck} .internalbind odef
  21. %****** FOLLOWING IS WRONG ******
  22. /shareddict currentdict /globaldict .knownget not { 20 dict } if def
  23. % Global and LocalFontDirectory must remain in systemdict
  24. % even if we temporarily exit Level 2 mode.
  25. end % level2dict
  26. systemdict begin
  27. /SharedFontDirectory .FontDirectory .gcheck
  28. { .currentglobal //false .setglobal
  29. currentdict
  30. /LocalFontDirectory .FontDirectory dup maxlength dict copy
  31. .forceput % LocalFontDirectory is local, systemdict is global
  32. .setglobal .FontDirectory
  33. } executeonly
  34. {
  35. currentdict
  36. /LocalFontDirectory .FontDirectory
  37. .forceput % LocalFontDirectory is local, systemdict is global
  38. 50 dict
  39. }executeonly
  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. } .forcebind odef
  52. % Don't just copy (load) the definition of .setglobal:
  53. % it gets redefined for LL3.
  54. /setshared { /.setglobal .systemvar exec } odef
  55. .currentglobal setshared
  56. % See below for changes in save and restore.
  57. % ------ Fonts ------ %
  58. /selectfont % <fontname> <size> selectfont -
  59. {
  60. {
  61. 1 .argindex findfont
  62. 1 index dup type /arraytype eq { makefont } { scalefont } ifelse
  63. setfont pop pop
  64. } stopped { /selectfont .systemvar $error /errorname get signalerror } if
  65. } odef
  66. % undefinefont has to take local/global VM into account.
  67. /undefinefont % <fontname> undefinefont -
  68. { //.FontDirectory 1 .argindex .forceundef % FontDirectory is readonly
  69. .currentglobal
  70. { % Current mode is global; delete from local directory too.
  71. //systemdict /LocalFontDirectory .knownget
  72. { 1 index .forceundef } executeonly % LocalFontDirectory is readonly
  73. if
  74. }
  75. { % Current mode is local; if there was a shadowed global
  76. % definition, copy it into the local directory.
  77. //systemdict /SharedFontDirectory .knownget
  78. { 1 index .knownget
  79. { //.FontDirectory 2 index 3 -1 roll .forceput } % readonly
  80. if
  81. }
  82. if
  83. }
  84. ifelse pop
  85. } .forcebind odef
  86. % If we load a font into global VM within an inner save, the restore
  87. % will delete it from FontDirectory but not from SharedFontDirectory.
  88. % We have to handle this by making restore copy missing entries from
  89. % SharedFontDirectory to FontDirectory. Since this could slow down restore
  90. % considerably, we define a new operator .forcecopynew for this purpose.
  91. % Furthermore, if FAKEFONTS is in effect, we want global real fonts to
  92. % override fake local ones. We handle this by brute force.
  93. /restore % <save> restore -
  94. { dup //restore
  95. /LocalFontDirectory .systemvar
  96. FAKEFONTS
  97. { mark
  98. % We want to delete a fake font from the local directory
  99. % iff the global directory now has no definition for it,
  100. % or a non-fake definition.
  101. 1 index dup
  102. { % Stack: lfd mark lfd key ... lfd key value
  103. length 1 gt
  104. { % This is a real local definition; don't do anything.
  105. pop
  106. }
  107. { % This is a fake local definition, check for global.
  108. //SharedFontDirectory 1 index .knownget
  109. { % A global definition exists, check for fake.
  110. length 1 eq { pop } { 1 index } ifelse
  111. }
  112. { % No global definition, delete the local one.
  113. 1 index
  114. }
  115. ifelse
  116. }
  117. ifelse
  118. } forall
  119. pop counttomark 2 idiv { .forceundef } executeonly repeat pop % readonly
  120. }
  121. if
  122. //SharedFontDirectory exch .forcecopynew pop
  123. .currentglobal .setglobal % Rebind FontDirectory according to current VM.
  124. pop
  125. } .forcebind odef
  126. end % level2dict