NTK and The NTK Project
are properties of Jn Dechereux
Home | Documentation | FAQ.

Vanilla 1.1.8 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    •  
      CommentAuthorwaltspon
    • CommentTimeApr 3rd 2017
     
    Hello everyone,
    I'm new and would like to know how can I get a font object from a font which is not installed in the Windows font directory? i.e. The TTF file (a barcode font)is located in same dir as my program exe. Any idea or piece of code?
    TIA
    Walter
    •  
      CommentAuthorccarrignon
    • CommentTimeApr 4th 2017 edited
     
    Hi Walter,
    You should use SKN_LoadExternalTTF() & SKN_DeleteTTF() functions.
    e.g.
    ...
    aExtTTF := {}
    AADD( aExtTTF, { "SWZ721C.TTF", "SWZ721C.FOT", "SWIS721 BLKCN BT" } )
    AADD( aExtTTF, { "SWZ721KC.TTF", "SWZ721KC.FOT", "SWIS721 CN BT" } )
    AADD( aExtTTF, { "PAGODA.TTF", "PAGODA.FOT", "PAGODA SF" } )
    AADD( aExtTTF, { "REPORTER.TTF", "REPORTER.FOT", "REPORTER-TWO" } )
    FontDir := NTK_GetCurrentDirectory()+"\Resources\Font\"
    // Delete existing .FOT files
    FOR i:= 1 TO 4
    DELETE FILE (FontDir+aExtTTF[i,2])
    NEXT
    SKN_LoadExternalTTF(FontDir,aExtTTF)
    CREATE FONT hObjFONT1 FACENAME "SWIS721 BLKCN BT" SIZE 14 WIDTH 0 WEIGHT 0
    CREATE FONT hObjFONT2 FACENAME "SWIS721 CN BT" SIZE 14 WIDTH 0 WEIGHT 0
    CREATE FONT hObjFONT3 FACENAME "PAGODA SF" SIZE 20 WIDTH 0 WEIGHT 0
    CREATE FONT hObjFONT4 FACENAME "REPORTER-TWO" SIZE 30 WIDTH 0 WEIGHT 0
    ...
    Check out this sample: \wntk4hrb\NtkAddon\NTKSkin\DEMO1\DemoNTKSkin.prg to find out more.
    HTH
    -Chris
    •  
      CommentAuthorwaltspon
    • CommentTimeApr 4th 2017
     
    Hello Chris,
    Thank you for your help. I tried with your code. Of course, I made the needed amendements related to my font, but no success. I even can't link my App, always have the following error:
    Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
    Error: Unresolved external '_HB_FUN_SKN_LOADEXTERNALTTF' referenced from C:\
    CRYSTALP\CRTEST.PRG
    Info: Link time = 0.07 seconds
    After some readings, I found out SKN_* functions are part of the NTKSkin library.
    Unfortunately I only have a NTK Pro version. so cannot use your solution. :(
    Any other idea/workaround?
    Walter
    •  
      CommentAuthorccarrignon
    • CommentTimeApr 5th 2017
     
    Morning Walter,
    Indeed, I confirm the code I've posted works well but requires NTKSkin.lib and by the way NTK-Premium.
    Sorry I do not know of any other means. I'm just an average programmer not a win32 guru.
    But no doubts some people here are better experimented than me to help you fixing your issue.
    -Chris
    •  
      CommentAuthorxbasefan
    • CommentTimeApr 6th 2017 edited
     
    hi walter, welcome aboard.
    well, as you don't have NTK-Premium it's a bit more tricky but doable.
    first, you have to write a wrapper to get access to the CreateScalableFontResource win32 api
    _DLL FUNCTION CreateScalableFontResource( nHidden AS int, cFontRes AS string , cFontFile AS string ,;
                  cCurrentPath AS string  ) AS bool  PASCAL:GDI32.CreateScalableFontResourceA
    

    and then, another piece of code to deal with
    . . .
    hFontDigit := nil
    . . .
    // Load, then create a memory font object from an external TTF file
    IF CreateScalableFontResource( 0,;   // 0=RW permission - 1=RO permission+Hidden from other apps.
                                   ".\res\digital-7 (mono).fot",;  // filename for font resource
                                   ".\res\digital-7 (mono).ttf",;  // filename for scalable font
                                   NULL ) // path to font file
    
       If NTK_AddFontResource( ".\res\digital-7 (mono).fot" ) >0
          CREATE FONT hFontDigit FACENAME "DIGITAL-7" SIZE -20 WIDTH 7 WEIGHT FW_MEDIUM PITCH FIXED_PITCH
          if hFontDigit == 0
             alert( "cannot Create the Digital font, so use a default one... " )
             hFontDigit := NTK_GetStockObject( SYSTEM_FONT )
          endif
       Else
          alert( "cannot add the Digital font as a new resource, so use a default one... " )
          hFontDigit := NTK_GetStockObject( SYSTEM_FONT )
       EndIf
    ELSE
       alert( "cannot Load the Digital font, so use a default one... " )
       hFontDigit := NTK_GetStockObject( SYSTEM_FONT )
    ENDIF
    . . .
    

    as u can see nothing that can't be overcome.
    also, for a fully working example just look at the following demo:
    c:\wntk4hrb\NTKRAD\activeXdemo\GoogleEarth.prg
    hope it inspires you.
    wilson
    •  
      CommentAuthorwaltspon
    • CommentTimeApr 7th 2017
     
    Hey xbasefan,
    Just made a few changes to your code and now fits my needs perfectly. :)
    Thank you so much for your help. Actually, I had heard about
    CreateScalableFontResource(), but had no idea on how to implement it
    and msdn related documentation is definitely not very helpful.
    Thousand thanks.
    walter
Add your comments
  • Format comments as