Announcement

Collapse
No announcement yet.

TrueType Font

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

  • TrueType Font

    Let's say I have a truetype font file alphalcd.ttf...

    How do you load into your own code/exe programatically?
    Is this possible?

    Regards,
    Jules


    ------------------
    Best regards
    Jules
    www.rpmarchildon.com

  • #2
    Read file into string. Is this what you wanted?

    ------------------
    Roy Cline
    Roy Cline

    Comment


    • #3
      Jules,

      I posted the same question some time ago. Search for my name.

      I wanted to know how to register a font by running a program.

      Cheers


      ------------------
      I'd rather be hated for who I am, then being loved for who I am not.
      So here we are, this is the end.
      But all that dies, is born again.
      - From The Ashes (In This Moment)

      Comment


      • #4
        AddFontResource

        [LATER]
        Mr. Pringels posted same time as did I.

        AddFontResource addresses the original challenge only... makes a font from a file available to the current process. It does NOT install the font permanently. For that you need, let me see if I can find it...no, but I found this comment under AddFontResource..
        This function installs the font only for the current session. When the system restarts, the font will not be present. To have the font installed even after restarting the system, the font must be listed in the registry.
        [/LATER]



        [This message has been edited by Michael Mattias (edited February 16, 2007).]
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Roy, sorry, should have specified, I want to render it.

          Steven, Michael, Thanks!

          I'll look for the thread.

          Regards,
          Jules


          ------------------
          Best regards
          Jules
          www.rpmarchildon.com

          Comment


          • #6
            Okay, that was simple enough... loading from file, or from resource. Thanks guys!

            <later> doesn't load from resource as shown below, see post below from MCM for better solution </later>

            you can get the LCD font here: http://members.tripod.com/~mdileo/alphalcd.zip

            Code:
            #RESOURCE "truetype.pbr"  'MyFont RCDATAT alphalcd.ttf   
             
            CASE %WM_INITDIALOG
                         
                        sFontFile = "C:\PowerBasic\Samples\alphalcd.ttf" '<-if from file
                       'sFontFile = "MyFont"                             '<-if from resource/ note: doesn't work
                        lRt& = AddFontResource(BYVAL STRPTR(sFontFile))
                       'SendMessage(%HWND_BROADCAST, %WM_FONTCHANGE, 0, 0) '<--not necessary if confined within your own process.
                       'SendMessage(%HWND_BROADCAST, %WM_SETTINGCHANGE, 0, 0)'<-- ditto
             
                        hFont = PBFormsMakeFont("Alphanumeric LCD",80,400,%FALSE,%FALSE,%FALSE,%ANSI_CHARSET)
             
                    CASE %WM_COMMAND
                        SELECT CASE AS LONG CBCTL
                            CASE %IDC_BUTTON1
                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                                                      
                                    A$ = FORMAT$(123456, "00\:00\:00")
                                    CONTROL SET TEXT CBHNDL, %IDC_LABEL1,A$
                                    CONTROL SEND CBHNDL, %IDC_LABEL1, %WM_SETFONT, hFont, 0
                                    CONTROL REDRAW CBHNDL, %IDC_LABEL1
                                     
                                END IF
             
                        END SELECT
                         
                    CASE %WM_DESTROY
                        DeleteObject hFont
                        RemoveFontResource( BYVAL STRPTR(sFontFile))  '<--corrected VARPTR to STRPTR per MCM catch.

            ------------------




            [This message has been edited by Jules Marchildon (edited February 18, 2007).]
            Best regards
            Jules
            www.rpmarchildon.com

            Comment


            • #7
              Another cool effect today...

              A few comments...

              First.....
              Code:
              lRt& = AddFontResource(BYVAL STRPTR(sFontFile))
              ...
                    RemoveFontResource( BYVAL VARPTR(sFontFile))
              Both lines should use VARPTR if sFontFile = ASCIIZ
              Both lines should use STRPTR if sFontFile = STRING

              Second... what are the 'use and redistribution' rules on that font? There is precisely zero info in the zip file.

              Third, anyone know where there might be a "seven-segment LED type font" available?

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Ok, I found a font at Mr.Harvey Twyman's Web site. http://www.twyman.org.uk/Fonts/ . Free, too!

                I combined this with today's other neat feature (set numbers whilst button is down by Pierre Bellisle) to arrive at this PB/WIN 8x demo code:

                (oops, needed to change szFontFile to STATIC)(Ok, so I'm lazy sometimes myself).

                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
                 STATIC 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)
                       ' LED font would not work with 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,   USING$("Count #,", TimerCount)
                         
                     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 / LED FONT", , , 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
                '______________________________________________________________________________
                Wasn't someone asking about a 'digital' clock display earlier this week?

                MCM




                [This message has been edited by Michael Mattias (edited February 17, 2007).]
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  That's good Michael, thanks for sharing!

                  I tested the 7 segment and 3D version loading as a file and all works well.
                  however, when embedded into a resource as done earlier with the alphalcd.ttf file,
                  the 7 segment will not load, returns "0" ...some more homework.

                  Also, nice effect is to change the forecolor and backcolors...
                  CONTROL SET COLOR hDlg, %IDC_LABEL3, %RED, %BLACK

                  Regards,
                  Jules


                  ------------------


                  [This message has been edited by Jules Marchildon (edited February 18, 2007).]
                  Best regards
                  Jules
                  www.rpmarchildon.com

                  Comment


                  • #10
                    ..when embedded into a resource as done earlier with the alphalcd.ttf file, the 7 segment will not load, returns "0" ...some more homework.
                    well.... you could take the real man's fast route to a solution: cheat!

                    store the file as a user defined resource .. and extract it to temp file at runtime using....
                    user-defined resource demo january 26 2003

                    mcm

                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      I tricked myself again! The original test I did with embedding it into a resource,..
                      -> #RESOURCE "truetype.pbr" 'MyFont RCDATAT alphalcd.ttf
                      ...actually yeilded errornous results, ...while playing around with "load from file first", I had
                      this line in the code -> SendMessage(%HWND_BROADCAST, %WM_FONTCHANGE, 0, 0) ,.. and later
                      testing loading the .ttf from resource & since I don't turn off or reset my computer that often,
                      the alphalcd.ttf font continued to reside on my system, and it didn't mater if I loaded from file
                      or resource, when I created the font, it worked anyway. Well, I'm not always the sharpest tool in the shed!!
                      Just wanted to corret myself, it didn't work using that particular load from resource method.
                      But,... Michaels excellent suggestion looks promising. Thanks!

                      Regards,
                      Jules



                      ------------------
                      Best regards
                      Jules
                      www.rpmarchildon.com

                      Comment


                      • #12
                        Thanks, Michael & Jules. Now that I know about those API's, I can
                        start playing around. Thanks for the link to the free "7 Segment"
                        font, Michael. I've wanted such a font for a long time, and now am at
                        a time when I will start playing with this stuff.


                        ------------------
                        Clay 's Website
                        mailto:[email protected][email protected]</A>

                        Comment


                        • #13
                          If you really are grateful, the person to thank is Harvey Twyman.

                          I sent him a thank you note; you can, too.

                          (There's a clickable email link at the referenced site.)

                          MCM


                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            Yup, very good point, Michael. I'll do that sometime during these
                            AM hours.


                            ------------------
                            Clay 's Website
                            mailto:[email protected][email protected]</A>

                            Comment


                            • #15
                              Nothing - and I mean nothing - encourages 'code contributors' more than the occasional thank-you note. Nothing.

                              (Did I mention 'nothing?')



                              [This message has been edited by Michael Mattias (edited February 20, 2007).]
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment

                              Working...
                              X