Jump to content

Add new font to Client


Recommended Posts

  • Active Member

Version of Files XXX

Hi,

 

I wanna add a new font (.ttf) to my client.

I've tried to use "AddFontResourceEx()"(Binary) and on root "fontname":"xxx"

But it does not work =(
Maybe somebody already have done this and can give me a useful hint.

 

thanks

 

  • Metin2 Dev 2
  • Love 4
Link to comment
Share on other sites

  • 4 weeks later...
  • Former Staff

Metin2 can support different fonts, you just have to call SetFontName("(Font name):(size)") and it will do the job of loading the font for you.

The way the client loads fonts it's oddly complex, but the fonts are loaded as long the first time that the client requires it and then cache em.

The client looks for (font name).fnt, ".fnt" is an internal extension used for identify what font to load (they do not exist in any EterPack nor they actually should unless you really want to)

After all the class complex structure, we finally know that CGraphicText is the one responsable for texts and CGraphicFontTexture is the one who loads the texture.

CGraphicText::OnLoad is called and it creates our FontTexture, specifically it calls CGraphicFontTexture::Craete

 

From this function, we understand that GDI+ is being used to load fonts (sigh),

the responsable in font creation is  CGraphicFontTexture::GetFont(WORD codePage).

 

The simpliest solution I can think of is having your users to install the font you'd like to and call SetFontName (Python).

If you really want to load TTF, you actually have to load somewhere your font somewhere by using AddFontMemResourceEx. This would also help you packing your font in EterPacks.

Once the font is loaded, you would have to store the HANDLE inside "m_fontMap"

Metin2 will take care of freeing the memory for you and load the font once it's cached. GDI can load TTF so that's not an issue.

 

 

Oh, he's asking about ADDING a new font not changing it.

Edited by arves100
  • Love 1

Everyday you wake up as a Metin2 developer is a bad day...

METIN1 src when

Link to comment
Share on other sites

  • 3 years later...
On 5/20/2024 at 10:43 AM, tyzumah said:

Can you give an example on how to achieve that please?

I would like to add 2 fonts on my client. I already added the EterPack with them but I don't know on how to really add them into the client.

sry for my english btw xD

Since your font file is inside a pack file, you will need to load it into memory, then pass a pointer to this memory to AddFontMemResourceEx() function.

To use the font, pass the font name to CreateFont() and similar functions (note that the font name is not always the same as it's filename, so open the font file to confirm the name).

Consult the microsoft GDI docs for more information on AddFontMemResourceEx().

Link to comment
Share on other sites

2 hours ago, TheEqualizer said:

Since your font file is inside a pack file, you will need to load it into memory, then pass a pointer to this memory to AddFontMemResourceEx() function.

To use the font, pass the font name to CreateFont() and similar functions (note that the font name is not always the same as it's filename, so open the font file to confirm the name).

Consult the microsoft GDI docs for more information on AddFontMemResourceEx().

Thx for the reply and sorry for being a newbie here.

I have a pack file named "fonts" and inside that I have those fonts. The problem here is I don't understand exactly where I can load those fonts from pack into memory and after that, where should I call that AddFontMemResourceEx() function.

Link to comment
Share on other sites

I am not sure what you are asking here.

If you have a pack file, then I assume you have a way to load data from this pack file (via some kind of file manager). So just load it.

If a pack file is making things difficult then extract your fonts from the pack file and store them in one of the client's folders, then in your client code, pass the filename of the extracted font you wish to add to AddFontResourceEx() function.

Note that to load directly from a font file, you use AddFontResourceEx() and not AddFontMemResource(). Again consult the docs for information on how to use these functions.

Link to comment
Share on other sites

19 minutes ago, TheEqualizer said:

I am not sure what you are asking here.

If you have a pack file, then I assume you have a way to load data from this pack file (via some kind of file manager). So just load it.

If a pack file is making things difficult then extract your fonts from the pack file and store them in one of the client's folders, then in your client code, pass the filename of the extracted font you wish to add to AddFontResourceEx() function.

Note that to load directly from a font file, you use AddFontResourceEx() and not AddFontMemResource(). Again consult the docs for information on how to use these functions.

You are totally right. I have a file named "index" inside pack folder which is used for loading all the packs I said there. So, I think I'm already loading them into memory, otherwise, I can place inside "root" folder and create a new "fonts" folder there. That will guarantee the load of those fonts.

 

I already understood what you are saying about those functions, I just dont know exactly where to call those functions. That's my problem for now...and since I'm newbie here, if you could provide an example it would be great, please. The example that I need it would be like showing where in the code should I call that "AddFontMemResource" function and how to use it because I already saw the docs but for me is almost chinese ahahaha.

 

Once more, sorry for the trouble

Link to comment
Share on other sites

Posted (edited)

Where you call the functions is up to you, but you have to do it before you use the font. So I recommend you call those functions during initialization of your client.

There is no secret about using these functions, you just pass valid parameters. I will try to post example code later, right now I am on my phone.

Edited by TheEqualizer
Link to comment
Share on other sites

5 minutes ago, TheEqualizer said:

Where you call the functions is up to you, but you have to do it before you use the font. So I recommend you call those functions during initialization of your client.

There is no secret about using these functions, you just pass valid parameters. I will try to post example code later, right now I am on my phone.

Ok, thank you very very much. I'm at work so I can't test it too but I will wait for the code and try it later today.❤️

Link to comment
Share on other sites

  • 2 weeks later...
On 5/22/2024 at 11:02 AM, TheEqualizer said:

Where you call the functions is up to you, but you have to do it before you use the font. So I recommend you call those functions during initialization of your client.

There is no secret about using these functions, you just pass valid parameters. I will try to post example code later, right now I am on my phone.

Hello again. How far is your home bro? Just joking xD
But please, respond as soon as you can

Link to comment
Share on other sites

6 hours ago, tyzumah said:

Hello again. How far is your home bro? Just joking xD
But please, respond as soon as you can

Loading new fonts when initializing the client would probably be the best option.. But I simply thought why not do it in the patcher, as a requirement to install a new font on the system when the patcher is first launched (similar to c++ runtime libraries for example)

Link to comment
Share on other sites

16 hours ago, tyzumah said:

Hello again. How far is your home bro? Just joking xD
But please, respond as soon as you can

I live on the moon, so I have to wait for a shuttle to be available to get there...OK I simply forgot, and you should have figured things out by now, but here's an example code:

 

constexpr auto gFontFilename = "my_font.ttf";
constexpr auto gFlags = FR_PRIVATE | FR_NOT_ENUM;

bool AddFontResourceExample()
{
auto result = AddFontResourceEx(gFontFilename, gFlags, nullptr);
if(result == 0) return false;

/*After you are done with the font you should call RemoveFontResourceEx with the same parameters you passed to AddFontResourceEx*/

return true;
}

I had to post this on my phone so there might be syntax errors, and you may need to add more code for correctness, but this should be a good base.

As you can see, there is nothing special about using AddFontResourceEx().

Link to comment
Share on other sites

4 hours ago, TheEqualizer said:

I live on the moon, so I have to wait for a shuttle to be available to get there...OK I simply forgot, and you should have figured things out by now, but here's an example code:

 

constexpr auto gFontFilename = "my_font.ttf";
constexpr auto gFlags = FR_PRIVATE | FR_NOT_ENUM;

bool AddFontResourceExample()
{
auto result = AddFontResourceEx(gFontFilename, gFlags, nullptr);
if(result == 0) return false;

/*After you are done with the font you should call RemoveFontResourceEx with the same parameters you passed to AddFontResourceEx*/

return true;
}

I had to post this on my phone so there might be syntax errors, and you may need to add more code for correctness, but this should be a good base.

As you can see, there is nothing special about using AddFontResourceEx().

I was just joking with tou bro xD
Thank you a lot, I will test it later today. One more thing, my fonts are inside "root/fonts" folder and they are being loaded into memory already.

So I just need to say "fonts/my_font.ttf" right? Should I call AddFontMemResource, since they are in memory or AddFontResourceEx as you have shown?

Link to comment
Share on other sites

10 minutes ago, tyzumah said:

I was just joking with tou bro xD
Thank you a lot, I will test it later today. One more thing, my fonts are inside "root/fonts" folder and they are being loaded into memory already.

So I just need to say "fonts/my_font.ttf" right? Should I call AddFontMemResource, since they are in memory or AddFontResourceEx as you have shown?

I know you were joking. The code I posted will load from a file. I recommend you practice with loading from a file (because it's simpler in my opinion), then you can try loading from memory. So extract your fonts to a folder and experiment until you get it working.

Link to comment
Share on other sites

6 minutes ago, TheEqualizer said:

I know you were joking. The code I posted will load from a file. I recommend you practice with loading from a file (because it's simpler in my opinion), then you can try loading from memory. So extract your fonts to a folder and experiment until you get it working.

Ok thank you a lot, I will test it later and tell you if I got it to work or not.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.