News:

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

Enumerate all fonts installed

Started by starzboy, December 17, 2008, 10:45:58 AM

Previous topic - Next topic

starzboy

Hello guys, i have been looking lately at EnumFonts, as i need to list all fonts installed on the system.
So far i have been unsuccessfull, can some please some shed some light on it or perhaps an example.

Thnakyou

kromag

I just seen a post by Donkey where
he claims to have something doing the same on his site!
---
Will

donkey

The example is for a font menu, the actual snippet for enumerating fonts is this....

// load the LOGFONT structure to pass info to the enumeration API
mov B[lf.lfCharSet],ANSI_CHARSET
mov B[lf.lfFaceName],0
mov B[lf.lfPitchAndFamily],0
// We need a device context in order to enumerate fonts, any screen window will do (or printer DC if you want printer fonts)
invoke GetDlgItem,[hDlg],1001
mov esi,eax
invoke GetDC,esi
mov ebx,eax
invoke EnumFontFamiliesExA,ebx,ADDR lf,OFFSET EnumFontFamExProc,[SubMenuHandle],0
// release the device context
invoke ReleaseDC,esi,ebx


EnumFontFamExProc FRAME lpelfe,lpntme,FontType,lParam
uses ebx

// The font data is passed in a ENUMLOGFONTEX struct at address lpelfe
// you can get the font name from that structure in ENUMLOGFONTEX.LOGFONT.lfFaceName
// Or alternatively you can use the full font name in ENUMLOGFONTEX.elfFullName
// Note that ENUMLOGFONTEX.elfFullName doesn't provide the same data on 9x and NT based systems
mov ebx,[lpelfe]
add ebx,ENUMLOGFONTEX.elfFullName
// EBX points to the full font name

... Do what you want to with the font name here

// continue the enumeration until all fonts are processed
mov eax,TRUE
RET
ENDF
"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

Rainstorm

just a related question. . .
suppose i want to display info on  fonts that are not in the font table but like in a folder, what would i do ?
successively load each font into the font table, get the info i want.. then unload it ? or is there some other way ?
- - - - - - - - - - -
Also, suppose i supply a typeface name in the LOGFONT structure, but that font wasn't found..would the function return some other font that matched the criteria most closely ? - and if it did.. would it alert me to the fact that it is not the typeface name i asked for .

thanks!

donkey

Since the API really only allows you to get information about a font with reference to the device context and handle of the font, it must be added to the font table before you can examine it. Windows allows an application to add a font (for its use only if you like) and remove it, you can add the font using AddFontResource enumerate it then remove it using RemoveFontResource. Alternatively you can examine the file directly by writing a parser to read the TTF file format (if you are working with true type fonts) which is very similar to RIFF files in structure.
"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

Rainstorm

thanks for the advice & the useful link   :thumbu

xandaz

    i kinda took this from your post donkey and made an example out of it, Very simple thingy. Thanks for the help donkey. It was something i dodnt know how to do.

xandaz

   Hey... i was trying to upgrade the enumfonts thingy to show the actually font draw within the listbox but things aren't working yet. I'm just processing ODA_DRAWENTIRE at the moment. I don't know if there's something wrong with the ENUMLOGFONTEX pointer. Can someone check this out? Thanks

dedndave

your attachment has no enumeration code
it makes a nice window, is all   :bg

i did notice the absence of
WndProc PROC uses edi hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

xandaz

   Sorry. I'm not sure what you mean but i'm devastated. Thanks

dedndave

in WndProc, you use EDI without preserving it

xandaz

   yeah.... i tried uses edi esi and doesn't work wither.

dedndave

well - that is A problem - not the only problem

in the EnumFontFamExProc callback function, you are not accessing the LOGFONT structure members
it says you can cast it as a ENUMLOGFONTEX struc, but that over-complicates things if you do not need the metrics
just cast it as a LOGFONT to access the members

dedndave

if you do want the metrics, to access members of the LOGFONT part of the ENUMLOGFONTEX struc, use...
assume  esi:PTR ENUMLOGFONTEX
mov eax,dword ptr [esi].elfLogFont.lfFaceName

to get the first 4 letters of the name of the font, for example

the LOGFONT struc is a sub-member of the ENUMLOGFONTEX struc
it is named elfLogFont

xandaz

   Damn i get register value overwritten by invoke. Any ideas on what this means? Can fix it.