Talk:Cover Pages

From Wiki
Revision as of 22:49, 23 December 2020 by Garulfo (talk | contribs)
Jump to navigation Jump to search

A test

%------------------------------------------------------------------------------

\setuppapersize  [A5]

%------------------------------------------------------------------------------

\def\MyFont{\definedfont[name:%
texgyrepagellabold%
%exo2black%
%agaramondprobold%
*default at 25pt]}

%------------------------------------------------------------------------------

\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