News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using TrueType Fonts

Started by OldTimer, November 13, 2008, 02:25:47 AM

Previous topic - Next topic

OldTimer

Hi,
     I'm writing a program that will print a diary using a variety of fonts and Dingbats.

      My first problem was obtaining the font name from within the font file.    Google gave me several snippets but most were in 'C' or VB.  The MASM one I chose uses an un-documented API function, GetFontResourceInfoW in gdi32.dll.   I had to modify two lines that used a chr$ operator and didn't compile.

              invoke LoadLibrary,chr$("gdi32.dll")    ; is chr$ a macro ?

      First the font is loaded into Windows,     
              invoke AddFontResource,addr FontFileNameAsciiz

      Then this bit of code will obtain the Fontname.
              GetFontResourceInfoW,(ptr to Font Filename in Unicode),
                                  (ptr to sizeof receive structure) ,
                                  (ptr to receive structure [92bytes]),
                                  2 ; function 2=put fontname in structure

        [The fontname starts at offset 28 in the receive structure.]

      Lastly, remove the font from windows.
             invoke RemoveFontResource,addr FontFileNameAsciiz
 
      I then discovered that some fonts do not contain numbers.   I had to manually identify and remove them.  Can this be done by code ?

      Next problem was font size.  I wanted the output text string to fill a specified area on the screen.   I wrote two loops that incrementally increased the font size until this was achieved.

                increase 'x' value
                invoke  CreateFont
                invoke  SelectObject
                invoke  GetTextExtentPoint
                invoke  SelectObject   ; to release the font
                invoke  DeleteObject
   compare  SIZEL.x to width of area on screen
                loop if smaller
                increase 'y' value
                etc.

      There has to be an easier way.

      Now for the unsolved problem, the Dingbat files.   As mentioned earlier, I need to find out the characters in the file that have a fontface.   Some Dingbat fonts only have a few pictures, so how do you marry the pic to an ascii character ?

      Now for something completely different.
      The template that I'm using has :-
                invoke  SetMapMode, hdcPrn, MM_ISOTROPIC
                invoke  SetWindowExtEx, hdcPrn, 1500, 1500, NULL

      As a result, the vertical positions for TextOut have to be negative.
      Why is it so ?

(BTW the Dingbat or Flying Dingo is extinct in Australia and its cousin, the Flying Fox, is endangered.   In the country a Dingbat is an animal whose droppings cause dents in your car's roof or bonnet.    In town, a Dingbat is the tool a panelbeater uses to remove such dents.   Just thought you'd like to know.)

Cheers,
Les.

donkey

I once wrote an example of enumerating fonts and creating a menu using the fonts. It is still available on my website but I guess the thread I posted here with it is relegated to the old forum which is no longer accessible. So , I will post it here, it has a few font functions which you might find useful though it was mostly to demonstrate owner-drawn menus...



[attachment deleted by admin]
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

OldTimer

   Thanks Donkey.   Your program lists all the available fonts in the system.   I need to obtain a list of the individual typefaces (pics) within an individual font file and the ascii keys that they relate to.  For example, the attached zip contains a font called Mrmen.ttf.  It contains 38 drawings of the Mr Men characters.  I have hard coded this font into my programs data section.   To create the list I single stepped through the file and wrote down the list of ascii chars that were programmed in the font.   

.data
Pic1        db    '\masm32\Declan\Pics\Mrmen.ttf',0
CharList1   db    'abcdefghijklABCDEFGHIJKLMNOPQRSTUVWXYZ',0

    I've got over 30 more font files to go !    It would save time if there was a way of writing a routine to create the list on-the-fly.    I've created a cut-down version of the program just to display the pics, so my "worst case" option is to get the program to step through the entire alphabet, upper and lower, for each font file and for me to sit at the keyboard and hit a 'yes' or 'no' key.

Cheers,
Les.


[attachment deleted by admin]

Mark Jones

Hello Les, great project. May I suggest taking a look here:

http://www.truetype-typography.com/ttspec.htm

It may be possible to programatically analyze the font file itself to determine which characters are (and are not) available.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

drhowarddrfine

Just as an aside, I was just reading an article the other day from a typographer.  Apparently they despise "true type" because it doesn't faithfully render font faces as they were meant to be.  I'll try and find it.