Announcement

Collapse
No announcement yet.

Why wont FONT NEW load the font I request?

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

  • Why wont FONT NEW load the font I request?

    Would some kind person tell me why the first program prints text using the font I request, but the second program prints the text in a substitute font? This is driving me up the wall. And, yes, I have tried installing the font on my Win7 system first rather than trying to use it directly from its ttf file, but the result is the same - "FONT NEW" always gets a substitute font.

    Unfortunately I'm not allowed to upload the font file.

    My compiler is CC 6.02

    This prints the text in the requested font...

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    
    FUNCTION PBMAIN () AS LONG
     LOCAL hWin, hFnt, hDC AS LONG
     LOCAL sCPath, sFontFileName, sFName AS STRING
    
     GRAPHIC WINDOW NEW "", 0, 0, 1000, 1200 TO hWin
     GRAPHIC ATTACH hWin, 0, REDRAW
     GRAPHIC COLOR %GREEN, %BLACK
     GRAPHIC CLEAR
     GRAPHIC SET WRAP -1
     GRAPHIC REDRAW
    
     sCPath = EXE.PATH$ + "\unicode_fonts\Noto\NotoSansDisplay-hinted\"
    
     sFontFileName = sCPath + "NotoSansDisplay-Thin.ttf" + $NUL
    
     AddFontResourceEx(BYVAL STRPTR(sFontFileName), %FR_PRIVATE, 0)
    
     sFName = "Noto Sans Disp Thin" 
    
     GRAPHIC GET DC TO hDC
    
     hFnt = CreateFont(50,0,0,0,%FW_THIN,%FALSE,%FALSE,%FALSE,%DEFAULT_CHARSET,%OUT_OUTLINE_PRECIS, %CLIP_DEFAULT_PRECIS, %CLEARTYPE_QUALITY, %VARIABLE_PITCH, BYVAL STRPTR(sFName))
    
     SelectObject(hDC, hFnt)
    
     TextOut(hDC, 0, 0, BYVAL STRPTR(sFName), LEN(sFName))
    
     GRAPHIC REDRAW
     GRAPHIC WAITKEY$
    
     DeleteObject(hFnt)
     RemoveFontResourceEx(BYVAL STRPTR(sFontFileName), %FR_PRIVATE, 0)
    
    END FUNCTION
    This doesn't...

    Code:
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "WIN32API.INC"
    
    FUNCTION PBMAIN () AS LONG
     LOCAL hWin, hFnt, hDC AS LONG
     LOCAL sCPath, sFontFileName, sFName, sTxt AS STRING
    
     GRAPHIC WINDOW NEW "", 0, 0, 1000, 1200 TO hWin
     GRAPHIC ATTACH hWin, 0, REDRAW
     GRAPHIC COLOR %GREEN, %BLACK
     GRAPHIC CLEAR
     GRAPHIC SET WRAP -1
     GRAPHIC REDRAW
    
     sCPath = EXE.PATH$ + "\unicode_fonts\Noto\NotoSansDisplay-hinted\"
     sFontFileName = sCPath + "NotoSansDisplay-Thin.ttf" 
    
     AddFontResourceEx(BYVAL STRPTR(sFontFileName), %FR_PRIVATE, 0)
    
     sFName = "Noto Sans Disp Thin"
    
     FONT NEW sFName, 20 , 0, 0, 0, 0 TO hFnt
     GRAPHIC SET FONT hFnt
    
     GRAPHIC PRINT sFName
    
     GRAPHIC REDRAW
     GRAPHIC WAITKEY$
    
     FONT END hFnt
    
     RemoveFontResourceEx(BYVAL STRPTR(sFontFileName), %FR_PRIVATE, 0)
    
    END FUNCTION

  • #2
    Might be relevant, might not be: in the second function you've omitted the trailing $NUL from the assignment sFontFileName = ...
    Dan

    Comment


    • #3
      I tried in the FONT NEW example
      FONT NEW sFName, 33, 0, 0, 0, 0 TO hFnt
      and didn't see any difference from the CreateFont example.
      Rod
      "To every unsung hero in the universe
      To those who roam the skies and those who roam the earth
      To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

      Comment


      • #4
        Thanks, Dan. The $NUL was there when I pasted the code in my message. I must have inadvertently deleted it while removing all the extraneous debugging code from the listing.

        Comment


        • #5
          Hi Rodney. Which font did you try? Thanks.

          Comment


          • #6
            changed mind
            Dale

            Comment


            • #7
              Mark,

              Try FONT NEW sFName, 24 , 0, 1, 0, 0 TO hFnt

              (Font available here http://www.google.com/get/noto/)
              Last edited by Dave Biggs; 10 May 2018, 06:59 PM.
              Rgds, Dave

              Comment


              • #8
                Dave, that fixed it. I thought zero was the value for the default char set. Thanks very much.

                Comment


                • #9
                  Originally posted by Mark Bullivant View Post
                  Dave, that fixed it. I thought zero was the value for the default char set. Thanks very much.
                  Help is a bit confusing on that issue.

                  It says
                  "You may use the value zero (0) for any of the numeric parameters to designate that the compiler should use the default for that item."

                  But it also says under charset$:
                  0 ANSI CharSet
                  1 Default CharSet


                  IOW: The "default for the parameter charset" is not "Default Charset", it is "ANSI Charset".
                  --
                  [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                  PNG Domain Hosting[/URL]

                  Comment

                  Working...
                  X