SDL2 front end: "Text has zero width" error with ttf set as DEFAULT_FONT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smbhax
    Swordsman
    • Oct 2021
    • 340

    SDL2 front end: "Text has zero width" error with ttf set as DEFAULT_FONT

    I'm trying to set this font https://www.dafont.com/perfect-dos-vga-437.font as the game's default font. I have it in lib\fonts\Perfect DOS VGA 437.ttf. However, when I run an angband.exe compiled with the following in main-sdl2.c:

    #define DEFAULT_FONT "Perfect DOS VGA 437.ttf"

    and no \lib\user\sdl2init.txt, I get a Fatal Error window:

    "font cache rendering failed for ' ' (ASCII 0) in font 'Perfect DOS VGA 437.ttf': Text has zero width"

    If I instead compile main-sdl2.c with the regular

    #define DEFAULT_FONT "10x20x.fon"

    then the game runs okay and I can SWITCH to Perfect DOS VGA 437.ttf in the SDL2 front end's game menu with no error. And the game runs with no error if there's an sdl2init.txt with

    subwindow-font:0:16:Perfect DOS VGA 437.ttf

    But that fatal error will occur if I try to use Perfect DOS VGA 437.ttf as DEFAULT_FONT, and I'm too ignorant to understand why. I'd really like to be able to run with that font as the default. : )

    My Angband videos
  • smbhax
    Swordsman
    • Oct 2021
    • 340

    #2
    Ah well, as a workaround I've converted Perfect DOS VGA 437.ttf to size 16 and 32 .fon raster fonts using https://www.vertopal.com/en/convert/font , and those work fine as DEFAULT_FONT. ^ _^
    My Angband videos

    Comment

    • backwardsEric
      Knight
      • Aug 2019
      • 523

      #3
      In load_subwindow(), there are these lines:

      Code:
      try_names[n_tries] = DEFAULT_FONT;
      try_sizes[n_tries] = 0;
      The second of those lines assumes that DEFAULT_FONT is a raster font. Changing that line to

      Code:
      try_sizes[n_tries] = (suffix_i(DEFAULT_FONT, ".fon")) ? 0 : DEFAULT_VECTOR_FONT_SIZE;
      may help. I'll submit that change as a pull request since all the other places where fonts are used tolerate both raster and vector fonts.

      Comment

      • smbhax
        Swordsman
        • Oct 2021
        • 340

        #4
        That did it! Those were among the lines I looked over and over and of course had no idea what actually to do with them. ; ) Thanks! (And for all the other recent SDL2 fixes. : ))
        My Angband videos

        Comment

        • Christopher1078
          Rookie
          • Sep 2024
          • 1

          #5
          have you tried changing the font size to something other than 16 sometimes that helps cause the game might have trouble loading the default font in the wrong size try 14 or 12 and see if that works

          Christopher

          Comment

          • smbhax
            Swordsman
            • Oct 2021
            • 340

            #6
            Originally posted by Christopher1078
            have you tried changing the font size to something other than 16 sometimes that helps cause the game might have trouble loading the default font in the wrong size try 14 or 12 and see if that works

            Christopher
            I set the default font size to 16.
            My Angband videos

            Comment

            Working...
            😀
            😂
            🥰
            😘
            🤢
            😎
            😞
            😡
            👍
            👎