
¿Hay alguna forma de producir exactamente el siguiente código PS y SVG con Metapost
/ Metafun
? Desafortunadamente, unfill
no funcionará para mí, ya que hay un fondo en la página resultante. Y este ejemplo es simplificado, ya que el camino real es mucho más complejo.
Salida de posdata deseada:
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 100 100
%%BeginProlog
%%EndProlog%%Page: 1 1
newpath 0 100 moveto 100 100 lineto 100 0 lineto 0 0 lineto 0 100 lineto closepath
10 90 moveto 10 10 lineto 90 10 lineto 90 90 lineto 10 90 lineto closepath
fill
%%EOF
Salida SVG deseada:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="125" height="125">
<g transform="matrix(1.25,0,0,-1.25,0,125)">
<g transform="scale(0.1,0.1)">
<path d="m 0,1000 1000,0 L 1000,0 0,0 0,1000 z m 100,-100 0,-800 800,0 0,800 -800,0" id="3"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none" />
</g>
</g>
</svg>
Respuesta1
Hay un truco estándar para hacer esto en MetaPost. Decidí incluir la solución porque el desllenado de MetaPost realmente no vacía nada, sino que lo rellena con el color de fondo.
A continuación se muestra la solución.
beginfig( 0 )
path clockwisepath, anticlockwisepath;
clockwisepath := (0,100) -- (100,100) -- (100,0) -- (0,0) -- (0,100) -- cycle;
anticlockwisepath := (10,90) -- (10,10) -- (90,10) -- (90,90) -- (10,90) -- cycle;
fill clockwisepath -- anticlockwisepath -- cycle;
endfig;
end.
El siguiente es el eps producido:
%!PS
%%BoundingBox: 0 0 100 100
%%HiResBoundingBox: 0 0 100 100
%%Creator: MetaPost 1.902
%%CreationDate: 2014.12.19:1511
%%Pages: 1
%%BeginProlog
%%EndProlog
%%Page: 1 1
0 0 0 setrgbcolor
newpath 0 100 moveto 100 100 lineto 100 0 lineto 0 0 lineto 0 100 lineto
0 100 lineto 10 90 lineto 10 10 lineto 90 10 lineto 90 90 lineto
10 90 lineto 10 90 lineto
closepath fill
showpage
%%EOF
Tenga en cuenta que el código no produce exactamente los mismos eps, pero para completarlo realmente no importa.
Respuesta2
Llenar y vaciar:
%% naid.mp
u:=1bp;
beginfig(1);
fill (0,0)--(100u,0)--(100u,100u)--(0,100u)--cycle;
unfill (10u,10u)--(90u,10u)--(90u,90u)--(10u,90u)--cycle;
endfig;
end.
Aquí está el resultado de mpost naid.mp
:
%!PS
%%BoundingBox: 0 0 100 100
%%HiResBoundingBox: 0 0 100 100
%%Creator: MetaPost 1.803
%%CreationDate: 2013.12.23:1356
%%Pages: 1
%%BeginProlog
%%EndProlog
%%Page: 1 1
0 0 0 setrgbcolor
newpath 0 0 moveto
100 0 lineto
100 100 lineto
0 100 lineto
closepath fill
1 1 1 setrgbcolor
newpath 10 10 moveto
90 10 lineto
90 90 lineto
10 90 lineto
closepath fill
showpage
%%EOF
y aquí está la salida de
mpost '\outputformat:="svg";outputtemplate:="%j-%c.svg";input naid.mp'
en archivonaid-1.svg
<?xml version="1.0"?>
<!-- Created by MetaPost 1.803 on 2013.12.23:1445 -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100.000000" height="100.000000" viewBox="0 0 100.000000 100.000000">
<!-- Original BoundingBox: 0.000000 0.000000 100.000000 100.000000 -->
<path d="M0.000000 100.000000L100.000000 100.000000L100.000000 -0.000000L0.000000 -0.000000Z" style="fill: rgb(0.000000%,0.000000%,0.000000%);stroke: none;"></path>
<path d="M10.000000 90.000000L90.000000 90.000000L90.000000 10.000000L10.000000 10.000000Z" style="fill: rgb(100.000000%,100.000000%,100.000000%);stroke: none;"></path>
</svg>
Respuesta3
Nunca he usado Metapost, pero dado que Asymptote se basa en él, una respuesta de Asymptote posiblemente podría ayudar a alguien a descubrir una respuesta de Metapost.
Crea un archivo foo.asy
con el siguiente contenido:
fill((0,100)--(100,100)--(100,0)--(0,0)--cycle ^^ (10,90)--(10,10)--(90,10)--(90,90)--cycle);
Al ejecutar asy foo.asy
desde la línea de comando, se obtiene un archivo eps foo.eps
con el siguiente contenido (módulo con algunas diferencias obvias, por ejemplo, tiempo de creación):
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 255 345 356 446
%%HiResBoundingBox: 255.5 345.5 355.5 445.5
%%Creator: Asymptote 2.23
%%CreationDate: 2013.12.23 10:10:49
%%Pages: 1
%%Page: 1 1
/Setlinewidth {0 exch dtransform dup abs 1 lt {pop 0}{round} ifelse
idtransform setlinewidth pop} bind def
gsave
255.5 345.5 translate
newpath 0 100 moveto
100 100 lineto
100 0 lineto
0 0 lineto
0 100 lineto
closepath
10 90 moveto
10 10 lineto
90 10 lineto
90 90 lineto
10 90 lineto
closepath
0 setgray
0.5 Setlinewidth
1 setlinecap
1 setlinejoin
10 setmiterlimit
fill
grestore
showpage
%%EOF
El resultado en forma gráfica: