ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Howto fit text into a box
@ 2008-06-09  1:06 Uwe Koloska
  2008-06-09 13:44 ` Wolfgang Schuster
  0 siblings, 1 reply; 3+ messages in thread
From: Uwe Koloska @ 2008-06-09  1:06 UTC (permalink / raw)
  To: ntg-context

Hello,

for a CD-Cover I have to fit a given text into a fixed box. I have tried to 
achieve this with the help of mag-0010 "Good looking shapes" but was not 
successful :-(

Can you help me with this?

The conditions:
  - the text is of fixed length
  - the area is of given size (has a given ratio)
  - the text has to fit completely inside this area
  - the last line must be justified, too
  - the fontsize of the text is the variable that can be changed
  - I have the current minimal context installation

and as an addition:
  - if possible the words should not be hyphenated at all or hyphenated
    at an arbitrary character without a hyphenation mark (the text
    consists of names)

A possible algorithm (similar to the one from mag-0010)
  1 start with a small box with the given ratio
  2 fill the text into the box
  3 if all text fits in with a small penalty we are ready
  4 make the box a bit larger
  5 goto 2

Unfortunately, I'm not able to understand the code from the mag nor can I code 
the algorithm in context ...

I would appreciate any input on this problem!

Thank you
Uwe Koloska
___________________________________________________________________________________
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Howto fit text into a box
  2008-06-09  1:06 Howto fit text into a box Uwe Koloska
@ 2008-06-09 13:44 ` Wolfgang Schuster
  2008-06-11 12:56   ` Wolfgang Schuster
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Schuster @ 2008-06-09 13:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, Jun 9, 2008 at 3:06 AM, Uwe Koloska <ml@koloro.de> wrote:
> Hello,
>
> for a CD-Cover I have to fit a given text into a fixed box. I have tried to
> achieve this with the help of mag-0010 "Good looking shapes" but was not
> successful :-(
>
> Can you help me with this?
>
> The conditions:
>  - the text is of fixed length
>  - the area is of given size (has a given ratio)
>  - the text has to fit completely inside this area
>  - the last line must be justified, too
>  - the fontsize of the text is the variable that can be changed
>  - I have the current minimal context installation
>
> and as an addition:
>  - if possible the words should not be hyphenated at all or hyphenated
>    at an arbitrary character without a hyphenation mark (the text
>    consists of names)
>
> A possible algorithm (similar to the one from mag-0010)
>  1 start with a small box with the given ratio
>  2 fill the text into the box
>  3 if all text fits in with a small penalty we are ready
>  4 make the box a bit larger
>  5 goto 2
>
> Unfortunately, I'm not able to understand the code from the mag nor can I code
> the algorithm in context ...
>
> I would appreciate any input on this problem!
>
> Thank you
> Uwe Koloska

Not perfect but you could use it as a start. I used ruledvbox only to
take a look
at the boxsize. There is a parameter to disable the indenting for the last line
but I don't know it's name without looking into a TeX book.

\startbuffer[cover]
\input ward
\stopbuffer

\definetwopasslist{cover}

\newbox\cover
\newdimen\coverheight \coverheight= 7cm
\newdimen\coverwidth  \coverwidth = 7cm
\newdimen\coverfont   \coverfont  =12pt
\newdimen\fontstep    \fontstep   = 1pt

\starttext

\definefont[Cover][Sans at \the\coverfont]

\gettwopassdata{cover}
\iftwopassdatafound
  \coverfont\twopassdata
  \definefont[Cover][Sans at \the\coverfont]
\fi

\setbox\cover\ruledvbox
  {\hsize\coverwidth
   \Cover\setupinterlinespace
   \setupalign[nothyphenated]
   \emergencystretch\maxdimen
   \getbuffer[cover]}

\ifdim\ht\cover<\coverheight
  \advance\coverfont\fontstep
  \savetwopassdata{cover}{1}{\the\coverfont}
\else
  \advance\coverfont-\fontstep
  \savetwopassdata{cover}{1}{\the\coverfont}
\fi

\ruledvbox to 7cm{\box\cover}

\stoptext

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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Howto fit text into a box
  2008-06-09 13:44 ` Wolfgang Schuster
@ 2008-06-11 12:56   ` Wolfgang Schuster
  0 siblings, 0 replies; 3+ messages in thread
From: Wolfgang Schuster @ 2008-06-11 12:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, Jun 9, 2008 at 3:44 PM, Wolfgang Schuster
<schuster.wolfgang@googlemail.com> wrote:
> On Mon, Jun 9, 2008 at 3:06 AM, Uwe Koloska <ml@koloro.de> wrote:
>> Hello,
>>
>> for a CD-Cover I have to fit a given text into a fixed box. I have tried to
>> achieve this with the help of mag-0010 "Good looking shapes" but was not
>> successful :-(
>>
>> Can you help me with this?
>>
>> The conditions:
>>  - the text is of fixed length
>>  - the area is of given size (has a given ratio)
>>  - the text has to fit completely inside this area
>>  - the last line must be justified, too
>>  - the fontsize of the text is the variable that can be changed
>>  - I have the current minimal context installation
>>
>> and as an addition:
>>  - if possible the words should not be hyphenated at all or hyphenated
>>    at an arbitrary character without a hyphenation mark (the text
>>    consists of names)
>>
>> A possible algorithm (similar to the one from mag-0010)
>>  1 start with a small box with the given ratio
>>  2 fill the text into the box
>>  3 if all text fits in with a small penalty we are ready
>>  4 make the box a bit larger
>>  5 goto 2
>>
>> Unfortunately, I'm not able to understand the code from the mag nor can I code
>> the algorithm in context ...
>>
>> I would appreciate any input on this problem!
>>
>> Thank you
>> Uwe Koloska
>
> Not perfect but you could use it as a start. I used ruledvbox only to
> take a look
> at the boxsize. There is a parameter to disable the indenting for the last line
> but I don't know it's name without looking into a TeX book.
>
> \startbuffer[cover]
> \input ward
> \stopbuffer
>
> \definetwopasslist{cover}
>
> \newbox\cover
> \newdimen\coverheight \coverheight= 7cm
> \newdimen\coverwidth  \coverwidth = 7cm
> \newdimen\coverfont   \coverfont  =12pt
> \newdimen\fontstep    \fontstep   = 1pt
>
> \starttext
>
> \definefont[Cover][Sans at \the\coverfont]
>
> \gettwopassdata{cover}
> \iftwopassdatafound
>  \coverfont\twopassdata
>  \definefont[Cover][Sans at \the\coverfont]
> \fi
>
> \setbox\cover\ruledvbox
>  {\hsize\coverwidth
>   \Cover\setupinterlinespace
>   \setupalign[nothyphenated]
>   \emergencystretch\maxdimen
>   \getbuffer[cover]}
>
> \ifdim\ht\cover<\coverheight
>  \advance\coverfont\fontstep
>  \savetwopassdata{cover}{1}{\the\coverfont}
> \else
>  \advance\coverfont-\fontstep
>  \savetwopassdata{cover}{1}{\the\coverfont}
> \fi
>
> \ruledvbox to 7cm{\box\cover}
>
> \stoptext

Another version, this did work without multiple passes and is faster.

\newbox\cover
\newdimen\coverheight \coverheight= 7cm
\newdimen\coverwidth  \coverwidth = 7cm
\newdimen\coverfont   \coverfont  =12pt
\newdimen\fontstep    \fontstep   = 1pt

\def\startcover
  {\dostartbuffer[cover][startcover][stopcover]}

\def\stopcover
  {\setups[cover:place]}

\def\boxsize
  {\setbox\cover\vbox
     {\hsize\coverwidth
      \definedfont[Serif at \the\coverfont]\setupinterlinespace
      \setupalign[nothyphenated]
      \emergencystretch\maxdimen
      \getbuffer[cover]}}

\def\covertext
  {\boxsize\doloop
     {\boxsize
      \ifdim\ht\cover>\coverheight
        \global\advance\coverfont-\fontstep
        \exitloop
      \else
        \global\advance\coverfont\fontstep
      \fi}}

\startsetups[cover:place]

  \covertext
  \boxsize
  \ruledvbox to\coverheight{\box\cover}

\stopsetups

\starttext

\startcover
\strut\input ward
\stopcover

\stoptext

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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

end of thread, other threads:[~2008-06-11 12:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-09  1:06 Howto fit text into a box Uwe Koloska
2008-06-09 13:44 ` Wolfgang Schuster
2008-06-11 12:56   ` Wolfgang Schuster

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