
Metapost
/를 사용하여 정확히 다음 PS 및 SVG 코드를 생성할 수 있는 방법이 있습니까 Metafun
? 불행히도 unfill
결과 페이지에 배경이 있으므로 나에게는 작동하지 않습니다. 실제 경로는 훨씬 더 복잡하므로 이 예는 생략되었습니다.
원하는 포스트스크립트 출력:
%!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
원하는 SVG 출력:
<?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>
답변1
MetaPost에는 이를 수행하는 표준 트릭이 있습니다. MetaPost의 unfill은 실제로 아무것도 채우지 않고 배경색으로 채우기 때문에 솔루션을 포함하기로 결정했습니다.
다음은 해결 방법을 보여줍니다.
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.
생성된 EPS는 다음과 같습니다.
%!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
코드는 정확히 동일한 EPS를 생성하지 않지만 채우기에는 실제로 중요하지 않습니다.
답변2
채우기 및 채우기:
%% 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.
출력은 다음과 같습니다 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
그리고 여기에 출력이 있습니다
mpost '\outputformat:="svg";outputtemplate:="%j-%c.svg";input naid.mp'
파일에naid-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>
답변3
나는 Metapost를 사용한 적이 없지만 Asymptote가 이를 기반으로 하기 때문에 Asymptote 답변은 누군가가 Metapost 답변을 알아내는 데 도움이 될 수 있습니다.
foo.asy
다음 내용으로 파일을 만듭니다 .
fill((0,100)--(100,100)--(100,0)--(0,0)--cycle ^^ (10,90)--(10,10)--(90,10)--(90,90)--cycle);
asy foo.asy
명령줄에서 실행하면 foo.eps
다음 내용이 포함된 EPS 파일이 제공됩니다(모듈로 몇 가지 명백한 차이점(예: 생성 시간)).
%!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
결과를 그래픽으로 표시하면 다음과 같습니다.