yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
font_loader.mm
Go to the documentation of this file.
1// FontLoader.mm
3
4#include "imgui/imgui.h"
5
6#include "app/gui/icons.h"
7
8#if defined(__APPLE__) && defined(__MACH__)
9/* Apple OSX and iOS (Darwin). */
10#include <TargetConditionals.h>
11
12#import <CoreText/CoreText.h>
13
14#if TARGET_IPHONE_SIMULATOR == 1
15/* iOS in Xcode simulator */
16void LoadSystemFonts() {}
17
18#elif TARGET_OS_IPHONE == 1
19/* iOS */
20void LoadSystemFonts() {}
21
22#elif TARGET_OS_MAC == 1
23/* macOS */
24
25#import <Cocoa/Cocoa.h>
26
27// MacOS Implementation
28void LoadSystemFonts() {
29 // List of common macOS system fonts
30 NSArray *fontNames = @[ @"Helvetica", @"Times New Roman", @"Courier", @"Arial", @"Verdana" ];
31
32 for (NSString *fontName in fontNames) {
33 NSFont *font = [NSFont fontWithName:fontName size:14.0];
34 if (!font) {
35 NSLog(@"Font not found: %@", fontName);
36 continue;
37 }
38
39 CTFontDescriptorRef fontDescriptor =
40 CTFontDescriptorCreateWithNameAndSize((CFStringRef)font.fontName, font.pointSize);
41 CFURLRef fontURL = (CFURLRef)CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontURLAttribute);
42 NSString *fontPath = [(NSURL *)fontURL path];
43 CFRelease(fontDescriptor);
44
45 if (fontPath != nil && [[NSFileManager defaultManager] isReadableFileAtPath:fontPath]) {
46 // Load the font into ImGui
47 ImGuiIO &io = ImGui::GetIO();
48 ImFontConfig icons_config;
49 icons_config.MergeMode = true;
50 icons_config.GlyphOffset.y = 5.0f;
51 icons_config.GlyphMinAdvanceX = 13.0f;
52 icons_config.PixelSnapH = true;
53 static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
54 static const float ICON_FONT_SIZE = 18.0f;
55 ImFont *imFont = io.Fonts->AddFontFromFileTTF([fontPath UTF8String], 14.0f);
56 if (!imFont) {
57 NSLog(@"Failed to load font: %@", fontPath);
58 }
59 io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_MD, ICON_FONT_SIZE, &icons_config,
60 icons_ranges);
61 } else {
62 NSLog(@"Font file not accessible: %@", fontPath);
63 }
64
65 if (fontURL) {
66 CFRelease(fontURL);
67 }
68 }
69}
70#else
71// Unsupported platform
72#endif
73
74#endif
void LoadSystemFonts()
#define ICON_MIN_MD
Definition icons.h:8
#define FONT_ICON_FILE_NAME_MD
Definition icons.h:6