Difference between revisions of "Talk:Cover Pages"
Jump to navigation
Jump to search
(Created page with "A test <context source="yes"> %------------------------------------------------------------------------------ \setuppapersize [A4] %-------------------------------------...") |
|||
Line 2: | Line 2: | ||
<context source="yes"> | <context source="yes"> | ||
− | |||
%------------------------------------------------------------------------------ | %------------------------------------------------------------------------------ | ||
Line 55: | Line 54: | ||
%------------------------------------------------------------------------------ | %------------------------------------------------------------------------------ | ||
− | \def\ | + | \def\EmptyLetters#1% |
{% | {% | ||
\resetMPdrawing | \resetMPdrawing | ||
Line 61: | Line 60: | ||
% | % | ||
\startMPdrawing | \startMPdrawing | ||
− | + | picture pic[], pictA ; | |
− | |||
− | |||
− | picture pic[] ; | ||
numeric wid[], len[], pos[], n ; | numeric wid[], len[], pos[], n ; | ||
wid[0] := len[0] := pos[0] := n := 0 ; | wid[0] := len[0] := pos[0] := n := 0 ; | ||
− | |||
numeric scaling; | numeric scaling; | ||
− | + | path pictB , frame ; | |
− | |||
− | path pictB ; | ||
− | |||
pair shiftB ; | pair shiftB ; | ||
− | |||
picture monImageA; monImageA := nullpicture; | picture monImageA; monImageA := nullpicture; | ||
picture monImageB; monImageB := nullpicture; | picture monImageB; monImageB := nullpicture; | ||
− | + | color colorframe; colorframe := 0.6white; | |
− | |||
− | |||
− | |||
− | color colorframe; | ||
− | |||
% | % | ||
\stopMPdrawing | \stopMPdrawing | ||
% | % | ||
− | \MyFont | + | \MyFont\handletokens#1\with\whatever |
− | \handletokens#1\with\whatever | ||
% | % | ||
\startMPdrawing | \startMPdrawing | ||
Line 101: | Line 86: | ||
draw monImageA ; | draw monImageA ; | ||
\stopMPdrawing | \stopMPdrawing | ||
− | % | + | % |
\MPdrawingdonetrue | \MPdrawingdonetrue | ||
\getMPdrawing} | \getMPdrawing} | ||
Line 116: | Line 101: | ||
% | % | ||
\mpdefineoutlines{M}{MaLettre} | \mpdefineoutlines{M}{MaLettre} | ||
+ | % | ||
\startMPdrawing | \startMPdrawing | ||
pictA := textext.drt("\MyFont M") ; | pictA := textext.drt("\MyFont M") ; | ||
Line 124: | Line 110: | ||
\doifinstringelse{~}{#1}{}{% HOW TO PROPERLY COPE WITH SPACES ? | \doifinstringelse{~}{#1}{}{% HOW TO PROPERLY COPE WITH SPACES ? | ||
\mpdefineoutlines{#1}{MyGlyph} | \mpdefineoutlines{#1}{MyGlyph} | ||
+ | % | ||
\startMPdrawing | \startMPdrawing | ||
string sb; sb := "i"; | string sb; sb := "i"; | ||
Line 163: | Line 150: | ||
%============================================================================== | %============================================================================== | ||
%============================================================================== | %============================================================================== | ||
− | |||
\starttext | \starttext | ||
Line 188: | Line 174: | ||
%------------------------------------------------------------------------------ | %------------------------------------------------------------------------------ | ||
− | \ | + | \EmptyLetters{MetaPost~is~fun!} |
− | \ | + | \EmptyLetters{ABCDEFGHIJ} |
− | \ | + | \EmptyLetters{KLMNOPQRST} |
− | \ | + | \EmptyLetters{UVWXYZ!?\&*} |
− | \ | + | \EmptyLetters{abcdefghij} |
− | \ | + | \EmptyLetters{klmnopqrst} |
− | \ | + | \EmptyLetters{uvwxyz<>;:@} |
− | \ | + | \EmptyLetters{0123456789} |
+ | |||
+ | %------------------------------------------------------------------------------ | ||
\stoptext | \stoptext | ||
− | |||
− | |||
− | |||
− | |||
− | |||
</context> | </context> |
Revision as of 22:49, 23 December 2020
A test
%------------------------------------------------------------------------------ \setuppapersize [A4] %------------------------------------------------------------------------------ \def\MyFont{\definedfont[name:% texgyrepagellabold% %exo2black% %agaramondprobold% *default at 55pt]} %------------------------------------------------------------------------------ \startluacode 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 = shapedata.glyphs or { } local glyph = shapeglyphs[c.index] if glyph and (glyph.segments or glyph.sequence) then local units = shapedata.units or 1000 local factor = 100/units return fonts.metapost.paths(glyph,factor) end end return { } end 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 garulfo end \stopluacode %------------------------------------------------------------------------------ \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}} %------------------------------------------------------------------------------ \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 contour frame withpostscript "evenodd" withcolor transparent (1,1.,colorframe); draw monImageB ; draw monImageA ; \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} %------------------------------------------------------------------------------ \stoptext