Hi all,

I figured out how to load fonts directly from font files, so I'll share my
story and hope this helps someone else!


##########################################

use Win32::API;

# First, export the AddFontResource function:

my $addFontResource = Win32::API->new( 'gdi32', 'AddFontResource', 'P', 'I'
);


# Next, call the function on the desired font file. In my case, the font
file
# is in the same directory as my script:

$addFontResource->Call("Kristen ITC.ttf");


# The font is now in the system font table and can be called by name
("Kristen 
# ITC" in this example) as if it were installed in the %windir%\Fonts
folder:

my $kristenITC = Win32::GUI::Font->new
(
    -name => "Kristen ITC",
    -size => 14,
    -bold => 1,
);

##########################################


My problem was actually a fundamental misunderstanding of .lib files versus
.dll files. I was trying to call Win32::API on Gdi32.lib when I should have
been calling it on gdi32.dll! Apparently .lib files just provide
information/references for .dll files. So, when you find a really cool
function in MSDN that references a .lib file (Gdi32.lib in my case), check
to see if you have the .dll version of the file (gdi32.dll in my case).

-Rob


________________________________________
From: Perl Rob [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 06, 2007 8:54 PM
To: 'Win32 GUI Users Mailing List'
Subject: Create font object from file?

Hi,

Is it possible to create a Win32::GUI::Font object directly from a font file
(e.g. "arial.ttf")? If not, does anyone have a good copy of Gdi32.lib? It
has a function called AddFontResource() (which I could load with Win32::API)
that's exactly what I'm looking for, but my Gdi32.lib file throws an error
that it's not a valid image file and may be corrupt.

Thanks,
Rob


Reply via email to