[NTG-context] \limitatefirstline (or slave to the wiki)

Peter Rolf indiego at gmx.net
Sun Sep 11 14:39:40 CEST 2005


Peter Rolf wrote:
> Hi all,
> 
> I've tested the latest version of \limitatefirstline and it still
> doesn't work as expected. This is really a complex story (problem).
> 
> - the clip mechanism cuts off the lowest part of some special chars
>   (clipping graphics is easy, but I don't understand what happens here)
This one is unsolved. I added height to the clipping (\struttotal; maybe
not enought for \underbar). Now I get complete characters, but the
cropped text and the sentinel are not on the same baseline anymore.

> - text is sometimes cropped at word boundaries (example 110pt),
>   instead of beeing clipped
I have fixed this one. There must be another check in case of a
successful break (else it acts like \limitatetext). Haven't thought
about this :)

So just ignore the prior mail (example) and look at the attached code
instead.

Greetings,

Peter
-------------- next part --------------
% interface=en output=pdftex
% Time-stamp: <Sonntag, 11 September 2005 14:19:53; crop.tex>
%

\setupcolors[state=start]
\setupstrut

\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}%
%%       \hbox to #2
%%         {\ifx\clip\undefined
%%            \box\plusone
%%          \else\ifdim\wd\plusone>\hsize
%%            \clip[\c!width=\hsize]{\box\plusone}%
%%          \else
%%            \box\plusone
%%          \fi\fi
%%          \removeunwantedspaces\hss#3}}%
%%  \else
%%    #1%
%%  \fi
%%  \egroup}


\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}%
      \hbox to #2
        {\ifx\clip\undefined
           \box\plusone
         \else
           \ifdim\wd\plusone>\hsize
             \clip[\c!width=\hsize,\c!height=\struttotal]{\ruledhbox{\box\plusone}}
           \else
             \ifdim\wd\plusone<\dimexpr\hsize-2ex\relax% tolerance for "successful" breaking
               \clip[\c!width=\hsize,\c!height=\struttotal]{\ruledhbox{#1}}% must be #1 here
             \else
               \box\plusone
             \fi
           \fi
         \fi
         \removeunwantedspaces\hss#3}}%
 \else
   #1%
 \fi
 \egroup}

\protect


\def\CropSymbol{\red...}%

\starttext

% blue for the limitatetext examples

\setupframed[offset=overlay, framecolor=lightgray]

\framed[width=8ex,height=\struttotal,background=color,backgroundcolor=black]{\white 8ex}
\framed{\limitatefirstline{\underbar{WqTextdummy}}{8ex}{\CropSymbol}}
\framed{\limitatetext{\blue\underbar{WqTextdummy}}{8ex}{\CropSymbol}}

\blank

\framed[width=120pt,height=\struttotal,background=color,backgroundcolor=black]{\white 120 pt}
\framed{\limitatefirstline{\textbar \_\textcircumflex\texttilde \%\$\#\textbraceleft \textbraceright \textpm \copyright \registered \pi \textdegree <>\&}{120pt}{\CropSymbol}}
\framed{\limitatetext{\blue\textbar \_\textcircumflex\texttilde \%\$\#\textbraceleft \textbraceright \textpm \copyright \registered \pi \textdegree <>\&}{120pt}{\CropSymbol}}

\blank

\framed[width=110pt,height=\struttotal,background=color,backgroundcolor=black]{\white 110 pt}
\framed{\limitatefirstline{\textbar \_\textcircumflex\texttilde \%\$\#\textbraceleft \textbraceright \textpm \copyright \registered \pi \textdegree <>\&}{110pt}{\CropSymbol}}
\framed{\limitatefirstline{This text is definitely too long to fit this frame.}{110pt}{\CropSymbol}}
\framed{\limitatetext{\blue This text is definitely too long to fit this frame.}{110pt}{\CropSymbol}}

\blank

\framed[width=100pt,height=\struttotal,background=color,backgroundcolor=black]{\white 100 pt}
\framed{\limitatefirstline{\textbar \_\textcircumflex\texttilde \%\$\#\textbraceleft \textbraceright \textpm \copyright \registered\space \pi \textdegree <>\&}{100pt}{\CropSymbol}}

\stoptext

%%% Local Variables:
%%% mode: context
%%% TeX-master: ""
%%% End:


More information about the ntg-context mailing list