Customising font style in add-on

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Customising font style in add-on

Post by WhiteWolf »

Hi,

I would like to use a custom font-style at some parts of an add-on. Unfortunately I haven't found anything in wml as to how to include it.
I'm aware of using the Pango formatting codes, which can specify span font, but how do I make sure that the font I choose is also available on to user's computer? So the basic question is, how to basically install a custom font type, which gets downloaded with the add-on, and Pango recognises it?

Thanks for the answers,
WhiteWolf
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Customising font style in add-on

Post by gfgtdf »

There is not documented way to do this, quite soem time ago i opened this bugreport https://gna.org/bugs/index.php?21948 but it wasnt implemented yet.

Note that currntly the fontloading code is different on the OS. so a way that works on your computer might not work on other computers.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Customising font style in add-on

Post by WhiteWolf »

Yeah, what you can be sure that every computer has are Courier New and Times New Roman. None of them the nice handwritten font we'd need :hmm:

I've been experimenting a bit, it seems like that if you specify a font type which is not installed, then Wesnoth sticks to its standard font. So trying to give a font which might be installed on most of the computers will note cause bugs and it will work for some people. It's more than nothing, but still, it's not the same as implementing this idea :(
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
gnombat
Posts: 683
Joined: June 10th, 2010, 8:49 pm

Re: Customising font style in add-on

Post by gnombat »

I believe Pango will allow you to specify multiple fonts, so you could try something like this:

Code: Select all

<span font_desc='Segoe Script, URW Chancery L'>text</span>
This will probably give you a font on most Windows and Linux systems, as most Windows systems have Segoe Script installed, and most Linux systems have URW Chancery L installed.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Customising font style in add-on

Post by Dugi »

Image
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Customising font style in add-on

Post by gfgtdf »

@dugi:
But that coudl increase the size of the adon quite a bit, specially if you have multiple places whre you wan to use that font and multiple translations.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Customising font style in add-on

Post by Dugi »

gfgtdf wrote:But that coudl increase the size of the adon quite a bit, specially if you have multiple places whre you wan to use that font and multiple translations.
Could be done letter by letter.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Customising font style in add-on

Post by gfgtdf »

uhm and then reimplenting the whole text drawing code like in where to place letters, when do do linebreaks etc in lua? doesn't sound like a seious suggestion to me.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Customising font style in add-on

Post by Dugi »

What's so impossible on it? Create a new WML tag via lua, for example named [pretty_message], which replaces all letters with codes to include pictures in the text and then calls wesnoth.wml_actions.message on the output. All you need is to prepare a table of single-character strings, break the text into single letter strings and replace every string that is included in the table with its counterpart. Nothing particularly hard. The drawing will be probably quite heavy, but [message] isn't something supposed to react particularly fast.
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Customising font style in add-on

Post by beetlenaut »

Or Wesnoth could just ship with several font choices. (Then using Pango to choose your font would be guaranteed to work.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Customising font style in add-on

Post by Dugi »

Or allow add-ons to ship their own fonts.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Customising font style in add-on

Post by gfgtdf »

Dugi wrote:What's so impossible on it? Create a new WML tag via lua, for example named [pretty_message], which replaces all letters with codes to include pictures in the text and then calls wesnoth.wml_actions.message on the output. All you need is to prepare a table of single-character strings, break the text into single letter strings and replace every string that is included in the table with its counterpart. Nothing particularly hard. The drawing will be probably quite heavy, but [message] isn't something supposed to react particularly fast.
well if you for example do it that way you'd still have to figure out how wide your 'text area' should be (depdent on the window with), And you still dont have things like text size, text color, underline.. . Even its its possible to implement those things in lua that way its still a lot of work.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Customising font style in add-on

Post by Dugi »

gfgtdf wrote:
Dugi wrote:...
well if you for example do it that way you'd still have to figure out how wide your 'text area' should be (depdent on the window with), And you still dont have things like text size, text color, underline.. . Even its its possible to implement those things in lua that way its still a lot of work.
Wesnoth breaks lines automatically in [message] and you rarely need italic text, unusual text sizes, colours or underlines. Colours could actually be done using ImageFunctionPathWML.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Customising font style in add-on

Post by gfgtdf »

If you generate your 'text' using images then wesnoth doesnt know anymore about liness and will not break them autoatically.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Customising font style in add-on

Post by WhiteWolf »

It's actually for a [story], not a [message], so the closest I could get is write the text with the selected font in Gimp, and then overlay it onto the background.
Problems with these are:

- It can only be scaled vertically then to keep aspect ratio, on some screens text might be too small
- Even if I'd do it letter-by-letter, translatability is completely lost, which is a huge I issue I think :(
Also the nice animation of the text-appearation is lost.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Post Reply