什么是PostScript字典,以及如何访问(通过Ghostscript)? [英] What are PostScript dictionaries, and how can they be accessed (via Ghostscript)?

查看:196
本文介绍了什么是PostScript字典,以及如何访问(通过Ghostscript)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常将 ghostscript 看作命令行工具;然而,我从不停止对这里存在的大量设置和选项感到惊讶 - 这是因为 ghostscript 是一个完整的PostScript语言解释器经常忘记)。

I usually look at ghostscript as a command line tool; however, I never cease to be amazed at the sheer amount of settings and options present there - which is due to the fact that ghostscript is a full blown PostScript language interpreter (which I often forget).

例如,在,查询Ghostscript ;输入设备的输出设备,如/ 11002313#comment14584841_11002313一个学习如何检索给定输出设备的默认选项。不过,我想知道的是 - 这些选项与所谓的PostScript字典有关吗?

For instance, in Querying Ghostscript for the default options/settings of an output device (such as 'pdfwrite' or 'tiffg4'); one learns how to retrieve default options for a given output device. However, what I'd like to know is - are these options related to so-called PostScript dictionaries?

或者换句话说 - 什么是PostScript词典?以及 ghostscript 有哪些功能可以查询(可能)修改此数据?

Or, to put it in other words - what are PostScript dictionaries; and what facilities does ghostscript have, to query (and possibly) modify this data?

推荐答案

使用最简单的术语:在PostScript中,字典是键的列表(名称)+值对。字典允许PostScript解释器查找是否存在键,并获取其值以在任何过程中使用它。解释器还可以创建密钥,存储或修改值,甚至创建完整的自定义字典(由PostScript代码处理)。键通常是类型名称(但是除了 null 之外,它们可能是任何其他类型的)。

To put it in the most simple terms: In PostScript, a dictionary is a list of key (name) + value pairs. Dictionaries allow the PostScript interpreter to lookup if a key exists and fetch its value to use it in any procedure. The interpreter also can create keys, store or modify values and even create complete custom dictionaries (dictated by the PostScript code its processing). Keys usually are of type name (but they may be of any other type as well with the exception of null).

对于PostScript解释器的任何实现,其中两个字典必须始终存在:

Two of these dictionaries must always be present, for any implementation of a PostScript interpreter:


  • systemdict
    这一个包含预定义的PostScript操作符(和实现,使他们做什么PostScript规范期望他们)。

  • systemdict This one holds pre-defined PostScript operators (and the implementations to make them do what the PostScript specification expects them to).

userdict
这一个包含PostScript程序的变量和过程(将程序视为由语言定义的运算符和程序定义的值和参数的组合构成的函数或子例程)。

userdict This one holds variables and procedures of a PostScript program (think of 'procedures' as being functions or subroutines which are constructed by the combination of language-defined operators and program-defined values and parameters).

一个关于名称的单词:名称是其他编程语言是uniq 标识符是区分大小写的)。这些标识符可以是变量或过程名称。它们可以由ASCII的256个字符的任意组合组成(但是它们不是字符串)。

One word about names: names are what to other programming languages are uniq identifiers (and they are case-sensitive). These identifiers may be variables or procedure names. They may be made up of any combination of the 256 characters of ASCII (but they are no strings).

如您所知,PostScript是一种堆栈方向的语言。它使用几个堆栈:

As you may be aware, PostScript is a stack-oriented language. It uses several stacks:


  • 操作数堆栈
    此堆栈保存每个操作数,每个中间操作的结果(将最后一个结果临时转换为操作数堆栈的最顶层元素)。

  • operand stack This stack holds every single operand and every result of intermediate operations (turning the last result temporarily into the top-most element of the operand stack).

字典堆栈
正如名称所示:此堆栈只包含字典。因此,该栈定义了任何密钥/名称查找的当前上下文。

dictionary stack As the name says: this stack holds only dictionaries. As such the stack defines the current context for any key/name lookup.

执行堆栈
这个保存可执行程序对象,即主要是程序文件。如果解释器中断当前对象的执行,则将中断的对象放入此堆栈。一个对象被完全执行后,它从堆栈中移除,并且执行继续是最前面的一个。

execution stack This one holds executable objects, i.e. mainly procedures and files which are currently being executed. If the interpreter interrupts the execution of a current object, it puts the interrupted object onto this stack. After an object was completely executed, it is removed from the stack and execution continues with the one that is top-most now.

图形状态堆栈
此堆栈主持用于弹出图形元素的当前上下文:当前行宽度设置,当前字体,当前颜色或灰度值,当前路径...当前图形状态可能被保存( gsave )并恢复( grestore )。最顶层的图形状态始终是当前图形状态。

所有这些堆栈彼此独立。然而,操作数,字典和图形状态堆栈都受到PostScript程序的控制(也就是可能被它操纵)。执行堆栈是解释器的唯一属性。

All these stacks are independent from each other. However, the operand, dictionary and graphics state stacks are under the control of the PostScript program (that is, may be manipulated by it). The execution stack is the sole property of the interpreter.

对于每个堆栈,存在一些限制(对于可能存储在其上的元素的数量等) 。 PostScript知道可以操纵堆栈的操作符:在堆栈上放置一个新元素,删除最顶层的元素( pop ),最重要的元素( dup ),将堆栈中的元素顺序( roll ),交换两个最重要的元素( exch ),还有更多(PostScript编程很好的介绍是Adobe的蓝皮书。

For each stack there are certain limitations (as for the number of elements which may be stored on it, etc.). PostScript knows operators which can manipulate stacks: put a new element on the stack, remove the top-most element (pop), duplicate the top-most element (dup), shuffle the order of elements on the stack (roll), swap the two top-moste elements (exch), and quite some more (a good intro into PostScript programming is the 'Bluebook' from Adobe).

正如我已经说过的,字典有自己的 PostScript解释器可能使用的所有字典。

As I already said, dictionaries have their own stack which holds all dictionaries a PostScript interpreter may use.

在该堆栈中,可能会有单独的字体字典,或PostScript程序想要创建的任何数量的字典(使用 dict 关键字),并使用私有或特定于某些PostScript解释器的某些字典,如Ghostscript。

On that stack there may be a separate dictionary of fonts, or any number of dictionaries a PostScript program wants to create (using the dict keyword) and use privately, or some dictionaries that are specific to a certain PostScript interpreter, such as Ghostscript.

systemdict 始终是最底层的一个;以上是 userdict 。这两个不能从字典堆栈中删除,所有其他的都可以受任何堆栈操作操作符(例如 pop ,它将删除

The systemdict always is the bottom-most one; above this is the userdict. These two cannot be removed from the dictionary stack, wheres all the other ones can be subject to any stack manipulation operator (such as pop which removes the topmost element from a stack).

每当解释器查找一个名称时,它会从字典中搜索该名称,从最顶尖的字典开始。因此,在 systemdict 之前搜索 userdict 。找到名称(一个键)后,解释器将停止搜索并使用该键(或者说它所持有的值)。这种架构的后果是PostScript程序员可能会使用自己的变体覆盖在 systemdict 中预定义的任何PostScript操作符。

Whenever the interpreter is looking up a name, it searches the dictionaries for that name, starting with the top-most dictionary. Hence userdict is searched before systemdict. As soon as the name is found (a key), the interpreter stops searching and uses that key (or rather, the value it holds). The consequence of this architecture is that the PostScript programmer may overwrite any PostScript operator that is pre-defined in systemdict with his own variant.

另外,一些词典可以用于PS程序'私人'(不可访问,如字体字典)或'只读'。

Also, some dictionaries can be for the PS program 'private' (no-access, such as font dictionaries) or 'read-only'.

更新 - 更多答案:

  • How can I obtain a list of other dictionaries contained in userdict or systemdict?
  • How can a Ghostscript power user print out dictionary contents?

这篇关于什么是PostScript字典,以及如何访问(通过Ghostscript)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆