From: Taco Hoekwater <taco@elvenkind.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: MetaFun - "remove the paths of text" from a rectangle to let the background visible
Date: Mon, 21 Dec 2020 16:29:28 +0100 [thread overview]
Message-ID: <C5FB94A0-DB0E-40C1-8A34-FE20F13BC00D@elvenkind.com> (raw)
In-Reply-To: <50497bef-784f-816e-6471-9524ccdd17d9@azules.eu>
> On 21 Dec 2020, at 16:09, Garulfo <garulfo@azules.eu> wrote:
>
> Hi,
>
>
> * I try to "remove the paths of text" from a metapost pictures to let
> the background visible.
>
> * Using
> https://mailman.ntg.nl/pipermail/ntg-context/2018/thread.html#92725
>
> * I was able to get the following with one glyph (MVE code below)
>
> https://wiki.contextgarden.net/images/d/d2/test_extract_glyphs.pdf
>
>
> 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 ?
What you get is the order of the paths as defined in the font, which is arbitrary, as you discovered.
A quick trick (that will not always work, but should work quite well for font variations of alphabetics) is to check the actual arclength of the paths. The longest one will typically be the outer one.
But much depends on the font, so a generic solution is likely quite complicated. Consider an outline font’s colon glyph ;)
>
> 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,
> Garulfo
>
>
> %==============================================================================
>
>
>
>
> \starttext
>
> %------------------------------------------------------------------------------
>
> \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("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
> end
>
> \stopluacode
>
> %------------------------------------------------------------------------------
>
> \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}}
>
> %------------------------------------------------------------------------------
>
> \startMPpage
>
> numeric dimA ; dimA := 20cm;
>
> path pathbackground ;
> pathbackground := unitsquare scaled dimA ;
> fill pathbackground withshademethod "linear" withshadedirection(0,1) withshadecolors (red,blue);
>
> %--------------------------------------
>
> \mpdefineoutlines{B}{B}
>
> %--------------------------------------
>
> 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
> frame
> 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;
>
> \stopMPpage
>
> \stoptext
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
Taco Hoekwater
Elvenkind BV
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2020-12-21 15:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-21 15:09 Garulfo
2020-12-21 15:29 ` Taco Hoekwater [this message]
2020-12-23 23:14 ` Garulfo
2020-12-23 23:46 ` Otared Kavian
2020-12-24 0:42 ` Hans Hagen
2020-12-23 23:58 ` Hans Hagen
2020-12-24 9:02 ` Taco Hoekwater
2020-12-24 17:04 ` Garulfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C5FB94A0-DB0E-40C1-8A34-FE20F13BC00D@elvenkind.com \
--to=taco@elvenkind.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).