Changes

Jump to navigation Jump to search
3,823 bytes removed ,  16:48, 24 December 2020
no edit summary
<context source="yes">
%------------------------------------------------------------------------------\startMPpage
\setuppapersize [A5]%------------------------------------------------------------------------------
picture tt ; tt := lmt_outline [ kind = "fillup", text = "\definedfont[name:texgyrepagellabold*default]%------------------------------------------------------------------------------ \framed[frame=off,offset=3mm,align=normal,strut=none] {MetaPost is Fun ! @\\ Aujourd'hui\\Today}", ] xsized 20cm ;
\def\MyFont{\definedfont[name path bb ; bb :%texgyrepagellabold%%exo2black%%agaramondprobold%*default at 40pt]}= boundingbox tt;
%------------------------------------------------------------------------------
\startluacode path pp ; pp := bb enlarged 1cm ; fill pp withshademethod "linear" withshadedirection right withshadecolors (red, blue); %------------------------------------------------------------------------------
function document.outlinepaths(character) local chardata = fonts.hashes.characters[true] -- by unicode local shapedata = fonts.hashes.shapes[true] -- by index local c = chardata[character] if c and c.index and shapedata then local shapeglyphs picture Paddmissing; Paddmissing := shapedata.glyphs or { }nullpicture; local glyph picture Pwoletters; Pwoletters := shapeglyphs[c.index]nullpicture; if glyph and (glyph.segments or glyph.sequence) then local units color colorframe; colorframe := shapedata.units or 1000 local factor = 100/units return fonts0.metapost.paths(glyph,factor) end end return { }15white;end numeric testwithin ;
function document.defineoutline(char,target) local outlines = document.outlinepaths(char) local nofpaths = #outlines context("\\startMPdrawing") %---------------------------------------------------------------------------- ADDED by garulfo context("path %s[] ;",target) context("numeric %sn ; %sn := %s ;",target,target,nofpaths) for i=1,nofpaths do context("%s[%i] := %s ; ",target,i,outlines[i]) end context("\\stopMPdrawing") -- ADDED by garulfoend
\stopluacode for i within tt : if stroked i or filled i : testwithin :=0;
%------------------------------------------------------------------------------ for j within tt : if stroked j or filled j: if (((xpart llcorner i) > (xpart llcorner j)) and ((ypart llcorner i) > (ypart llcorner j)) and ((xpart urcorner i) < (xpart urcorner j)) and ((ypart urcorner i) < (ypart urcorner j))) : testwithin :=1; fi; fi; endfor;
\def\mpdefineoutlines# if testwithin == 1#2{\ctxlua{document.defineoutline: addto Paddmissing contour (\number`#1,pathpart i) withcolor colorframe; else: addto Pwoletters contour (pathpart i) withpostscript "#2collect")}}; fi;
%------------------------------------------------------------------------------ fi ; endfor ;
\def\EmptyLetters#1%{%\resetMPdrawing\MPtoks={}%\startMPdrawing picture pic[], pictA ; numeric wid[], len[], pos[], n ; wid[0] := len[0] := pos[0] := n := 0 ; numeric scaling; path pictB , frame ; pair shiftB ; picture monImageA; monImageA := nullpicture; picture monImageB; monImageB := nullpicture; color colorframe; colorframe := 0.6white;% \stopMPdrawing%\MyFont\handletokens#1\with\whatever%\startMPdrawing frame := unitsquare xscaled ( (xpart urcorner monImageB - xpart llcorner monImageB) + 5mm ) yscaled ( (ypart urcorner monImageB - ypart llcorner monImageB) + 5mm );---------------------------------------------------------------------------- frame := frame shifted (center monImageB - center frame); addto monImageB Pwoletters contour frame bb
withpostscript "evenodd"
withcolor transparent (1,1.,colorframe); draw monImageB Pwoletters ; draw monImageA Paddmissing ;\stopMPdrawing% \MPdrawingdonetrue\getMPdrawing} %------------------------------------------------------------------------------ \def\whatever#1% {\appendtoks#1\to\MPtoks \setbox\MPbox=\hbox{\MyFont\the\MPtoks}% % \startMPdrawing n := n + 1 ; len[n] := \the\wd\MPbox ; \stopMPdrawing % \mpdefineoutlines{M}{MaLettre} % \startMPdrawing pictA := textext.drt("\MyFont M") ; pictB := MaLettre[1]; scaling := bbheight pictA / bbheight pictB; \stopMPdrawing % \doifinstringelse{~}{#1}{}{% HOW TO PROPERLY COPE WITH SPACES ? \mpdefineoutlines{#1}{MyGlyph} % \startMPdrawing string sb; sb := "i"; pic[n] := textext.drt("\MyFont\setstrut\strut#1") ; % shiftB := - llcorner pic[n]; pic[n] := pic[n] shifted shiftB ; % wid[n] := abs(xpart urcorner pic[n] - xpart llcorner pic[n]) ; pos[n] := len[n]-wid[n] ; % addto monImageB contour ((MyGlyph[1] scaled scaling) shifted ( (pos[n],0) + shiftB)) withpostscript "collect"; % if MyGlyphn > 1 : for ind=2 upto MyGlyphn : if (((xpart llcorner MyGlyph[ind]) > (xpart llcorner MyGlyph[1])) and ((ypart llcorner MyGlyph[ind]) > (ypart llcorner MyGlyph[1])) and ((xpart urcorner MyGlyph[ind]) < (xpart urcorner MyGlyph[1])) and ((ypart urcorner MyGlyph[ind]) < (ypart urcorner MyGlyph[1]))) : % addto monImageA contour (MyGlyph[ind] scaled scaling) shifted ( (pos[n],0) + shiftB) withcolor transparent (1,1.,colorframe); else : addto monImageB contour (MyGlyph[ind] scaled scaling) shifted ( (pos[n],0) + shiftB) withpostscript "collect"; fi; endfor; fi; \stopMPdrawing}}  %==============================================================================%============================================================================== \starttext %------------------------------------------------------------------------------ \startuseMPgraphic{MyBackgroundGraphic} path pathbackground ; numeric dimA ; dimA := \the\paperwidth; numeric dimB ; dimB := \the\paperheight; pathbackground := unitsquare xscaled dimA yscaled dimB ; fill pathbackground withshademethod "linear" withshadedirection(0,1) withshadecolors (red,blue);\stopuseMPgraphic %------------------------------------------------------------------------------ \definelayer[MyBackgroundLayer]\setlayer[MyBackgroundLayer]{\useMPgraphic{MyBackgroundGraphic}}\setupbackgrounds[page][background={MyBackgroundLayer}] %------------------------------------------------------------------------------ \EmptyLetters{MetaPost~is~fun!}\EmptyLetters{ABCDEFGHIJ}\EmptyLetters{KLMNOPQRST}\EmptyLetters{UVWXYZ!?\&*}\EmptyLetters{abcdefghij}\EmptyLetters{klmnopqrst}\EmptyLetters{uvwxyz<>;:@}\EmptyLetters{0123456789} %------------------------------------------------------------------------------ \stoptextstopMPpage
</context>

Navigation menu