ghostscript - Postscript 资源文件 : How to pass function parameters?

标签 ghostscript postscript resource-files

我有一些用于在任何 postscript 文件中绘制对象(标志)的 postscript 资源文件(受到 Terry Burton 的 postscriptbarcode 的启发)。

用于绘制flags的文件位于Flaggs子文件夹中(不带扩展名.ps),以及一些辅助文件, 特别是 sethexcolor,定义了一个函数 sethexcolor,用于从十六进制字符串设置 RGB 颜色。

我在子文件夹 Flaggs 上方有一个文件 sample.ps ,其中包含代码:

100 600 moveto
100 /square /Flaggs findresource exec   % draw a square of size 100
showpage

文件square有代码:

1 dict
dup /sethexcolor dup /Flaggs findresource put
begin
/square {
    /size exch def
    currentpoint translate
    /red (ff0000) def
    red sethexcolor
    % 1 0 0 setrgbcolor
} bind def
/square dup load /Flaggs defineresource pop
end

我在 Windows 7 中使用 Ghostscript 9.10 工作。 使用命令行参数 -P 调用 Ghostscript,首先在当前文件夹中查找文件。 (可以在命令 shell 中使用 gswin32c [-P] -h 查看搜索路径)。通常这工作得很好(例如使用 postscriptbarcode,见上文)。

但在这里它不起作用:启动sample.ps,我收到一条错误消息:

Error: /undefined in sethexcolor
Operand stack:
   (ff0000)

(使用1 0 0 setrgbcolor设置RGB颜色后,就可以了。)

如果我将 red sethexcolor 更改为 red/sethexcolorred//sethexcolor,则不会出现错误消息,并且会绘制一个正方形 - 但是黑色的,不是红色的。

这段后记代码有什么问题? 为什么函数square不能调用函数sethexcolor在同一文件夹中?

沃尔夫冈

最佳答案

尝试

red //sethexcolor exec

使用直接名称(带有 //)将在构造 square 过程体时加载当前定义。由于 sethexcolor (可能)是一个过程,因此您必须显式 exec 它才能执行。

关于ghostscript - Postscript 资源文件 : How to pass function parameters?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20913012/

相关文章:

c# - 在运行时更改资源的提取位置?

c# - Resharper 本地化复杂字符串

class - 将资源嵌入可重用 MFC 类的正确方法是什么?

random - 在PostScript中生成间隔随机数

postscript - 为什么在递归 Postscript 过程中使用保存/恢复?

pdf - Ghostscript 旋转页面

ghostscript - Ghostscript 转换文件在 adobe reader 中无法查看

javascript - 错误 : Cloud Functions for Firebase spawn EACCES (ghostscript)

php - 使用 PHP + GhostScript 裁剪 PDF 奇偶页

pdf - 在 postscript 和 pdfmaker 末尾带有两个超链接的简单行