简体   繁体   English

PDF 着色类型 1(基于函数)和 FunctionType 4(PostScriptt 计算器函数)的简单示例

[英]Simple example of PDF Shading Type 1 (Function Based) with FunctionType 4 (PostScriptt Calculator Function)

I am trying to write custom function for PDF shading using Type 1 (Function based) shading with FunctionType 4 (Postscript calculator).我正在尝试为 PDF 着色编写自定义 function,使用类型 1(基于函数)着色和 FunctionType 4(Postscript 计算器)。 Here's what I tried as a base:这是我尝试的基础:

...
5 0 obj
<<
/Type /Page
/Parent 1 0 R
/MediaBox [0 0 500 400]
/Resources << /Shading << /Sh1 8 0 R  >> >>
/Contents 6 0 R
>>
endobj
6 0 obj  %Contents
<<
/Length 37
>>
stream
2 J
0 200 200 200 re
q
W n        %clip to 200x200 rectangle
/Sh1 sh    %fill with shading
Q
endstream
endobj
7 0 obj  %The function itself
<<
/FunctionType 4
/Domain [0 1 0 1]
/Range [0 1 0 1 0 1]
/Length 24
>>
stream
{
pop  %pop parameters - I guess these are x, y coordinates (?)
pop
0.5   %half red , green, blue = gray
0.5
0.5
}
endstream
endobj
8 0 obj       %The shading
<<
/ShadingType 1
/ColorSpace /DeviceRGB
/Function 7 0 R
>>
endobj
...

I think this should make the square 200x200 gray.我认为这应该使正方形 200x200 灰色。 But the result is nothing - the canvas stays empty (tried in Adobe PDF reader).但结果是什么 - canvas 保持为空(在 Adobe PDF 阅读器中尝试)。

Could anybody tell me what am I doing wrong?谁能告诉我我做错了什么?

Or - can someone provide an example of such kind of PDF - with custom shading function?或者 - 有人可以提供这种 PDF 的示例 - 带有自定义阴影 function? I need something to start with.我需要一些东西来开始。 (Later I want to implement radial shading with repeating mode for my SWF to PDF converter using that function) (稍后我想使用该功能为我的 SWF 到 PDF 转换器实现具有重复模式的径向着色)

I haven't found any related PDF examples on the internet with Shading Type 1.我在 Internet 上没有找到任何相关的 PDF 示例,其中包含着色类型 1。

I found the problem now.我现在发现了问题。

/FunctionType 4
/Domain [0 1 0 1]

I set the domain of function to 0-1, which will crop the coordinates to maximum of 1. For some reasons I though the incoming coordinates is 0-1.我将 function 的域设置为 0-1,这会将坐标裁剪为最大值 1。由于某些原因,我虽然传入的坐标是 0-1。

Modification for修改为

/FunctionType 4
/Domain [0 1000 0 1000]

works for me and the rectangle is gray.对我有用,矩形是灰色的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM