ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
Subject: Re: cropping with \limitatefirstline
Date: Thu, 08 Sep 2005 17:28:45 +0200	[thread overview]
Message-ID: <432058AD.1040900@wxs.nl> (raw)
In-Reply-To: <4320499B.5050002@gmx.net>

Peter Rolf wrote:

>Hi,
>
>Hans Hagen wrote:
>  
>
>>Peter Rolf wrote:
>>
>>    
>>
>>>Sorry to bother you Hans, but the macro is not working as expected...
>>>
>>>I can see the cropped text (\underbar + special symbols) and there is an
>>>hyphen symbol in the text only example.
>>>
>>>I've added the example code I used for tests with \limitatetext and
>>>\doboundtext.
>>> 
>>>
>>>      
>>>
>>\def\limitatefirstline#1#2#3%
>> {\hbox\bgroup\strut
>>  \setbox\scratchbox\hbox{#1}%
>>  \ifdim\wd\scratchbox>#2\relax
>>    \setbox\scratchbox\hbox{#3}%
>>    \hsize#2\relax
>>    \advance\hsize-\wd\scratchbox
>>    \setbox\scratchbox\vbox{\forgetall\veryraggedright#1}%
>>    \setbox\scratchbox\vsplit\scratchbox to \lineheight
>>    \vbox
>>      {\unvbox\scratchbox
>>       \global\setbox\plusone\lastbox
>>       \global\setbox\plusone\hbox{\unhbox\plusone}}%
>>    
>>
>^^^^
>
>  
>
>>    \box\plusone\removeunwantedspaces#3%
>>  \else
>>    #1%
>>  \fi
>>  \egroup}
>>
>>of course there must be something to break (not possible with the non
>>letters, so there you either need to add \hskip0pt's or do real clipping
>>Hans
>>    
>>
>
>So it fails in any case of nonbreakable text.
>
>How about adding a failsafe test ala
>
>\ifdim\dimexpr\wd\plusone+\wd of sentinel\relax>#2\relax
>  \clip[width=\wd\plusone,...]{...#1...}\removeunwantedspaced#3%
>\else
>  \box\plusone\removeunwantedspaces#3%
>\fi
>
>One (ugly looking) partial character is still better than a bunch of
>characters, that cross the width border.
>
>I have played around with \clip, but it acts a little wild (vertical
>position and height). Can't subdue it myself...
>  
>
\unprotect

\def\limitatefirstline#1#2#3%
  {\hbox\bgroup\strut
   \setbox\scratchbox\hbox{#1}%
   \ifdim\wd\scratchbox>#2\relax
     \setbox\scratchbox\hbox{#3}%
     \hsize#2\relax
     \advance\hsize-\wd\scratchbox
     \setbox\scratchbox\vbox{\forgetall\veryraggedright#1}%
     \setbox\scratchbox\vsplit\scratchbox to \lineheight
     \vbox
       {\unvbox\scratchbox
        \global\setbox\plusone\lastbox
        \global\setbox\plusone\hbox{\unhbox\plusone}%
        \ifx\clip\undefined
          \box\plusone\removeunwantedspaces#3%
        \else\ifdim\wd\plusone>\hsize
          \hbox{\clip[\c!width=\hsize]{\box\plusone}#3}%
        \else
          \box\plusone\removeunwantedspaces#3%
        \fi\fi}%
   \else
     #1%
   \fi
   \egroup}

\protect

\ruledhbox{\limitatefirstline{xxxxxxxxxxxxxxxxxxxx}{3cm}{...}}


now you owe this list at least three wiki pages -) 

Hans 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

  reply	other threads:[~2005-09-08 15:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-07 14:33 Peter Rolf
2005-09-07 15:55 ` Hans Hagen
2005-09-07 16:18   ` Peter Rolf
2005-09-08 14:24   ` Peter Rolf
2005-09-08 15:28     ` Hans Hagen [this message]
2005-09-08 15:56       ` Peter Rolf
2005-09-08 17:22         ` Patrick Gundlach
2005-09-08 16:34       ` Peter Rolf
2005-09-08 17:21         ` Hans Hagen
2005-09-08 17:32           ` Peter Rolf
2005-09-08 18:55         ` Hans Hagen

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=432058AD.1040900@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /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).