Search code examples
linuxvisual-studio-codefontsmonogame

Monogame "Could not find font file" when running


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>&#32;</Start>
        <End>&#126;</End>
      </CharacterRegion>
    </CharacterRegions>
  </Asset>
</XnaContent>

Thanks for any help.


Solution

  • 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.