Font: simplify code; fix memleaks (macOS)

This commit is contained in:
李通洲
2022-11-16 18:20:28 +08:00
parent d0c18c4679
commit 0361a30c40
2 changed files with 9 additions and 18 deletions
+4 -4
View File
@@ -12,10 +12,10 @@ typedef struct FFFontResult
FFstrbuf error;
/**
* Linux / BSD: QT, GTK2, GTK3, GTK4
* MacOS: System, User, Monospace, Application
* Windows: Desktop, Unset, Unset, Unset
* Other: Unset, Unset, Unset, Unset
* Linux / BSD: QT, GTK2, GTK3, GTK4
* MacOS: System, User, System Mono, User Mono
* Windows: Desktop, Unset, Unset, Unset
* Other: Unset, Unset, Unset, Unset
*/
FFstrbuf fonts[FF_DETECT_FONT_NUM_FONTS];
} FFFontResult;
+5 -14
View File
@@ -1,23 +1,14 @@
#include "common/font.h"
#include "common/io.h"
#include "util/apple/cf_helpers.h"
#include "font.h"
#import <AppKit/AppKit.h>
static void detectFontForType(CTFontUIFontType uiType, FFstrbuf* font)
{
CTFontRef ctFont = CTFontCreateUIFontForLanguage(uiType, 12, NULL);
ffCfStrGetString(CTFontCopyFamilyName(ctFont), font);
}
#import <AppKit/NSFont.h>
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
{
FF_UNUSED(instance);
ffSuppressIO(true);
detectFontForType(kCTFontUIFontSystem, &result->fonts[0]);
detectFontForType(kCTFontUIFontUser, &result->fonts[1]);
detectFontForType(kCTFontUIFontUserFixedPitch, &result->fonts[2]);
detectFontForType(kCTFontUIFontApplication, &result->fonts[3]);
ffSuppressIO(false);
ffStrbufAppendS(&result->fonts[0], [NSFont systemFontOfSize:12].familyName.UTF8String);
ffStrbufAppendS(&result->fonts[1], [NSFont userFontOfSize:12].familyName.UTF8String);
ffStrbufAppendS(&result->fonts[2], [NSFont monospacedSystemFontOfSize:12 weight:400].familyName.UTF8String);
ffStrbufAppendS(&result->fonts[3], [NSFont userFixedPitchFontOfSize:12].familyName.UTF8String);
}