ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: ntg-context@ntg.nl, Rudolf Bahr <quasi@quasi.de>
Subject: Re: How to calculate the height of text of a certain width?
Date: Tue, 24 Mar 2020 19:29:26 +0100	[thread overview]
Message-ID: <b83e91d0-5615-8111-eac9-cef807fb9c09@gmail.com> (raw)
In-Reply-To: <20200324180452.GA7686@nan>

Rudolf Bahr schrieb am 24.03.2020 um 19:04:
> On Tue, Mar 24, 2020 at 04:43:17PM +0100, Wolfgang Schuster wrote:
>>> \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.
>>
>> I have no idea where you get 0 (0pt?).
> 
> Nor do I, in the meantime. Sorry for my noise, I don't know what sort of
> mistakes I did to get "0.0pt".
> Corona? :-)
> 
> This is my test, which is essentially the same what Aditya suggests:
> -----------------------------------------
> \starttext
> 
> \setbox0=\vbox{\hsize=300pt\input ward }
> \copy0
> 
> wd0=\the\wd0, ht0=\the\ht0
> 
> \vskip12pt
> 
> \startalign[flushleft]
> \setbox1=\vbox{\hsize=300pt\input ward }
> \stopalign
> \copy1
> 
> wd1=\the\wd1, ht1=\the\ht1
> 
> \stoptext
> -----------------------------------------
> The .pdf-file is appended

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

> Now to your proposal, Wolfgang:
>>
>> \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
> 
> Up to now I cannot say anything about it, because there are some
> commands which are new to me. I have to study them first.

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

___________________________________________________________________________________
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
___________________________________________________________________________________

  reply	other threads:[~2020-03-24 18:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24 11:19 Rudolf Bahr
2020-03-24 14:56 ` Wolfgang Schuster
2020-03-24 15:29   ` Rudolf Bahr
2020-03-24 15:36     ` Aditya Mahajan
2020-03-24 18:41       ` Rudolf Bahr
2020-03-24 15:43     ` Wolfgang Schuster
2020-03-24 18:04       ` Rudolf Bahr
2020-03-24 18:29         ` Wolfgang Schuster [this message]
2020-03-25 10:30           ` Rudolf Bahr
2020-03-25 11:00           ` Rudolf Bahr

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=b83e91d0-5615-8111-eac9-cef807fb9c09@gmail.com \
    --to=wolfgang.schuster.lists@gmail.com \
    --cc=ntg-context@ntg.nl \
    --cc=quasi@quasi.de \
    /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).