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:
oFont := XbpFont():new() // Create XbpFont object
oFont:familyName := "Times New Roman" // Describe font
oFont:height := 16
oFont:width := 8
oFont:create() // Create font
GraSetFont ( , oFont ) // Select font
GraStringAt( , {10,300}, "Font" ) // Output characters
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).
// This example sequentially selects various system fonts
// and displays the font name as a sample.
#include "Font.ch"
PROCEDURE Main
LOCAL oFont, aSettings, i, imax
aSettings := { ;
FONT_DEFFIXED_SMALL , ;
FONT_DEFPROP_MEDIUM , ;
FONT_HELV_LARGE , ;
FONT_TIMES_SMALL , ;
FONT_TIMES_MEDIUM , ;
FONT_TIMES_LARGE , ;
FONT_TIMES_XLARGE + FONT_STYLE_BOLD , ;
FONT_TIMES_XLARGE + FONT_STYLE_ITALIC + FONT_STYLE_BOLD ;
}
SETCOLOR( "N/W" )
CLS
imax := LEN(aSettings)
oFont := XbpFont():new() // Create font object
oFont:create() // and font
FOR i:=1 TO imax
oFont:configure( aSettings[i] ) // Load new font
GraSetFont ( , oFont ) // Set current font
graStringAt( , {10, 360 - 30* i } , ; // Graphics x,y
STR(oFont:nominalPointSize,2)+; // coordinates!
"." + oFont:compoundName )
NEXT
SETPOS( MAXROW()-1, 0 )
WAIT "Press a key"
RETURN
// In this example, an XbpFont object is created and the method
// :list() is immediately executed. This creates an array
// containing XbpFont objects that describe all available
// system fonts. The instance variables of the XbpFont objects
// are written into a DBF file and displayed.
#include "inkey.ch"
PROCEDURE Main
LOCAL oFont, aFontList, aStruct, aIVars, oTbrowse, oColumn
oFont := XbpFont():New() // Create XbpFont object
aFontList := oFont:list() // Create array of fonts
oFont:familyName:= "Default values of font object"
AINS( aFontList, 1, oFont ) // Insert XbpFont object at
// the beginning of the list.
aIVars := { ; // Code to access all of the
{|o| o:antiAliased }, ; // instance variables of an
{|o| o:baseLine }, ; // XbpFont object in code
{|o| o:bold }, ; // blocks.
{|o| o:codePage }, ;
{|o| o:compoundName }, ;
{|o| o:dbcs }, ;
{|o| o:familyName }, ;
{|o| o:fixed }, ;
{|o| o:generic }, ;
{|o| o:height }, ;
{|o| o:italic }, ;
{|o| o:kerning }, ;
{|o| o:mbcs }, ;
{|o| o:nominalPointSize }, ;
{|o| o:outlined }, ;
{|o| o:strikeout }, ;
{|o| o:underscore }, ;
{|o| o:vector }, ;
{|o| o:weightClass }, ;
{|o| o:width }, ;
{|o| o:widthClass } ;
}
aStruct := { ; // Structure for DBF file
{ "antiAlias" , "L", 1, 0 }, ;
{ "baseLine" , "N", 3, 0 }, ;
{ "bold" , "L", 1, 0 }, ;
{ "codePage" , "N", 5, 0 }, ;
{ "compName" , "C",32, 0 }, ;
{ "dbcs" , "L", 1, 0 }, ;
{ "familyName" , "C",32, 0 }, ;
{ "fixed" , "L", 1, 0 }, ;
{ "generic" , "L", 1, 0 }, ;
{ "height" , "N", 3, 0 }, ;
{ "italic" , "L", 1, 0 }, ;
{ "kerning" , "L", 1, 0 }, ;
{ "mbcs" , "L", 1, 0 }, ;
{ "pointSize" , "N", 3, 0 }, ;
{ "outlined" , "L", 1, 0 }, ;
{ "strikeout" , "L", 1, 0 }, ;
{ "underscore" , "L", 1, 0 }, ;
{ "vector" , "L", 1, 0 }, ;
{ "weightClas" , "N", 3, 0 }, ;
{ "width" , "N", 3, 0 }, ;
{ "widthClass" , "N", 3, 0 } ;
}
DBCREATE("FONTS", aStruct) // Create and open
USE Fonts // DBF file
AEVAL( aFontList, ; // Import all fonts into
{|o| oFont := o, DBAPPEND(), ; // file. Write instance
AEVAL( aIVars, ; // variables to fields
{|b,i| FIELDPUT(i, EVAL(b,oFont)) } ;
) ; // in the file
} ;
)
oTBrowse := TBROWSEDB(2, 2, 22, 77) // Create Tbrowse
AEVAL( DBSTRUCT(), ; // object
{|a| oTBrowse:AddColumn( ; // Add columns
TBColumnNew(a[1], &("{||"+a[1]+"}")) );
} ;
)
oColumn := oTbrowse:delColumn( 5 ) // Place column with
oTBrowse:insColumn( 1, oColumn ) // :compoundName at left
oTBrowse:freeze := 1 // and freeze
DISPBOX(1, 1, 23, 78, 1 )
DO WHILE LASTKEY() <> K_ESC // browse
DO WHILE ! oTBrowse:stabilize()
IF (nKey := INKEY()) <> 0
EXIT
ENDIF
ENDDO
IF oTBrowse:stable
nKey := INKEY(0)
ENDIF
TBNavigate(oTBrowse, nKey)
ENDDO
RETURN
*********************************
PROCEDURE TBNavigate( oTB, nKey )
DO CASE
CASE nKey == K_DOWN ; oTB:down()
CASE nKey == K_PGDN ; oTB:pageDown()
CASE nKey == K_CTRL_PGDN ; oTB:goBottom()
CASE nKey == K_LEFT ; oTB:left()
CASE nKey == K_CTRL_LEFT ; oTB:panLeft()
CASE nKey == K_HOME ; oTB:home()
CASE nKey == K_CTRL_HOME ; oTB:panHome()
CASE nKey == K_RIGHT ; oTB:right()
CASE nKey == K_CTRL_RIGHT ; oTB:panRight()
CASE nKey == K_END ; oTB:_end()
CASE nKey == K_CTRL_END ; oTB:panEnd()
CASE nKey == K_UP ; oTB:up()
CASE nKey == K_PGUP ; oTB:pageUp()
CASE nKey == K_CTRL_PGUP ; oTB:goTop()
ENDCASE
RETURN
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.