ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Rule under length of last line
@ 2006-07-31 16:59 Duncan Hothersall
  2006-07-31 17:47 ` Taco Hoekwater
  2006-07-31 18:56 ` Hans Hagen
  0 siblings, 2 replies; 6+ messages in thread
From: Duncan Hothersall @ 2006-07-31 16:59 UTC (permalink / raw)


I've had a last-minute impossible request for a typesetting style, and
having already told the person it can't be done in the time available,
wondered whether it can actually be done at all.

The request is for a subsection heading to have a continuous horizontal
rule under both its number and title, at a distance of about 6pt from
the baseline (i.e. not underlining), extending just the length of the
heading. I can do that by setting both number and title in a TABLE,
setting the offsets and specifying the bottom frame to be on - no problem.

However, the tricky part is that where a longer title runs beyond one
line, the line should only appear under the last line, and only to the
length of the last line of text.

In other words, for viewers with fixed width fonts:

1.1.1 Short title
-----------------

1.1.2 Longer title which wraps onto a
      second line like this
---------------------------

We generate the ConTeXt code from XML, so ideally a solution wouldn't
require the last line to be set separately, but would just work whether
the heading was single or multiple line. What I'm really looking for is
a subsection setup that will automatically do this whatever length of title.

I have to say I think it's quite ugly, but can anyone give me a pointer
as to how it could be done? Is there a box left at the end of a par
which shows the width of the last line?

As I say, I've already said no, so this is just out of interest, no
urgency.

Thanks,

Duncan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Rule under length of last line
  2006-07-31 16:59 Rule under length of last line Duncan Hothersall
@ 2006-07-31 17:47 ` Taco Hoekwater
  2006-07-31 19:12   ` Hans Hagen
  2006-07-31 18:56 ` Hans Hagen
  1 sibling, 1 reply; 6+ messages in thread
From: Taco Hoekwater @ 2006-07-31 17:47 UTC (permalink / raw)


Duncan Hothersall wrote:
> We generate the ConTeXt code from XML, so ideally a solution wouldn't
> require the last line to be set separately, but would just work whether
> the heading was single or multiple line. What I'm really looking for is
> a subsection setup that will automatically do this whatever length of title.

It is easier than you think:

   \def\Myway#1%
     {#1\vrule height 0pt depth 6pt width 0pt}% title + force 6pt
      \optimizedisplayspacingtrue\setlastlinewidth % core-mat macro
      \global\advance\lastlinewidth-\hangindent\par % adjust
      \hrule width \the\lastlinewidth}

   \setuphead[section][textcommand=\Myway]

The key element is \setlastlinewidth, which measures the width
of the final line of the current paragraph.

Cheers, Taco

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Rule under length of last line
  2006-07-31 16:59 Rule under length of last line Duncan Hothersall
  2006-07-31 17:47 ` Taco Hoekwater
@ 2006-07-31 18:56 ` Hans Hagen
  1 sibling, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2006-07-31 18:56 UTC (permalink / raw)


Duncan Hothersall wrote:
> I've had a last-minute impossible request for a typesetting style, and
> having already told the person it can't be done in the time available,
> wondered whether it can actually be done at all.
>   
depends on the amount of time, and it the case of customers what they 
are willing to pay -)

many things can be done, esp because designers are not that accustomed 
to thinking on programmable designs
> The request is for a subsection heading to have a continuous horizontal
> rule under both its number and title, at a distance of about 6pt from
> the baseline (i.e. not underlining), extending just the length of the
> heading. I can do that by setting both number and title in a TABLE,
> setting the offsets and specifying the bottom frame to be on - no problem.
>
> However, the tricky part is that where a longer title runs beyond one
> line, the line should only appear under the last line, and only to the
> length of the last line of text.
>
> In other words, for viewers with fixed width fonts:
>
> 1.1.1 Short title
> -----------------
>
> 1.1.2 Longer title which wraps onto a
>       second line like this
> ---------------------------
>
> We generate the ConTeXt code from XML, so ideally a solution wouldn't
> require the last line to be set separately, but would just work whether
> the heading was single or multiple line. What I'm really looking for is
> a subsection setup that will automatically do this whatever length of title.
>
> I have to say I think it's quite ugly, but can anyone give me a pointer
>   
you don't wanna know hwo much time i've spent in programming ugly stuff -)
> as to how it could be done? Is there a box left at the end of a par
> which shows the width of the last line?
>
> As I say, I've already said no, so this is just out of interest, no
> urgency.
>   
anyhow, it's doable; the first solution took me 30 minutes, the second one 15 minutes

\def\FirstSolution#1#2%
  {\vbox\bgroup
   \setbox0\hbox{#1}
   \hsize.4\textwidth
   \beginshapebox#2\endshapebox
   \gdef\SetLastLineWidth{\xdef\LastLineWidth{\the\wd\scratchbox}}%
   \reshapebox
     {\setbox\scratchbox\hbox{\unhbox\shapebox}%
      \SetLastLineWidth
      \globallet\SetLastLineWidth\relax
      \box\scratchbox}%
   \scratchdimen\dimexpr\wd0+.25em+\LastLineWidth\relax
% \setbox2\ruledvbox   {\innerflushshapebox} 
% why is correction needed
   \setbox2\vbox        {\vskip-\lineskip\innerflushshapebox}
   \setbox0\vbox to \ht2{\box0}
   \hbox{\box0\hskip.25em\box2}
   \offinterlineskip
   \vskip.25ex
   \blackrule[width=\scratchdimen,height=2pt]
   \egroup}

\doglobal\newcounter\NextLinePos

\def\SecondSolution#1#2%
  {\vbox\bgroup
   \hsize.4\textwidth
   \doglobal\increment\NextLinePos
   \setbox\scratchbox\hbox{#1}
   \hbox{\vtop{\copy\scratchbox}\hskip.25em\vtop{#2}}%
   \offinterlineskip
   \scratchdimen\dimexpr\wd\scratchbox+.25em+
     \MPx{e:npl:\NextLinePos}-\MPx{b:npl:\NextLinePos}\relax
   \vskip.25ex
   \blackrule[width=\scratchdimen,height=2pt]
   \egroup}

\def\DoSecondSolution#1%
  {\bpos{npl:\NextLinePos}#1\epos{npl:\NextLinePos}}

% \showstruts

\setuphead[section][command=\FirstSolution]

\starttext

\section{is this nice or not}

\section{is this nice or not nice, that's the question}

\setuphead[section][command=\SecondSolution,deeptextcommand=\DoSecondSolution]

\section{is this nice or not}

\section{is this nice or not nice, that's the question}

\stoptext

Now it's your turn to wikify this ... 

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Rule under length of last line
  2006-07-31 17:47 ` Taco Hoekwater
@ 2006-07-31 19:12   ` Hans Hagen
  2006-08-01  7:43     ` Taco Hoekwater
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2006-07-31 19:12 UTC (permalink / raw)


Taco Hoekwater wrote:
> Duncan Hothersall wrote:
>   
>> We generate the ConTeXt code from XML, so ideally a solution wouldn't
>> require the last line to be set separately, but would just work whether
>> the heading was single or multiple line. What I'm really looking for is
>> a subsection setup that will automatically do this whatever length of title.
>>     
>
> It is easier than you think:
>
>    \def\Myway#1%
>      {#1\vrule height 0pt depth 6pt width 0pt}% title + force 6pt
>       \optimizedisplayspacingtrue\setlastlinewidth % core-mat macro
>       \global\advance\lastlinewidth-\hangindent\par % adjust
>       \hrule width \the\lastlinewidth}
>
>    \setuphead[section][textcommand=\Myway]
>
> The key element is \setlastlinewidth, which measures the width
> of the final line of the current paragraph.
>   
i was thinking of that as a third solution but somehow you trust \setlastlinewidth more than i do -) 

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Rule under length of last line
  2006-07-31 19:12   ` Hans Hagen
@ 2006-08-01  7:43     ` Taco Hoekwater
  0 siblings, 0 replies; 6+ messages in thread
From: Taco Hoekwater @ 2006-08-01  7:43 UTC (permalink / raw)




Hans Hagen wrote:
>>
>>The key element is \setlastlinewidth, which measures the width
>>of the final line of the current paragraph.
>>  
> 
> i was thinking of that as a third solution but somehow you 
> trust \setlastlinewidth more than i do -) 

The cases where it fails are very unlikely to happen in section titles.

Taco

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Rule under length of last line
       [not found] <mailman.132.1154372189.2039.ntg-context@ntg.nl>
@ 2006-07-31 19:33 ` Duncan Hothersall
  0 siblings, 0 replies; 6+ messages in thread
From: Duncan Hothersall @ 2006-07-31 19:33 UTC (permalink / raw)


Wow, very cool. Will adapt and wikify. Thanks - it's even better to say
no and then do it anyway. :)

Thanks again.

Duncan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-08-01  7:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-31 16:59 Rule under length of last line Duncan Hothersall
2006-07-31 17:47 ` Taco Hoekwater
2006-07-31 19:12   ` Hans Hagen
2006-08-01  7:43     ` Taco Hoekwater
2006-07-31 18:56 ` Hans Hagen
     [not found] <mailman.132.1154372189.2039.ntg-context@ntg.nl>
2006-07-31 19:33 ` Duncan Hothersall

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).