[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
The other day, I needed to find the divide (÷) and multiply (×) symbols for use in an arithmetic drill program. They are part of most standard fonts, but where?
I wrote this FontViewer program in an hour or two and found them. ( ÷ has decimal value 247, hexadecimal F7, and × has value 215, hex D7). Since the program uses the OnDrawCell event exit in TStringGrid, I decided it would make a good Delphi-Techniques item.
Characters in fonts are 1 byte, 8 bits, in length. Since each bit is a binary digit, 8 bits can represent 28, or 256 different symbols with values between 0 and 255. . This program displays all 256 possible symbols from a font selected using the TFontDialog component.
The display is a 17*17 stringgrid, with row 0 and column 0 used for labeling the rows and columns. If we "name" the characters with their hexadecimal value we get convenient 2 digit identifiers ranging from 00 to FF. The units position of this identifier is used to label the columns and the leftmost (16's) position to name the rows. So, for example, the space character has decimal value 32, hex 20, and appears in our grid in the row labeled 2 and and column labeled 0.
Most of the work is done by the DrawCell procedure. Borders cells use the InttoHex function to convert row or column numbers to hexadecimal characters, interior cells assign the Fontdialog1 font to the Stringgrid1's canvas, then calculates the numeric value of the character to be displayed as 16*(row-1)+column-1. (The -1's are necessary since row and column zero are used for labels, forcing character 00 to display in row, 1, column 1. )
There's an AdjustGrid procedure here which adjusts the grid size to just enclose the column widths and borders. Seems like TStringGrid should have an Autosize property to handle this,. but I haven't been able to find one.
I thought about increasing grid size to allow for display of larger font sizes, but decided it wasn't worth it. So character displays may get clipped for large font sizes.
Modified: July 29, 2017
Copyright © 2000-2017, Gary Darby All rights reserved.