Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Shrinking text to fit

edited April 2003 in General
I have a memo field on a report. The text it it usually fits fine, but
occasionally there is a bit more text than fit.

For various external reasons, it is not feasible to extend this field larger
than its current size, nor to let it roll over to another page, etc.
Rather, the text font size therein needs to automatically adjusted downward
far enough for it to fit. So, for example, most of the time it would be at
11 point, it would sometimes reduce to 10, 9, 8, whatever, to make the text
fit.

In a past project with Ace Reporter, I implemented this with excellent
results. All I had to do was write a few lines of code to see if the text
fit in the alloted size, then put that in a loop to keep adjusting down
until it fit.

I've been looking all over the RB docs and example, and haven't been able to
figure out what hook to use to do this. Surely it must be possible, for RB
is a far more featureful and expensive package than Ace :-)

There was a previous post from Jim Bennett about this example:

http://www.digital-metaphors.com/tips/ForceFontToOnePageReport.zip

But that does not answer my question at all, unfortunately; it uses a much
larger-grained measurement of whether the whole report fit on a page; I need
to do this at a field level.

I have looked around and experimented with a variety of RB component
properties/methods, and I can't find any that actually exposes the answer to
the question "did this text fit in this box?", although some appear to be
related. I've also been unable to find out where to get a graphic context
that would let me ask that same question.

--
[ Kyle Cordes * kyle@kylecordes.com * http://kylecordes.com ]
[ Consulting and Software development tips and techniques ]
[ for Java, EJB, Delphi, the BDE Alternatives Guide, & more ]

Comments

  • edited April 2003
    The tip you founf was for a customer that wanted to always print a page on
    one piece of paper. Because RB relies on the printer driver for font sizes
    in order to determine pagaination, this demo forces a report that should be
    one page to always be one page and include all the information of the report
    by reducing the font so it fits. It isn't what you want, exactly.

    You'll need to generate your memo in memory. Use the TppPlainText function
    called WordWrap. See ppPlainText.pas for a listing of parameters. This class
    is meant to be an internal one, so it is not in the help file. Basically,
    you also need to search our source for uses of this routine. See ppMemo.pas
    as well for this. Also, TppCustomMemo.CalcSpaceUsed uses two functions of
    TppPlaintext to see if the wrapped lines (TppPlaintText.WordWrap) fit inside
    the count which TppPlainText.MaxLinesFit calculated.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited May 2003
    "Jim Bennett (Digital Metaphors)" wrote in
  • edited May 2003
    What may be happening is that you are using a different printer to calculate
    the memo wrapping. The WinAPI calls rely on the printer driver to provide
    the calculated text width and height. Every printer driver is different and
    you will get different measurements when using different printer drivers to
    measure the text widths and heights for the same font name and pt size.
    Check to make sure that Report.PrinterSetup.PrinterName is set to the
    printer that you want to use (it should be 'default'). Do not use the screen
    to measure any text. ReportBuilder always relies on the selected printer to
    measure text, and that is why the screen preview doesn't look as good as the
    printed output. The screen can't resolve the precise measurements that the
    printer can using the 96 ppi on the screen versus 600 on the printer.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.