Ask Reuben

GRW – Font Size of Compatibility Reports

With a GRW Compatibility Report, how can I change the font size?

The Compatibility Report feature of Genero Report Writer allows you to take an existing 4gl report that uses the REPORT syntax and outputs it via any of the Genero Report Writer devices.  By the addition of a handful of lines of code, this allows your existing 4gl report to be output to PDF.  This can be done very quickly, has no need to create a .4rp report design file, and for the majority of reports on your application this maybe sufficient to take them and output to PDF and other formats.  A question that gets asked with these reports is how to change the font size of the report?  The fgl_report_configureCompatabilityReport() function has a number of parameters but none of them are the font size.

The missing point in the developers knowledge is that for these compatibility reports is that the font size used is the biggest font size that will fit within the confines of the page.  That is the report engine looks at the selected font, the page size, the margins, the number of lines on each page of the report, and the number of columns in the report…

… and from these it determines the largest font size as an integer that will allow it to both …

  • fit the number of characters in the report across the page
  • fit the number of lines in the report down the page

If you have someone ask you to increase the font size or decrease the font size then you need to look at the above and review the values, there is no dedicated function or parameter.

There are some things you should observe …

  • The report will max out in one dimension before the other.  In that instance what you will observe is some space on the right or some space at the bottom.
  • You can use fgl_report_setPageMargins to better centre the output.
  • The result is an integer, so whilst a font size of 8.5 might use up 100% of the space, the selected font will be 8.
  • You may find that changing the page orientation from portrait to landscape or vice versa leads to a better result.  That is swap the order of parameters passed to fgl_report_configurePageSize
  • Different fonts have different aspect ratios.  That is the ratio of width to height may vary between different fonts.  This test program allows you to see these values if interested.
  • There is a minimum and maximum value. i.e we won’t calculate an absurd font size.

From my experience the #1 solution is to use fgl_report_configurePageSize to print the report in landscape.  Someone has taken a 132 column x 66 line report printed on green bar paper and is now printing on A4 or Letter paper with portrait orientation, when really you should print this on A4 or Letter paper with a landscape orientation to better match the original.  So it is simply a case of changing the order of the parameters to fgl_report_configurePageSize to print in landscape and not portrait.

The #2 solution involves the RIGHT MARGIN.  The report does not explicitly mention it so the 4gl defaults to 132 which is carried through to the compatibility report.  This may not accurately reflect the actual margin of the report.  So the solution is to add the actual right margin to the 4gl, either via the RIGHT MARGIN syntax in the REPORT block, or as the first argument to fgl_report_configureCompatabilityReport, so that a better right margin is used.

To understand and to see the effects I have prepared this sample program with the code below.  You can experiment changing the value of the macros at the top.  You should observe that the report will typically either fill up in one dimension but not the other dimension as per the two screenshots.  The default values are for a 132 column report that has 66 lines being printed onto A4 paper.  The difference between the two screenshots is that one has portrait orientation and one has landscape orientation.  You should observe that if the font size was increased, the report would overflow in one dimension, so that is the maximum font size that can be used, and hence that is the calculated font size for the compatibility report.

&define COLUMN_COUNT 132
&define PAGE_LENGTH 66
&define TOTAL_COUNT 1000
&define ORIENTATION_PORTRAIT TRUE

MAIN
    DEFINE grw om.SaxDocumentHandler
    DEFINE r RECORD
        idx INTEGER
    END RECORD

    IF NOT fgl_report_loadCurrentSettings(NULL) THEN
        EXIT PROGRAM 1
    END IF
    CALL fgl_report_selectDevice("SVG")
    CALL fgl_report_selectPreview(TRUE)
    IF ORIENTATION_PORTRAIT THEN
        CALL fgl_report_configurePageSize("a4width", "a4length")
    ELSE
        CALL fgl_report_configurePageSize("a4length", "a4width")
    END IF
    #CALL fgl_report_setPageMargins(0,0,0,0)
    LET grw = fgl_report_commitCurrentSettings()

    START REPORT compat_report TO XML HANDLER grw
    FOR r.idx = 1 TO TOTAL_COUNT
        OUTPUT TO REPORT compat_report(r.*)
    END FOR
    FINISH REPORT compat_report

END MAIN

REPORT compat_report(r)
    DEFINE r RECORD
        idx INTEGER
    END RECORD
    DEFINE i   INTEGER
    DEFINE sb  base.StringBuffer

    OUTPUT
        TOP MARGIN 0
        LEFT MARGIN 0
        RIGHT MARGIN COLUMN_COUNT
        BOTTOM MARGIN 0
        PAGE LENGTH PAGE_LENGTH

    ORDER EXTERNAL BY r.idx

    FORMAT

        ON EVERY ROW
            -- Create a string 1234567890, first number is lineno mod 10
            LET sb = base.StringBuffer.create()
            FOR i = 1 TO COLUMN_COUNT
                CALL sb.append(((i + LINENO) MOD 10) USING "&")
            END FOR
            PRINT sb.toString()

END REPORT