Background
Looking to devise a scaling factor for two fonts such that the text, when added to the final document, fits on one line.
Example
In the images below, the two fonts are the first character (e.g., "M") and the title text ("My Extraordinary Title"). In the first image, the text is split across two lines:
While the second image, which is desired, has the font scaled to fit on one line:
The large M in the second image should be scaled down at the same ratio as the rest of the text, hence the desire for a scale factor that can be used against both the title text and its first character.
Problem
I'd like to define a macro along the lines of the following recursive function:
Integer fitText( String text, Integer fontSize, Integer minWidth, Integer maxWidth ) {
Integer currentWidth = scratchBox( text, fontSize );
if( currentWidth > maxWidth && currentWidth > minWidth ) {
return fitText( text, fontSize - 1pt, minWidth, maxWidth );
}
return fontSize;
}
Maybe I'm going about this the wrong way, though, and am open to other approaches.
For example, given a \frame
is it possible to scale the frame such that it fits the \textwidth
? That is:
\framed[
frame=off,
width=\textwidth * 4,
]{%
\BookStylizedChapter{\BookTitleText}
}
Then somehow scale the framed down if its content width exceeds the \textwidth
?
Question
How would you scale a line of text (or a framed
element) in ConTeXt such that line breaks do not occur, but the font scales down instead?
\FittingText
macro was revealed some time ago. I agree with @Aditya though that if you wish to fit only a single line, scaling the box itself is worth a try.