I have an application that writes text onto images using System.Drawing
(C#).
I am using specific fonts to do this.
Since I can't rely on my shared hosting servers to have all the custom fonts I may need (and since the list of fonts is likely to grow), how can I manage the fonts used for my application?
Could I include .ttf
files in my project and reference them somehow?
What about a SQL database containing fonts?
It should be possible to store your font files on disk or in database, and then use the PrivateFontCollection class to use the fonts at runtime.
Here is how you would use it:
PrivateFontCollection collection = new PrivateFontCollection();
// Add the custom font families.
// (Alternatively use AddMemoryFont if you have the font in memory, retrieved from a database).
collection.AddFontFile(@"E:\Downloads\actest.ttf");
using (var g = Graphics.FromImage(bm))
{
// Create a font instance based on one of the font families in the PrivateFontCollection
Font f = new Font(collection.Families.First(), 16);
g.DrawString("Hello fonts", f, Brushes.White, 50, 50);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With