Sign in to follow this  
Followers 0
nodrugs15

AddFontResource

6 posts in this topic

#1 ·  Posted (edited)

Hi,

I have a problem with fonts. I'd like to use a custom font which is not originally in windows.

The function I need for this is called AddFontResource from the gdi32 dll.

I'm trying and fail most of the times. (Yes sometimes it works, and a rerun later it doesn't)

There is one thing to say: Later in the script there is opened a child window with an transparent image.

Later both windows (The main and the image) are viewed.

Here is the code of the main window

;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;add constants;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;add other scripts;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include "load.au3"
#include "new.au3"
#include "save.au3"
#include "savegame.au3"
#include "inbox.au3"
#include "game.au3"
#include "manager.au3"
; Declare variables
global $web = "http://gocops.sourceforge.net"
global $svn = "https://gocops.svn.sourceforge.net/svnroot/gocops"
;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;main window;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;
; create window
$gc2tr = guicreate("Go Cops! 2: The Reanimation", 400, 500)
;get version
$version = iniread ( @AppDataDir & "Go Cops!settings.ini", "general", "version", "stable")

; create title-labels
$gocops   = guictrlcreatelabel("Go Cops! 2", 25, 225, 350, 100)
$rean   = guictrlcreatelabel("The reanimation", 25, 300, 150, 50)
; set font of title labels
     guictrlsetfont($gocops, 48, 800, 2, "Nobile")
     guictrlsetfont($rean, 12, 400, 2, "Nobile")
; create version-information
$ver   = guictrlcreatelabel("Version 1.2 (" & $version & ")", 1, 487)
; create credit
$created  = guictrlcreatelabel("Created by Jeroen De Meerleer", 252, 487)
; create buttons
$new   = guictrlcreatebutton("New game", 50, 350, 100, 50)
$save   = guictrlcreatebutton("Open saved game", 250, 350, 100, 50)
$manager  = guictrlcreatebutton("Open manager", 150, 350, 100, 50)
; create logo
$pic = guicreate("", 200, 200, 100, 25, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gc2tr)
$logo = guictrlcreatepic(@AppDataDir & "Go Cops!imageslogo.gif", 0, 0, 200, 200)
     ; view window
     GUISetState(@SW_SHOW, $gc2tr)
     GUISetState(@SW_SHOW, $pic)
while 1
; get pressed button
$msg  = guigetmsg()
select
  ; window is closed
  case $msg  = $GUI_EVENT_CLOSE
   ; ask to close
   $close  = msgbox(4, "Really quit?", "Are you sure you want to close Go Cops!?")
   ; if pressed yes then close Go Cops!
   if $close = 6 then Exit
; New game button is pressed
  case $msg  = $new
       ; start new game
       new()
  ; Open saved game button is pressed
  case $msg  = $save
       ; open window for selection of new game
       save()
  ; Open manager button is pressed
  case $msg  = $manager
       ; open manager
       manager()
EndSelect
wend

And this the file where the fonts are loaded

dircreate(@AppDataDir & "Go Cops!fonts")
dircreate(@AppDataDir & "Go Cops!images")

inetget("https://gocops.svn.sourceforge.net/svnroot/gocops/gocops/images/icon.gif", @appdatadir & "Go Cops!imageslogo.gif",1)
inetget("https://gocops.svn.sourceforge.net/svnroot/gocops/gocops/fonts/nobile.otf", @appdatadir & "Go Cops!fontsnobile.otf",1)
inetget("https://gocops.svn.sourceforge.net/svnroot/gocops/gocops/fonts/nobile_bold.otf", @appdatadir & "Go Cops!fontsnobile_bold.otf",1)
inetget("https://gocops.svn.sourceforge.net/svnroot/gocops/gocops/fonts/nobile_italic.otf", @appdatadir & "Go Cops!fontsnobile_italic.otf",1)
inetget("https://gocops.svn.sourceforge.net/svnroot/gocops/gocops/fonts/nobile_bold_italic.otf", @appdatadir & "Go Cops!fontsnobile_bold_italic.otf",1)
inetget("https://gocops.svn.sourceforge.net/svnroot/gocops/gocops/utils/RegisterFont.exe", @appdatadir & "Go Cops!coreRegisterFont.exe",1)

DllCall("gdi32.dll","Int","AddFontResource","str",@appdatadir & "Go Cops!fontsnobile.otf")
DllCall("gdi32.dll","Int","AddFontResource","str",@appdatadir & "Go Cops!fontsnobile_bold.otf")
DllCall("gdi32.dll","Int","AddFontResource","str",@appdatadir & "Go Cops!fontsnobile_italic.otf")
DllCall("gdi32.dll","Int","AddFontResource","str",@appdatadir & "Go Cops!fontsnobile_bold_italic.otf")

Hope you can help me

Edited by nodrugs15

Share this post


Link to post
Share on other sites



Did you search the forum for e.g. "AddFontResource"? There are numerous threads about the subject e.g.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here is a recent more post about usinf a font without installation: http://autoitscript.com/forum/topic/1293...lling-it/page__view__findpost_

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'm still wondering which font name i should use!

For some reason I'm not able to view the font! It stays the default one.

Is it the filename ("Nobile_bold.ttf") or the font name ("Nobile")

Edited by nodrugs15

Share this post


Link to post
Share on other sites

I assume "Nobile_bold".


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I guess the problem is somewhere else!

I tried another font and it worked!

I also tried to load the nobile font in Notepad, which failed. The other font succeed.

Conclusion: The problem has nothing to do with AutoIt but with the font which was corrupted.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • StMaSi
      By StMaSi
      Is there any way to embed characters/codes/data/etc. within a text file so that when the script reads the text file to populate the edit box, said characters/codes/data/etc. can let the script know this word needs to be capitalized, that word needs to be underscored, etc.?
      For example, the text file would contain something along these lines...
      <bold>This is the title</bold> This is a <italic>sample</italic> text file. This is <underscore>only</underscore> a text file. Does that make sense?
      Thanx.
    • czyt
      By czyt
      after searching google I only find the api  _WinAPI_GetStockObject ($OEM_FIXED_FONT) but I don't know how to put it work!could someone help with this?and  by the way if only giving a font  not installed ,how to detemine it's a fixed-with font? thx in advance!