Is it possible to automatically determine font size to fit text to a given space?
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.
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
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
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
Hans Hagen
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
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
participants (4)
-
Daniel Pittman
-
Gerben Wierda
-
Hans Hagen
-
Wolfgang Zillig