macos - 预览 OSX bug (?) 将 .eps 文件中的贝塞尔曲线转换为 .pdf

标签 macos bezier eps

我有一个小的 .eps 文件,它使用粗线宽的贝塞尔曲线来达到一定的效果。该文件按照我期望的方式在 gv 中显示,但是当我将其转换为 .pdf 时(例如使用 ps2pdf 或在运行 OSX 的 Mac 上使用“预览”打开文件),它会错误地渲染一些曲线(或者至少不会)以我期待的方式);在曲线的中间,曲线的法线似乎“翻转”,产生了奇怪的伪像。

这是有问题的 .eps 文件,代码如下:

%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 0 750 200
gsave 50 50 scale 1 3 translate

/edge{4 dict begin
/y2 exch def
/x2 exch def
/y1 exch def
/x1 exch def
gsave
1 setgray
1 8 div setlinewidth
newpath
x1 y1 moveto x2 y2 lineto
stroke
0 setgray
1 20 div setlinewidth
newpath
x1 y1 moveto x2 y2 lineto
stroke
x1 y1 0.07 0 360 arc fill stroke
x2 y2 0.07 0 360 arc fill stroke
grestore
end}def

/cur_edge{7 dict begin
/T exch def
/angle2 exch def
/y2 exch def
/x2 exch def
/angle1 exch def
/y1 exch def
/x1 exch def
gsave
1 setgray
1 8 div setlinewidth
newpath
x1 y1 moveto 
x1 angle1 cos T mul add y1 angle1 sin T mul add
x2 angle2 cos T mul add y2 angle2 sin T mul add
x2 y2 curveto
stroke
0 setgray
1 20 div setlinewidth
newpath
x1 y1 moveto 
x1 angle1 cos T mul add y1 angle1 sin T mul add
x2 angle2 cos T mul add y2 angle2 sin T mul add
x2 y2 curveto
stroke
x1 y1 0.07 0 360 arc fill stroke
x2 y2 0.07 0 360 arc fill stroke
grestore
end}def

/fat_edge{7 dict begin
/T exch def
/angle2 exch def
/y2 exch def
/x2 exch def
/angle1 exch def
/y1 exch def
/x1 exch def
gsave
0 setgray
1 4 div setlinewidth
newpath
x1 y1 moveto 
x1 angle1 cos T mul add y1 angle1 sin T mul add
x2 angle2 cos T mul add y2 angle2 sin T mul add
x2 y2 curveto
stroke
0.9 setgray
1 5 div setlinewidth
newpath
x1 y1 moveto 
x1 angle1 cos T mul add y1 angle1 sin T mul add
x2 angle2 cos T mul add y2 angle2 sin T mul add
x2 y2 curveto
stroke
grestore
end}def

/fat_vertex{4 dict begin
/angle exch def
/y exch def
/x exch def
/T 0.14 def
gsave
0.9 setgray
1 5.5 div setlinewidth
newpath
x y moveto
x angle cos T mul add y angle sin T mul add lineto
stroke
grestore
end}def

/extra_fat_vertex{5 dict begin
/y exch def
/x exch def
/w 0.16 def
gsave
1 setgray
newpath
x w sub y w sub moveto
x w add y w sub lineto
x w add y w add lineto
x w sub y w add lineto
closepath
fill
stroke
0 setgray
/v 0.12 def
newpath
x v sub y v sub moveto
x v add y v sub lineto
x v add y v add lineto
x v sub y v add lineto
closepath
fill    
0.9 setgray
/u 0.095 def
newpath
x u sub y u sub moveto
x u add y u sub lineto
x u add y u add lineto
x u sub y u add lineto
closepath
fill    
grestore
end}def

/extra_fat_triangle{5 dict begin
/y exch def
/x exch def
/w 0.16 def
gsave
1 setgray
newpath
x w sub y w sub moveto
x w 1.1 mul add y lineto
x w sub y w add lineto
closepath
fill
stroke
0 setgray
/v 0.12 def
newpath
x v sub y v sub moveto
x v add y lineto
x v sub y v add lineto
closepath
fill    
0.9 setgray
/u 0.095 def
newpath
x u sub y u sub moveto
x u 0.85 mul add y lineto
x u sub y u add lineto
closepath
fill    
grestore
end}def

/extra_fat_triangle_left{5 dict begin
/y exch def
/x exch def
/w 0.16 def
gsave
1 setgray
newpath
x w add y w sub moveto
x w 1.1 mul sub y lineto
x w add y w add lineto
closepath
fill
stroke
0 setgray
/v 0.12 def
newpath
x v add y v sub moveto
x v sub y lineto
x v add y v add lineto
closepath
fill    
0.9 setgray
/u 0.095 def
newpath
x u add y u sub moveto
x u 0.85 mul sub y lineto
x u add y u add lineto
closepath
fill    
grestore
end}def

0 0 90 2 0 270 1 cur_edge
% 0 0 270 2 0 90 1 cur_edge
2 0 90 0 0 270  1 cur_edge
0 0 180 0.5 -2 180 1 cur_edge
0.5 -2 90 1.5 -1.3 180 0.5 cur_edge
1.5 -1.3 270 2.5 -2 270 0.7 cur_edge
2.5 -2 90 0.5 -2 270 1 cur_edge %
2.5 -2 0 3 -0.75 0 1 cur_edge
3 -0.75 270 1.5 -1.3 0 0.7 cur_edge
3 -0.75 180 1.5 -1.3 90 0.7 cur_edge
3 -0.75 90 2 0 0 0.5 cur_edge

5 0 translate
0 0 90 2 0 270 1 fat_edge
% 0 0 270 2 0 90 1 fat_edge
2 0 90 0 0 270  1 fat_edge
0 0 180 0.5 -2 180 1 fat_edge
0.5 -2 90 1.5 -1.3 180 0.5 fat_edge
1.5 -1.3 270 2.5 -2 270 0.7 fat_edge
2.5 -2 90 0.5 -2 270 1 fat_edge
2.5 -2 0 3 -0.75 0 1 fat_edge
3 -0.75 270 1.5 -1.3 0 0.7 fat_edge
3 -0.75 180 1.5 -1.3 90 0.7 fat_edge
3 -0.75 90 2 0 0 0.5 fat_edge

0 0 90 fat_vertex
0 0 180 fat_vertex
0 0 270 fat_vertex
2 0 0 fat_vertex
2 0 90 fat_vertex
2 0 270 fat_vertex
0.5 -2 180 fat_vertex
0.5 -2 90 fat_vertex
2.5 -2 90 fat_vertex
2.5 -2 270 fat_vertex
1.5 -1.3 0 fat_vertex
1.5 -1.3 90 fat_vertex
1.5 -1.3 180 fat_vertex
1.5 -1.3 270 fat_vertex
3 -0.75 0 fat_vertex
3 -0.75 90 fat_vertex
3 -0.75 180 fat_vertex
3 -0.75 270 fat_vertex

5 0 translate
0 0 90 2 0 270 1 fat_edge
% 0 0 270 2 0 90 1 fat_edge
2 0 90 0 0 270  1 fat_edge

0 0 180 0.5 -2 180 1 fat_edge
0.5 -2 90 1.5 -1.3 180 0.5 fat_edge
1.5 -1.3 270 2.5 -2 270 0.7 fat_edge
2.5 -2 90 0.5 -2 270 1 fat_edge
2.5 -2 0 3 -0.75 0 1 fat_edge
3 -0.75 270 1.5 -1.3 0 0.7 fat_edge
3 -0.75 180 1.5 -1.3 90 0.7 fat_edge
3 -0.75 90 2 0 0 0.5 fat_edge

0 0 90 fat_vertex
0 0 180 fat_vertex
0 0 270 fat_vertex
2 0 0 fat_vertex
2 0 90 fat_vertex
2 0 270 fat_vertex
0.5 -2 180 fat_vertex
0.5 -2 90 fat_vertex
2.5 -2 90 fat_vertex
2.5 -2 270 fat_vertex
1.5 -1.3 0 fat_vertex
1.5 -1.3 90 fat_vertex
1.5 -1.3 180 fat_vertex
1.5 -1.3 270 fat_vertex
3 -0.75 0 fat_vertex
3 -0.75 90 fat_vertex
3 -0.75 180 fat_vertex
3 -0.75 270 fat_vertex

0 0 extra_fat_triangle
2 0 extra_fat_triangle_left
0.5 -2 extra_fat_triangle
1.5 -1.3 extra_fat_vertex
2.5 -2 extra_fat_triangle_left
3 -0.75 extra_fat_vertex

grestore
%eof

奇怪的是,.pdf 仅在调整到某些特定尺寸时才显示不正确(或者:在某些尺寸下正确显示)。我似乎无法预测它什么时候会起作用。

以下是它如何正确显示(图像的一部分):

correct image

这里它被调整大小并且显示不正确:

incorrect image
(来源:dannyc at math.uchicago.edu)

请注意,这些图像是从 .pdf 中获取的 .jpg。如果将上面的代码保存为 .eps 文件并在 Mac 上使用“预览”打开它,我认为它会表现出与我的计算机上相同的病理现象。

非常欢迎任何建议。我对 .pdf 中如何显示贝塞尔曲线了解不够(或:任何事情),无法知道这里可能存在什么问题。

最佳答案

这是一个显示相同渲染问题的简化案例:

%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 0 400 200
gsave 50 50 scale 1 3 translate

0 setgray
0.05 setlinewidth
newpath
0 0 moveto 
0 1 2 -1 2 0 curveto
stroke

grestore
%eof

没有比这更简单的了:只有两个点的贝塞尔曲线路径,全部都是整数值。

看起来苹果的渲染器在曲线中心周围存在一些数值不稳定。如果您稍微调整其中一个曲线控制点,则不会发生错误:

0 1.00001 2 -1 2 0 curveto

因此有一个解决方法:在原始文件中,向每条曲线中的一个角度添加一个小的模糊因子(度数的一小部分)。

我将每个 /angle1 exch def 更改为 0.01 add/angle1 exch def,它对我有用。这是EPS file以及由此产生的 PDF file .

(当然这不是必需的,但在您 file a bug 和 Apple 发布修复程序之前,这可能是最方便的解决方案。)

关于macos - 预览 OSX bug (?) 将 .eps 文件中的贝塞尔曲线转换为 .pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14133647/

相关文章:

ios - 无法将我的 9.0.1 iPhone 与 Xcode 一起使用

macos - 在没有 GPU 的 MAC OS X 上安装 CUDA(用于 cuda 模拟器)

Python - 在贝塞尔曲线上均匀分布对象

math - 平滑地连接两个贝塞尔曲线(C2连续)

css - 如何使用 .eps 文件中的图标并将它们加载到我的网站上?

pdf - 批量转换并将裁剪后记转换为pdf

cocoa - 将 NSWindow 显示为 NSView 的 subview

bezier - 查找穿过N点的曲线的贝塞尔曲线控制点

python - 在 Python Matplotlib 中将图形保存为 eps 时出错

java - 在 Java 中授予 macOS 上的权限后运行 .command 文件