TFileGTF
Source: source/classes/tfilegtf.prg
Standalone class
TFileGTF is a file writer for the GTF (Generic Text Format) file format. It provides structured text output with configurable alignment, font selection, and color applied per write operation. The class manages font and format tables internally and writes the GTF header and body segments to disk.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cName | Character | Target GTF file name |
hFile | Numeric | Windows file handle |
nAlign | Numeric | Current text alignment (ES_LEFT, ES_CENTER, ES_RIGHT) |
nFont | Numeric | Current font index in the font table |
nColor | Numeric | Current text color (RGB) |
Methods
| Method | Description |
|---|---|
New( cFileName ) | Create a new GTF file; writes header and font table |
End() | Finalize and close the GTF file |
Write( uVal, nFormat, nAlign, nFont, nColor, lReturn ) | Write a value with optional format, alignment, font, and color; lReturn appends CRLF |
_Return() | Write a blank line (CRLF) |
Utility Functions
| Function | Description |
|---|---|
GTFFont( cName, nHeight, nWidth, lBold, lItalic, lUnderline, lStrikeout ) | Define or retrieve a font; returns font index |
GTFFormat( nAlign, nFont, nColor ) | Define or retrieve a format triplet; returns format index |
SetGTFFormat( nFormat ) | Set current format by index |
SetGTFAlign( nAlign ) | Set default alignment |
SetGTFFont( nFont ) | Set default font index |
SetGTFColor( nColor ) | Set default text color |
Example: Writing a GTF File
#include "FiveWin.ch"
function Main()
local oGtf := TFileGTF():New( "output.gtf" )
GTFFont( "Arial", 14, 6, .T., .F., .F., .F. )
GTFFont( "Courier New", 12, 5, .F., .F., .F., .F. )
GTFFormat( ES_CENTER, 1, CLR_RED )
GTFFormat( ES_LEFT, 2, CLR_BLUE )
oGtf:Write( "Section Heading", 1 )
oGtf:_Return()
oGtf:Write( "Body text line", 2 )
oGtf:End()
return nil
Notes
- GTF is a tagged text format:
FORMAT_TEXT_TYPE + SP_REG + FORMAT_TEXT_VERSIONas header, followed by embedded font definitions and tagged content. - Fonts and formats are stored in module-level static arrays (
aFonts,aFormats) and shared across all TFileGTF instances. - Each
Write()call emits alignment/font/color tags only when the value changes from the previous call, keeping output compact. - The class was originally authored by Ramón Avendaño.