PDA

View Full Version : Trying to understand fonts in FG



Ampersandrew
August 24th, 2018, 20:58
Hi

I'm looking at that fonts in CoreRPG. The graphics_fonts.xml has lots of font tags.
These have all been defined with an ffgfile tag and a ttf tag. I'm trying to relate the fgffile name to the ttf tag's values

for instance defaultstringcontrol has an ffgfile graphics/fonts/regular-10.fgf

This strongly implies to me that this will be a 10 point rendering of some unknown font that was processed to produce the fgf file. Is this actually true?

The corresponding ttf tag for that entry has three data items.

file="graphics/fonts/Candara.ttf"
name="Candara SDF"
size="15"

I'm assuming that the ttf should produce glyphs of the same size as the fgf, if so:
1) why is the font name "Candara SDF", how do I know to put the SDF on it?
2) why is the size 15? is this not a 10 point font?
3) does the 15 not actaully relate to the 10 at all?

pindercarl
August 24th, 2018, 21:25
Fantasy Grounds uses a proprietary font format for rendering which are stored as FGF files. If an FGF is not specified, but a TTF file is, an FGF file is created when the ruleset is loaded. FGU, the next version of Fantasy Grounds in development, does not render with FGF files. In FGU the name and size are the important attributes. If an FGF file is specified, you can ignore the other data.

Talyn
August 24th, 2018, 21:32
You're barking up the wrong tree trying to equate the two. FGF (Fantasy Grounds Font) and TTF (TrueType Font) are two completely different things and they have separate tags.

Read the RefDoc for Fonts (https://www.fantasygrounds.com/refdoc/font.xcp):

FFG only uses the <ffgfile name="fontname.fgf"> tag, whereas <ttf> has several other parameter tags. File, name and size are required for TTF files. Despite what the RefDoc says, OTF is not supported (at least I've never gotten one to work in the past two years) so that's #FakeNews as far as I'm concerned. :)

The <name> section for TTF says "The font name to use from within the TTF file specified." (Emphasis mine) I always double-click the font to bring up the Windows Fonts and it will show me the name of the font. That's what I put in <name> because (it's been awhile so I forget which happened) it either just didn't work (most likely) and reverted to the default font definition or it threw an error (doubtful but possible).

So assuming that Candara.ttf font you're talking about has the name of Candara SDF in the Windows Fonts window, the markup you listed is correct:


<ttf file="graphics/fonts/Candara.ttf" name="Candara SDF" size="15" />


FGF fonts are "fake" fonts—they're an archive of pictures of a font at a specific size, which is why they usually have the font size in their filename. The default "body" font in CoreRPG, for example is:



<fgffile name="graphics/fonts/regular-10.fgf" />


So no matter what, that font is always 10 point because that's the point size the "fontshots" were sampled at.

The only advantage to FGF fonts is load time. @Moon Wizard guesstimates that each TTF font adds approximately 1 second to FG's overall load time. The disadvantages to FGF are they are limited to a single size so if the ruleset or theme needs multiple sizes of the same font, you need a separate .fgf file for each size. CoreRPG has (among several others) regular-8.fgf, regular-9.fgf, regular-10.fgf and regular-11.fgf. And as @pindercarl just mentioned above, FGF will be deprecated in Unity so every ruleset and theme is going to need to be updated anyway. (I didn't ask @Moon Wizard if Unity also experiences the same TTF load times or not.)

Ampersandrew
August 24th, 2018, 22:04
Thank you for your reply.


You're barking up the wrong tree. FGF (Fantasy Grounds Font) and TTF (TrueType Font) are two completely different things and they have separate tags.

Perhaps I should have been more explicit. I knew this. But, presumeably, if you specify an fgf and a ttf you'd want them to produce similar output. I'm trying to figure out how a size 15 font replaces a 10 point font. Is the size here points or something else?


Read the RefDoc for Fonts (https://www.fantasygrounds.com/refdoc/font.xcp)

FFG only uses the <ffgfile="fontname.fgf"> tag, whereas <ttf> has several other parameter tags. File, name and size are required for TTF files. Despite what the RefDoc says, OTF is not supported (at least I've never gotten one to work in the past two years) so that's #FakeNews as far as I'm concerned. :)

The <name> section for TTF says "The font name to use from within the TTF file specified." (Emphasis mine) I always double-click the font to bring up the Windows Fonts and it will show me the name of the font. That's what I put in <name> because (it's been awhile so I forget which happened) it either just didn't work (most likely) and reverted to the default font definition or it threw an error (doubtful but possible).

So assuming that Candara.ttf font you're talking about has the name of Candara SDF in the Windows Fonts window, the markup you listed is correct:


<ttf file="graphics/fonts/Candara.ttf" name="Candara SDF" size="15" />


FGF fonts are "fake" fonts—they're an archive of pictures of a font at a specific size, which is why they usually have the font size in their filename. The default "body" font in CoreRPG, for example is:



<fgffile name="graphics/fonts/regular-10.fgf" />


So no matter what, that font is always 10 point because that's the point size the "fontshots" were sampled at.

Thanks, I had already read the docs, but while they specify the tags, they don't actually tell you what they mean.

15 what? points? pixels? how does a "15 somethings" ttf font produce similar output to a 10 point fgf.

I can't find a "Candara SDF" font, I can find Candara. Candara is a microsoft font, it comes with windows. The font information for the instance on my machine and all the ones I can find online don't mention SDF. SDF appears to be Signed Distance Field text rendering, which is a low resource fast way to render fonts. The names of the four fonts on my Machine are Candara, Candara Bold, Candara Italic and Candara Bold Italic. Not a whiff of SDF.

There is a note at the top of the file that says that Fantasy Grounds defaults to using the fgf if present and FGU defaults to the ttf. I assume these entries have both because the developers are using the same ruleset to test FGU. Since they've said they want FGU to be mostly a drop in replacement for FGC where most stuff continues to work I'm assuming that both definitions of the font produce glyphs of the same size.

pindercarl
August 24th, 2018, 22:17
It's been a while since I was in the font rendering code, but if I recall the 15 specifies the full line-height of the text in pixels not the point size. It was a tad confusing to me, as well, when I had to reverse engineer the font rendering.

Talyn
August 24th, 2018, 22:18
15 what? points? pixels? how does a "15 somethings" ttf font produce similar output to a 10 point fgf.


Again from the RefDoc (for TTF):



<size > ... </size> The pixel height to use for this font asset.




I can't find a "Candara SDF" font, I can find Candara.


I'm not sure where you're even seeing this bit about Candara. I just unpacked CoreRPG v3.3.6A and not seeing it graphics_fonts.xml. But yes, given the way different fonts are created and how they render, it could be entirely possible you'd want a 15px height of a certain font in order to make it appear roughly equivalent to a 10px height in some other font. That 5px seems excessive, mind you, but I've certainly had to do more trial-and-error size experimentation with TTF than I thought I'd need.

Edit: Oh and FG does not (sadly) look into your OS fonts folder at all. I'm hoping Unity will but haven't heard one way or another officially yet. So for now, each font must be contained within the ruleset or theme.


It's been a while since I was in the font rendering code, but if I recall the 15 specifies the full line-height of the text in pixels not the point size. It was a tad confusing to me, as well, when I had to reverse engineer the font rendering.

Aha!!! Full line height very well may explain why some of my TTF needed to be so different from what the default FGF size was!

Ampersandrew
August 24th, 2018, 22:45
Thanks for taking the time to respond to this.


I'm not sure where you're even seeing this bit about Candara. I just unpacked CoreRPG v3.3.6A and not seeing it graphics_fonts.xml.

Making me doubt myself, I opened it with 7zip and read the graphics_fonts.xml. I'm definitely seeing it, here:

<ttf file="graphics/fonts/Candara.ttf" name="Candara SDF" size="15" />


But yes, given the way different fonts are created and how they render, it could be entirely possible you'd want a 15px height of a certain font in order to make it appear roughly equivalent to a 10px height in some other font. That 5px seems excessive, mind you, but I've certainly had to do more trial-and-error size experimentation with TTF than I thought I'd need.

I don't think it is 5 pixels difference. I looked again on the web and I found a reference relating points to pixels to ems

https://websemantics.uk/tools/convert-pixel-point-em-rem-percent/

11 points is 15 pixels per that doc. So, 10 point text with 2 pixels to avoid lines bashing into each other makes sense to me. I think.


Edit: Oh and FG does not (sadly) look into your OS fonts folder at all. I'm hoping Unity will but haven't heard one way or another officially yet. So for now, each font must be contained within the ruleset or theme.

Ah, that's good to know. I think that means the developers have a Candara SDF font that they're using to develop Unity with. So I'll need to include the ttf file in the fonts folder.

Thanks, I think I'm getting a better handle on this.

Ampersandrew
August 24th, 2018, 22:49
It's been a while since I was in the font rendering code, but if I recall the 15 specifies the full line-height of the text in pixels not the point size. It was a tad confusing to me, as well, when I had to reverse engineer the font rendering.

I missed that it was line height in pixels. Thanks.

Talyn
August 24th, 2018, 22:52
Making me doubt myself, I opened it with 7zip and read the graphics_fonts.xml. I'm definitely seeing it, here:
<ttf file="graphics/fonts/Candara.ttf" name="Candara SDF" size="15" />


Right you are! I still had an older version of graphics_fonts.xml loaded into Notepad++ when I unpacked v3.3.6 and it decided to not load the new one for some reason. But including both the FGF and TTF tags into a single font definition is a slick way of handling things right from the get-go. I'd imagine sooner or later they'll patch the rulesets and official themes in a similar manner so everything is ready to roll on Unity Launch Day.