ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Is it possible to automatically determine font size to fit text to a given space?
@ 2005-12-02  1:14 Daniel Pittman
  2005-12-02 14:02 ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Pittman @ 2005-12-02  1:14 UTC (permalink / raw)


G'day. 

One of the things I (ab)use ConTeXt for is printing little text labels
to Avery stock.  This works quite well, and I was pleasantly surprised
how easy it was to get working with some hints from Hans in the archives
of this list.

The labels, over time, have varying lengths of text on them, and to get
that to fit on a single label sometimes requires that I vary the font
size to avoid the text spilling over outside the bounding box.

Is there any reasonable way that I could automate the process of
adjusting the font size so that I got the biggest possible size while
keeping the text fully fitted to the label?


I don't mind automating this outside of TeX/ConTeXt, by using a script
to try the font sizes and examine the TeX output for overflow messages,
but I don't know quite what to look for.  

Hints about that, or a native TeX method[1], would be very much
appreciated.  At the moment it is a relatively slow process of manual
trial and error.

Regards,
        Daniel

Footnotes: 
[1]  I don't care if it takes ten minutes to run, since this isn't a
     performance critical job.

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

* Re: Is it possible to automatically determine font size to fit text to a given space?
  2005-12-02  1:14 Is it possible to automatically determine font size to fit text to a given space? Daniel Pittman
@ 2005-12-02 14:02 ` Hans Hagen
  2005-12-02 15:18   ` Wolfgang Zillig
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Hans Hagen @ 2005-12-02 14:02 UTC (permalink / raw)


Daniel Pittman wrote:

>Hints about that, or a native TeX method[1], would be very much
>appreciated.  At the moment it is a relatively slow process of manual
>trial and error.
>  
>
this is something tex is pretty good at and it runs as fast as normal

how does your current code look? (the solution depends a bit it); think 
of something

\doloop{
  \setbox\scratchbox=\vbox
     {the content of the label}
   \ifx\ht\scratchbox>10cm
       \switchtobodyfont[small] 
   \else
       \unvbox\scratchbox
       \exitloop
   \fi
}

Hans

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

* Re: Is it possible to automatically determine font size to fit text to a given space?
  2005-12-02 14:02 ` Hans Hagen
@ 2005-12-02 15:18   ` Wolfgang Zillig
  2005-12-02 15:30     ` Hans Hagen
  2005-12-03 10:10   ` Daniel Pittman
  2005-12-04  9:40   ` Gerben Wierda
  2 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Zillig @ 2005-12-02 15:18 UTC (permalink / raw)


Could't it be done by metapost?

Wolfgang

Hans Hagen schrieb:

> Daniel Pittman wrote:
>
>> Hints about that, or a native TeX method[1], would be very much
>> appreciated.  At the moment it is a relatively slow process of manual
>> trial and error.
>>  
>>
> this is something tex is pretty good at and it runs as fast as normal
>
> how does your current code look? (the solution depends a bit it); 
> think of something
>
> \doloop{
>  \setbox\scratchbox=\vbox
>     {the content of the label}
>   \ifx\ht\scratchbox>10cm
>       \switchtobodyfont[small]   \else
>       \unvbox\scratchbox
>       \exitloop
>   \fi
> }
>
> Hans
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>

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

* Re: Is it possible to automatically determine font size to fit text to a given space?
  2005-12-02 15:18   ` Wolfgang Zillig
@ 2005-12-02 15:30     ` Hans Hagen
  0 siblings, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2005-12-02 15:30 UTC (permalink / raw)


Wolfgang Zillig wrote:

> Could't it be done by metapost?
>
no, that is overkill, but what can be done is:

\startbuffer
the label
\stopbuffer

\externalfigure[buffer][factor=max]

or

\scale[factor=max]{\framed[align=normal]{the label text}}
 
that would scale each label to fit best

but it would look funny (all those different sizes)

a more clever solution would choose different sizes for different label 
components depending on the result

(there is a rudimentary strategy mechanism, one day i will perfect that, 
which can be used to optimize whole documents, think of manipulating the 
distance in columns, or fontsizes in order to stick within a certain 
amount of pages; pretty old and rusty code btw)

> Wolfgang
>
> Hans Hagen schrieb:
>
>> Daniel Pittman wrote:
>>
>>> Hints about that, or a native TeX method[1], would be very much
>>> appreciated.  At the moment it is a relatively slow process of manual
>>> trial and error.
>>>  
>>>
>> this is something tex is pretty good at and it runs as fast as normal
>>
>> how does your current code look? (the solution depends a bit it); 
>> think of something
>>
>> \doloop{
>>  \setbox\scratchbox=\vbox
>>     {the content of the label}
>>   \ifx\ht\scratchbox>10cm
>>       \switchtobodyfont[small]   \else
>>       \unvbox\scratchbox
>>       \exitloop
>>   \fi
>> }
>>
>> Hans
>> _______________________________________________
>> ntg-context mailing list
>> ntg-context@ntg.nl
>> http://www.ntg.nl/mailman/listinfo/ntg-context
>>
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

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

* Re: Is it possible to automatically determine font size to fit text to a given space?
  2005-12-02 14:02 ` Hans Hagen
  2005-12-02 15:18   ` Wolfgang Zillig
@ 2005-12-03 10:10   ` Daniel Pittman
  2005-12-04  9:40   ` Gerben Wierda
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel Pittman @ 2005-12-03 10:10 UTC (permalink / raw)


Hans Hagen <pragma@wxs.nl> writes:
> Daniel Pittman wrote:

G'day Hans.

>>Hints about that, or a native TeX method[1], would be very much
>>appreciated.  At the moment it is a relatively slow process of manual
>>trial and error.
>
> this is something tex is pretty good at and it runs as fast as normal
>
> how does your current code look? (the solution depends a bit it); think
> of something

Sorry, I should have included that.  The cut down version follows; I
have a few more comments and so forth so I can revisit it if I wish.

I didn't make any attempt to automate the process at this stage, but
will have a play with all the suggestion and see if I can get it to
work.


For reference, this is aimed at printing multiple identical labels in
each batch, rather than distinct content on each label, so I don't worry
about the font size changing between the individual labels in the run or
anything.

Regards,
        Daniel


\loadmapfile[ec-bitstream-vera.map]
\usetypescriptfile[type-bitstream-vera]
\usetypescript[fiee][bitstream-vera]
\setupbodyfont[bitstream-vera, ss, 10pt]

% Avery Slide labels (L7656) layout.
\definepapersize[L7656][width=46.0mm,height=11.1mm]

\setuppapersize [XY][A4]
\setuppaper     [topspace=15.9mm,backspace=6.0mm,dx=4.7mm,dy=1.6mm,nx=4,ny=21]
\setuplayout    [page] [topspace=15.9mm,backspace=6.0mm]
\setuplayout    [page]
\setuplayout    [location=middle]
\setuparranging [XY]

% The layout within the label
\setuplayout[
    width=fit,height=fit,
    header=1mm,footer=0mm,leftmargin=0mm,rightmargin=0mm,
    topspace=1mm,backspace=1mm,
]

\setuppagenumbering[state=stop]

\startbuffer[label]
\vbox{20051112 \crlf Black Rock Cider}
\stopbuffer

\starttext
% skip already printed labels
\dorecurse{30}{~~\page}%
% print a number of labels.
\dorecurse{129}{%
\bf\setupinterlinespace[line=2ex]%
\startalignment[middle]%
\getbuffer[label]%
\stopalignment%
\page}
\stoptext

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

* Re: Is it possible to automatically determine font size to fit text to a given space?
  2005-12-02 14:02 ` Hans Hagen
  2005-12-02 15:18   ` Wolfgang Zillig
  2005-12-03 10:10   ` Daniel Pittman
@ 2005-12-04  9:40   ` Gerben Wierda
  2005-12-04 20:46     ` Hans Hagen
  2 siblings, 1 reply; 7+ messages in thread
From: Gerben Wierda @ 2005-12-04  9:40 UTC (permalink / raw)


While we're at it. can I get the name of the current font somehow?

G

On Dec 2, 2005, at 15:02, Hans Hagen wrote:

> Daniel Pittman wrote:
>
>> Hints about that, or a native TeX method[1], would be very much
>> appreciated.  At the moment it is a relatively slow process of manual
>> trial and error.
>>
> this is something tex is pretty good at and it runs as fast as normal
>
> how does your current code look? (the solution depends a bit it); 
> think of something
>
> \doloop{
>  \setbox\scratchbox=\vbox
>     {the content of the label}
>   \ifx\ht\scratchbox>10cm
>       \switchtobodyfont[small]   \else
>       \unvbox\scratchbox
>       \exitloop
>   \fi
> }
>
> Hans
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>

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

* Re: Is it possible to automatically determine font size to fit text to a given space?
  2005-12-04  9:40   ` Gerben Wierda
@ 2005-12-04 20:46     ` Hans Hagen
  0 siblings, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2005-12-04 20:46 UTC (permalink / raw)


Gerben Wierda wrote:

> While we're at it. can I get the name of the current font somehow?

\fontname\font

or often (in context): \lastfontname

Hans

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

end of thread, other threads:[~2005-12-04 20:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-02  1:14 Is it possible to automatically determine font size to fit text to a given space? Daniel Pittman
2005-12-02 14:02 ` Hans Hagen
2005-12-02 15:18   ` Wolfgang Zillig
2005-12-02 15:30     ` Hans Hagen
2005-12-03 10:10   ` Daniel Pittman
2005-12-04  9:40   ` Gerben Wierda
2005-12-04 20:46     ` Hans Hagen

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