[SOLVED] Appropriating Pipeline spritefont code - stuck on SharpFont

I wish to have fonts resize with user resolution while having text as sharp as they can. By which I also mean they keep a scale of 1.0f in SpriteBatch.DrawString(). After thinking about several solution and trying a few, I’ve decided the simplest/best thing to do is use the MG pipeline’s spritefont generation code to generate a sprite. Only as required at game startup and after changing resolution and/or UI scale so there’s barely a speed impact - none while actually playing. What’s more, I can (most likely) use the current spritebatch code, etc… So my code should be quite brief, and updates to the pipeline should slot in quite easily.

This experiment has humbled me - at least in my knowledge of C#. I’ve learned several new things, but couldn’t find the entry point of the pipeline (the proverbial Main.cs, Pipeline.cs or Program.cs). Despite no VS solution/project I did manage to backtrack from FontDescription pretty well. Now I’m stuck on SharpFont. Never handled DLLs before (although it seems relatively easy), but I can’t find any DLL import in the pipeline source code. The SharpFont.dll and freetype6.dll aren’t included - the folder ThirdParty/Dependencies is empty. I could just muddle through and try writing my own DLL import, but that seems less than ideal.

Q1: How and/or where does the MG Pipeline code import SharpFont.dll (and perhaps freetype6.dll)?

Q2: This spritefont generation code works on Win, Linux and Mac desktops, correct? (after research various Git issues, I think Win and Linux yes, Mac not yet)

Also - and unrelated to SharpFont - why does SpriteFontContent.cs have
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
I understand every class used in SpriteFontContent.cs has it’s own _Class_Writer.cs (e.g. SpriteFontContentWriter.cs, ListWriter.cs or Texture2DContentWriter.cs) but are those writer classes used automagically? I can’t see the link in the code.

Q3: Why or how is Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler used in SpriteFontContent.cs?

Currently installed (for projects) MonoGame 3.5 stable. Copying code of Git source MonoGame-develop (11210 commits) downloaded 2017/02/08. SharpFont.dll and freetype6.dll are included in the MG 3.5 installation (C:/Program Files (x86)/MSBuild/MonoGame/v3.0/Tools). With a file date of 2016/03/30, these appear to be v3.0.1.

The Pipeline Tool is just a GUI frontend. When building content it runs MGCB.exe - the content building CLI - as a seperate process, which in turn delegates to MonoGame.Framework.Content.Pipeline to do the actual work. There’s a lot of automagic stuff going on in the MG Content Pipeline, so it’s hard to dig into the code as a whole. The easy route is to just run mgcb from your game to rebuild a font with different settings.

For the interesting parts of the font processing code check out the following files:

1 Like

@Jjagg Don’t believe I’ve found the GUI code. Only reason I’d want to is to trace what happens after the ‘build’ button is clicked, and trace how that leads to a sprite font. Not better or worse, but that top-down logic tends to be easier to me.

It’s not a coincidence you mention the two files that are using SharpFont; I had glossed over them but the lack of SharpFont kept me from going in-depth. Particularly SharpFontImporter has several errors (unresolved classes/namespace) that I generally prefer to solve before going in-depth on code.

Anyway, not the answer I expected but apparently I could use MGCB via CLI to simply gen the fonts (appeal of simplicity), or since SharpFont is open source I could go figure that out (appeal of understanding and controlling the black box). Thanks for the assist.