Re: [NTG-context] Center a text (Metafun)
On 3/6/2021 11:17 AM, Fabrice Couvreur wrote: Hi Hans, Some time ago, you offered this code to respond to a specific request from me. I used this code again and wanted to know if it was possible for the title "Algorithm" to be automatically centered based on the content. Thank you See Wolfgangs answer. If your using lmtx ... \startuseMPgraphic{MyFrame} picture p ; p := lmt_text [ width = OverlayWidth, height = OverlayHeight, text = "\bfx\framedtextparameter{Title}", color = "white", align = "normal", ] ; p := anchored.ulft (p, ulcorner OverlayBox shifted (0,EmWidth)) ; fill OverlayBox withcolor "MyBlue" ; fill boundingbox p enlarged .5EmWidth withcolor "maincolor" ; draw p ; setbounds currentpicture to OverlayBox ; \stopuseMPgraphic watch how also maincolor is accessed as string. Hans - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Center a text (Metafun)
Fabrice Couvreur schrieb am 06.03.2021 um 11:17: Hi Hans, Some time ago, you offered this code to respond to a specific request from me. I used this code again and wanted to know if it was possible for the title "Algorithm" to be automatically centered based on the content. Thank you Fabrice \definecolor[MyBlue][c=0.2 , m=0.03, y=0.00, k=0.00] \definecolor[maincolor] [b=.5] \defineframedtext [MyFrame] [frame=off, background=MyFrame, width=fit, height=fit, style=small] \startuseMPgraphic{MyFrame} path b; picture p; p := textext.rt("\tfx\bf\white\framedtextparameter{Title}"); p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight); p := textext.t("\tfx\bf\white\framedtextparameter{Title}"); p := p shifted (OverlayWidth/2,OverlayHeight-ypart center p+.25ExHeight); Wolfgang ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Center a text (Metafun)
Hi Hans, Some time ago, you offered this code to respond to a specific request from me. I used this code again and wanted to know if it was possible for the title "Algorithm" to be automatically centered based on the content. Thank you Fabrice \definecolor[MyBlue][c=0.2 , m=0.03, y=0.00, k=0.00] \definecolor[maincolor] [b=.5] \defineframedtext [MyFrame] [frame=off, background=MyFrame, width=fit, height=fit, style=small] \startuseMPgraphic{MyFrame} path b; picture p; p := textext.rt("\tfx\bf\white\framedtextparameter{Title}"); p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight); b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth topenlarged .5EmWidth bottomenlarged .5EmWidth ; fill OverlayBox withcolor "MyBlue" ; fill b withcolor \MPcolor{maincolor} ; draw p ; setbounds currentpicture to boundingbox currentpicture enlarged 2mm ; \stopuseMPgraphic \defineoverlay [MyFrame] [\useMPgraphic{MyFrame}] \starttext \MyFrame[Title=Algorithme]{% \m{a\gets 2x-1} \m{b\gets a²-1} \m{c\gets b\div 4} \m{d\gets c-a+x} } \stoptext ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___