Announcement

Collapse
No announcement yet.

Font filename to typeface name conversion?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    If you have a font FILE, you don't want to CreateFont(), you want to AddFontResource().

    I know there is a demo of doing that here somewhere. Something to do with 7-segment LED fonts. If you can't find it let me know, because I know I did it and have it here.. somewhere.

    I found it pretty quick (thank you Ultra-Edit "Find in Files")

    What I could not find was a way to find the font face name given only the file name. I also see you DO need to "Create Font", but you can only do that AFTER you AddFontResource.

    Let's look in the SDK for something which might tell us the face name(s?) of fonts in a file...no luck.

    I guess 'maybe' you could enum all the type faces before, then AddFontResource(), then enum again to know what faces were added by the AddFontResource, but I really don't like the sound of that for some reason.

    MCM


    ' While_button_down.bas
    ' Little example using WM_SETCURSOR message and a timer...

    'Pierre

    '
    Code:
    #COMPILE EXE '#Win 8.03#
    #REGISTER NONE
    #INCLUDE "Win32Api.inc" '#2005-01-27#
    #INCLUDE "Pbforms.inc"
    OPTION EXPLICIT
    
    %ButtonOne = 101
    %TimerOne  = 201
    %labelOne  = 301
    '______________________________________________________________________________
    
    CALLBACK FUNCTION DlgProc
     STATIC TimerCount AS LONG
     LOCAL  hCtrl AS LONG, szFontFile AS ASCIIZ * %MAX_PATH
     LOCAL  hFont AS LONG, I AS LONG
    
     LOCAL  sFontFace AS STRING
    
    
     SELECT CASE CBMSG
    
       CASE %WM_INITDIALOG
           CONTROL HANDLE  CBHNDL, %LabelOne TO hCtrl
           ' file from Jules Marchildon / tripod
            szFontFile     =  "alphalcd.ttf"
            sFontFace  = "Alphanumeric LCD"
           ' file from Harvey Twyman
            szFontFile     =  "7 Segment.ttf"
            sFontFace      =  "7 Segment"
    
    
    
           I = AddFontResource(BYVAL VARPTR(szFontFile))
           MSGBOX USING$ ("Added # fonts", I)
    
           'hFont = PBFormsMakeFont(sFontFace, 36, 200,%FALSE,%FALSE,%FALSE,%ANSI_CHARSET)
    
           hFont = PBFormsMakeFont(sFontFace, 30, 200,%FALSE,%FALSE,%FALSE,%DEFAULT_CHARSET)
           IF ISFALSE hFont THEN
               MSGBOX "MakeFont failed"
           END IF
           CONTROL SEND CBHNDL, %LabelOne, %WM_SETFONT, hFont, %NULL
           CONTROL SET USER CBHNDL, %LabelOne, 1, hFont
    
    
       CASE %WM_SETCURSOR
         IF (CBWPARAM = GetDlgItem(CBHNDL, %ButtonOne)) AND _ 'Is it the button handle
            (HI(WORD, CBLPARAM) = %WM_LBUTTONDOWN) THEN       'Is button pushed
           DIALOG SET TEXT CBHNDL, HEX$(HI(WORD, CBLPARAM)) & " : Button is down "
           SetTimer CBHNDL, %TimerOne, 100, BYVAL %NULL       'Set a 100 miliseconds timer
         ELSE
           DIALOG SET TEXT CBHNDL, HEX$(HI(WORD, CBLPARAM)) & " : Button is up"
           KillTimer CBHNDL, %TimerOne
         END IF
    
       CASE %WM_DESTROY
           CONTROL GET USER CBHNDL, %LabelOne, 1 TO hFont
           DeleteObject  hFont
           RemoveFontResource( BYVAL VARPTR(szFontFile))
    
    
       CASE %WM_TIMER
         SELECT CASE CBWPARAM
           CASE %TimerOne
             INCR    TimerCount
             CONTROL SET TEXT CBHNDL, %ButtonOne, "Timercount :" & STR$(Timercount)
             CONTROL SET TEXT CBHNDL, %LabelOne,   FORMAT$(TimerCount, "Count  00\:00\:00")
    
         END SELECT
    
       CASE %WM_COMMAND
         SELECT CASE LOWRD(CBWPARAM)
           CASE %ButtonOne
             IF CBCTLMSG = %BN_CLICKED THEN
             END IF
         END SELECT
    
      END SELECT
    
    END FUNCTION
    '______________________________________________________________________________
    
    FUNCTION PBMAIN()
     LOCAL hDlg AS DWORD
    
     DIALOG NEW %HWND_DESKTOP ,"Button down", , , 200, 120, _
            %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
    
     SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION)
    
     CONTROL ADD BUTTON, hDlg, %ButtonOne, "Button", 50, 43, 100, 15, _
             %BS_CENTER OR %BS_VCENTER OR %WS_TABSTOP, %WS_EX_LEFT
    
     CONTROL ADD LABEL, hDlg, %LabelOne, "", 50,63,120, 80
    
    
     DIALOG SHOW MODAL hDlg CALL DlgProc
    
    END FUNCTION
    '______________________________________________________________________________
    
    '
    Last edited by Michael Mattias; 31 Jan 2008, 02:04 PM.

    Leave a comment:


  • John Gleason
    replied
    You could create a scan table to translate all fonts you may need. Any font viewer should provide the typeface names. If you know the exact capitalization of the file names, you don't need the UCASE$.

    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
        LOCAL fileName, typeFaceName AS STRING
        
        filename = "Vera.ttf"
        SELECT CASE AS CONST$ UCASE$(fileName)
           CASE "TIMES.TTF"  : typeFaceName = "Times New Roman"
           CASE "VERA.TTF"   : typeFaceName = "Bitstream Vera Sans"
           CASE "REFSER.TTF" : typeFaceName = "MS Reference Serif"
    '       ...             
    '       ...    'continue until all possible fonts are translated
        END SELECT
        
        ? fileName & " converts to " & typeFaceName
    
    END FUNCTION

    Leave a comment:


  • Dominic Mitchell
    replied
    You have not provided enough information. For example, is the app using embedded fonts?

    Due to the lack of info, the only course of action I will suggest at the moment is to use the following registry key to do the mapping.
    By the way, this is not reliable for embedded fonts.

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Fonts

    Leave a comment:


  • C.M. Rouleau
    started a topic Font filename to typeface name conversion?

    Font filename to typeface name conversion?

    Hello,

    In order to make a call to CreateFont, one needs a typeface name, such as "Arial" or "Times New Roman". No problem there. However, I have an application the returns the font filename instead of the typeface name. For example, if I use "Times New Roman" in the application, it returns Times.TTF. So, any thoughts on going from the font file name to the typeface name?

    -CMR
Working...
X