MetaUML 生成的 PS 有错误

MetaUML 生成的 PS 有错误

如果我使用以下示例(或任何其他示例):

input metauml;

beginfig(1);
Class.A("Point")
       ("+x: int",
        "+y: int") ();

Class.B("Circle")
       ("radius: int")
       ("+getRadius(): int",
        "+setRadius(r: int):void");

topToBottom(45)(A, B);

drawObjects(A, B);

clink(aggregationUni)(A, B)
endfig;

end;

它生成了我无法在 evince 和 gs 中查看的 PS:

GPL Ghostscript  9.00 (2010-09-14)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /undefined in ptmr8r
Operand stack:
   (Point)
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1894   1   3   %oparray_pop   1893   1   3   %oparray_pop   1877   1   3   %oparray_pop   1771   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1157/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Current file position is 895
GPL Ghostscript  9.00: Unrecoverable error, exit code 1

生成的代码:

%!PS
%%BoundingBox: -33 -141 71 1 
%%HiResBoundingBox: -32.34918 -140.52289 70.86105 0.25 
%%Creator: MetaPost 1.211
%%CreationDate: 2010.11.13:2050
%%Pages: 1
%*Font: ptmr8r 9.96265 9.96265 20:80c000201000a0005d4b3ec
%%BeginProlog
%%EndProlog
%%Page: 1 1
 0.7 0.7 0.7 setrgbcolor
newpath 1 -1 moveto
38.76186 -1 lineto
38.76186 -43.25916 lineto
1 -43.25916 lineto
 closepath fill
 0.9 0.9 0.9 setrgbcolor
newpath 0 0 moveto
37.76186 0 lineto
37.76186 -42.25916 lineto
0 -42.25916 lineto
 closepath fill
 0 0 0 setrgbcolor 0 0.5 dtransform truncate idtransform setlinewidth pop
 [] 0 setdash 1 setlinejoin 10 setmiterlimit
newpath 0 0 moveto
37.76186 0 lineto
37.76186 -42.25916 lineto
0 -42.25916 lineto
 closepath stroke
 1 setlinecap
newpath 0 -12.75458 moveto
37.76186 -12.75458 lineto stroke
newpath 0 -37.75916 moveto
37.76186 -37.75916 lineto stroke
8.3605 -9.75458 moveto
(Point) ptmr8r 9.96265 fshow
13 -23.25916 moveto
(x:\040int) ptmr8r 9.96265 fshow
13 -33.75916 moveto
(y:\040int) ptmr8r 9.96265 fshow
 0.4 0.4 0.4 setrgbcolor
newpath 2 -20.5592 moveto
7.95004 -20.5592 lineto
7.95004 -23.25916 lineto
2 -23.25916 lineto
 closepath fill
 0.7 0.7 0.7 setrgbcolor
newpath 7.95004 -23.25916 moveto
9 -22.2092 lineto
9 -19.50925 lineto
7.95004 -20.5592 lineto
 closepath fill
 0.6 0.6 0.6 setrgbcolor
newpath 7.95004 -20.5592 moveto
9 -19.50925 lineto
3.04996 -19.50925 lineto
2 -20.5592 lineto
 closepath fill
 0.4 0.4 0.4 setrgbcolor
newpath 2 -31.0592 moveto
7.95004 -31.0592 lineto
7.95004 -33.75916 lineto
2 -33.75916 lineto
 closepath fill
 0.7 0.7 0.7 setrgbcolor
newpath 7.95004 -33.75916 moveto
9 -32.7092 lineto
9 -30.00925 lineto
7.95004 -31.0592 lineto
 closepath fill
 0.6 0.6 0.6 setrgbcolor
newpath 7.95004 -31.0592 moveto
9 -30.00925 lineto
3.04996 -30.00925 lineto
2 -31.0592 lineto
 closepath fill
 0.7 0.7 0.7 setrgbcolor
newpath -31.09918 -88.25916 moveto
70.86105 -88.25916 lineto
70.86105 -140.52289 lineto
-31.09918 -140.52289 lineto
 closepath fill
 0.9 0.9 0.9 setrgbcolor
newpath -32.09918 -87.25916 moveto
69.86105 -87.25916 lineto
69.86105 -139.52289 lineto
-32.09918 -139.52289 lineto
 closepath fill
 0 0 0 setrgbcolor
newpath -32.09918 -87.25916 moveto
69.86105 -87.25916 lineto
69.86105 -139.52289 lineto
-32.09918 -139.52289 lineto
 closepath stroke
newpath -32.09918 -100.01373 moveto
69.86105 -100.01373 lineto stroke
newpath -32.09918 -114.51831 moveto
69.86105 -114.51831 lineto stroke
6.7068 -97.01373 moveto
(Circle) ptmr8r 9.96265 fshow
-19.09918 -110.51831 moveto
(radius:\040int) ptmr8r 9.96265 fshow
-19.09918 -125.02289 moveto
(getRadius\(\):\040int) ptmr8r 9.96265 fshow
-19.09918 -135.52289 moveto
(setRadius\(r:\040int\):void) ptmr8r 9.96265 fshow
 0.4 0.4 0.4 setrgbcolor
newpath -30.09918 -107.81836 moveto
-24.14914 -107.81836 lineto
-24.14914 -110.51831 lineto
-30.09918 -110.51831 lineto
 closepath fill
 0.7 0.7 0.7 setrgbcolor
newpath -24.14914 -110.51831 moveto
-23.09918 -109.46835 lineto
-23.09918 -106.7684 lineto
-24.14914 -107.81836 lineto
 closepath fill
 0.6 0.6 0.6 setrgbcolor
newpath -24.14914 -107.81836 moveto
-23.09918 -106.7684 lineto
-29.04922 -106.7684 lineto
-30.09918 -107.81836 lineto
 closepath fill
 0.3 0.3 0.3 setrgbcolor 0 0.79701
 dtransform truncate idtransform setlinewidth pop 0 setlinecap
newpath -28.5242 -105.04338 moveto
-28.00685 -104.4082 -27.40976 -103.75253 -26.59918 -103.76831 curveto
-25.12357 -103.79704 -24.63 -105.58928 -24.67416 -107.29338 curveto stroke
 0.4 0.4 0.4 setrgbcolor
newpath -30.09918 -122.32294 moveto
-24.14914 -122.32294 lineto
-24.14914 -125.02289 lineto
-30.09918 -125.02289 lineto
 closepath fill
 0.7 0.7 0.7 setrgbcolor
newpath -24.14914 -125.02289 moveto
-23.09918 -123.97293 lineto
-23.09918 -121.27298 lineto
-24.14914 -122.32294 lineto
 closepath fill
 0.6 0.6 0.6 setrgbcolor
newpath -24.14914 -122.32294 moveto
-23.09918 -121.27298 lineto
-29.04922 -121.27298 lineto
-30.09918 -122.32294 lineto
 closepath fill
 0.4 0.4 0.4 setrgbcolor
newpath -30.09918 -132.82294 moveto
-24.14914 -132.82294 lineto
-24.14914 -135.52289 lineto
-30.09918 -135.52289 lineto
 closepath fill
 0.7 0.7 0.7 setrgbcolor
newpath -24.14914 -135.52289 moveto
-23.09918 -134.47293 lineto
-23.09918 -131.77298 lineto
-24.14914 -132.82294 lineto
 closepath fill
 0.6 0.6 0.6 setrgbcolor
newpath -24.14914 -132.82294 moveto
-23.09918 -131.77298 lineto
-29.04922 -131.77298 lineto
-30.09918 -132.82294 lineto
 closepath fill
 0 0 0 setrgbcolor 0.5
 0 dtransform exch truncate exch idtransform pop setlinewidth
newpath 18.88094 -54.75896 moveto
18.88094 -74.75975 lineto stroke
newpath 18.88094 -54.75896 moveto
18.88094 -42.25922 lineto stroke
 0 0.5 dtransform truncate idtransform setlinewidth pop
newpath 18.88094 -42.25922 moveto
13.88094 -54.75896 lineto stroke
newpath 18.88094 -42.25922 moveto
23.88094 -54.75896 lineto stroke
 1 1 1 setrgbcolor
newpath 18.88094 -74.75957 moveto
23.88094 -81.00945 lineto
18.88094 -87.25931 lineto
13.88094 -81.00945 lineto
 closepath fill
 0 0 0 setrgbcolor
newpath 18.88094 -74.75957 moveto
23.88094 -81.00945 lineto
18.88094 -87.25931 lineto
13.88094 -81.00945 lineto
 closepath stroke
showpage
%%EOF

我究竟做错了什么?

编辑:当我使用 pdflatex 时,它会生成一个正确的 pdf(至少 /usr/share/ghostscript/GS_Version/Resource/Init/Fontmap.GS 经过修改)

答案1

我也遇到了同样的问题。幸运的是,我刚刚找到了解决方案:在 ghostscript 中显示 MetaPost 输出

为了避免这个问题,正如他们建议的那样,您只需在文件开头添加以下行.mp

prologues := 2;

然后使用或任何您喜欢的工具处理您的.mp文件。gsconvert

我对 MetaPost 了解不多,所以不知道它到底是干什么的。但它至少可以避免那个恼人的错误 :)

希望其他人也发现它有用!

答案2

创建一个 LaTeX 文档:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{<mpfile>.1}
\end{document}

或者使用mptopdfConTeXt 或者以这种方式使用

mpost -tex=tex <mpfile>
tex "\input epsf\relax\epsfbox{<mpfile>.1}\bye"
dvips zz

它将生成一个包含 ptmr8r 字体的 ps。用您的文件名替换。

答案3

ptmr8r 字体可能出了问题。快速谷歌搜索后,我发现了一些建议http://www.mediawiki.org/wiki/Extension:UML如何修复该问题。

答案4

如果您不想编辑文件,您可以创建自定义内存转储:

mpost -ini <<EOF

\input plain
prologues := 2
\dump

EOF

您应该会得到一个 mpout.mem 文件。将其重命名为您喜欢的任何名称(例如 foobar.mem)并将其用于:

mpost '&foobar' file

您可以定义一个别名:

alias mp2eps="mpost '&foobar'"

(您可能希望将 mem 文件放入 kpathsea 搜索路径,但我不知道如何设置它)。

相关内容