[NTG-context] Putting things over a figure

nico nicolas.marsgui at libertysurf.fr
Sun Apr 23 20:23:46 CEST 2006


Hello,

I need a mechanism with which I can put several things (text, image) at a  
precise position over a figure. The position is expressed in percentage  
(x,y) of the figure dimensions. The lower-left corner is (0,0).

I did the following that works for my own needs, but maybe a higher level  
interface (layer?) could do the same. Any comment or improvement is  
welcome.


\newdimen\overfigwd
\newdimen\overfight

% Put the figure and define the x/y percentage factor for the calspairs.
\def\startoverfig
   {\dodoubleempty\dostartoverfig}

\def\dostartoverfig[#1][#2]%
   {\bgroup
    \setbox\scratchbox\hbox{\externalfigure[#1][#2]}%
    \overfigwd=\wd\scratchbox
    \overfight=\ht\scratchbox
    \setuppositioning[unit=pt,
                      xfactor=\withoutpt\the\dimexpr(\overfigwd/100),
                      yfactor=\withoutpt\the\dimexpr(\overfight/100)]%
    \startpositioning
      \position(0,0){\box\scratchbox}}

\def\stopoverfig
   {\stoppositioning\egroup}

% Put (centered) at the position (x%,y%) on the figure.
% The lower-left corner is (0,0)
\def\calspair(#1,#2)#3%
   {\setbox0\hbox{#3}%
    \position[xoffset=\dimexpr(-\wd0/2),
              yoffset=\dimexpr(-\ht0/2)](#1,{\numexpr(100-#2)}){#3}}

%%

\setupcolors[state=start]

\starttext

\startoverfig[duck-small]
   \calspair(0,0){A}
   \calspair(100,100){B}
\stopoverfig

\startoverfig[duck-small][width=4cm,frame=on]
   \calspair(0,0){A}
   \calspair(100,100){B}
   \calspair(50,50){\framed[background=color,backgroundcolor=green]{Hello}}
\stopoverfig

\startoverfig[unknown]
   \calspair(30,0){A}
   \calspair(100,100){B}
\stopoverfig

\stoptext

Regards,
BG


More information about the ntg-context mailing list