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 1
  • Love 2
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • 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.