MetaFun - Pragma ADE
MetaFun - Pragma ADE MetaFun - Pragma ADE
136 \startMPcode picture p ; p := \MPbetex {1} ; picture q ; q := textext( \MPstring{2} ) ; picture r ; r := thelabel("\MPtext {3}",origin) ; for i=p, boundingbox p : draw i withcolor .625red ; endfor ; for i=q, boundingbox q : draw i withcolor .625yellow ; endfor ; for i=r, boundingbox r : draw i withcolor .625white ; endfor ; currentpicture := currentpicture scaled 2 ; draw origin withpen pencircle scaled 5.0mm withcolor white ; draw origin withpen pencircle scaled 2.5mm withcolor black ; draw boundingbox currentpicture withpen pencircle scaled .1mm dashed evenly ; \stopMPcode The first two lines return text typeset by TEX, while the last line leaves this to METAPOST. Text See streams what happens become Now ispictures. here. this TEX or not? If you watch closely, you will notice that the first (red) alternative is positioned with the baseline on the origin. \startMPcode picture p ; p := \MPbetex {1} ; picture q ; q := textext.origin( \MPstring{2} ) ; picture r ; r := thelabel.origin("\MPtext {3}",origin) ; for i=p, boundingbox p : draw i withcolor .625red ; endfor ; for i=q, boundingbox q : draw i withcolor .625yellow ; endfor ; for i=r, boundingbox r : draw i withcolor .625white ; endfor ; currentpicture := currentpicture scaled 2 ; draw origin withpen pencircle scaled 5.0mm withcolor white ; draw origin withpen pencircle scaled 2.5mm withcolor black ; draw boundingbox currentpicture withpen pencircle scaled .1mm dashed evenly ; \stopMPcode This draws: Now See Textwhat is streams this happens TEX become or here. not? pictures. This picture demonstrates that we can also position textext's and label's on the baseline. For this purpose the repertoire of positioning directives (top, lft, etc.) is extended with an origin directive. Another extra positioning directive is raw. This one does not do any positioning at all. picture q ; q := textext.origin( \MPstring{2} ) ; picture r ; r := thelabel.origin("\MPtext {3}",origin) ; Enhancing the layout Graphics and macros
We will now apply this knowledge of text inclusion in graphics to a more advanced example. The next definitions are the answer to a question on the CONTEXT mailinglist with regards to framed texts with titles. Zapf (1) Coming back to the use of typefaces in electronic publishing: many of the new typographers receive their knowledge and information about the rules of typography from books, from computer magazines or the instruction manuals which they get with the purchase of a PC or software. In this example, the title is positioned on top of the frame. Title and text are entered as: \FrameTitle{Zapf (1)} \StartFrame Coming back to the use of typefaces in electronic publishing: many of the new typographers receive their knowledge and information about the rules of typography from books, from computer magazines or the instruction manuals which they get with the purchase of a PC or software. \StopFrame The implementation is not that complicated and uses the frame commands that are built in CONTEXT. Instead of letting TEX draw the frame, we use METAPOST, which we also use for handling the title. The graphic is defined as follows: \startuseMPgraphic{FunnyFrame} picture p ; numeric w, h, o ; p := textext.rt(\MPstring{FunnyFrame}) ; w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ; p := p shifted (2o,h-ypart center p) ; draw p ; drawoptions (withpen pencircle scaled 1pt withcolor .625red) ; draw (2o,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner p,h) ; draw boundingbox p ; setbounds currentpicture to unitsquare xyscaled(w,h) ; \stopuseMPgraphic Because the framed title is partly positioned outside the main frame, and because the main frame will be combined with the text, we need to set the boundingbox explicitly. This is a way to create so called free figures, where part of the figure lays beyond the area that is taken into account when positioning the graphic. The shift ... shifted (2o,h-ypart center p) ensures that the title is vertically centered over the top line of the main box. The macros that use this graphic combine some techniques of defining macros, using predefined CONTEXT classes, and passing information to graphics. Graphics and macros Enhancing the layout 137
- Page 89 and 90: The tension specifier can be used t
- Page 91 and 92: The asymetrical tensions are less p
- Page 93 and 94: z0 .. z1 .. z2 z0 {curl 1} .. z1 ..
- Page 95 and 96: 7 In literature concerning POSTSCRI
- Page 97 and 98: currentpicture := currentpicture sl
- Page 99 and 100: We can achieve this by defining poi
- Page 101 and 102: We're still not there. Like in a pr
- Page 103 and 104: Due to the thicker line width used
- Page 105 and 106: left up down right The previous def
- Page 107 and 108: Here the & glues strings together,
- Page 109 and 110: picture p ; p := "MetaFun" normalin
- Page 111 and 112: pickup pencircle scaled 2pt ; draw
- Page 113 and 114: Because the z--variables are used f
- Page 115 and 116: 3 Embedded graphics In addition to
- Page 117 and 118: \startMPcode fill fullcircle scaled
- Page 119 and 120: \startuniqueMPgraphic{right or wron
- Page 121 and 122: {\externalfigure[mprun:extrafun::my
- Page 123 and 124: \startlinecorrection[blank] \proces
- Page 125 and 126: In order to prevent problems, we ad
- Page 127 and 128: There are a few more low level swit
- Page 129 and 130: When we convert color to gray, we u
- Page 131 and 132: 4 Enhancing the layout One of the m
- Page 133 and 134: 4.2 Overlay variables [offset=3pt,f
- Page 135 and 136: This background demonstrates that a
- Page 137 and 138: As you may know, TEX's ambassador i
- Page 139: This works as expected: \RotatedTex
- Page 143 and 144: p := p shifted (2o,OverlayHeight-yp
- Page 145 and 146: We demonstrated that when defining
- Page 147 and 148: 5 Positional graphics In this chapt
- Page 149 and 150: 5.2 Anchors and layers In a previou
- Page 151 and 152: pab := pab cutafter (pab intersecti
- Page 153 and 154: fill p withcolor \MPcolor{lightgray
- Page 155 and 156: The previous example also demonstra
- Page 157 and 158: \setMPlayer [test] [somepos-1] [loc
- Page 159 and 160: 6 Page backgrounds Especially in in
- Page 161 and 162: As soon as you want to make an elec
- Page 163 and 164: do_it (1,4,false) ; do_it (5,4,fals
- Page 165 and 166: gigigi Watch how the bounding boxes
- Page 167 and 168: You can test this concept yourself
- Page 169 and 170: StartPage ; fill Area[Text][Text] s
- Page 171 and 172: fi ; Main := Main enlarged 6pt ; pi
- Page 173 and 174: ulcorner Field[Text] [Text] -urcorn
- Page 175 and 176: The left picture demonstrates what
- Page 177 and 178: There are two more operators: inner
- Page 179 and 180: 7 Shapes, symbols and buttons One c
- Page 181 and 182: Table 7.1 demonstrates how scratch
- Page 183 and 184: for i := 1 upto \MPvar{n} : xpos :=
- Page 185 and 186: This table is defined as: \bTABLE[f
- Page 187 and 188: Since we have collected some nice b
- Page 189 and 190: 8 Special effects Sometimes we want
136<br />
\startMPcode<br />
picture p ; p := \MPbetex {1} ;<br />
picture q ; q := textext( \MPstring{2} ) ;<br />
picture r ; r := thelabel("\MPtext {3}",origin) ;<br />
for i=p, boundingbox p : draw i withcolor .625red ; endfor ;<br />
for i=q, boundingbox q : draw i withcolor .625yellow ; endfor ;<br />
for i=r, boundingbox r : draw i withcolor .625white ; endfor ;<br />
currentpicture := currentpicture scaled 2 ;<br />
draw origin withpen pencircle scaled 5.0mm withcolor white ;<br />
draw origin withpen pencircle scaled 2.5mm withcolor black ;<br />
draw boundingbox currentpicture withpen pencircle scaled .1mm dashed evenly ;<br />
\stopMPcode<br />
The first two lines return text typeset by TEX, while the last line leaves this to METAPOST.<br />
Text See streams what happens become Now ispictures. here. this TEX or not?<br />
If you watch closely, you will notice that the first (red) alternative is positioned with the baseline<br />
on the origin.<br />
\startMPcode<br />
picture p ; p := \MPbetex {1} ;<br />
picture q ; q := textext.origin( \MPstring{2} ) ;<br />
picture r ; r := thelabel.origin("\MPtext {3}",origin) ;<br />
for i=p, boundingbox p : draw i withcolor .625red ; endfor ;<br />
for i=q, boundingbox q : draw i withcolor .625yellow ; endfor ;<br />
for i=r, boundingbox r : draw i withcolor .625white ; endfor ;<br />
currentpicture := currentpicture scaled 2 ;<br />
draw origin withpen pencircle scaled 5.0mm withcolor white ;<br />
draw origin withpen pencircle scaled 2.5mm withcolor black ;<br />
draw boundingbox currentpicture withpen pencircle scaled .1mm dashed evenly ;<br />
\stopMPcode<br />
This draws:<br />
Now See Textwhat is streams this happens TEX become or here. not? pictures.<br />
This picture demonstrates that we can also position textext's and label's on the baseline. For<br />
this purpose the repertoire of positioning directives (top, lft, etc.) is extended with an origin<br />
directive. Another extra positioning directive is raw. This one does not do any positioning at all.<br />
picture q ; q := textext.origin( \MPstring{2} ) ;<br />
picture r ; r := thelabel.origin("\MPtext {3}",origin) ;<br />
Enhancing the layout Graphics and macros