()
| 389 | } |
| 390 | |
| 391 | func HandleFontReload() { |
| 392 | |
| 393 | if globals.TriggerReloadFonts { |
| 394 | |
| 395 | fontPath := LocalRelativePath("assets/NotoSans-Bold.ttf") |
| 396 | |
| 397 | customFontPath := globals.Settings.Get(SettingsCustomFontPath).AsString() |
| 398 | if customFontPath != "" { |
| 399 | if FileExists(customFontPath) { |
| 400 | fontPath = customFontPath |
| 401 | } else { |
| 402 | globals.EventLog.Log(`ERROR: Custom font "%s" doesn't exist. Please check path.`, false, customFontPath) |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | if globals.LoadedFontPath != fontPath { |
| 407 | |
| 408 | if globals.LoadedFontPath != "" { |
| 409 | if customFontPath != "" { |
| 410 | globals.EventLog.Log("Custom font [%s] set.\nIt may not display correctly until after restarting MasterPlan.", false, customFontPath) |
| 411 | } else { |
| 412 | globals.EventLog.Log("Custom font un-set.\nOriginal font will be used. It may not display correctly until after restarting MasterPlan.", false) |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | // The Basic Multilingual Plane, or BMP, contains characters for almost all modern languages, and consistutes the first 65,472 code points of the first 163 Unicode blocks. |
| 417 | // See: https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane |
| 418 | |
| 419 | // For silver.ttf, 21 is the ideal font size. Otherwise, 30 seems to be reasonable. |
| 420 | |
| 421 | // loadedFont, err := ttf.OpenFont(fontPath, int(globals.Settings.Get(SettingsFontSize).AsFloat())) |
| 422 | loadedFont, err := ttf.OpenFont(fontPath, 48) |
| 423 | |
| 424 | if err != nil { |
| 425 | panic(err) |
| 426 | } |
| 427 | |
| 428 | loadedFont.SetKerning(true) // I don't think this really will do anything for us here, as we're rendering text using individual characters, not strings. |
| 429 | |
| 430 | loadedFont.SetHinting(ttf.HINTING_NORMAL) |
| 431 | |
| 432 | globals.Font = loadedFont |
| 433 | |
| 434 | globals.LoadedFontPath = fontPath |
| 435 | |
| 436 | globals.TextRenderer.DestroyGlyphs() |
| 437 | |
| 438 | // We have to refresh the font RenderTextures |
| 439 | RefreshRenderTextures() |
| 440 | |
| 441 | if globals.Project != nil { |
| 442 | // We call this specifically because reloading fonts causes textures to be recreated, meaning Map images turn blank after changing fonts |
| 443 | globals.Project.SendMessage(NewMessage(MessageRenderTextureRefresh, nil, nil)) |
| 444 | } |
| 445 | |
| 446 | } |
| 447 | |
| 448 | globals.TriggerReloadFonts = false |
no test coverage detected