Difference between revisions of "Talk:Cover Pages"

From Wiki
Jump to navigation Jump to search
Line 2: Line 2:
  
 
<context source="yes">
 
<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 := boundingbox tt;
texgyrepagellabold%
 
%exo2black%
 
%agaramondprobold%
 
*default at 40pt]}
 
  
%------------------------------------------------------------------------------
+
%------------------------------------------------------------------------------      
  
\startluacode
+
  path pp ; pp := bb enlarged 1cm ;
 +
  fill pp
 +
      withshademethod "linear"
 +
      withshadedirection right
 +
      withshadecolors (red, blue);
 +
 
 +
%------------------------------------------------------------------------------       
  
function document.outlinepaths(character)
+
  picture Paddmissing; Paddmissing := nullpicture;
    local chardata  = fonts.hashes.characters[true] -- by unicode
+
  picture Pwoletters; Pwoletters := nullpicture;
    local shapedata = fonts.hashes.shapes[true] -- by index
+
  color colorframe; colorframe := 0.15white;
    local c        = chardata[character]
+
  numeric testwithin ;
    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
+
  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#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}}
+
      if testwithin == 1:
 +
        addto Paddmissing contour
 +
              (pathpart i)
 +
              withcolor colorframe;
 +
      else:
 +
        addto Pwoletters contour
 +
              (pathpart i)
 +
              withpostscript "collect";
 +
      fi; 
  
%------------------------------------------------------------------------------
+
    fi ;
 +
  endfor ;
  
\def\EmptyLetters#1%
+
%------------------------------------------------------------------------------       
{%
+
    
\resetMPdrawing
+
   addto Pwoletters contour  
\MPtoks={}
+
         bb
%
 
\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"  
 
         withpostscript "evenodd"  
         withcolor transparent (1,1.,colorframe);
+
         withcolor colorframe;
   draw monImageB ;
+
   draw Pwoletters ;
   draw monImageA ;
+
   draw Paddmissing ;
\stopMPdrawing
+
    
%
+
\stopMPpage
\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
 
 
</context>
 
</context>

Revision as of 16:48, 24 December 2020

A test

\startMPpage

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

  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 ;

  path bb ; bb := boundingbox tt;

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

  path pp ; pp := bb enlarged 1cm ;
  fill pp
       withshademethod "linear"
       withshadedirection right
       withshadecolors (red, blue);

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

  picture Paddmissing; Paddmissing := nullpicture;
  picture Pwoletters; Pwoletters := nullpicture;
  color colorframe;  colorframe := 0.15white;
  numeric testwithin ; 

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

  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;

      if testwithin == 1:
        addto Paddmissing contour 
              (pathpart i)
              withcolor colorframe;
      else:
        addto Pwoletters contour 
              (pathpart i) 
              withpostscript "collect";
      fi;  

    fi ;
  endfor ;

%------------------------------------------------------------------------------        
  
  addto Pwoletters contour 
        bb 
        withpostscript "evenodd" 
        withcolor colorframe;
  draw Pwoletters ;
  draw Paddmissing ;
  
\stopMPpage