Applying Different Font Styles in the Report Writer

ID: Q88444

The information in this article applies to:

SUMMARY

In the FoxPro report writer, to apply different font styles to objects that are printed on a non-PostScript printer, you must modify the GEN_PD.PRG and DRIVER.PRG printer drivers and the P_CODES.DBF database file. The text below describes the modifications required. General knowledge about printer drivers and specific knowledge about FoxPro printer drivers is required in order to use the procedures in this article.

NOTE: This can also be done by placing the escape sequences (control codes) directly into the report expression. They can be added to the field that is output or placed in a field of their own.

MORE INFORMATION

In version 2.0 of the FoxPro report writer, the user can assign various font styles to objects using the Style check box in the Report Expression Dialog box. To access the Report Expression dialog box, choose Field from the Report menu. The various font styles are bold, italic, underline, subscript, and superscript.

When the user selects a style, the report writer automatically places the associated code in the Code edit control. For example, when the Bold check box is selected, the letter "B" appears in the Code edit control. Alternatively, the user can type "B" in the Code edit control to apply the bold formatting attribute. When the user runs the report, FoxPro sends the style code associated with the object to the PDOBJECT procedure in the DRIVER.PRG file, where it is interpreted for the chosen printer. When the report runs, the control code or escape sequence is sent to the printer to enable the selected font style.

While version 2.0 of the FoxPro report writer supports assigning various font styles to objects, it does not support assigning different fonts to various objects. To extend the report writer to support this feature, you must define the style codes for the different fonts that the PDOBJECT procedure can interpret to send appropriate control codes to the printer. The user interface should be the same; to assign a font (Helvetica, Times, New Century Schoolbook, and so on) to an object, the user enters in the Code edit control the style code that corresponds to the font type. The programmer defines the appropriate syntax. For example "F25P12" is an intuitive method for the user to specify a font type and point size.

To implement this functionality, do the following:

1. In the GENPD.PJX project, modify the main program, GEN_PD.PRG, to

   specify the user of the XBase, non-PostScript printer driver.
   Remove the comment from the following line:

      _PDRIVER = "DRIVER.PRG"

   And add a comment to the following line:

      _PDRIVER = "DRIVER2.PLB"

2. Modify the PDOBJECT procedure in the XBase, non-PostScript printer
   driver program, DRIVER.PRG, to recognize the entered style codes.
   The translations for these codes (the control codes or escape
   sequences sent to the printer) can be specified in the program.
   However, for additional flexibility, the program code should be
   general enough to accommodate using different font types with
   different printers.

3. If the program uses variables instead of containing the actual
   printer control codes, add new fields that contain the control
   codes to P_CODES.DBF, the printer control code database. The number
   of additional fields required depends on how the codes are sent to
   the printer, which varies between printers and is also impacted by
   the program design.

   For the Hewlett-Packard Printer Control Language (HP-PCL), for
   example, the font ID and font size are known only at run time.
   Therefore, the program code must be written such that the font ID
   and font size are distinct. To do this, specify a start code and an
   end code for both the font ID and the font size. In this case, four
   new fields must be added to P_CODES.DBF.

4. If new fields are added to P_CODES.DBF, modify the declaration of
   the global _pdparms array to reflect the new number of array
   elements.

5. Define the new elements of the _pdparms array at the end of the
   array.

6. Press CTRL+F1 until the GENPD.PJX window is on top.

7. Select BUILD from the project. Then, select both BUILD APPLICATION

   and REBUILD ALL. Choose OK to have the changes take effect.

8. Save any changes to the project, if prompted to do so.

9. Save the .APP file (GENPD.APP) in the same directory as

   FoxPro version 2.0 (C:\FOXPRO2 is the default) by changing values in
   the Directory menu popup.

Additional reference words: FoxDos 2.00 pdparms KBCategory: kbprg KBSubcategory:

Last Reviewed: April 17, 1995