ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Calling \followtokens from with in metapost
@ 2013-10-13  7:59 Magnus J
  2013-10-13 21:46 ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Magnus J @ 2013-10-13  7:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 573 bytes --]

Hello list,

How can I call the \followtokens macro (or a similar solution) from within
metapost?  Specifically, I want to integrate text between the semi-circle
arcs in a rainbow-like structure (with the text placed inbetween the arcs,
that should alsó be drawn). The text should not be stretched but center on
the top, flowing evenly distributed on each side. This link will give you
an idea:

http://www.heilsuefling.is/heilsuefling/upload/images/whp_in_general/determinants_of_health/determinants_of_health.jpg

How can this achieved?

Regards,

Magnus

[-- Attachment #1.2: Type: text/html, Size: 783 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling \followtokens from with in metapost
  2013-10-13  7:59 Calling \followtokens from with in metapost Magnus J
@ 2013-10-13 21:46 ` Hans Hagen
  2013-10-13 22:11   ` Marco Patzer
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2013-10-13 21:46 UTC (permalink / raw)
  To: ntg-context

On 10/13/2013 9:59 AM, Magnus J wrote:
> Hello list,
>
> How can I call the \followtokens macro (or a similar solution) from
> within metapost?  Specifically, I want to integrate text between the
> semi-circle arcs in a rainbow-like structure (with the text placed
> inbetween the arcs, that should alsó be drawn). The text should not be
> stretched but center on the top, flowing evenly distributed on each
> side. This link will give you an idea:
>
> http://www.heilsuefling.is/heilsuefling/upload/images/whp_in_general/determinants_of_health/determinants_of_health.jpg
>
> How can this achieved?

a bit clumsy but workable

\starttext

\useMPlibrary[txt]

\startsetups text-a
     \startuseMPgraphic{followtokens}
         path RotPath ; RotPath := reverse halfcircle xyscaled 5cm ;
         draw RotPath ;
     \stopuseMPgraphic
     \followtokens{some text but not that long{\hskip1em}}
\stopsetups

\startsetups text-b
     \startuseMPgraphic{followtokens}
         path RotPath ; RotPath := reverse halfcircle xyscaled 3cm  ;
         draw RotPath ;
     \stopuseMPgraphic
     \followtokens{{\hskip1em}some text{\hskip1em}}
\stopsetups

\startMPpage
     draw textext("\setups{text-a}") ;
     draw textext("\setups{text-b}") shifted (0,-.5cm);
\stopMPpage

\stoptext



-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling \followtokens from with in metapost
  2013-10-13 21:46 ` Hans Hagen
@ 2013-10-13 22:11   ` Marco Patzer
  2013-10-14 22:27     ` Marco Patzer
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Patzer @ 2013-10-13 22:11 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 1433 bytes --]

On 2013–10–13 Hans Hagen wrote:

> >inbetween the arcs, that should alsó be drawn). The text should not be
> >stretched but center on the top, flowing evenly distributed on each
> >side. This link will give you an idea:
> >
> >http://www.heilsuefling.is/heilsuefling/upload/images/whp_in_general/determinants_of_health/determinants_of_health.jpg
> >
> >How can this achieved?
> 
> a bit clumsy but workable
> 
> \starttext
> 
> \useMPlibrary[txt]
> 
> \startsetups text-a
>     \startuseMPgraphic{followtokens}
>         path RotPath ; RotPath := reverse halfcircle xyscaled 5cm ;
>         draw RotPath ;
>     \stopuseMPgraphic
>     \followtokens{some text but not that long{\hskip1em}}
> \stopsetups
> 
> \startsetups text-b
>     \startuseMPgraphic{followtokens}
>         path RotPath ; RotPath := reverse halfcircle xyscaled 3cm  ;
>         draw RotPath ;
>     \stopuseMPgraphic
>     \followtokens{{\hskip1em}some text{\hskip1em}}
> \stopsetups
> 
> \startMPpage
>     draw textext("\setups{text-a}") ;
>     draw textext("\setups{text-b}") shifted (0,-.5cm);
> \stopMPpage
> 
> \stoptext

This stretches the text. One has to use \hskip to squeeze the text
back to its normal inter character space, but I assume that's what
you meant by clumsy. I assume the OP wanted a solution which keeps
the natural spacing (whatever that means when text is aligned to a
path).

Marco

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling \followtokens from with in metapost
  2013-10-13 22:11   ` Marco Patzer
@ 2013-10-14 22:27     ` Marco Patzer
  2013-10-15  8:20       ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Patzer @ 2013-10-14 22:27 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 3292 bytes --]

On 2013–10–14 Marco Patzer wrote:

> On 2013–10–13 Hans Hagen wrote:
> 
> > >inbetween the arcs, that should alsó be drawn). The text should not be
> > >stretched but center on the top, flowing evenly distributed on each
> > >side. This link will give you an idea:
> > >
> > >http://www.heilsuefling.is/heilsuefling/upload/images/whp_in_general/determinants_of_health/determinants_of_health.jpg
> > >
> > >How can this achieved?

Here is a slightly modified version of the \followtokens macro with
centres the text without stretching it to the path size.

\useMPlibrary [txt]

\unexpanded\def\followtokenscentred#1%%
  {\vbox\bgroup
   \forgetall
   \dontcomplain
   \startMPenvironment
     \doifundefined{RotFont}{\definefont[RotFont][RegularBold]}
   \stopMPenvironment
   \MPtoks\emptytoks
   \resetMPdrawing
   \startMPdrawing
     \includeMPgraphic{followtokenscentred} ;
     picture pic[] ; numeric len[], n ; n := 0 ;
   \stopMPdrawing
   \handletokens#1\with\processfollowingtoken
   \startMPdrawing
     if unknown RotPath  : path    RotPath  ; RotPath  := origin ; fi ;
     if unknown RotColor : color   RotColor ; RotColor := black  ; fi ;
     if unknown TraceRot : boolean TraceRot ; TraceRot := false  ; fi ;
     if unknown ExtraRot : numeric ExtraRot ; ExtraRot := 0      ; fi ;
     numeric al, at, pl, wid, pos ; pair ap, ad ;
     al := arclength RotPath ;
     if al=0 :
       al := len[n] + ExtraRot ;
       RotPath := origin -- (al,0) ;
     fi ;
     if al<len[n]:
       RotPath := RotPath scaled ((len[n]+ExtraRot)/al) ;
       al := arclength RotPath ;
     fi ;
     pl := (al-len[n])/(if n>1 : (n-1) else : 1 fi) ;
     pl := 0cm;
     if TraceRot :
       draw RotPath withpen pencircle scaled 1pt withcolor blue ;
     fi ;
     for i=1 upto n :
       wid := abs(xpart urcorner pic[i] - xpart llcorner pic[i]) ;
       pos := len[i]-wid/2 + (i-1)*pl + arclength RotPath/2 - len[n]/2 ;
       at := arctime   pos of RotPath ;
       ap := point     at  of RotPath ;
       ad := direction at  of RotPath ;
       draw pic[i] shifted (-wid/2,0) rotated(angle(ad)) shifted ap
         withcolor RotColor ;
       if TraceRot :
         draw boundingbox
            pic[i] shifted (-wid/2,0) rotated(angle(ad)) shifted ap
            withpen pencircle scaled .25pt withcolor red ;
         draw ap
            withpen pencircle scaled .50pt withcolor green ;
       fi ;
     endfor ;
   \stopMPdrawing
   \MPdrawingdonetrue
   \getMPdrawing
   \resetMPdrawing
   \egroup}

\def\followtokengraphicscale#1{%%
  \startuseMPgraphic {followtokenscentred}
    path RotPath; RotPath :=  reverse halfcircle scaled #1 ;
    setbounds currentpicture to boundingbox fullcircle scaled 12cm ;
  \stopuseMPgraphic}

\starttext

\startoverlay
  {\followtokengraphicscale{10cm}%%
   \followtokenscentred{General socioeconomic cultural and environmental conditions}}
  {\followtokengraphicscale{8cm}%%
   \followtokenscentred{Living and working conditions}}
  {\followtokengraphicscale{6cm}%%
   \followtokenscentred{Social and community influences}}
  {\followtokengraphicscale{4cm}%%
   \followtokenscentred{Individual lifestyle factors}}
\stopoverlay

\stoptext

Marco

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling \followtokens from with in metapost
  2013-10-14 22:27     ` Marco Patzer
@ 2013-10-15  8:20       ` Hans Hagen
  0 siblings, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2013-10-15  8:20 UTC (permalink / raw)
  To: ntg-context

On 10/15/2013 12:27 AM, Marco Patzer wrote:
> On 2013–10–14 Marco Patzer wrote:
>
>> On 2013–10–13 Hans Hagen wrote:
>>
>>>> inbetween the arcs, that should alsó be drawn). The text should not be
>>>> stretched but center on the top, flowing evenly distributed on each
>>>> side. This link will give you an idea:
>>>>
>>>> http://www.heilsuefling.is/heilsuefling/upload/images/whp_in_general/determinants_of_health/determinants_of_health.jpg
>>>>
>>>> How can this achieved?
>
> Here is a slightly modified version of the \followtokens macro with
> centres the text without stretching it to the path size.

I figured out the differnces (next time put a % MP after the lines) and 
made it a variant in the txt file. You can check it in the beta.

I'm probably rewrite that code in a more mkiv way ... when I'm bored on 
a raining day or so.

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Calling \followtokens from with in metapost
@ 2013-10-14 19:29 Magnus J
  0 siblings, 0 replies; 6+ messages in thread
From: Magnus J @ 2013-10-14 19:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2446 bytes --]

Thanks for the code, the stretching is ok (can be hand-tuned) but I find
the positioning a bit odd. Look at the additions to your example:

------------------
\starttext

\useMPlibrary[txt]

\startsetups text-a
     \startuseMPgraphic{followtokens}
         path RotPath ; RotPath := reverse halfcircle xyscaled 5cm ;
         draw RotPath ;
     \stopuseMPgraphic
     \followtokens{some text but not that long{\hskip1em}}
\stopsetups

\startsetups text-b
     \startuseMPgraphic{followtokens}
         path RotPath ; RotPath := reverse halfcircle xyscaled 3cm  ;
         draw RotPath ;
     \stopuseMPgraphic
     \followtokens{{\hskip1em}some text{\hskip1em}}
\stopsetups

\startMPpage
     draw textext("\setups{text-a}") ;
     draw textext("\setups{text-b}") shifted (0,-.5cm);

     % equal to RotPath in text-b
     path RotPath ; RotPath := reverse halfcircle xyscaled 3cm  ;
     draw RotPath shifted (0,-.5cm) withcolor red ;

     % vertically aligned (by trial and error), but not horizontally)
     draw RotPath shifted (0,-1.5cm) withcolor blue ;
\stopMPpage
------------------

I guess the red arc needs to be shifted further down since is has no text,
but what about the horizontal alignment (as shown in blue)? If you look
closely, the two spacing is different even between the black arcs on left
and right sides.

Regards,

Magnus

On 2013-10-13 Hans Hagen wrote:

> >inbetween the arcs, that should als? be drawn). The text should not be
> >stretched but center on the top, flowing evenly distributed on each
> >side. This link will give you an idea:
> >
> >
http://www.heilsuefling.is/heilsuefling/upload/images/whp_in_general/determinants_of_health/determinants_of_health.jpg
> >
> >How can this achieved?
>
> a bit clumsy but workable
>
> \starttext
>
> \useMPlibrary[txt]
>
> \startsetups text-a
>     \startuseMPgraphic{
followtokens}
>         path RotPath ; RotPath := reverse halfcircle xyscaled 5cm ;
>         draw RotPath ;
>     \stopuseMPgraphic
>     \followtokens{some text but not that long{\hskip1em}}
> \stopsetups
>
> \startsetups text-b
>     \startuseMPgraphic{followtokens}
>         path RotPath ; RotPath := reverse halfcircle xyscaled 3cm  ;
>         draw RotPath ;
>     \stopuseMPgraphic
>     \followtokens{{\hskip1em}some text{\hskip1em}}
> \stopsetups
>
> \startMPpage
>     draw textext("\setups{text-a}") ;
>     draw textext("\setups{text-b}") shifted (0,-.5cm);
> \stopMPpage
>
> \stoptext

[-- Attachment #1.2: Type: text/html, Size: 3206 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-10-15  8:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-13  7:59 Calling \followtokens from with in metapost Magnus J
2013-10-13 21:46 ` Hans Hagen
2013-10-13 22:11   ` Marco Patzer
2013-10-14 22:27     ` Marco Patzer
2013-10-15  8:20       ` Hans Hagen
2013-10-14 19:29 Magnus J

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).