0

I have a custom font .ttf file specified in a folder on my project. I want to import that specific font into Fontfamily function.

I have tried this:

FontFamily fontFamily = new FontFamily("/myfontpath/fontname.ttf");

and this:

FontFamily fontFamily = new FontFamily("/myfontpath/fontname.ttf#font name");

but those do not seem to solve the problem. The output i received was Font "/myfontpath/fontname.ttf" cannot be found.

How to solve this problem? Thank you.

emirryhn
  • 11
  • 3
  • starting with a "/" means it will start searching in the root folder, not your project folder – Garr Godfrey Nov 10 '21 at 03:37
  • isn't root folder a project folder? – emirryhn Nov 10 '21 at 03:41
  • 1
    the root of the current hard drive. i.e. "C:\" if on windows, or simply "/" on unix – Garr Godfrey Nov 10 '21 at 03:43
  • Generally best to determine the full path. removing the slash will usually work...depending on how the app is run. see https://stackoverflow.com/questions/6719293/defining-a-working-directory-for-executing-a-program-c – Garr Godfrey Nov 10 '21 at 03:45
  • should I change "C:\" and put the full path instead then? – emirryhn Nov 10 '21 at 03:46
  • As a first check to see whether the font works, you can put in the full path. But for the final program you don't want to depend on a specific hardcoded location. So find a way to get the path relative to your application (or maybe use an "embedded resource") – Hans Kesting Nov 10 '21 at 07:58

0 Answers0