VGA Default Font

General FreeBASIC programming questions.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

VGA Default Font

Postby MichaelW » Aug 26, 2007 5:08

This is an adaptation of the VGA default font for use with Draw String. The font includes all of the characters defined by the VGA BIOS.

Instead of storing the font pixel patterns as a 4096-byte array, I chose to store them in a 2-dimensional array.

fntvgadef.bi:

Code: Select all

'' This creates a 2-dimensional array and initializes it with the
'' pixel patterns for the default VGA font, consisting of the 8x16
'' ROM font with the 9x16 supplement. The pixel patterns for each
'' character form an 8x16 matrix, one bit per pixel and one byte
'' per row, with the rows stored in sequence from top to bottom.
'' The bits in each byte are reversed to match the FB layout.

dim shared font_data(0 to 255, 0 to 15) as ubyte = { _
{000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000}, _
{000,000,126,129,165,129,129,189,153,129,129,126,000,000,000,000}, _
{000,000,126,255,219,255,255,195,231,255,255,126,000,000,000,000}, _
{000,000,000,000,054,127,127,127,127,062,028,008,000,000,000,000}, _
{000,000,000,000,008,028,062,127,062,028,008,000,000,000,000,000}, _
{000,000,000,024,060,060,231,231,231,024,024,060,000,000,000,000}, _
{000,000,000,024,060,126,255,255,126,024,024,060,000,000,000,000}, _
{000,000,000,000,000,000,024,060,060,024,000,000,000,000,000,000}, _
{255,255,255,255,255,255,231,195,195,231,255,255,255,255,255,255}, _
{000,000,000,000,000,060,102,066,066,102,060,000,000,000,000,000}, _
{255,255,255,255,255,195,153,189,189,153,195,255,255,255,255,255}, _
{000,000,120,112,088,076,030,051,051,051,051,030,000,000,000,000}, _
{000,000,060,102,102,102,102,060,024,126,024,024,000,000,000,000}, _
{000,000,252,204,252,012,012,012,012,014,015,007,000,000,000,000}, _
{000,000,254,198,254,198,198,198,198,230,231,103,003,000,000,000}, _
{000,000,000,024,024,219,060,231,060,219,024,024,000,000,000,000}, _
{000,001,003,007,015,031,127,031,015,007,003,001,000,000,000,000}, _
{000,064,096,112,120,124,127,124,120,112,096,064,000,000,000,000}, _
{000,000,024,060,126,024,024,024,126,060,024,000,000,000,000,000}, _
{000,000,102,102,102,102,102,102,102,000,102,102,000,000,000,000}, _
{000,000,254,219,219,219,222,216,216,216,216,216,000,000,000,000}, _
{000,062,099,006,028,054,099,099,054,028,048,099,062,000,000,000}, _
{000,000,000,000,000,000,000,000,127,127,127,127,000,000,000,000}, _
{000,000,024,060,126,024,024,024,126,060,024,126,000,000,000,000}, _
{000,000,024,060,126,024,024,024,024,024,024,024,000,000,000,000}, _
{000,000,024,024,024,024,024,024,024,126,060,024,000,000,000,000}, _
{000,000,000,000,000,024,048,127,048,024,000,000,000,000,000,000}, _
{000,000,000,000,000,012,006,127,006,012,000,000,000,000,000,000}, _
{000,000,000,000,000,000,003,003,003,127,000,000,000,000,000,000}, _
{000,000,000,000,000,036,102,255,102,036,000,000,000,000,000,000}, _
{000,000,000,000,008,028,028,062,062,127,127,000,000,000,000,000}, _
{000,000,000,000,127,127,062,062,028,028,008,000,000,000,000,000}, _
{000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000}, _
{000,000,024,060,060,060,024,024,024,000,024,024,000,000,000,000}, _
{000,102,102,102,036,000,000,000,000,000,000,000,000,000,000,000}, _
{000,000,000,054,054,127,054,054,054,127,054,054,000,000,000,000}, _
{024,024,062,099,067,003,062,096,096,097,099,062,024,024,000,000}, _
{000,000,000,000,067,099,048,024,012,006,099,097,000,000,000,000}, _
{000,000,028,054,054,028,110,059,051,051,051,110,000,000,000,000}, _
{000,012,012,012,006,000,000,000,000,000,000,000,000,000,000,000}, _
{000,000,048,024,012,012,012,012,012,012,024,048,000,000,000,000}, _
{000,000,012,024,048,048,048,048,048,048,024,012,000,000,000,000}, _
{000,000,000,000,000,102,060,255,060,102,000,000,000,000,000,000}, _
{000,000,000,000,000,024,024,126,024,024,000,000,000,000,000,000}, _
{000,000,000,000,000,000,000,000,000,024,024,024,012,000,000,000}, _
{000,000,000,000,000,000,000,127,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,000,000,000,000,000,024,024,000,000,000,000}, _
{000,000,000,000,064,096,048,024,012,006,003,001,000,000,000,000}, _
{000,000,060,102,195,195,219,219,195,195,102,060,000,000,000,000}, _
{000,000,024,028,030,024,024,024,024,024,024,126,000,000,000,000}, _
{000,000,062,099,096,048,024,012,006,003,099,127,000,000,000,000}, _
{000,000,062,099,096,096,060,096,096,096,099,062,000,000,000,000}, _
{000,000,048,056,060,054,051,127,048,048,048,120,000,000,000,000}, _
{000,000,127,003,003,003,063,096,096,096,099,062,000,000,000,000}, _
{000,000,028,006,003,003,063,099,099,099,099,062,000,000,000,000}, _
{000,000,127,099,096,096,048,024,012,012,012,012,000,000,000,000}, _
{000,000,062,099,099,099,062,099,099,099,099,062,000,000,000,000}, _
{000,000,062,099,099,099,126,096,096,096,048,030,000,000,000,000}, _
{000,000,000,000,024,024,000,000,000,024,024,000,000,000,000,000}, _
{000,000,000,000,024,024,000,000,000,024,024,012,000,000,000,000}, _
{000,000,000,096,048,024,012,006,012,024,048,096,000,000,000,000}, _
{000,000,000,000,000,126,000,000,126,000,000,000,000,000,000,000}, _
{000,000,000,006,012,024,048,096,048,024,012,006,000,000,000,000}, _
{000,000,062,099,099,048,024,024,024,000,024,024,000,000,000,000}, _
{000,000,000,062,099,099,123,123,123,059,003,062,000,000,000,000}, _
{000,000,008,028,054,099,099,127,099,099,099,099,000,000,000,000}, _
{000,000,063,102,102,102,062,102,102,102,102,063,000,000,000,000}, _
{000,000,060,102,067,003,003,003,003,067,102,060,000,000,000,000}, _
{000,000,031,054,102,102,102,102,102,102,054,031,000,000,000,000}, _
{000,000,127,102,070,022,030,022,006,070,102,127,000,000,000,000}, _
{000,000,127,102,070,022,030,022,006,006,006,015,000,000,000,000}, _
{000,000,060,102,067,003,003,123,099,099,102,092,000,000,000,000}, _
{000,000,099,099,099,099,127,099,099,099,099,099,000,000,000,000}, _
{000,000,060,024,024,024,024,024,024,024,024,060,000,000,000,000}, _
{000,000,120,048,048,048,048,048,051,051,051,030,000,000,000,000}, _
{000,000,103,102,102,054,030,030,054,102,102,103,000,000,000,000}, _
{000,000,015,006,006,006,006,006,006,070,102,127,000,000,000,000}, _
{000,000,195,231,255,255,219,195,195,195,195,195,000,000,000,000}, _
{000,000,099,103,111,127,123,115,099,099,099,099,000,000,000,000}, _
{000,000,062,099,099,099,099,099,099,099,099,062,000,000,000,000}, _
{000,000,063,102,102,102,062,006,006,006,006,015,000,000,000,000}, _
{000,000,062,099,099,099,099,099,099,107,123,062,048,112,000,000}, _
{000,000,063,102,102,102,062,054,102,102,102,103,000,000,000,000}, _
{000,000,062,099,099,006,028,048,096,099,099,062,000,000,000,000}, _
{000,000,255,219,153,024,024,024,024,024,024,060,000,000,000,000}, _
{000,000,099,099,099,099,099,099,099,099,099,062,000,000,000,000}, _
{000,000,195,195,195,195,195,195,195,102,060,024,000,000,000,000}, _
{000,000,195,195,195,195,195,219,219,255,102,102,000,000,000,000}, _
{000,000,195,195,102,060,024,024,060,102,195,195,000,000,000,000}, _
{000,000,195,195,195,102,060,024,024,024,024,060,000,000,000,000}, _
{000,000,255,195,097,048,024,012,006,131,195,255,000,000,000,000}, _
{000,000,060,012,012,012,012,012,012,012,012,060,000,000,000,000}, _
{000,000,000,001,003,007,014,028,056,112,096,064,000,000,000,000}, _
{000,000,060,048,048,048,048,048,048,048,048,060,000,000,000,000}, _
{008,028,054,099,000,000,000,000,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,000,000,000,000,000,000,000,000,255,000,000}, _
{012,012,024,000,000,000,000,000,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,030,048,062,051,051,051,110,000,000,000,000}, _
{000,000,007,006,006,030,054,102,102,102,102,062,000,000,000,000}, _
{000,000,000,000,000,062,099,003,003,003,099,062,000,000,000,000}, _
{000,000,056,048,048,060,054,051,051,051,051,110,000,000,000,000}, _
{000,000,000,000,000,062,099,127,003,003,099,062,000,000,000,000}, _
{000,000,028,054,038,006,015,006,006,006,006,015,000,000,000,000}, _
{000,000,000,000,000,110,051,051,051,051,051,062,048,051,030,000}, _
{000,000,007,006,006,054,110,102,102,102,102,103,000,000,000,000}, _
{000,000,024,024,000,028,024,024,024,024,024,060,000,000,000,000}, _
{000,000,096,096,000,112,096,096,096,096,096,096,102,102,060,000}, _
{000,000,007,006,006,102,054,030,030,054,102,103,000,000,000,000}, _
{000,000,028,024,024,024,024,024,024,024,024,060,000,000,000,000}, _
{000,000,000,000,000,103,255,219,219,219,219,219,000,000,000,000}, _
{000,000,000,000,000,059,102,102,102,102,102,102,000,000,000,000}, _
{000,000,000,000,000,062,099,099,099,099,099,062,000,000,000,000}, _
{000,000,000,000,000,059,102,102,102,102,102,062,006,006,015,000}, _
{000,000,000,000,000,110,051,051,051,051,051,062,048,048,120,000}, _
{000,000,000,000,000,059,110,102,006,006,006,015,000,000,000,000}, _
{000,000,000,000,000,062,099,006,028,048,099,062,000,000,000,000}, _
{000,000,008,012,012,063,012,012,012,012,108,056,000,000,000,000}, _
{000,000,000,000,000,051,051,051,051,051,051,110,000,000,000,000}, _
{000,000,000,000,000,195,195,195,195,102,060,024,000,000,000,000}, _
{000,000,000,000,000,195,195,195,219,219,255,102,000,000,000,000}, _
{000,000,000,000,000,195,102,060,024,060,102,195,000,000,000,000}, _
{000,000,000,000,000,099,099,099,099,099,099,126,096,048,031,000}, _
{000,000,000,000,000,127,051,024,012,006,099,127,000,000,000,000}, _
{000,000,112,024,024,024,014,024,024,024,024,112,000,000,000,000}, _
{000,000,024,024,024,024,000,024,024,024,024,024,000,000,000,000}, _
{000,000,014,024,024,024,112,024,024,024,024,014,000,000,000,000}, _
{000,000,110,059,000,000,000,000,000,000,000,000,000,000,000,000}, _
{000,000,000,000,008,028,054,099,099,099,127,000,000,000,000,000}, _
{000,000,060,102,067,003,003,003,067,102,060,048,096,062,000,000}, _
{000,000,051,000,000,051,051,051,051,051,051,110,000,000,000,000}, _
{000,048,024,012,000,062,099,127,003,003,099,062,000,000,000,000}, _
{000,008,028,054,000,030,048,062,051,051,051,110,000,000,000,000}, _
{000,000,051,000,000,030,048,062,051,051,051,110,000,000,000,000}, _
{000,006,012,024,000,030,048,062,051,051,051,110,000,000,000,000}, _
{000,028,054,028,000,030,048,062,051,051,051,110,000,000,000,000}, _
{000,000,000,000,060,102,006,006,102,060,048,096,060,000,000,000}, _
{000,008,028,054,000,062,099,127,003,003,099,062,000,000,000,000}, _
{000,000,099,000,000,062,099,127,003,003,099,062,000,000,000,000}, _
{000,006,012,024,000,062,099,127,003,003,099,062,000,000,000,000}, _
{000,000,102,000,000,028,024,024,024,024,024,060,000,000,000,000}, _
{000,024,060,102,000,028,024,024,024,024,024,060,000,000,000,000}, _
{000,006,012,024,000,028,024,024,024,024,024,060,000,000,000,000}, _
{000,099,000,008,028,054,099,099,127,099,099,099,000,000,000,000}, _
{028,054,028,000,028,054,099,099,127,099,099,099,000,000,000,000}, _
{024,012,006,000,127,102,006,062,006,006,102,127,000,000,000,000}, _
{000,000,000,000,000,118,220,216,126,027,059,238,000,000,000,000}, _
{000,000,124,054,051,051,127,051,051,051,051,115,000,000,000,000}, _
{000,008,028,054,000,062,099,099,099,099,099,062,000,000,000,000}, _
{000,000,099,000,000,062,099,099,099,099,099,062,000,000,000,000}, _
{000,006,012,024,000,062,099,099,099,099,099,062,000,000,000,000}, _
{000,012,030,051,000,051,051,051,051,051,051,110,000,000,000,000}, _
{000,006,012,024,000,051,051,051,051,051,051,110,000,000,000,000}, _
{000,000,099,000,000,099,099,099,099,099,099,126,096,048,030,000}, _
{000,099,000,062,099,099,099,099,099,099,099,062,000,000,000,000}, _
{000,099,000,099,099,099,099,099,099,099,099,062,000,000,000,000}, _
{000,024,024,126,195,003,003,003,195,126,024,024,000,000,000,000}, _
{000,028,054,038,006,015,006,006,006,006,103,063,000,000,000,000}, _
{000,000,195,102,060,024,255,024,255,024,024,024,000,000,000,000}, _
{000,063,102,102,062,070,102,246,102,102,102,207,000,000,000,000}, _
{000,112,216,024,024,024,126,024,024,024,024,024,027,014,000,000}, _
{000,024,012,006,000,030,048,062,051,051,051,110,000,000,000,000}, _
{000,048,024,012,000,028,024,024,024,024,024,060,000,000,000,000}, _
{000,024,012,006,000,062,099,099,099,099,099,062,000,000,000,000}, _
{000,024,012,006,000,051,051,051,051,051,051,110,000,000,000,000}, _
{000,000,110,059,000,059,102,102,102,102,102,102,000,000,000,000}, _
{110,059,000,099,103,111,127,123,115,099,099,099,000,000,000,000}, _
{000,060,054,054,124,000,126,000,000,000,000,000,000,000,000,000}, _
{000,028,054,054,028,000,062,000,000,000,000,000,000,000,000,000}, _
{000,000,012,012,000,012,012,006,003,099,099,062,000,000,000,000}, _
{000,000,000,000,000,000,127,003,003,003,003,000,000,000,000,000}, _
{000,000,000,000,000,000,127,096,096,096,096,000,000,000,000,000}, _
{000,003,003,067,099,051,024,012,006,115,217,096,048,248,000,000}, _
{000,003,003,067,099,051,024,012,102,115,105,124,096,096,000,000}, _
{000,000,024,024,000,024,024,024,060,060,060,024,000,000,000,000}, _
{000,000,000,000,000,108,054,027,054,108,000,000,000,000,000,000}, _
{000,000,000,000,000,027,054,108,054,027,000,000,000,000,000,000}, _
{136,034,136,034,136,034,136,034,136,034,136,034,136,034,136,034}, _
{170,085,170,085,170,085,170,085,170,085,170,085,170,085,170,085}, _
{187,238,187,238,187,238,187,238,187,238,187,238,187,238,187,238}, _
{024,024,024,024,024,024,024,024,024,024,024,024,024,024,024,024}, _
{024,024,024,024,024,024,024,031,024,024,024,024,024,024,024,024}, _
{024,024,024,024,024,031,024,031,024,024,024,024,024,024,024,024}, _
{108,108,108,108,108,108,108,111,108,108,108,108,108,108,108,108}, _
{000,000,000,000,000,000,000,127,108,108,108,108,108,108,108,108}, _
{000,000,000,000,000,031,024,031,024,024,024,024,024,024,024,024}, _
{108,108,108,108,108,111,096,111,108,108,108,108,108,108,108,108}, _
{108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108}, _
{000,000,000,000,000,127,096,111,108,108,108,108,108,108,108,108}, _
{108,108,108,108,108,111,096,127,000,000,000,000,000,000,000,000}, _
{108,108,108,108,108,108,108,127,000,000,000,000,000,000,000,000}, _
{024,024,024,024,024,031,024,031,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,000,000,031,024,024,024,024,024,024,024,024}, _
{024,024,024,024,024,024,024,248,000,000,000,000,000,000,000,000}, _
{024,024,024,024,024,024,024,255,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,000,000,255,024,024,024,024,024,024,024,024}, _
{024,024,024,024,024,024,024,248,024,024,024,024,024,024,024,024}, _
{000,000,000,000,000,000,000,255,000,000,000,000,000,000,000,000}, _
{024,024,024,024,024,024,024,255,024,024,024,024,024,024,024,024}, _
{024,024,024,024,024,248,024,248,024,024,024,024,024,024,024,024}, _
{108,108,108,108,108,108,108,236,108,108,108,108,108,108,108,108}, _
{108,108,108,108,108,236,012,252,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,252,012,236,108,108,108,108,108,108,108,108}, _
{108,108,108,108,108,239,000,255,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,255,000,239,108,108,108,108,108,108,108,108}, _
{108,108,108,108,108,236,012,236,108,108,108,108,108,108,108,108}, _
{000,000,000,000,000,255,000,255,000,000,000,000,000,000,000,000}, _
{108,108,108,108,108,239,000,239,108,108,108,108,108,108,108,108}, _
{024,024,024,024,024,255,000,255,000,000,000,000,000,000,000,000}, _
{108,108,108,108,108,108,108,255,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,255,000,255,024,024,024,024,024,024,024,024}, _
{000,000,000,000,000,000,000,255,108,108,108,108,108,108,108,108}, _
{108,108,108,108,108,108,108,252,000,000,000,000,000,000,000,000}, _
{024,024,024,024,024,248,024,248,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,248,024,248,024,024,024,024,024,024,024,024}, _
{000,000,000,000,000,000,000,252,108,108,108,108,108,108,108,108}, _
{108,108,108,108,108,108,108,255,108,108,108,108,108,108,108,108}, _
{024,024,024,024,024,255,024,255,024,024,024,024,024,024,024,024}, _
{024,024,024,024,024,024,024,031,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,000,000,248,024,024,024,024,024,024,024,024}, _
{255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}, _
{000,000,000,000,000,000,000,255,255,255,255,255,255,255,255,255}, _
{015,015,015,015,015,015,015,015,015,015,015,015,015,015,015,015}, _
{240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240}, _
{255,255,255,255,255,255,255,000,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,110,059,027,027,027,059,110,000,000,000,000}, _
{000,000,030,051,051,051,027,051,099,099,099,051,000,000,000,000}, _
{000,000,127,099,099,003,003,003,003,003,003,003,000,000,000,000}, _
{000,000,000,000,127,054,054,054,054,054,054,054,000,000,000,000}, _
{000,000,000,127,099,006,012,024,012,006,099,127,000,000,000,000}, _
{000,000,000,000,000,126,027,027,027,027,027,014,000,000,000,000}, _
{000,000,000,000,102,102,102,102,102,062,006,006,003,000,000,000}, _
{000,000,000,000,110,059,024,024,024,024,024,024,000,000,000,000}, _
{000,000,000,126,024,060,102,102,102,060,024,126,000,000,000,000}, _
{000,000,000,028,054,099,099,127,099,099,054,028,000,000,000,000}, _
{000,000,028,054,099,099,099,054,054,054,054,119,000,000,000,000}, _
{000,000,120,012,024,048,124,102,102,102,102,060,000,000,000,000}, _
{000,000,000,000,000,126,219,219,219,126,000,000,000,000,000,000}, _
{000,000,000,192,096,126,219,219,207,126,006,003,000,000,000,000}, _
{000,000,056,012,006,006,062,006,006,006,012,056,000,000,000,000}, _
{000,000,000,062,099,099,099,099,099,099,099,099,000,000,000,000}, _
{000,000,000,000,127,000,000,127,000,000,127,000,000,000,000,000}, _
{000,000,000,000,024,024,126,024,024,000,000,255,000,000,000,000}, _
{000,000,000,012,024,048,096,048,024,012,000,126,000,000,000,000}, _
{000,000,000,048,024,012,006,012,024,048,000,126,000,000,000,000}, _
{000,000,112,216,216,024,024,024,024,024,024,024,024,024,024,024}, _
{024,024,024,024,024,024,024,024,027,027,027,014,000,000,000,000}, _
{000,000,000,000,024,024,000,126,000,024,024,000,000,000,000,000}, _
{000,000,000,000,000,110,059,000,110,059,000,000,000,000,000,000}, _
{000,028,054,054,028,000,000,000,000,000,000,000,000,000,000,000}, _
{000,000,000,000,000,000,000,024,024,000,000,000,000,000,000,000}, _
{000,000,000,000,000,000,000,000,024,000,000,000,000,000,000,000}, _
{000,240,048,048,048,048,048,055,054,054,060,056,000,000,000,000}, _
{000,027,054,054,054,054,054,000,000,000,000,000,000,000,000,000}, _
{000,014,027,012,006,019,031,000,000,000,000,000,000,000,000,000}, _
{000,000,000,000,062,062,062,062,062,062,062,000,000,000,000,000}, _
{000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000}}

Test of an 8bpp implementation:

Code: Select all

#include "fntvgadef.bi"

screenres 640, 480

'' Force an 8x16 character size for the print statement.

width 80, 30

dim as integer i
dim as ubyte ptr font, p

'' The character pixel patterns are defined as an 8x16 matrix, but
'' the default VGA character box is 9x16. The image buffer height
'' is specified as 17 pixels to allow room for the font header.

font = imagecreate(256 * 9, 17)

'' The image buffer is now filled with the default color, which for
'' an 8-bit color depth mode is 0.

'' Set a pointer to the start of the font header, which coincides
'' with the start of the first line of image pixel data, skipping
'' over the image buffer header, which is assumed to be the new
'' 32-byte extended header.

p = font + 32

'' Initialize the first three bytes of the font header with the
'' version, currently 0, and the ASCII codes of the first and
'' last characters.

p[0] = 0
p[1] = 0
p[2] = 255

'' Fill the next 256 bytes with the width of the characters.

for i as integer = 0 to 255
  p[3+i] = 9
next

'' Advance the pointer to the second line of image pixel data.

p = font + 32 + 256 * 9

'' For each set bit in the character pixel patterns, set the
'' corresponding byte in the image pixel data to the character
'' foreground color. For the range of characters where the
'' character must extend entirely across the character box,
'' with no inter-character spacing, duplicate the action of
'' the VGA hardware, making the ninth pixel a duplicate of
'' the eighth.

for row as integer = 0 to 15
  for char as integer = 0 to 255
    i = font_data( char, row )
    if bit(i,0) then p[0] = 15
    if bit(i,1) then p[1] = 15
    if bit(i,2) then p[2] = 15
    if bit(i,3) then p[3] = 15
    if bit(i,4) then p[4] = 15
    if bit(i,5) then p[5] = 15
    if bit(i,6) then p[6] = 15
    if bit(i,7) then p[7] = 15
    if char >= 192 and char <= 223 then p[8] = p[7]
    p += 9
  next
next

print "0123456789"
print
draw string (0,16), "0123456789", , font

print "abcdefghijklmnopqrstuvwxyz"
print
draw string (0,48), "abcdefghijklmnopqrstuvwxyz", , font

print "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print
draw string (0,80), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", , font

for i as integer = 0 to 7
  for j as integer = 0 to 31
    draw string( j * 9, i * 16 + 112 ),chr( i * 32 + j ), , font
  next
next

locate 17,0
print "Variable Types"
print
draw string (0,272), "Variable Types", , font
print "FreeBASIC Manual Table of Contents"
print
draw string (0,304), "FreeBASIC Manual Table of Contents", , font
print "Andre Victor"
print
draw string (0,336), "Andre Victor", , font
print "Windows XP"
print
draw string (0,368), "Windows XP", , font

imagedestroy font

sleep

Test of a 32bpp implementation:

Code: Select all

#include "fntvgadef.bi"

screenres 640, 480, 32

'' Force an 8x16 character size for the print statement.

width 80, 30

dim as integer i
dim as ubyte ptr font, p
dim as uinteger ptr _p

'' The character pixel patterns are defined as an 8x16 matrix, but
'' the default VGA character box is 9x16. The image buffer height
'' is specified as 17 pixels to allow room for the font header.

font = imagecreate(256 * 9, 17, , 32)

'' The image buffer is now filled with the default color, which for
'' a 32-bit color depth mode is &hFFFF00FF.

'' Set a pointer to the start of the font header, which coincides
'' with the start of the first line of image pixel data, skipping
'' over the image buffer header, which is assumed to be the new
'' 32-byte extended header.

p = font + 32

'' Initialize the first three bytes of the font header with the
'' version, currently 0, and the ASCII codes of the first and
'' last characters.

p[0] = 0
p[1] = 0
p[2] = 255

'' Fill the next 256 bytes with the width of the characters.

for i as integer = 0 to 255
  p[3+i] = 9
next

'' Set a uinteger pointer to the second line of image pixel data.

_p = cast(uinteger ptr, font + 32 + 256 * 9 * 4)

'' For each set bit in the character pixel patterns, set the
'' corresponding dword in the image pixel data to the character
'' foreground color. For the range of characters where the
'' character must extend entirely across the character box,
'' with no inter-character spacing, duplicate the action of
'' the VGA hardware, making the ninth pixel a duplicate of
'' the eighth.

for row as integer = 0 to 15
  for char as integer = 0 to 255
    i = font_data( char, row )
    if bit(i,0) then _p[0] = &hffffff
    if bit(i,1) then _p[1] = &hffffff
    if bit(i,2) then _p[2] = &hffffff
    if bit(i,3) then _p[3] = &hffffff
    if bit(i,4) then _p[4] = &hffffff
    if bit(i,5) then _p[5] = &hffffff
    if bit(i,6) then _p[6] = &hffffff
    if bit(i,7) then _p[7] = &hffffff
    if char >= 192 and char <= 223 then _p[8] = _p[7]
    _p += 9
  next
next

print "0123456789"
print
draw string (0,16), "0123456789", , font

print "abcdefghijklmnopqrstuvwxyz"
print
draw string (0,48), "abcdefghijklmnopqrstuvwxyz", , font

print "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print
draw string (0,80), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", , font

for i as integer = 0 to 7
  for j as integer = 0 to 31
    draw string( j * 9, i * 16 + 112 ),chr( i * 32 + j ), , font
  next
next

locate 17,0
print "Variable Types"
print
draw string (0,272), "Variable Types", , font
print "FreeBASIC Manual Table of Contents"
print
draw string (0,304), "FreeBASIC Manual Table of Contents", , font
print "Andre Victor"
print
draw string (0,336), "Andre Victor", , font
print "Windows XP"
print
draw string (0,368), "Windows XP", , font

imagedestroy font

sleep

In the course of doing this, I determined that the 8bpp font can be BSAVEd to a BMP, then BLOADed into an image buffer and used, but a 32bpp font gets corrupted in the process (even though the BMP looks OK).
Eternal_Pain
Posts: 32
Joined: Aug 25, 2007 17:07

Postby Eternal_Pain » Aug 26, 2007 5:27

Hi,
sorry my nescience but, you declare a ubyte ptr 'p' in

Dim As Ubyte Ptr font, p

and the next you use this 'pointer'

p = font + 32

p[0] = 0
p[1] = 0
p[2] = 255

but i think this pointer has no handle to what?

Edit:
Sorry, i've oversight this %)
' Set a pointer to the start of the font header,[...]
p = font + 32

Code: Select all


#include "fntvgadef.bi"

screenres 640, 480, 32

'' Force an 8x16 character size for the print statement.

Width 80, 30

Dim As Integer i
Dim As Ubyte Ptr font, p
Dim As Uinteger Ptr _p

'' The character pixel patterns are defined as an 8x16 matrix, but
'' the default VGA character box is 9x16. The image buffer height
'' is specified as 17 pixels to allow room for the font header.

font = imagecreate(256 * 8, 16)

'' The image buffer is now filled with the default color, which for
'' a 32-bit color depth mode is &hFFFF00FF.

'' Set a pointer to the start of the font header, which coincides
'' with the start of the first line of image pixel data, skipping
'' over the image buffer header, which is assumed to be the new
'' 32-byte extended header.

p = font + 32

'' Initialize the first three bytes of the font header with the
'' version, currently 0, and the ASCII codes of the first and
'' last characters.

p[0] = 0
p[1] = 0
p[2] = 255

'' Fill the next 256 bytes with the width of the characters.

For i As Integer = 0 To 255
  p[3+i] = 8
Next

'' Set a uinteger pointer to the second line of image pixel data.

_p = cast(Uinteger Ptr, font + 32 + 256 * 8 * 4)

'' For each set bit in the character pixel patterns, set the
'' corresponding dword in the image pixel data to the character
'' foreground color. For the range of characters where the
'' character must extend entirely across the character box,
'' with no inter-character spacing, duplicate the action of
'' the VGA hardware, making the ninth pixel a duplicate of
'' the eighth.

For row As Integer = 0 To 15
  For char As Integer = 0 To 255
    i = font_data( char, row )
    If bit(i,0) Then _p[0] = &hffffff
    If bit(i,1) Then _p[1] = &hffffff
    If bit(i,2) Then _p[2] = &hffffff
    If bit(i,3) Then _p[3] = &hffffff
    If bit(i,4) Then _p[4] = &hffffff
    If bit(i,5) Then _p[5] = &hffffff
    If bit(i,6) Then _p[6] = &hffffff
    If bit(i,7) Then _p[7] = &hffffff
    If char >= 192 And char <= 223 Then _p[8] = _p[7]
    _p += 8
  Next
next

Print "0123456789"
Print
Draw String (0,16), "0123456789", , font

Print "abcdefghijklmnopqrstuvwxyz"
Print
Draw String (0,48), "abcdefghijklmnopqrstuvwxyz", , font

Print "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Print
Draw String (0,80), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", , font

For i As Integer = 0 To 7
  For j As Integer = 0 To 31
    Draw String( j * 8, i * 15 + 112 ),Chr( i * 32 + j ), , font
  Next
next

Locate 17,0
Print "Variable Types"
Print
Draw String (0,272), "Variable Types", , font
Print "FreeBASIC Manual Table of Contents"
Print
Draw String (0,304), "FreeBASIC Manual Table of Contents", , font
Print "Andre Victor"
Print
Draw String (0,336), "Andre Victor", , font
Print "Windows XP"
Print
Draw String (0,368), "Windows XP", , font

imagedestroy font

Sleep

''look like better ;o)
''Regards, EP



regards
EP
Eternal_Pain
Posts: 32
Joined: Aug 25, 2007 17:07

Postby Eternal_Pain » Aug 26, 2007 17:10

I've try it and have saved the font so...

Code: Select all

BSave "testfontabc.bmp",font


my testcode...

Code: Select all

Screen 18, 32

Sub getBMPSize (byval Filename as String, byref bmp_W as Integer, byref bmp_H as Integer)
    Dim As Integer FF = Freefile
   
    Open FileName For Binary As #FF
        Get #FF, 19, bmp_W
        Get #FF, 23, bmp_H             
    Close #FF                     
End Sub

Dim font as any ptr
Dim as integer XSize,YSize

getBMPSize "testfontabc.bmp",XSize,YSize
font=imagecreate(XSize,YSize)

BLoad "testfontabc.bmp",font

'' here crashed this Programm... i don't know why oO
''compiled with the -exx option !
Draw String (100,100),"Test 123!",,font

sleep


regards
EP
Eternal_Pain
Posts: 32
Joined: Aug 25, 2007 17:07

Postby Eternal_Pain » Aug 26, 2007 17:33

I've testing zour Data with my own method :o)
so it's work...

Code: Select all

#include "fntvgadef.bi"
Screen 18,32

Dim font as ubyte ptr
font=ImageCreate((256*8),16)

Font[32]=0     ''Internal PixelFormat Header
Font[33]=0     ''Firt char
Font[34]=255   ''last char

For l as integer=0 to 255
    Font[35+l]=8  ''Witdh of the Char
   
    for y as integer=0 to 15
        for x as integer=0 to 7
            if bit(font_data(l,y),x) Then Pset font,(x+(l*8),1+y),&hFFFFFF
        next x
    next y
next l

Draw String (100,100),"Test 123!",,font

sleep


Testing...

Code: Select all

Screen 18, 32

Sub getBMPSize (Byval Filename As String, Byref bmp_W As Integer, Byref bmp_H As Integer)
    Dim As Integer FF = Freefile
   
    Open FileName For Binary As #FF
        Get #FF, 19, bmp_W
        Get #FF, 23, bmp_H             
    Close #FF                     
End Sub

Dim font As Ubyte Ptr
Dim As Integer XSize,YSize

getBMPSize "testfont123.bmp",XSize,YSize
font=imagecreate(XSize,YSize)

''it crashed without these lines... oO(i don't now whats wrong..)?
Bload "testfont123.bmp",font
Font[32]=0     ''Internal PixelFormat Header
Font[33]=0     ''Firt char
Font[34]=255   ''last char
for l as integer=0 to 255
    font[35+l]=8
next l

''compiled with the -exx option !
Draw String (100,100),"Test 123!",,font

Sleep


Yeah, i think i know now why :o)
The BMP is saved with the ALPHA Information=+&hFF000000
thats make the crash, maybe ?
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » Aug 26, 2007 19:46

I didn’t try to determine exactly how and why the 32bpp font data was being corrupted, because saving the font as a BMP wastes so much space, but I did determine that the changes start in the first line, overwriting some of the width values.
Before BSAVE:

Code: Select all

=============================================================================
00000000  07 00 00 00 04 00 00 00 - 00 09 00 00 11 00 00 00  ................
00000010  00 24 00 00 00 00 00 FF - 00 00 00 00 00 00 00 00  .$..............
00000020  00 00 FF 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000030  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000040  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000050  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000060  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000070  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000080  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000090  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
000000A0  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
000000B0  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
000000C0  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
000000D0  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
000000E0  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
000000F0  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000100  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000110  09 09 09 09 09 09 09 09 - 09 09 09 09 09 09 09 09  ................
00000120  09 09 09 FF FF 00 FF FF - FF 00 FF FF FF 00 FF FF  ................

After BLOAD:

Code: Select all

=============================================================================
00000000  07 00 00 00 04 00 00 00 - 00 09 00 00 11 00 00 00  ................
00000010  00 24 00 00 00 00 00 FF - 00 00 00 00 00 00 00 00  .$..............
00000020  00 00 FF FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000030  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000040  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000050  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000060  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000070  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000080  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000090  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
000000A0  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
000000B0  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
000000C0  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
000000D0  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
000000E0  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
000000F0  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000100  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000110  09 09 09 FF 09 09 09 FF - 09 09 09 FF 09 09 09 FF  ................
00000120  09 09 09 FF FF 00 FF FF - FF 00 FF FF FF 00 FF FF  ................
Eternal_Pain
Posts: 32
Joined: Aug 25, 2007 17:07

Postby Eternal_Pain » Aug 26, 2007 20:41

thats the base why I'd at few days write my own Font Routine with my own Font FileFormat based on Pointer maybe without Draw String if i tested what is faster to use ;o)

Regards
EP
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » Aug 26, 2007 22:47

The pixel patterns in fntvgadef.bi are 8x16, but the patterns are intended for use in a 9x16 character box. For this reason the width of the image must be 256 * 9 and the width of the characters must be specified as 9.

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests