From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/23323 Path: news.gmane.org!not-for-mail From: andrea valle Newsgroups: gmane.comp.tex.context Subject: Re: maximum of \externalfigure in MP Date: Tue, 8 Nov 2005 11:31:51 +0100 Message-ID: References: <4f78d01fe831138d14a4846f8a3b9898@di.unito.it> <436F0F50.7040800@elvenkind.com> <01ddfc3564274a7bf95dd962dbf43700@di.unito.it> <436F38DF.30604@elvenkind.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1131446064 6490 80.91.229.2 (8 Nov 2005 10:34:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 8 Nov 2005 10:34:24 +0000 (UTC) Original-X-From: ntg-context-bounces@ntg.nl Tue Nov 08 11:34:15 2005 Return-path: Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by ciao.gmane.org with esmtp (Exim 4.43) id 1EZQlp-0005dE-Uo for gctc-ntg-context-518@m.gmane.org; Tue, 08 Nov 2005 11:32:06 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 68D0A127E6; Tue, 8 Nov 2005 11:32:04 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 19729-03; Tue, 8 Nov 2005 11:31:58 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id D386A127C6; Tue, 8 Nov 2005 11:31:57 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 7865D127C6 for ; Tue, 8 Nov 2005 11:31:56 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 19885-08 for ; Tue, 8 Nov 2005 11:31:54 +0100 (CET) Original-Received: from swip.net (mailfe05.tele2.it [212.247.154.141]) by ronja.ntg.nl (Postfix) with ESMTP id 51430127BA for ; Tue, 8 Nov 2005 11:31:54 +0100 (CET) X-T2-Posting-ID: K+vsftSFIw076cEyPj85jnAdTvyyxk/k4XBbHoCgE7s= Original-Received: from [81.211.227.138] ([81.211.227.138] verified) by mailfe05.swip.net (CommuniGate Pro SMTP 4.3.8) with ESMTP id 5234250 for ntg-context@ntg.nl; Tue, 08 Nov 2005 11:31:52 +0100 In-Reply-To: <436F38DF.30604@elvenkind.com> Original-To: mailing list for ConTeXt users X-Mailer: Apple Mail (2.622) X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.5 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:23323 Archived-At: (Taco, thanks for all the infos. Now, just trying to understand). Why the bug manifest itself in this particular tex file? I mean: I have=20= made other pieces, both with far less either with far more included=20 pdfs and everything was ok. What's special in the bug-raiser tex we discussed about? Thanks -a- On 7 Nov 2005, at 12:22, Taco Hoekwater wrote: > andrea valle wrote: >> It's the same file but I commented out a part of the section=20 >> dedicated to importing and drawing little notes attached to=20 >> arrowlines between music fragments. >> Everything not commented is now displayed: on my machine it seems to=20= >> be deterministic. > > Ok, got it. There is a bug in mp-spec.mp (inside metafun). Because > of a wrapping number, it fails to recognize the fact that there are > embedded specials at all. Attached is an updated version of > mp-spec.mp. > > The corrected definition of add_special_signal is: > > vardef add_special_signal =3D % write the version number > if (length _global_specials_<>0) or (length _local_specials_ <>0) = : > special ("%%MetaPostSpecials: 1.0 " & decimal _special_signal_ )=20= > ; > fi ; > enddef ; > > It now tests for "not equal to zero" instead of "larger than zero": > because of all the included files, the string _local_specials_ becomes > longer than the maximum number 'length' can return, so it returns > -32768 instead, and that is of course less than zero. > > > Don't forget that you have to re-create the metafun format as well! > > Cheers, Taco > %D \module > %D [ file=3Dmp-spec.mp, > %D version=3D1999.6.26, > %D title=3D\CONTEXT\ \METAPOST\ graphics, > %D subtitle=3Dspecial extensions, > %D author=3DHans Hagen, > %D date=3D\currentdate, > %D copyright=3D{PRAGMA / Hans Hagen \& Ton Otten}] > %C > %C This module is part of the \CONTEXT\ macro||package and is > %C therefore copyrighted by \PRAGMA. See licen-en.pdf for > %C details. > > % Spot colors are not handled by mptopdf ! > > % (r,g,b) =3D> cmyk : r=3D123 g=3D 1 b=3Dhash > % =3D> spot : r=3D123 g=3D 2 b=3Dhash > % =3D> transparent rgb : r=3D123 g=3D 3 b=3Dhash > % =3D> transparent cmyk : r=3D123 g=3D 4 b=3Dhash > % =3D> transparent spot : r=3D123 g=3D 5 b=3Dhash > % =3D> rest : r=3D123 g=3Dn>10 b=3Dwhatever > > %D This module is rather preliminary and subjected to > %D changes. Here we closely cooperates with the \METAPOST\ > %D to \PDF\ converter module built in \CONTEXT\ and provides > %D for instance shading. More information can be found in > %D type {supp-mpe.tex}. > > if unknown context_tool : input mp-tool ; fi ; > if known context_spec : endinput ; fi ; > > boolean context_spec ; context_spec :=3D true ; > > numeric _special_counter_ ; _special_counter_ :=3D 0 ; > numeric _color_counter_ ; _color_counter_ :=3D 11 ; % < 10 = reserved > numeric _special_signal_ ; _special_signal_ :=3D 123 ; > > %D When set to \type {true}, shading will be supported. Some > %D day I will also write an additional directive. > > boolean _inline_specials_ ; _inline_specials_ :=3D false ; > > %D Because we want to output only those specials that are > %D actually used in a figure, we need a bit complicated > %D bookkeeping and collection of specials. At the cost of some > %D obscurity, we now have rather efficient resources. > > string _global_specials_ ; _global_specials_ :=3D "" ; > string _local_specials_ ; _local_specials_ :=3D "" ; > > vardef add_special_signal =3D % write the version number > if (length _global_specials_<>0) or (length _local_specials_ <>0) : > special ("%%MetaPostSpecials: 1.0 " & decimal _special_signal_ ) ; > fi ; > enddef ; > > vardef add_extra_specials =3D > scantokens _global_specials_ ; > scantokens _local_specials_ ; > enddef ; > > vardef reset_extra_specials =3D > % only local ones > _local_specials_ :=3D "" ; > enddef ; > > boolean insidefigure ; insidefigure :=3D false ; > > % todo: alleen als special gebruikt flush > > extra_beginfig :=3D > " insidefigure :=3D true ; " & > " reset_extra_specials ; " & > extra_beginfig ; > > extra_endfig :=3D > " add_special_signal ; " & > extra_endfig & > " add_extra_specials ; " & > " reset_extra_specials ; " & > " insidefigure :=3D false ; " ; > > def set_extra_special (expr s) =3D > if insidefigure : > _local_specials_ :=3D _local_specials_ & s ; > else : > _global_specials_ :=3D _global_specials_ & s ; > fi > enddef ; > > def flush_special (expr typ, siz, dat) =3D > _special_counter_ :=3D _special_counter_ + 1 ; > if _inline_specials_ : > set_extra_special > ( "special " > & "(" & ditto > & dat & " " > & decimal _special_counter_ & " " > & decimal typ & " " > & decimal siz > & " special" > & ditto & ");" ) ; > else : > set_extra_special > ( "special " > & "(" & ditto > & "%%MetaPostSpecial: " > & decimal siz & " " > & dat & " " > & decimal _special_counter_ & " " > & decimal typ > & ditto & ");" ) ; > fi ; > enddef ; > > %D The next hack is needed in case you use a version of > %D \METAPOST\ that does not provide you the means to configure > %D the buffer size. Patrick Gundlach suggested to use arrays > %D in this case. > > boolean bufferhack ; bufferhack :=3D false ; % true ; > > if bufferhack : > > string _global_specials_[] ; numeric _nof_global_specials_ ; > string _local_specials_[] ; numeric _nof_local_specials_ ; > > _nof_global_specials_ :=3D _nof_local_specials_ :=3D 0 ; > > vardef add_special_signal =3D % write the version number > if (_nof_global_specials_>0) or (_nof_local_specials_>0) : > special ("%%MetaPostSpecials: 1.0 " & decimal _special_signal_ )=20= > ; > fi ; > enddef ; > > vardef add_extra_specials =3D > for i=3D1 upto _nof_global_specials_ : > scantokens _global_specials_[i] ; > endfor; > for i=3D1 upto _nof_local_specials_ : > scantokens _local_specials_[i] ; > endfor; > enddef ; > > vardef reset_extra_specials =3D > string _local_specials_[] ; _nof_local_specials_ :=3D 0 ; > enddef ; > > def set_extra_special (expr s) =3D > if insidefigure : > _local_specials_[incr(_nof_local_specials_)] :=3D s ; > else : > _global_specials_[incr(_nof_global_specials_)] :=3D s ; > fi > enddef ; > > fi ; > > %D So far for this hack. > > %D Shade allocation. > > newinternal shadefactor ; shadefactor :=3D 1 ; > > pair shadeoffset ; shadeoffset :=3D origin ; > > vardef define_linear_shade (expr a, b, ca, cb) =3D > flush_special(30, 15, "0 1 " & decimal shadefactor & " " & > dddecimal ca & " " & ddecimal (a shifted shadeoffset) & " " & > dddecimal cb & " " & ddecimal (b shifted shadeoffset) ) ; > _special_counter_ > enddef ; > > vardef define_circular_shade (expr a, b, ra, rb, ca, cb) =3D > flush_special(31, 17, "0 1 " & decimal shadefactor & " " & > dddecimal ca & " " & ddecimal (a shifted shadeoffset) & " " &=20 > decimal ra & " " & > dddecimal cb & " " & ddecimal (b shifted shadeoffset) & " " &=20 > decimal rb ) ; > _special_counter_ > enddef ; > > %D A few predefined shading macros. > > boolean trace_shades ; trace_shades :=3D false ; > > % if (n=3D1) : a :=3D llcorner p ; b :=3D urcorner p ; > % elseif (n=3D2) : a :=3D llcorner p ; b :=3D ulcorner p ; > % elseif (n=3D3) : a :=3D lrcorner p ; b :=3D ulcorner p ; > % else : a :=3D llcorner p ; b :=3D lrcorner p ; > % fi ; > > def set_linear_vector (suffix a,b)(expr p,n) =3D > if (n=3D1) : a :=3D llcorner p ; > b :=3D urcorner p ; > elseif (n=3D2) : a :=3D lrcorner p ; > b :=3D ulcorner p ; > elseif (n=3D3) : a :=3D urcorner p ; > b :=3D llcorner p ; > elseif (n=3D4) : a :=3D ulcorner p ; > b :=3D lrcorner p ; > elseif (n=3D5) : a :=3D .5[ulcorner p,llcorner p] ; > b :=3D .5[urcorner p,lrcorner p] ; > elseif (n=3D6) : a :=3D .5[llcorner p,lrcorner p] ; > b :=3D .5[ulcorner p,urcorner p] ; > elseif (n=3D7) : a :=3D .5[lrcorner p,urcorner p] ; > b :=3D .5[llcorner p,ulcorner p] ; > elseif (n=3D8) : a :=3D .5[urcorner p,ulcorner p] ; > b :=3D .5[lrcorner p,llcorner p] ; > else : a :=3D .5[ulcorner p,llcorner p] ; > b :=3D .5[urcorner p,lrcorner p] ; > fi ; > enddef ; > > def linear_shade (expr p, n, ca, cb) =3D > begingroup ; > save a, b, sh ; pair a, b ; > set_linear_vector(a,b)(p,n) ; > fill p withshade define_linear_shade (a,b,ca,cb) ; > if trace_shades : > drawarrow a -- b withpen pencircle scaled 1pt ; > fi ; > endgroup ; > enddef ; > > vardef predefined_linear_shade (expr p, n, ca, cb) =3D > save a, b, sh ; pair a, b ; > set_linear_vector(a,b)(p,n) ; > set_shade_vector(a,b)(p,n) ; > define_linear_shade (a,b,ca,cb) > enddef ; > > def set_circular_vector (suffix ab, r)(expr p,n) =3D > if (n=3D1) : ab :=3D llcorner p ; > elseif (n=3D2) : ab :=3D lrcorner p ; > elseif (n=3D3) : ab :=3D urcorner p ; > elseif (n=3D4) : ab :=3D ulcorner p ; > else : ab :=3D center p ; r :=3D .5r ; > fi ; > enddef ; > > def circular_shade (expr p, n, ca, cb) =3D > begingroup ; > save ab, r ; pair ab ; numeric r ; > r :=3D (xpart lrcorner p - xpart llcorner p) ++ > (ypart urcorner p - ypart lrcorner p) ; > set_circular_vector(ab,r)(p,n) ; > fill p withshade define_circular_shade(ab,ab,0,r,ca,cb) ; > if trace_shades : > drawarrow ab -- ab shifted (0,r) withpen pencircle scaled 1pt ; > fi ; > endgroup ; > enddef ; > > vardef predefined_circular_shade (expr p, n, ca, cb) =3D > save ab, r ; pair ab ; numeric r ; > r :=3D (xpart lrcorner p - xpart llcorner p) ++ > (ypart urcorner p - ypart lrcorner p) ; > set_circular_vector(ab,r)(p,n) ; > define_circular_shade(ab,ab,0,r,ca,cb) > enddef ; > > %D Since a \type {fill p withshade s} syntax looks better > %D than some macro, we implement a new primary. > > primarydef p withshade sc =3D % =3D=3D p withcolor shadecolor(sh) > hide (_color_counter_ :=3D _color_counter_ + 1) > p withcolor (_special_signal_/1000,_color_counter_/1000,sc/1000) > enddef ; > > vardef shadecolor(expr sc) =3D > hide (_color_counter_ :=3D _color_counter_ + 1) > (_special_signal_/1000,_color_counter_/1000,sc/1000) > enddef ; > > %D Figure inclusion. > > %numeric cef ; cef :=3D 0 ; > > def externalfigure primary filename =3D > doexternalfigure (filename) > enddef ; > > def doexternalfigure (expr filename) text transformation =3D > begingroup ; save p, t ; picture p ; transform t ; > p :=3D nullpicture ; t :=3D identity transformation ; > flush_special(10, 9, > dddecimal (xxpart t, yxpart t, xypart t) & " " & > dddecimal (yypart t, xpart t, ypart t) & " " & filename) ; > addto p contour unitsquare scaled 0 ; > setbounds p to unitsquare transformed t ; > _color_counter_ :=3D _color_counter_ + 1 ; > draw p withcolor=20 > (_special_signal_/1000,_color_counter_/1000,_special_counter_/1000) ; > %draw p withcolor=20 > (_special_signal_/1000,cef/1000,_special_counter_/1000) ; > endgroup ; > enddef ; > > %D Experimental: > > %numeric currenthyperlink ; currenthyperlink :=3D 0 ; > > def hyperlink primary t =3D dohyperlink(t) enddef ; > def hyperpath primary t =3D dohyperpath(t) enddef ; > > def dohyperlink (expr destination) text transformation =3D > begingroup ; save somepath ; path somepath ; > somepath :=3D fullsquare transformation ; > dohyperpath(destination) somepath ; > endgroup ; > enddef ; > > def dohyperpath (expr destination) expr somepath =3D > begingroup ; > flush_special(20, 7, > ddecimal (xpart llcorner somepath, ypart llcorner somepath) & " " = & > ddecimal (xpart urcorner somepath, ypart urcorner somepath) & " "=20= > & destination) ; > % currenthyperlink :=3D currenthyperlink + 1 ; > _color_counter_ :=3D _color_counter_ + 1 ; > fill boundingbox unitsquare scaled 0 withcolor > =20 > (_special_signal_/1000,_color_counter_/1000,_special_counter_/1000) ; > % =20 > (_special_signal_/1000,currenthyperlink/1000,_special_counter_/1000) ; > endgroup ; > enddef ; > > % \setupinteraction[state=3Dstart] > % \setupcolors [state=3Dstart] > % > % Hello There! \blank > % > % \startMPcode > % pickup pencircle scaled 5 ; > % draw fullcircle scaled 4cm withcolor red ; > % hyperpath "nextpage" boundingbox currentpicture ; > % draw origin withcolor blue ; > % \stopMPcode > % > % \blank Does it work or not? > % > % \startMPcode > % pickup pencircle scaled 5 ; > % draw fullcircle scaled 4cm withcolor red ; > % hyperpath "nextpage" fullcircle scaled 4cm ; > % draw origin withcolor blue ; > % draw fullcircle scaled 4cm shifted (1cm,1cm); > % \stopMPcode > % > % \blank Does it work or not? \page Hello There! \blank > % > % \startMPcode > % pickup pencircle scaled 5 ; > % draw fullcircle scaled 2cm shifted (-2cm,-1cm) ; > % draw fullcircle scaled 3cm shifted (2cm,1cm) withcolor red ; > % draw fullcircle scaled 1cm ; > % hyperlink "previouspage" scaled 3cm shifted (2cm,1cm) ; > % draw origin withcolor blue ; > % \stopMPcode > % > % \blank Does it work or not? > > _cmyk_counter_ :=3D 0 ; > > extra_endfig :=3D " resetcmykcolors ; " & extra_endfig ; > > def resetcmykcolors =3D > numeric cmykcolorhash[][][][] ; > enddef ; > > resetcmykcolors ; boolean cmykcolors ; cmykcolors :=3D false ; % true > > string cmykcolorpattern[] ; % needed for transparancies > > vardef cmyk(expr c,m,y,k) =3D > if cmykcolors : > save ok ; boolean ok ; > if unknown cmykcolorhash[c][m][y][k] : > ok :=3D false ; % not yet defined > elseif cmykcolorhash[c][m][y][k] =3D -1 : > ok :=3D false ; % locally defined and undefined > else : > ok :=3D true ; % globally already defined > fi ; > if not ok : > save s ; string s ; s :=3D dddecimal (c,m,y) & " " & decimal k ; > _cmyk_counter_ :=3D _cmyk_counter_ + 1 ; > cmykcolorpattern[_cmyk_counter_/1000] :=3D s ; > cmykcolorhash[c][m][y][k] :=3D _cmyk_counter_ ; > flush_special(1, 7, decimal _cmyk_counter_ & " " & s) ; > _local_specials_ :=3D _local_specials_ & > " cmykcolorhash[" & decimal c & "][" & decimal m & > "][" & decimal y & "][" & decimal k & "] :=3D -1 ; " ; > fi ; > (_special_signal_/1000,1/1000,cmykcolorhash[c][m][y][k]/1000) > else : > (1-c-k,1-m-k,1-y-k) > fi > enddef ; > > % newcolor truecyan, truemagenta, trueyellow ; > % > % truecyan =3D cmyk (1,0,0,0) ; > % truemagenta =3D cmyk (0,1,0,0) ; > % trueyellow =3D cmyk (0,0,1,0) ; > > %D Spot colors > > _spotcolor_counter_ :=3D 0 ; > _spotcolor_number_ :=3D 0 ; > > extra_endfig :=3D " resetspotcolors ; " & extra_endfig ; > > def resetspotcolors =3D > numeric spotcolorhash[][] ; > enddef ; > > resetspotcolors ; boolean spotcolors ; spotcolors :=3D false ; % true > > string spotcolorpattern[] ; % needed for transparancies > > % vardef spotcolor(expr p, s) =3D > % if spotcolors : > % save ok, pc_tag ; boolean ok ; string pc_tag ; > % pc_tag :=3D "_pct_"&p ; > % if not unstringed(pc_tag) : > % _spotcolor_number_ :=3D _spotcolor_number_ + 1 ; > % setunstringed(pc_tag,_spotcolor_number_) ; > % fi ; > % pp :=3D getunstringed(pc_tag) ; > % if unknown spotcolorhash[pp][s] : > % ok :=3D false ; % not yet defined > % elseif spotcolorhash[pp][s] =3D -1 : > % ok :=3D false ; % locally defined and undefined > % else : > % ok :=3D true ; % globally already defined > % fi ; > % if not ok : > % save ss ; string ss ; ss :=3D p & " " & decimal s ; > % _spotcolor_counter_ :=3D _spotcolor_counter_ + 1 ; > % spotcolorpattern[_spotcolor_counter_/1000] :=3D ss ; > % spotcolorhash[pp][s] :=3D _spotcolor_counter_ ; > % flush_special(2, 5, decimal _spotcolor_counter_ & " " & ss) ; > % _local_specials_ :=3D _local_specials_ & > % "spotcolorhash["&decimal pp&"]["&decimal s&"]:=3D-1;" ; > % fi ; > % (_special_signal_/1000,2/1000,spotcolorhash[pp][s]/1000) > % else : > % (1-s,1-s,1-s) > % fi > % enddef ; > > % vardef spotcolor(expr p, s) =3D > % if spotcolors : > % save ok, pc_tag ; boolean ok ; string pc_tag ; > % pc_tag :=3D "_pct_"&p ; > % if not unstringed(pc_tag) : > % _spotcolor_number_ :=3D _spotcolor_number_ + 1 ; > % setunstringed(pc_tag,_spotcolor_number_) ; > % fi ; > % pp :=3D getunstringed(pc_tag) ; > % if unknown spotcolorhash[pp][s] : > % ok :=3D false ; % not yet defined > % elseif spotcolorhash[pp][s] =3D -1 : > % ok :=3D false ; % locally defined and undefined > % else : > % ok :=3D true ; % globally already defined > % fi ; > % if not ok : > % save ss ; string ss ; ss :=3D p & " " & decimal s ; > % _spotcolor_counter_ :=3D _spotcolor_counter_ + 1 ; > % spotcolorpattern[_spotcolor_counter_/1000] :=3D ss ; > % spotcolorhash[pp][s] :=3D _spotcolor_counter_ ; > % flush_special(2, 5, decimal _spotcolor_counter_ & " " & ss) ; > % _local_specials_ :=3D _local_specials_ & > % "spotcolorhash["&decimal pp&"]["&decimal s&"]:=3D-1;" ; > % fi ; > % (_special_signal_/1000,2/1000,spotcolorhash[pp][s]/1000) > % else : > % (1-s,1-s,1-s) > % fi > % enddef ; > > vardef spotcolor(expr p, s) =3D > multitonecolor(p, 1, "", decimal s) > enddef ; > > vardef multitonecolor(expr n, f, d, p) =3D % name fractions names = factors > if spotcolors : > save ok, pc_tag ; boolean ok ; string pc_tag ; > pc_tag :=3D "_pct_" & n ; > if not unstringed(pc_tag) : > _spotcolor_number_ :=3D _spotcolor_number_ + 1 ; > setunstringed(pc_tag,_spotcolor_number_) ; > fi ; > pp :=3D getunstringed(pc_tag) ; > pc_tag :=3D "_pct_"& decimal f & "_" & if d =3D "" : n else : d fi = &=20 > "_" & p ; % check for d empty > if not unstringed(pc_tag) : > _spotcolor_number_ :=3D _spotcolor_number_ + 1 ; > setunstringed(pc_tag,_spotcolor_number_) ; > fi ; > ps :=3D getunstringed(pc_tag) ; > if unknown spotcolorhash[pp][ps] : > ok :=3D false ; % not yet defined > elseif spotcolorhash[pp][ps] =3D -1 : > ok :=3D false ; % locally defined and undefined > else : > ok :=3D true ; % globally already defined > fi ; > if not ok : > save ss ; string ss ; ss :=3D n & " " & decimal f & " " & if d =3D= =20 > "" : n else : d fi & " " & p ; > _spotcolor_counter_ :=3D _spotcolor_counter_ + 1 ; > spotcolorpattern[_spotcolor_counter_/1000] :=3D ss ; > spotcolorhash[pp][ps] :=3D _spotcolor_counter_ ; > flush_special(2, 7, decimal _spotcolor_counter_ & " " & ss) ; > _local_specials_ :=3D _local_specials_ & > "spotcolorhash["&decimal pp&"]["&decimal ps&"]:=3D-1;" ; > fi ; > (_special_signal_/1000,2/1000,spotcolorhash[pp][ps]/1000) > else : > .5white > fi > enddef ; > > %D Transparency > > normaltransparent :=3D 1 ; multiplytransparent :=3D 2 ; > screentransparent :=3D 3 ; overlaytransparent :=3D 4 ; > softlighttransparent :=3D 5 ; hardlighttransparent :=3D 6 ; > colordodgetransparent :=3D 7 ; colorburntransparent :=3D 8 ; > darkentransparent :=3D 9 ; lightentransparent :=3D 10 ; > differencetransparent :=3D 11 ; exclusiontransparent :=3D 12 ; > > % nottransparent :=3D 0 ; > % compatibletransparent :=3D 99 ; > > % fill fullcircle scaled 10cm withcolor transparant(.8,3,color) ; > > % vardef transparent(expr n, t, c) =3D > % save s, ss, nn, cc, is_cmyk, is_spot, ok ; > % string s, ss ; numeric nn ; color cc ; boolean is_cmyk, is_spot,=20= > ok ; > % % transparancy type > % if string n : > % if expandafter known scantokens(n&"transparent") : > % nn :=3D scantokens(n&"transparent") ; > % else : > % nn :=3D 0 ; > % fi > % else : % nn :=3D min(n,13) > % nn :=3D if n<13 : n else : nn :=3D 0 fi ; > % fi ; > % % we need to expand the color (can be cmyk(..) or predefined) > % cc :=3D c ; % expand color > % % check for cmyk special > % is_cmyk :=3D (redpart cc =3D _special_signal_/1000) > % and (greenpart cc =3D 1/1000) ; > % is_spot :=3D (redpart cc =3D _special_signal_/1000) > % and (greenpart cc =3D 2/1000) ; > % % build special string, fetch cmyk components > % s :=3D decimal nn & " " & decimal t & " " & > % if is_cmyk : cmykcolorpattern[bluepart cc] > % elseif is_spot : spotcolorpattern[bluepart cc] > % else : dddecimal cc fi ; > % % check if this one is already used > % ss :=3D "tr_" & s ; > % % efficiency hack > % if expandafter unknown scantokens(ss) : > % ok :=3D false ; % not yet defined > % elseif scantokens(ss) < 0 : > % ok :=3D false ; % locally defined and undefined > % else : > % ok :=3D true ; % globally already defined > % fi ; > % if not ok : > % if is_spot : > % flush_special(5, 6, s) ; > % elseif is_cmyk : > % flush_special(4, 8, s) ; > % else : > % flush_special(3, 7, s) ; > % fi ; > % scantokens(ss) :=3D _special_counter_ ; > % _local_specials_ :=3D _local_specials_ & > % "scantokens(" & ditto & ss & ditto & ") :=3D -1 ;" ; > % fi ; > % % go ahead > % if is_spot : > % (_special_signal_/1000,5/1000,scantokens(ss)/1000) > % elseif is_cmyk : > % (_special_signal_/1000,4/1000,scantokens(ss)/1000) > % else : > % (_special_signal_/1000,3/1000,scantokens(ss)/1000) > % fi > % enddef ; > > vardef transparent(expr n, t, c) =3D > save s, ss, nn, cc, is_cmyk, is_spot, ok ; > string s, ss ; numeric nn ; color cc ; boolean is_cmyk, is_spot, ok = ; > % transparancy type > if string n : > if expandafter known scantokens(n&"transparent") : > nn :=3D scantokens(n&"transparent") ; > else : > nn :=3D 0 ; > fi > else : % nn :=3D min(n,13) > nn :=3D if n<13 : n else : nn :=3D 0 fi ; > fi ; > % we need to expand the color (can be cmyk(..) or predefined) > cc :=3D c ; % expand color > % check for cmyk special > is_cmyk :=3D (redpart cc =3D _special_signal_/1000) > and (greenpart cc =3D 1/1000) ; > is_spot :=3D (redpart cc =3D _special_signal_/1000) > and (greenpart cc =3D 2/1000) ; > % build special string, fetch cmyk components > s :=3D decimal nn & " " & decimal t & " " & > if is_cmyk : cmykcolorpattern[bluepart cc] > elseif is_spot : spotcolorpattern[bluepart cc] > else : dddecimal cc fi ; > % check if this one is already used > ss :=3D cleanstring("tr_" & s) ; > % we now have rather unique names, i.e. a color spec of .234 becomes > % tr..._234.... and metapost gives a number overflow (parse error) > % for variables like tr_12345678 which may result from many decimal > % positions (imo mp bug) > ss :=3D asciistring(ss) ; > % efficiency hack > if expandafter unknown scantokens(ss) : > ok :=3D false ; % not yet defined > elseif scantokens(ss) < 0 : > ok :=3D false ; % locally defined and undefined > else : > ok :=3D true ; % globally already defined > fi ; > if not ok : > if is_spot : > flush_special(5, 8, s) ; > elseif is_cmyk : > flush_special(4, 8, s) ; > else : > flush_special(3, 7, s) ; > fi ; > scantokens(ss) :=3D _special_counter_ ; > _local_specials_ :=3D _local_specials_ & > "scantokens(" & ditto & ss & ditto & ") :=3D -1 ;" ; > fi ; > % go ahead > if is_spot : > (_special_signal_/1000,5/1000,scantokens(ss)/1000) > elseif is_cmyk : > (_special_signal_/1000,4/1000,scantokens(ss)/1000) > else : > (_special_signal_/1000,3/1000,scantokens(ss)/1000) > fi > enddef ; > > %D This function returns true of false, dependent on transparency. > > vardef is_transparent(text t) =3D > begingroup ; save transparent ; save _c_, _b_ ; > vardef transparent(expr nn, tt, cc) =3D _b_ :=3D true ; cc enddef = ; > boolean _b_ ; _b_ :=3D false ; > color _c_ ; _c_ :=3D t ; _b_ > endgroup > enddef ; > > %D This function returns the not transparent color. > > vardef not_transparent(text t) =3D > begingroup ; save transparent ; > vardef transparent(expr nn, tt, cc) =3D cc enddef ; > t endgroup > enddef ; > > %D Basic position tracking: > > def register (expr label, width, height, offset) =3D > begingroup ; > flush_special(50, 7, > ddecimal offset & " " & > decimal width & " " & > decimal height & " " & label) ; > endgroup ; > enddef ; > > %D We cannot scale cmyk colors directly since this spoils > %D the trigger signal (such colors are no real colors). > > vardef scaledcmyk(expr c,m,y,k,sf) =3D > cmyk(sf*c,sf*m,sf*y,sf*k) > enddef ; > > vardef scaledcmykasrgb(expr c,m,y,k,sf) =3D > (sf*(1-c-k,1-m-k,1-y-k)) > enddef ; > > vardef scaledrgbascmyk(expr c,m,y,k,sf) =3D > scaledcmyk(1-c,1-m,1-y,0,sf) > enddef ; > > vardef scaledrgb(expr r,g,b,sf) =3D > (sf*(r,g,b)) > enddef ; > > vardef scaledgray(expr s,sf) =3D > (sf*(s,s,s)) > enddef ; > > % spotcolor is already scaled > > endinput ; > > % just an exercise (due to a question by Chof on the context mailing=20= > list); scaling of > % 'special' colors is not possible and the next solution is incomplete=20= > (spot colors, > % transparency, etc); watch the the tricky chained macro construction > > % vardef normalgray(expr s ) =3D (s,s,s) enddef ; > % vardef normalrgb (expr r,g,b ) =3D (r,g,b) enddef ; > % vardef normalcmyk(expr c,m,y,k) =3D if cmykcolors : save ok ; = boolean=20 > ok ; if unknown cmykcolorhash[c][m][y][k] : ok :=3D false ; elseif=20 > cmykcolorhash[c][m][y][k] =3D -1 : ok :=3D false ; else : ok :=3D true = ; fi=20 > ; if not ok : save s ; string s ; s :=3D dddecimal (c,m,y) & " " &=20 > decimal k ; _cmyk_counter_ :=3D _cmyk_counter_ + 1 ;=20 > cmykcolorpattern[_cmyk_counter_/1000] :=3D s ; = cmykcolorhash[c][m][y][k]=20 > :=3D _cmyk_counter_ ; flush_special(1, 7, decimal _cmyk_counter_ & " " = &=20 > s) ; _local_specials_ :=3D _local_specials_ & " cmykcolorhash[" &=20 > decimal c & "][" & decimal m & "][" & decimal y & "][" & decimal k &=20= > "] :=3D -1 ; " ; fi ;=20 > (_special_signal_/1000,1/1000,cmykcolorhash[c][m][y][k]/1000) else :=20= > (1-c-k,1-m-k,1-y-k) fi enddef ; > > % vardef gray(expr s) =3D normalgray(s ) enddef ; > % vardef rgb (expr r,g,b) =3D normalrgb (r,g,b ) enddef ; > % vardef cmyk(expr c,m,y,k) =3D normalcmyk(c,m,y,k) enddef ; > > % numeric _scaled_color_t_ ; > % color _scaled_color_c_ ; > > % def withscaledcolor =3D > % hide ( > % _scaled_color_t_ :=3D 0 ; % direct > % def gray(expr s) =3D > % hide ( > % _gray_s_ :=3D s ; > % _scaled_color_t_ :=3D 1; % gray > % ) > % 0 > % enddef ; > % def rgb (expr r,g,b) =3D > % hide ( > % _rgb_r_ :=3D r ; _rgb_g_ :=3D g ; _rgb_b_ :=3D b ; > % _scaled_color_t_ :=3D 2 ; % rgb > % ) > % 0 > % enddef ; > % def cmyk (expr c,m,y,k) =3D > % hide ( > % _cmyk_c_ :=3D c ; _cmyk_m_ :=3D m ; _cmyk_y_ :=3D y = ;=20 > _cmyk_k_ :=3D k ; > % _scaled_color_t_ :=3D 3 ; % cmyk > % ) > % 0 > % enddef ; ) > % dowithscaledcolor > % enddef ; > > % def dowithscaledcolor expr t =3D > % hide ( > % if color t : _scaled_color_c_ :=3D t fi ; > % vardef gray(expr s) =3D normalgray(s) enddef ; > % vardef rgb (expr r,g,b) =3D normalrgb (r,g,b) enddef ; > % vardef cmyk(expr c,m,y,k) =3D normalcmyk(c,m,y,k) enddef ; > % ) > % enddef ; > > % def by expr s =3D > % if _scaled_color_t_ =3D 0 : > % withcolor s*_scaled_color_c_ > % elseif _scaled_color_t_ =3D 1 : > % withcolor gray(s*_gray_s_) > % elseif _scaled_color_t_ =3D 2 : > % withcolor rgb (s*_rgb_r_, s*_rgb_g_, s*_rgb_b_) > % elseif _scaled_color_t_ =3D 3 : > % withcolor cmyk(s*_cmyk_c_, s*_cmyk_m_, s*_cmyk_y_,=20 > s*_cmyk_k_) > % fi > % enddef ; > > % fill fullcircle scaled 10cm withscaledcolor cmyk(0,0,1,0) by .5 ; > % fill fullcircle scaled 8cm withscaledcolor rgb (0,0,1) by .5 ; > % fill fullcircle scaled 6cm withscaledcolor gray(1) by .5 ; > % fill fullcircle scaled 4cm withscaledcolor (0,1,0) by .5 ; > _______________________________________________ > ntg-context mailing list > ntg-context@ntg.nl > http://www.ntg.nl/mailman/listinfo/ntg-context > Andrea Valle DAMS - Facolt=E0 di Scienze della Formazione Universit=E0 degli Studi di Torino andrea.valle@unito.it