Finding a Font

Finding a Font

Postby dulsi » 04 Mar 2016, 05:33

smcameron complained about the changes needed to run Ostrich Riders. I'd like to make the program easier to install. How should I find a font? I can parse the /etc/font/font.conf to get the directory but that doesn't help much since Mint and Fedora both use /usr/share/font but keep it in different subdirectories. I could have the makefile run
{l Code}: {l Select All Code}
fc-match LiberationSans-Regular.ttf -f "%{file}"
and set a define but that isn't ideal since you would need to recompile if you moved the font. I could run the command when starting Ostrich Riders or link to libfontconfig. I'm leaning towards linking to libfontconfig. It requires installing fontconfig include files to be installed to compile which is unfortunate. How do other projects handle it?
dulsi
 
Posts: 570
Joined: 18 Feb 2016, 15:24

Re: Finding a Font

Postby c_xong » 04 Mar 2016, 13:06

Usually games include their own font files. Yes this can be wasteful of disk space but font files are tiny. Plus many games use bitmap fonts because they are faster to render.
User avatar
c_xong
 
Posts: 234
Joined: 06 Sep 2013, 04:33

Re: Finding a Font

Postby charlie » 04 Mar 2016, 14:09

c_xong {l Wrote}:Usually games include their own font files. Yes this can be wasteful of disk space but font files are tiny. Plus many games use bitmap fonts because they are faster to render.

Disk space is about the cheapest commodity going. Don't even worry about it unless you are in some crazy niche trying to stuff as much into a C64 emulator or something.
Free Gamer - it's the dogz
Vexi - web UI platform
User avatar
charlie
Global Moderator
 
Posts: 2131
Joined: 02 Dec 2009, 11:56
Location: Manchester, UK

Re: Finding a Font

Postby dulsi » 06 Mar 2016, 04:50

Well if you want to be packaged on Fedora, I believe you can't include your own font. Even if the disk space is not a big deal, the right thing to do is not to duplicate the font. Here is my solution:

{l Code}: {l Select All Code}
   std::string FindDefaultFont()
   {
      std::string answer("/usr/share/fonts/liberation/LiberationSans-Regular.ttf");
      FcFontSet   *fs;
      FcPattern   *pat;
      FcResult   result;
      if (!FcInit())
      {
         return answer;
      }
      pat = FcNameParse((FcChar8 *)"LiberationSans-Regular.ttf");
      FcConfigSubstitute(0, pat, FcMatchPattern);
      FcDefaultSubstitute(pat);

      fs = FcFontSetCreate();
      FcPattern   *match;
      match = FcFontMatch(0, pat, &result);
      if (match)
      {
         FcChar8 *file;
         if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch)
         {
            answer = (const char *)file;
         }
         FcPatternDestroy(match);
      }
      FcPatternDestroy(pat);
      FcFini();
      return answer;
   }
dulsi
 
Posts: 570
Joined: 18 Feb 2016, 15:24

Re: Finding a Font

Postby onpon4 » 06 Mar 2016, 14:33

Well if you want to be packaged on Fedora, I believe you can't include your own font.


Don't be silly. Games include all kinds of things in their data packages. Sometimes they include rendered text characters. I'm not aware of any example of a game being excluded from a repo because it depends on loading a font distributed with the game. Most games that use fonts in the first place do that.

It didn't take me any effort at all to find an example of a game including fonts in its data packaged for Debian. Zaz is distributed with FreeMono Bold, FreeSans, and a third font with the file name "font1.ttf". The Debian package doesn't modify the code of Zaz to make it use system fonts. That would be stupid. It just replaces the FreeMono Bold and FreeSans files with dynamic links to the system fonts' locations, and leaves "font1.ttf" as it is. Fedora hasn't refused to include Zaz in its repository, as far as I am aware. And there are several more examples, all treated exactly the same way. For example:

- Neverball
- Blob Wars
- Freecol
- Endgame: Singularity
- Extreme Tux Racer

You are worrying about a non-issue. Just distribute the font with the game. Relying on system fonts is a really bad idea in general, anyway.
onpon4
 
Posts: 596
Joined: 13 Mar 2014, 18:38

Re: Finding a Font

Postby Akien » 06 Mar 2016, 14:37

Actually he's right. Most distros have more or less strong policies that packages should use system fonts instead of bundling their own ones.

That's the theory; as your example shows, it's often quite difficult to make a specific code look for system wide fonts, so often packagers will just rely on symlinks instead, but that's considered bad practice (as it shown e.g. that games "provide" a font when they actually don't, they just use one).

I've spent quite some time myself unbundling fonts in games I packaged. It's a real PITA... So from time to time I tend to make as if I did not notice that there were bundled fonts, and just package it as it was meant by upstream. Distro policies are sometime too hard to comply to for the gain they provide. Still, it's good to be aware that such policies exist (and that some distros like Debian will enforce with more rigour than the distro I package for).
Godot Engine project manager and maintainer.
Occasional FOSS gamedev: Lugaru, OpenDungeons, Jetpaca, Minilens.
User avatar
Akien
 
Posts: 737
Joined: 22 Feb 2014, 13:14

Re: Finding a Font

Postby leilei » 07 Mar 2016, 04:24

There's also the additional potential legal troubles of handling some fonts. There's lots of font licenses out there which could conflict with certain clauses, and then there's those little banal type patents (which may or may not have expired). Usually the legal workaround is to prerender the font to a bitmap and just use the bitmap, but then to consider unicode/utf-8 support and more sizes, you'll bloat up the memory usage drastically just for text.

"disk space is hardly anything its okay" is not an excuse to everything, and being against bloat doesn't imply it's for dinosaur computer development only.
User avatar
leilei
 
Posts: 154
Joined: 03 Apr 2012, 02:53

Re: Finding a Font

Postby onpon4 » 07 Mar 2016, 06:26

If you're using a font which has licensing problems, you shouldn't be using that font. Lots of systems (like Debian and Fedora) just won't have it if that's the case. There are plenty of libre fonts to choose from.

And a font's copyleft clause doesn't relate at all to a game using the font, because the font is a separate work distributed alongside the game program, not a part of the game program.

Usually the legal workaround is to prerender the font to a bitmap and just use the bitmap


I'm not aware of any patents on font formats, and even if they exist, I don't want to know about them. Ignorance is actually a legitimate (partial) defense against claims of patent infringement, and given how numerous and ridiculous software idea patents can be, it's a programmer's best defense to remain ignorant of as many of them as possible. (Ironic, since the whole point of the patent system was to get people with good ideas to publish them, but that's the insanity of software idea patents, of course.)

But for restrictive copyright licenses, using a bitmap version may or may not help depending on jurisdiction. Font faces cannot be copyrighted in the U.S., so a basic raster graphic version of a font face will not cause you trouble there. But for example, my understanding is they are copyrighted in the U.K.

"disk space is hardly anything its okay" is not an excuse to everything, and being against bloat doesn't imply it's for dinosaur computer development only.

The justification for distributing font files with games hasn't been expressed in this thread, but it isn't "disk space is hardly anything its okay". It's "there is absolutely no standard whatsoever for what system fonts are available, and if I try to use a system font that's unavailable, the visuals of the game could be completely ruined depending on what font actually ends up being used". It's exactly the same reason PDFs embed the fonts they use. If you want to make sure something that includes text looks exactly the same on every system, including the font is usually the most efficient way to do it.
onpon4
 
Posts: 596
Joined: 13 Mar 2014, 18:38

Who is online

Users browsing this forum: No registered users and 1 guest