Load font from font file (Not installed on system Font)

Load font from font file (Not installed on system Font)

Postby hebert_j_vargas » Fri Apr 15, 2016 12:01 pm

Hi,
does anybody how to load and use a true type font from a font file?

Regard's
Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20141106)
FiveWin Version: FWHX 15.01
BCC 5.8.2
User avatar
hebert_j_vargas
 
Posts: 99
Joined: Thu Aug 02, 2012 3:21 pm

Re: Load font from font file (Not installed on system Font)

Postby hebert_j_vargas » Fri Apr 15, 2016 7:51 pm

I Found a way to embed the font into the EXE program using GDI+. this is the sample program
Code: Select all  Expand view

#include "Fivewin.ch"
#include "Dll.ch"

function Main()
   local oDlg
   local lFivePro
   local lDialog
   local lObjects
   local nNivel
   local cName
   local cAddress
   local cPhone
   local nAge
   local oBtn
   local oFnt := GetNewFont()

   lFivePro = .T.
   lDialog  = .T.
   lObjects = .F.
   nNivel   = 1
   cName    = SPACE( 10 )
   cAddress = SPACE( 30 )
   cPhone   = SPACE( 30 )
   nAge     = 0

   DEFINE DIALOG oDlg FROM 8, 2 TO 25, 65 ;
      TITLE  "Customer Update"

   @ 1,  1 SAY "&Name:" OF oDlg FONT oFnt
   @ 1,  6 GET cName OF oDlg FONT oFnt
   @ 2,  1 SAY "&Address:" OF oDlg
   @ 2,  6 GET cAddress OF oDlg

   @ 3,  1 GROUP TO 7, 8 LABEL "Products" OF oDlg
   @ 4,  2 CHECKBOX lFivePro PROMPT "&FivePro" OF oDlg
   @ 5,  2 CHECKBOX lDialog  PROMPT "&Dialog"  OF oDlg
   @ 6,  2 CHECKBOX lObjects PROMPT "&Objects" OF oDlg

   @ 3,  9 GROUP TO 7, 17 LABEL "Level" OF oDlg
   @ 4,  10 RADIO nNivel PROMPT "&Novice", "A&vanced", "&Expert" OF oDlg

   @ 4, 25 SAY "&Phone:" OF oDlg
   @ 4, 21 GET cPhone OF oDlg SIZE 60, 11 PICTURE "@R 99-999-9999999"

   @ 6, 25 SAY OemToAnsi( "&Age:" ) OF oDlg
   @ 6, 21 GET nAge OF oDlg SIZE 20, 11


   @ 6,  9 BUTTON oBtn PROMPT  "&Acept"  OF oDlg SIZE 50, 12 ACTION MsgInfo( oBtn:Cargo , ValType( oBtn:Cargo) )
   oBtn:bGotFocus := { | Self, hCtlLost | Self:Cargo := hCtlLost  }


   @ 6, 19 BUTTON "&Cancel" OF oDlg SIZE 50, 12 ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED


return nil
//--------------------------------------------------------------------------//
FUNC GetNewFont(cFont) //Resource Matrix Font
     LOCAL hRes  := FindResource( GetResources(), "MYFONT", 10) //RT_RCDATA )
     LOCAL hFont := LoadResource( GetResources(), hRes )
     LOCAL cResFont := cResToStr("MYFONT",10)
     LOCAL nFonts   := 0
     LOCAL nHandle  := AddFontMemResourceEx( hFont, Len(cResFont), 0, @nFonts)
     LOCAL oFont := TFont():New("ScreenMatrix",0,-11)
     oFont:hFont = CreateFont( { -11, 0, 0,;
                              0,, .f.,;
                              .f., .f., 1,;
                              0, 0,;
                              0, 0, "ScreenMatrix" } )
RETURN oFont
//--------------------------------------------------------------------------//
DLL32 FUNCTION AddFontMemResourceEx(nAddr AS PTR, nLen AS DWORD, nPdv AS LONG, @nCnt AS DWORD) ;
      AS LONG PASCAL FROM "AddFontMemResourceEx" LIB "gdi32.dll"
DLL32 FUNCTION RemoveFontMemResourceEx( nHnd AS LONG) AS BOOL;
              PASCAL FROM "RemoveFontMemResourceEx" LIB "gdi32.dll"
 


In my sample I used "ScreenMatrix.ttf" font
This is RC File:
Code: Select all  Expand view

ico ICON .\..\ICONS\FiveWin.ico

#ifdef __FLAT__
  1 24 "WinXP/WindowsXP.Manifest"
#endif

#ifdef __64__
  1 24 "WinXP/WindowsXP.Manifest64"
#endif

MYFONT RCDATA "ScreenMatrix.ttf"
 
Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20141106)
FiveWin Version: FWHX 15.01
BCC 5.8.2
User avatar
hebert_j_vargas
 
Posts: 99
Joined: Thu Aug 02, 2012 3:21 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 72 guests