Garry's Mod Wiki

Revision Difference

Finding_the_Font_Name#561568

<title>How to Create a Font and Find its Name</title>⤶ <cat>Dev.UI</cat> To use your font in game you need to know the name of your font. This is required for <page>surface.CreateFont</page>.⤶ ⤶ The font name is **not** a file name of that font. Your file can have any name, GMod finds the font only by its real name.⤶ ⤶ Make sure your font is .ttf, it's in your `resource/fonts/` folder and it's included for downloading. <note>It's generally good practice to keep file paths lowercase using underscores(`_`) or hyphens(`-`) for spaces, especially on Linux. Example: `resource/fonts/arial_bold.ttf`</note>⤶ ⤶ # Windows⤶ 1. Right click on your font and click `Preview` or double click it⤶ <upload src="19952/8d7ac8f0fde3c86.png" size="4373" name="111.png" />⤶ ⤶ 2. In opened window find `Font name:` line⤶ <upload src="19952/8d7ac8f56346600.png" size="11641" name="fontview_HV8L4tuEW0.png" />⤶ ⤶ 3. The name goes after `Font name: ` (In this example, it's `Digital-7 Mono`)⤶ <upload src="19952/8d7ac8f88417667.png" size="6024" name="fontview_NyCOKo3ZRc.png" />⤶ ⤶ Example <page>surface.CreateFont</page>:⤶ ```⤶ surface.CreateFont("MySuperFont", { font = "Digital-7 Mono",⤶ size = 15⤶ })⤶ ⤶ draw.SimpleText( "Hello world", "MySuperFont", 120, 120, Color(255, 255, 255) )⤶ ```⤶ ⤶ # MacOS⤶ ⤶ # Linux⤶ ⤶ ## GNOME Font Viewer⤶ ⤶ # How to Create a Font⤶ ⤶ ## Place the Font File in Your Addon⤶ When Garry's Mod loads fonts, it looks for them in the `/garrysmod/addons/{Your Addon's Folder}/resource/fonts/` folder. Example: `resource/fonts/arial_bold.ttf`⤶ ⤶ Due to inconsistencies between operating systems, it's good practice to ensure that your addon's files and folders (including font files) use entirely lowercase names which do not contain spaces. Spaces should be replaced by underscores (`_`) or hyphens (`-`). ⤶ This is *especially* true on Linux. ⤶ ⤶ ⤶ **Note:** All fonts **must** be in the `.ttf` format.⤶ ⤶ In addition, make sure that the font's `.ttf` file is available clientside, otherwise players will not be able to use it. ⤶ You can do this via <page>resource.AddSingleFile</page>⤶ ⤶ ⤶ ## Find the Font's Name⤶ To use your font in Garry's Mod, you need to know the name of your font. This is required for <page>surface.CreateFont</page>.⤶ ⤶ The font name is **not** the `.ttf` file's file name. Instead, the `.ttf` file has the name of the font embedded within it. This embedded name is what Garry's Mod uses to create the font and make it available in-game. ⤶ ### Windows⤶ 1. Right click on your `.ttf` font file and click `Preview`⤶ <image src="19952/8d7ac8f0fde3c86.png" size="4373" name="111.png" />⤶ ⤶ 2. In the window that opens, find the line that begins with "Font name"⤶ <image src="19952/8d7ac8f56346600.png" size="11641" name="fontview_HV8L4tuEW0.png" />⤶ ⤶ 3. The name you will need to use in Garry's Mod is the text following "Font name" ⤶ In the example below, the name is `Digital-7 Mono`⤶ <image src="19952/8d7ac8f88417667.png" size="6024" name="fontview_NyCOKo3ZRc.png" />⤶ ⤶ ### MacOS⤶ ⤶ ### Linux⤶ ⤶ #### GNOME Font Viewer⤶ Package name: [`gnome-font-viewer`](https://snapcraft.io/gnome-font-viewer) 1. Open the font 2. Find the label at the center of the top menu (In this example, it's `Arial`, style is not a part of the font here) 3. Additionally you can check the font name by click `Info` on the top menu and find `Name: ` <upload src="8d978/8d7acd56a1f3bec.png" size="95226" name="gnome-font-viewer_arial_example.png" /> ⤶ Example <page>surface.CreateFont</page>:⤶ ```⤶ surface.CreateFont("Arial", {⤶ font = "Arial",⤶ size = 15⤶ })⤶ ```<image src="8d978/8d7acd56a1f3bec.png" size="95226" name="gnome-font-viewer_arial_example.png" /> ⤶ ## Creating the Font⤶ For information and examples on how to use the font you have now installed and found the name of, see <page>surface.CreateFont</page>