[NTG-context] How to calculate the height of text of a certain width?
Rudolf Bahr
quasi at quasi.de
Wed Mar 25 11:30:41 CET 2020
On Tue, Mar 24, 2020 at 07:29:26PM +0100, Wolfgang Schuster wrote:
>
> When you need the height for the layer offset you can use \dowithnextbox
> because it hides \setbox etc.
>
> \definelayer[TextBox]
>
> \showframe[text][text]
>
> \starttext
>
> \dowithnextbox
> {\setlayer
> [TextBox]
> [x=\the\dimexpr(\textwidth -\nextboxwd)/3\relax,
> y=\the\dimexpr(\textheight-\nextboxht)/3\relax]
> {\flushnextbox}}
> \hbox{\framed[width=300pt,align=normal]{\samplefile{ward}}}
>
> \flushlayer[TextBox]
>
> \stoptext
Thank you! I played with the example a bit, all works well with one exception:
When I replace "align=normal" by "align=left" the frame gets too wide at it's
left edge. I append this pdf-file. But "align=right" works well and that's what
I'm using most. Your Example is well suited to be used in page design!
> > >
> > > \starttexdefinition NextboxDimension
> > > \starttabulate
> > > \NC Width \EQ \the\nextboxwd \NC\NR
> > > \NC Height \NC \the\nextboxht \NC\NR
> > > \stoptabulate
> > > \stoptexdefinition
> > >
> > > \starttext
> > >
> > > \dowithnextboxcs
> > > \NextboxDimension
> > > \vbox
> > > {\samplefile{ward}}
> > >
> > > \dowithnextboxcs
> > > \NextboxDimension
> > > \vbox
> > > {\setupalign[flushright]
> > > \samplefile{ward}}
> > >
> > > \dowithnextboxcs
> > > \NextboxDimension
> > > \vbox
> > > {\hsize=200pt
> > > \samplefile{ward}}
> > >
> > > \dowithnextboxcs
> > > \NextboxDimension
> > > \vbox
> > > {\hsize=200pt
> > > \setupalign[flushright]
> > > \samplefile{ward}}
> > >
> > > \stoptext
> >
> The \dowithnextbox command stores the passed argument in the named box
> \nextbox and performs the content of the first argument (or the command when
> you use \dowithnextbox*cs*).
>
> The get the width and height of the box you can use \wd\nextbox or the
> wrapper \nextboxwd. The content of the box can be flushed with \flushnextbox
> but when you need only a copy of it you have to use \copy\nextbox.
>
> Wolfgang
>
Thank you very much for the example and the explanation therefore! It should
be well suitable to evaluate width and height of boxes and to pass them to
luacode programs by 'tokens.getters.macro("...")' for instance.
Thank you again!
Rudolf
More information about the ntg-context
mailing list