PostScript 过程集和资源存储在哪里?

Where are PostScript procedure sets and resources stored?

PostScript 包含程序集 (ProcSets)。 过程集是包含命名过程和运算符的字典。

这些程序集是按类别组织的。 现在这些类别存储在哪里?

  1. (常规)资源存储在哪里? (例如字体、CIDFont、CMap、ProcSet 等)
  2. ProcSet的类别存储在哪里?

您是否只需要在 systemdict 中使用两个额外的词典(localDict 和一个 globalDict 来存储资源,或者它们究竟存储在哪里?)

更新 1:(在 KenS 回答后)

好的,也许现在第一个问题应该是。资源如何存储在解释器中。

据我了解,可能有这样的结构:

Resources (Dictionary ??? is this local or global or ...?)
- Font (Dictionary)
- CIDFont (Dictionary)
--- CIDFontType (integer)
--- CIDFontName (name)
--- CIDSystemInfo (dictionary)
--- FontBBox (array)
--- FontMatrix (array)
--- FontType (integer)
--- ...
--- ...
- CMap (Dictionary)
- FontSet (Dictionary)
- Encoding (Array)
- Form (Dictionary)
- Pattern (Dictionary)
- ProcSet (Dictionary)
--- BitmapFontInit (Dictionary)
--- CIDInit (Dictionary)
--- ColorRendering (Dictionary)
--- FontSetInit (Dictionary)
--- Trapping (Dictionary)
- ColorSpace (Array)
- ...
- ...
- Category (Dictionary)
--- Generic (Dictionary)

其中大部分是存储在 VM 中的字典。在本地 VM 或全局 VM 中。

userdict 和 globaldict 中是否也添加了这些资源,因为:

参见 PostScript 语言参考手册 3(第 66 页第 3 章):

The dictionaries userdict and globaldict are intended to be the principal repositories for application-defined dictionaries and other objects. When a PostScript program creates a dictionary in local VM, it then typically associates that dictionary with a name in userdict. Similarly, when the program creates a dictionary in global VM, it typically associates the dictionary with a name in globaldict.

所以最简单的方法是创建 2 个词典:"MyLocalResources" 和 "MyGlobalResources",其中第一个存储在 userdict 中,另一个存储在 globaldict 中。 这两个词典将包含类别(字体、CIDFont、ProcSet 等...)。

findresource 运算符是一种您必须自己实现的机制,它将在这两个词典中的一个中查找。

这是正确的吗?

FontDirectoryGlobalFontDirectory这些实际上是本地和全局"Font"类别资源的实现吗?

首先确定程序集按类别排列,它们与其他资源一样是资源。因此,您通过名称和类别引用它们(在这种情况下,类别是 ProcSet)。

Stored Resources可以存储在任何便于实现的地方。通常这是在磁盘上,但不一定是;例如 Ghostscript 可以将其标准资源存储在 ROM 文件系统中。

实例化后,无论是通过从 PostScript 程序创建定义,还是通过定位和实例化命名资源,资源都会存储在 VM 中。

我看不出您需要在 localdict 或 globaldict 中添加任何额外的条目,因为 findresource 可以使用您喜欢的任何机制来定位资源(请注意,字体的行为略有不同,并且有一些规则要遵循)

老实说,ProcSet 资源或多或少没有意义,它的唯一用途是让 PostScript 程序生成器避免在每次生成新的 PostScript 程序时将自己的 ProcSet 定义发送给解释器。

显然这只适用于紧凑的工作流程,您可以控制 PostScript 的生成方式。这是非常罕见的。对于大多数应用程序 ProcSet,每次发送 ProcSet 的开销与程序的其余部分相比非常小。我想这在当时看来是个好主意。

[post 问题编辑]

如果您遵循 PLRM 中定义的规则,则如何定义资源由您决定。例如,Ghostscript 确实定义了两个 'instances' 字典,一个用于全局 VM,一个用于本地 VM 实例,这些是在 localdict 和 globaldict 中定义的 IIRC。您可以通过阅读 /ghostpdl/Resource/Init/gs_res.ps 了解更多有关此实现方式的信息,您可能会发现一些评论很有帮助。特别是关于复制通用资源类别实现的注意事项。

FontDirectory 和 GlobalFontDirectory 是字体类别实例的实现是完全合理的,但我认为没有实际要求。显然,在那种情况下,您必须让字体类别 findresource 实现首先在这些词典中查找现有实例。另一方面,如果您不以这种方式实现它,那么您必须使 FontDirectory 和 GlobalFontDirectory 与 Font Category 实例实现同步,这可能很尴尬和浪费。

正如您所指出的,字体与大多数其他资源略有不同,这确实是出于历史原因,并且向后兼容早期的 PostScript 版本。

不要忘记隐式资源实现。