OnDrawCell Font Viewer

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

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.  

Hexadecimal Primer

We need 16 symbols to represent hexadecimal, or base16 numbers,  the same way we need 10 symbols for decimal numbers.   "Hexadecimal"  is commonly shortened to "hex".  In hex, we use 0-9 and  A-F to represent the decimal numbers  0-15.   In decimal, each position to the left  represents next higher power of 10; in hexadecimal positions to the left represent higher powers of 16. 

 So instead of the 100's, 10's, 1's columns, we have the 256's, 16's, 1's columns. For example:
'10' in decimal represents one 10 and zero 1's. ('0A' in hex) 
'10' in hex represents one 16 and zero 1's. ('16' in decimal) 
'FF' in hex represents 15 16's plus 15 1's (or '255' in decimal).   

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.     

Browse/Download Programs 

bulletDownload source
bulletDownload executable

Further Explorations

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

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.