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

我有一个小的.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只有在调整大小到某些特定大小时才会显示不正确(或者:它以特定大小正确显示).我似乎无法预测它何时起作用.

以下是它正确显示(部分图像)的方式:

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

请注意,这些图像是从.pdf获得的.jpgs.如果您将上面的代码保存为.eps文件并在Mac上使用预览打开它,我认为它将显示与我在计算机上执行的相同的病理.

任何建议都会非常受欢迎.关于bepdier曲线如何在.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

不能简单得多:只有两个点的Bezier路径,都带有整数值.

看起来Apple的渲染器在曲线中心周围有一些数值不稳定.如果您将一个曲线控制点调整一小部分,则不会发生错误:

0 1.00001 2 -1 2 0 curveto

所以有一个解决方法:在原始文件中,向每条曲线中的一个角度添加一个小的软糖因子(一个度数的一小部分).

我将每个/ angle1 exch def更改为0.01 add / angle1 exch def,这对我有用.这是EPS filePDF file.

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

点赞