[NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible

Garulfo garulfo at azules.eu
Mon Dec 21 16:09:35 CET 2020


* I try to "remove the paths of text" from a metapost pictures to let
   the background visible.

* Using

* I was able to get the following with one glyph (MVE code below)


2 questions:

1/ for some fonts (e.g. dejavu vs latin modern) the "encompassing" path
    of the B glyph can switch from B[1] to B[Bn]. Is there a trick to
    identify which id match with "the encompassing" path ?

2/ now, I would like to do the same, but for text... a kind of
    derivative of "textext" or "outlinetext".
    Would you please give me some guidelines ?
	does it already exist ?
	should I use something like \handletokens, \scantokens ?
	do you have examples where I can get inspiration ?

Thanks again for your help,





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)
     return { }

function document.defineoutline(char,target)
     local outlines = document.outlinepaths(char)
     local nofpaths = #outlines
     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])






numeric dimA ; dimA := 20cm;

path pathbackground ;
pathbackground :=  unitsquare scaled dimA ;
fill pathbackground withshademethod "linear" withshadedirection(0,1) 
withshadecolors (red,blue);




numeric dimB  ; dimB := 2cm;
numeric vratio ; vratio := 2;

path frame ;
frame :=  unitsquare
           xscaled (dimA - 2 * dimB)
           yscaled (dimA / vratio)
           shifted (dimB , (dimA - (dimA / vratio))/2 );


pair shift ; shift := center frame;
numeric scal ; scal := (0.9) * (10cm / (bbheight B[1])) ;

picture monImageB; monImageB := nullpicture;
addto monImageB contour
       (B[1] shifted (- center B[1]) scaled scal)
       shifted shift
       withpostscript "collect";

addto monImageB contour
       withpostscript "evenodd";

for i=2 upto Bn :
   addto monImageB contour
         (B[i] shifted (- center B[1]) scaled scal)
         shifted shift;
endfor ;


draw monImageB withcolor white;



More information about the ntg-context mailing list