[ConTeXt 邮件列表中也提出了这个问题,但尚未得到答复,因此它可能足够复杂,很难得到答案,因此在这里重复一遍]
我想直接在宏中使用 transparent() 的结果,这样我就可以使用单个参数传递具有透明度的颜色。如果我理解 MetaFun 手册(我从中复制粘贴了此示例),那应该是可能的:
\starttext
\startMPpage[instance=doublefun]
vardef SampleText (expr t, c) =
save p ; picture p ;
p := image (draw t infont "\truefontname{Regular}") ;
draw (p shifted (- xpart center p,0)) scaled 5 withcolor c;
enddef ;
SampleText ("Much Of This" , transparent(1, .5, red )) ;
SampleText ("Functionality" , transparent(1, .5, green)) ;
SampleText ("Was Written" , transparent(1, .5, blue )) ;
SampleText ("While Listening", transparent(1, .5, cmyk(1,0,0,0))) ;
SampleText ("To the CD's Of" , transparent(1, .5, cmyk(0,1,0,0))) ;
SampleText ("Tori Amos" , transparent(1, .5, cmyk(0,0,1,0))) ;
\stopMPpage
\stoptext
但其结果是:
system > files > jobname 'testcolor', input './testcolor', result 'testcolor'
fonts > latin modern fonts are not preloaded
languages > language 'en' is active
open source > level 2, order 3, name './testcolor.tex'
fonts > preloading latin modern fonts (second stage)
fonts > 'fallback modern-designsize rm 12pt' is loaded
metapost > initializing instance 'doublefun:1' using format 'metafun' and method 'double'
metapost > loading 'metafun' as '/usr/local/context-osx-64/tex/texmf-context/metapost/context/base/mpiv/metafun.mpxl' using method 'double'
metapost > initializing number mode 'double'
metapost log >
metapost log > loading metafun, including plain.mp version 1.004 for metafun iv and xl
metapost log >
metapost log > ! Missing ')' has been inserted.
metapost log > <to be read again>
metapost log > withprescript
metapost log > transparent->(1)withprescript
metapost log > "tr_alternative="&decimal.transparency_alternat...
metapost log > <*> ... ("Much Of This" , transparent(1, .5, red )
metapost log > ) ; SampleText ("Functiona...
metapost log >
backend > xmp > using file '/usr/local/context-osx-64/tex/texmf-context/tex/context/base/mkiv/lpdf-pdx.xml'
pages > flushing realpage 1, userpage 1, subpage 1
close source > level 2, order 3, name './testcolor.tex'
close source > level 1, order 3, name 'cont-yes.mkiv'
对我来说,这并不是将颜色传递给 ConTeXt 来排版文本,这些是通常会绘制的颜色,withcolor ca withtransparency (method,factor)
但这需要传递更多的参数和更多的编码工作。
transparent() 是否可能会生成一个看起来像ca withtransparency (method,factor)
只能在 draw/fill/etc 语句中使用的字符串?但在这种情况下,如果没有 scantokens 来解析字符串,它如何工作?
有没有一种方法可以做到这一点,而不需要在我的宏中到处使用两倍的参数(并且我必须传递多种颜色)?
谢谢,
G
答案1
您可以将transparent()
参数作为text
类型传递。在这种情况下,直到行的其余部分;
被复制到参数中,并且可以在draw
命令中直接使用。我不确定我是否完全理解您的要求,但这似乎接近原始示例。
\starttext
\startMPpage[instance=doublefun]
vardef SampleText (expr t) text c =
save p ; picture p ;
p := image (draw t infont "\truefontname{Regular}") ;
draw (p shifted (- xpart center p,0)) scaled 5 withcolor c ;
enddef ;
SampleText ("Much Of This") transparent(1, .5, red ) ;
SampleText ("Functionality") transparent(1, .5, green) ;
SampleText ("Was Written") transparent(1, .5, blue ) ;
SampleText ("While Listening") transparent(1, .5, cmyk(1,0,0,0)) ;
SampleText ("To the CD's Of") transparent(1, .5, cmyk(0,1,0,0)) ;
SampleText ("Tori Amos") transparent(1, .5, cmyk(0,0,1,0)) ;
\stopMPpage
\stoptext
结果: