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

查看:24
本文介绍了什么是 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 以获取输出设备的默认选项/设置(例如pdfwrite"或tiffg4");学习如何检索给定输出设备的默认选项.但是,我想知道的是 - 这些选项与所谓的 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 中,字典是 key (name) + value 的列表 对. 字典允许 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).

用户字典它包含 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).

关于names的一句话:对于其他编程语言来说,名称是唯一的标识符(它们区分大小写).这些标识符可以是变量或过程名称.它们可以由 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.

执行堆栈这个包含 executable 对象,即主要是当前正在执行的 proceduresfiles.如果解释器中断了当前对象的执行,它会将被中断的对象放到这个堆栈中.在一个对象完全执行后,它会从堆栈中移除,并从现在最顶层的那个继续执行.

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).最顶层的图形状态始终是当前图形状态.

graphics state stack This stack hosts the current context for the ejection of graphical elements: current line width setting, current font, current color or grayscale value, current path... Current graphic states may be saved (gsave) and restored (grestore) later. The top-most graphics state is always the current graphics state.

所有这些堆栈都是相互独立的.然而,操作数、字典和图形状态堆栈都在 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 编程的一个很好的介绍是 Adob​​e 的 'Bluebook').

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).

每当解释器查找一个名称时,它都会在字典中搜索该名称,从最顶层的字典开始.因此 userdictsystemdict 之前被搜索.一旦找到名称(键),解释器就会停止搜索并使用该键(或者更确切地说,它保存的值).这种架构的结果是 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'.

更新 -- 更多答案:

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

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