skip to Main Content

I’m trying to learn the basics of Monogame, and I’ve successfully figured out how to use the Monogame Content Pipeline to load and display images on the screen. When I try to do the same with fonts, by loading a font called galleryFont.spritefont into the Monogame Content Pipeline everything is fine.

Please note: even before I import the font into my code, I get an error.

enter image description here

However, the problem occurs when I run the project. I get an error that looks like this:

enter image description here

It states:

error : Processor ‘FontDescriptionProcessor’ had unexpected failure!
System.IO.FileNotFoundException: Could not find "Arial" font file

I also get an error in my build tasks, stating this:

enter image description here

As you can see as well, the file is loaded, but what I noticed what was strange was that the monogame content pipeline did not save the file as an .xnb file in the Content/bin folder.

enter image description here

Or since the error said, "Could not find Arial font file," does this mean I need to somehow download the Arial font.ttf and link it somehow in my .spritefont file? Here is the .spritefont file if anyone is interested.

<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
  <Asset Type="Graphics:FontDescription">

    <!--
    Modify this string to change the font that will be imported.
    -->
    <FontName>Arial</FontName>
    <Size>24</Size>
    <Spacing>0</Spacing>
    <UseKerning>true</UseKerning>
    <Style>Regular</Style>

    <!--
    If you uncomment this line, the default character will be substituted if you draw
    or measure text that contains characters which were not included in the font.
    -->
    <!-- <DefaultCharacter>*</DefaultCharacter> -->
    <CharacterRegions>
      <CharacterRegion>
        <Start> </Start>
        <End>~</End>
      </CharacterRegion>
    </CharacterRegions>
  </Asset>
</XnaContent>

Thanks for any help.

3

Answers


  1. Chosen as BEST ANSWER

    After doing a ton of research, I found out that the font is not naturally loaded onto my computer. The tutorial I was using somehow had the Arial font already loaded, so they could just use <FontName>Arial</FontName> to load the font. However, I had to download a font, put it into my Content directory, then edit the .spritefont file to <FontName>font.ttf</FontName>. Finally, after doing this, the project would run.


  2. It looks like you’re trying to load the "Arial" font when you named your font "galleryFont". Try changing it to that in the code and see what happens. For example, here’s how I load a font in one of my games:

    protected override void LoadContent()
    {
       SpriteFont _font;
       _font = Content.Load<SpriteFont>("SuperArial");
    }
    

    "SuperArial" is what I named an Arial font I packed into my mgcb file.

    Login or Signup to reply.
  3. The Arial is specific to Windows.

    A version of these fonts are available to Linux users through the following:

    Ubuntu(same package as deb for debian)

    sudo apt install ttf-mscorefonts-installer`
    

    Arch:

    sudo yay -S ttf-ms-fonts ttf-vista-fonts ttf-office-2007-fonts ttf-win7-fonts ttf-ms-win8 ttf-ms-win10 ttf-ms-win11`
    

    Redhat:

    sudo rpm -i https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm
    

    All of these methods register the fonts, and can be used directly as specified.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search