答案1
也许渐近线作为 TeX 朋友,可以提供帮助。
这是一个简短的 MWE:
// fillGlyphHoles.asy
//
// run
// asy fillGlyphHoles.asy
//
// to get fillGlyphHoles.pdf
settings.tex="pdflatex";
size(9cm);
import fontsize;defaultpen(fontsize(9pt));
texpreamble("\usepackage{lmodern}"
+"\usepackage{amsmath}"
+"\usepackage{amsfonts}"
+"\usepackage{amssymb}"
);
void fillGlyphsWithHoles(Label L, pen holePen=currentpen, pen glyphPen=currentpen){
path[] tp=texpath(L);
path g; pair v; int nw;
for(int i=0;i<tp.length;++i){
g=tp[i];
if(cyclic(g)){
v=inside(g,glyphPen);
nw=windingnumber(tp,v);
if(!interior(nw,glyphPen)) fill(g,holePen);
}
}
fill(tp,glyphPen);
}
Label[] L={
Label("\texttt{Demo.}"),
Label("As any dedicated reader"),
Label("can \emph{clearly} see,"),
Label("$\mathbb{P}_{\alpha}=\frac{\sqrt{q}}{a^8+b^9}.$"),
};
fillGlyphsWithHoles(shift(0,100)*L[0],holePen=orange);
fillGlyphsWithHoles(shift(20,90)*rotate(12)*L[1],holePen=red+opacity(0.5));
fillGlyphsWithHoles(shift(30,80)*rotate(7)*L[2],holePen=green+opacity(0.9));
fillGlyphsWithHoles(shift(0,60)*rotate(7)*L[3],holePen=blue+opacity(0.5),glyphPen=olive);
shipout(bbox(Fill(paleyellow)));
编辑:
使用径向阴影:
// shadeGlyphHoles.asy
//
// run
// asy shadeGlyphHoles.asy
//
// to get shadeGlyphHoles.pdf
settings.tex="pdflatex";
size(9cm);
import fontsize;defaultpen(fontsize(9pt));
texpreamble("\usepackage{lmodern}"
+"\usepackage{amsmath}"
+"\usepackage{amsfonts}"
+"\usepackage{amssymb}"
);
void shadeGlyphsWithHoles(Label L,
pen holePenA=currentpen,
pen holePenB=currentpen,
pen glyphPenA=currentpen,
pen glyphPenB=currentpen){
path[] tp=texpath(L);
path g; pair v; int nw;
pair a,b;
for(int i=0;i<tp.length;++i){
g=tp[i];
a=min(g); b=max(g);
b=(a.x,b.y);
if(cyclic(g)){
v=inside(g,glyphPenA);
nw=windingnumber(tp,v);
if(!interior(nw,glyphPenA)) axialshade(g,holePenA,a,holePenB,b);;
}
}
axialshade(tp,glyphPenA,a,glyphPenB,b);
}
Label L=Label("can \emph{clearly} see,");
shadeGlyphsWithHoles(L,blue+opacity(0.3),white,blue,red+opacity(0.4));
shipout(bbox(Fill(lightgreen)));