[NTG-context] How to calculate the height of text of a certain width?

Aditya Mahajan adityam at umich.edu
Tue Mar 24 16:36:30 CET 2020


On Tue, 24 Mar 2020, Rudolf Bahr wrote:

> On Tue, Mar 24, 2020 at 03:56:18PM +0100, Wolfgang Schuster wrote:
>> Rudolf Bahr schrieb am 24.03.2020 um 12:19:
>> > Hello dear All,
>> > 
>> > the following MWE works best:
>> > 
>> > 
>> > \definelayer[LAY]
>> > \starttext
>> > 
>> > \setlayerframed[LAY]
>> >    [x=0pt,y=20pt]
>> >    [frame=on,
>> >     width=300pt,
>> >     align={right,}]   % tolerant}]
>> >    {\input ward }
>> > \flushlayer[LAY]
>> > \stoptext
>> > 
>> > 
>> > Now, it could have a favourable effect on designing a page if the height of a text
>> > of certain width could be calculated in advance, depending of the font.
>> > Is there a way?
>> > 
>> > As I fear, TeX's means "\setbox" woun't work with aligned texts.
>> 
>> Can you give more details, I have no idea what you mean with aligned texts
>> (layers?).
>> 
>> Wolfgang
>
>
> Hi Wolfgang,
>
> With "aligned texts" I thought of "align={right,}]" in the above example or
> text which is "flushed right":
>
> \setbox0=\vbox{... somehow flushed text ...} wount work, i.e \wd0 or \ht0
> will both result in 0. With "unflushed" text this means will work perfectly.

You can do:


\definelayer[LAY]

\starttext

\setbox\scratchbox=\vbox{\framed[width=300pt, align=flushleft]{\input 
ward\relax}}
The height of the box is \the\ht\scratchbox; the width is 
\the\wd\scratchbox.
\unvbox\scratchbox

\setlayerframed[LAY][x=0pt, y=20pt][width=300pt, align=flushleft]{\input 
ward\relax}
\flushlayer[LAY]

\stoptext

Aditya


More information about the ntg-context mailing list