Force text into allocated space when printing

fit()

Force text into allocated space when printing


SYNTAX

fit(field_id | expression [, width])[:format[:flags]]

Print the value of a field or expression, forcing it into its allocated space if necessary.

This function is useful when a proportional font is being used. It is essential that a nominal, fixed character width be defined so that the tab function works correctly, and so that a report can be printed in columns. Sculptor uses the width of the “0” character for this purpose. Since all digits in a proportional font are the same width, and most other characters are narrower, this usually allows ample space for alphanumeric text.

However, if a text item is much wider than average, it is either overwritten by the item following it, or is truncated by the edge of the page.

The fit function avoids this problem by forcing the text into its allocated space if necessary. Sculptor does this by calculating the width of the text in the current font size (ignoring trailing spaces). If the text fits into its nominal width, it is printed normally. If it is too wide, the font size is progressively reduced until the text fits.

field_id | expression

The field or expression to be printed.

width

The nominal field width, which may be smaller or larger than the natural width of the item. If width is omitted, the natural width is used. If a width is specified with the printh command, it is necessary to ensure that the same width is specified to all matching print lines. Otherwise, Sculptor does not have sufficient information to align the columns correctly. See Example 2 below.

format

An optional format to be applied to the field.

flags

Optional. The flags that can be used when printing are those defined under print[h].

If a text value which is wider than average is printed without using the fit function, it first overflows into any white space that exists between the print fields. This never happens when the fit function is used. It is therefore generally advisable, after using fit, to use the spc function:

spc(1)

or to set sys.Gap to 1 and to add spaces between other fields as required.

The Sculptor system variable sys.AutoFit can be used to apply the fit function to all printed fields or to all print items of any type. This ensures that a report looks tidy. Better results are usually obtained by applying fit only to those fields which really need it. If the function is not used, an item of text which is slightly wider than usual overflows into the space between columns, If fit is used, the text is forced into its nominal width, which does not include the space between columns.

This function does not accept the form *field_id, which can be used in a print[h] statement to represent the field’s heading. The alternative form:

field_id->heading

can be used instead.

This function is meaningless outside a print[h] command.


EXAMPLES

  1. Print an alpha field with format and flag:

    print fit(Total): "####0.00": "n"; spc(0);
    
  2. Print heading, data and spaces, correctly aligned:

    printh fit(Add.Name->heading, 30)
    printh fit(Add.Name, 30)
    printh nsp(30)
    

RELATED TOPICS

Reports

Report functions

spc()

tab()

print[h]

sys.AutoFit

Using proportional fonts