Displaying or printing characters in different fonts is by nature a very complex task. The difficulty lies not only in the large number of possible fonts but in the fact that the available fonts depend on the capabilities of the hardware. The operating system provides a number of system fonts that can be used with most hardware installations. Special device dependent fonts can include a large number of possible parameters that describe the font. For this reason creation of a specific font cannot be guaranteed. To ensure that the correct font was created, the values of the instance variable of the XbpFont after the font is created should be compared with the description of the desired font. In the examples at the end of this discussion, a program is shown that determines the parameters of all fonts available on the particular computer system, writes this to a DBF file and allows it to be viewed on the screen. These parameters can be used as values for describing and selecting a font.
Class XbpFont() Foundation
Class function of the XbpFont class.
Objects of the XbpFont class allow the fonts for character output to be selected and managed. Fonts can be defined for character output on the screen or any other output device. XbpFont objects are required by the Xbase++ graphics engine (GRA) functions in order to display different fonts. The most important GRA functions for displaying different fonts on the screen are GraSetFont(), GraSetAttrString(), GraStringAt()and GraQueryTextBox() (see each of these functions for more information on their capabilities). Other Xbase Parts, for example XbpPushButton and XbpCheckBox, also use XbpFont objects for text output on the screen.
The XbpFont class provide programmers an easy way to select different fonts. In order to use different fonts, XbpFont objects must be created. This is done when the class object generates a new XbpFont object via the class method :new(). After an XbpFont object is created, values describing the desired font must be assigned to the instance variables of the XbpFont object. The corresponding font then needs to be created before it can be used. This is comparable to opening a file. If a file already exists, the information in it can be used only after the file is opened.
Fonts are requested using the :create() method of the XbpFont object. This passes the description of the desired font to the operating system which actually provides the font. Whether a font is successfully requested can be determined using the :status()method. This method returns the value of the #define constant XBP_STAT_CREATE when the font is available (all #define constants for Xbase Parts are in the #include file XBP.CH). If the definition of the desired font does not match an existing font, the available font that has the "best fit" (the closest match) with the definition is selected.
The values in the instance variables of the XbpFont object may be different before and after the font is created. Before the method :create() is executed, these instance variables contain the values for the desired font. After the :create() method terminates, these instance variables contain values describing the font actually created.
After the font is loaded, it is available within the Xbase++ program. However, since several fonts can be loaded at the same time, the desired font for the display must be specified by assigning the font object to the GRA module. This occurs using the function GraSetFont(). Characters are output in the current font using the function GraStringAt(). The basic mechanism for installing and using a font is shown in the following lines of code:
Using fonts extensively requires knowledge of "presentation spaces" (see XbpPresSpace() for more information). This is an Xbase Part that provides an abstract drawing surface where characters can be output using any font (a presentation space is analogous to a blank sheet of paper).
A presentation space is generally required to output fonts to the printer. A context device is also required and is provided by the XbpPrinter() class. See the chapter "Graphic output devices" in the the Xbase++ documentation.
The XbpFontDialog class provides the standard font dialog that allows fonts to be selected and installed by the user at runtime (see XbpFontDialog() for more information).
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.