From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/41571 Path: news.gmane.org!not-for-mail From: "Wolfgang Schuster" Newsgroups: gmane.comp.tex.context Subject: Re: Howto fit text into a box Date: Wed, 11 Jun 2008 14:56:51 +0200 Message-ID: <115224fb0806110556v33f4eb03hf66013a0671fb84a@mail.gmail.com> References: <200806090306.39320.ml@koloro.de> <115224fb0806090644x678fa78cua58230bb53ea999a@mail.gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1213189125 26457 80.91.229.12 (11 Jun 2008 12:58:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Jun 2008 12:58:45 +0000 (UTC) To: "mailing list for ConTeXt users" Original-X-From: ntg-context-bounces@ntg.nl Wed Jun 11 14:59:24 2008 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by lo.gmane.org with esmtp (Exim 4.50) id 1K6Pv1-0004bV-A5 for gctc-ntg-context-518@m.gmane.org; Wed, 11 Jun 2008 14:59:15 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id CFD6A1FD5A; Wed, 11 Jun 2008 14:58:25 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 08482-01-3; Wed, 11 Jun 2008 14:57:39 +0200 (CEST) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 7B8331FC93; Wed, 11 Jun 2008 14:57:39 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 25F221FCA3 for ; Wed, 11 Jun 2008 14:57:37 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 08482-01-2 for ; Wed, 11 Jun 2008 14:57:02 +0200 (CEST) Original-Received: from yw-out-1718.google.com (yw-out-1718.google.com [74.125.46.158]) by ronja.ntg.nl (Postfix) with ESMTP id D2D351FB8C for ; Wed, 11 Jun 2008 14:57:01 +0200 (CEST) Original-Received: by yw-out-1718.google.com with SMTP id 5so2354108ywm.74 for ; Wed, 11 Jun 2008 05:56:51 -0700 (PDT) Original-Received: by 10.150.154.6 with SMTP id b6mr212910ybe.92.1213189011604; Wed, 11 Jun 2008 05:56:51 -0700 (PDT) Original-Received: by 10.151.113.9 with HTTP; Wed, 11 Jun 2008 05:56:51 -0700 (PDT) In-Reply-To: <115224fb0806090644x678fa78cua58230bb53ea999a@mail.gmail.com> Content-Disposition: inline X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.9 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:41571 Archived-At: On Mon, Jun 9, 2008 at 3:44 PM, Wolfgang Schuster wrote: > On Mon, Jun 9, 2008 at 3:06 AM, Uwe Koloska 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 ___________________________________________________________________________________