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