【问题标题】:A PDF with different outputs in different PDF viewers (with shades)在不同 PDF 查看器中具有不同输出的 PDF(带阴影)
【发布时间】:2021-04-30 14:52:00
【问题描述】:

考虑以下 PostScript 文件

[1 0 0.5 0.866 150 550] concat
<< 
   /ShadingType 2 
   /Coords [ 0 0 100 100] 
   /BBox [ 0 0 100 100] 
   /ColorSpace [ /DeviceRGB ] 
   /Function 
      << 
         /FunctionType 0 
         /Domain [0 1] 
         /Range [0 1 0 1 0 1] 
         /BitsPerSample 8 
         /Size [2] 
         /DataSource <FFA0A0FFE0E0> 
      >>
   /Extend [false false] 
>> 
shfill

考虑我们使用 GhostScript (ps2pdf) 或 Adob​​e Distiller 将该文件转换为 PDF。

生成的 PDF 在不同的 PDF 查看器中呈现方式不同:

  • 在 Adob​​e Reader 或 Firefox(使用 PDF.js)中,我们有一个平行四边形(不是矩形)。
  • 在 SumatraPDF(使用 MuPDF)和 Chrome(使用 PDFium)中,我们有一个矩形。

谁是对的?

【问题讨论】:

  • 请分享pdf内容。
  • PDF文件为here

标签: pdf pdf.js mupdf pdfium


【解决方案1】:

我认为 Adob​​e Acrobat 是正确的,但规范的解读也可能不同。

您的 PDF 包含以下内容流:

/GS1 gs
q
1 0 .5 .866 150 550 cm
/Sh1 sh
Q

即首先改变当前的变换矩阵,它被剪切和挤压一点,然后着色 Sh1 被绘制。该阴影又被定义为

<</BBox[0 0 100 100]/ColorSpace/DeviceRGB/Coords[0 0 100 100]/Function 15 0 R/ShadingType 2>>

即带有 100×100 方形边界框(解释为临时附加剪切路径)和沿其 (0, 0) 到 (100, 100) 对角线的轴向阴影,与您的 postscript 定义相匹配。

着色操作符sh指定为

Operands Operator Description
name sh (PDF 1.3) Paint the shape and colour shading described by a shading dictionary, subject to the current clipping path. The current colour in the graphics state is neither used nor altered. The effect is different from that of painting a path using a shading pattern as the current colour. name is the name of a shading dictionary resource in the Shading subdictionary of the current resource dictionary (see 7.8.3, "Resource dictionaries"). All coordinates in the shading dictionary are interpreted relative to the current user space. (By contrast, when a shading dictionary is used in a Type 2 pattern, the coordinates are expressed in pattern space.) All colours are interpreted in the colour space identified by the shading dictionary’s ColorSpace entry (see "Table 77 — Entries common to all shading dictionaries"). The Background entry, if present, is ignored.
This operator should be applied only to bounded or geometrically defined shadings. If applied to an unbounded shading, it paints the shading’s gradient fill across the entire clipping region, which may be time-consuming.

(ISO 32000-2:2017,表 76 - 着色运算符)

特别是:着色字典中的所有坐标都相对于当前用户空间进行解释。

因此,方形边界框/临时剪辑路径被当前变换矩阵挤压和剪切成非矩形平行四边形,如可以在 Adob​​e Acrobat 中查看的那样:

我在上面提到,规范也可以有不同的理解:如果将 BBox 条目视为两个点的坐标,即盒子的左下角和右上角,并且将结果变成一个盒子之前应用了转换,人们会得到一个压扁的、拉长的矩形,可以在 Chrome 中查看:

但是这里的 BBox 被指定为 一个由四个数字组成的数组,分别给出阴影边界框的左、下、右和上坐标(同上,表 77 —所有着色字典共有的条目),而不是作为对角线的两个端点的坐标。因此,我赞成 Adob​​e 也实施的第一种解释。

我还没有 ISO 32000-2:2020 的副本,所以也许已经以某种方式澄清了这一点。


如果在填充指令期间将阴影用于作为当前颜色的图案中,情况会有所不同。在这种情况下,规范说:

模式的外观是相对于它自己的内部坐标系来描述的。每个模式都有一个模式矩阵,一个将模式的内部坐标系映射到模式的父内容流(模式所在的内容流)的默认坐标系的变换矩阵。被定义为资源)。模式矩阵与父内容流的连接建立了模式坐标空间,模式中的所有图形对象都应在该空间内进行解释。

(ISO 32000-2:2017,第 8.7.2 节 - 模式的一般属性)

在这种情况下,带有对角轴向阴影的方形边界框不会受到当前变换矩阵的影响。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 2011-03-05
    • 1970-01-01
    • 2018-07-16
    相关资源
    最近更新 更多