BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to get font-name(s) inside a font-file (e.g. .ttf)?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
M_R
Guest





PostPosted: Mon May 09, 2005 8:27 am    Post subject: How to get font-name(s) inside a font-file (e.g. .ttf)? Reply with quote



How to get font-name(s) inside a font-file (e.g. .ttf)?

I found out, that trying to use a font of an external resource
temporarily (e.g. an own font) I can use something like this:

if( AddFontResourceEx(font_file_name.c_str(), FR_PRIVATE, 0)!=0)
...

but how get I some information about this new font-resource,
especially how do I get the name(s) 'font_name' to assign to
TFont::Name, as

Application->MainForm->Canvas->Font->Name=font_name;

?

Thanks a lot,

Michael

Back to top
Gary Setter
Guest





PostPosted: Mon May 09, 2005 1:10 pm    Post subject: Re: How to get font-name(s) inside a font-file (e.g. .ttf)? Reply with quote




<M_R> wrote

Quote:
How to get font-name(s) inside a font-file (e.g. .ttf)?

I found out, that trying to use a font of an external resource
temporarily (e.g. an own font) I can use something like this:

if( AddFontResourceEx(font_file_name.c_str(), FR_PRIVATE, 0)!=0)
...

but how get I some information about this new font-resource,
especially how do I get the name(s) 'font_name' to assign to
TFont::Name, as

Application->MainForm->Canvas->Font->Name=font_name;


Hi Michael,

It depends on why you a installing user fonts I suppose. Once the font is
installed, it is available via EnumFontFamilies or ChooseFont. I suppose you
could use EnumFontFamilies before and after installation and check for
differences.
Best regards,
Gary


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon May 09, 2005 5:09 pm    Post subject: Re: How to get font-name(s) inside a font-file (e.g. .ttf)? Reply with quote




<M_R> wrote


Quote:
How to get font-name(s) inside a font-file (e.g. .ttf)?

Read the TTF file data directly. You can find details about the TTF file
format at http://www.microsoft.com/typography/otspec/.


Gambit



Back to top
M_R
Guest





PostPosted: Wed May 11, 2005 5:17 am    Post subject: Re: How to get font-name(s) inside a font-file (e.g. .ttf)? Reply with quote

"Gary Setter" <setterg (AT) worldnet (DOT) att.net> schrieb:

Quote:
It depends on why you a installing user fonts I suppose. Once the font is
installed, it is available via EnumFontFamilies or ChooseFont. I suppose you
could use EnumFontFamilies before and after installation and check for
differences.


I tried it out, but did not really succeed:

int CALLBACK _EnumFontFamExProc(ENUMLOGFONTEX *_lpelfe,
NEWTEXTMETRICEX *_lpntme, DWORD _FontType, LPARAM _lParam) {
return(((AnsiString *)_lParam)->AnsiCompareIC((char
*)_lpelfe->elfFullName/*_lpelfe->elfStyle _lpelfe->elfScript*/)==0 ?
0/*stop, font-name has been found*/ : 1/*continue*/);
}

bool DoesFontExist(AnsiString _font_name) {
// does not work for all fonts...
int
enum_ret=EnumFontFamiliesEx(Application->MainForm->Canvas->Handle/*HDC
hdc*/, NULL/*LPCTSTR lpszFamily*/, (FONTENUMPROC)_EnumFontFamExProc,
(long)&_font_name, 0/*dw_flags (not used)*/);
return(enum_ret==0/*callback-function stops caller => font has been
found*/ ? true : false);
}

~~~~~~~~~~~

I changed the strategy a little, since there are application-tools
with which it's easy to find out the font-name within a file, so the
user of my application can (at first) give a not-yet-included
font-filename and behind the font-name.

Strange thing is that after reading these values and including the
font resource from a font-resource-file correctly:

// args[0] contains the font-file, args[1] the font-name

if(!FileExists(args[0]) || AddFontResourceEx(args[0], FR_PRIVATE,
0/*reserved*/)==0)
assert(!"Error accessing resource");

checking for the font-name now being inside the system the
DoesFontExist does not return 'true':

if(!DoesFontExist(args[1]))
assert(!"Font not found");

It's strange since when assigning the fontname to ..->Font->Name this
new font is correctly used.

What am I doing wrong?


Thanks a lot,

Michael


~~~~~~~~~~~

P.S.

( I also tried it with

if(Screen->Fonts->IndexOf(args[1])<0)
assert(!"Font not found");

but the result is the same.

Even checking
Screen->Fonts->Count
before and after calling
AddFontResourceEx(args[0], FR_PRIVATE, 0/*reserved*/)==0)
did not change it's value
)





Back to top
Gary Setter
Guest





PostPosted: Thu May 12, 2005 2:46 pm    Post subject: Re: How to get font-name(s) inside a font-file (e.g. .ttf)? Reply with quote

<snip>
What am I doing wrong?
<snip>
The second parameter of EnumFontFamiliesEx is suppose to be a pointer to a
LOGFONT struct. Passing a null does not seem like a good idea to me. Also,
why not set the lfFaceName member to the font you're looking for?

That might get you started.
Good luck,
Gary

Back to top
M_R
Guest





PostPosted: Fri May 13, 2005 10:55 am    Post subject: Re: How to get font-name(s) inside a font-file (e.g. .ttf)? Reply with quote

Quote:
The second parameter of EnumFontFamiliesEx is suppose to be a pointer to a
LOGFONT struct. Passing a null does not seem like a good idea to me. Also,
why not set the lfFaceName member to the font you're looking for?

You are right: I tried it and it works fine now.

Thanks a lot,

Michael

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.