7f0ae838d7
This changes the font plugin from using a font file to using a specific installed system font, which is searched for on each specific system and associated with the font file. It now uses a font property instead of a path property, and font size has been removed because the font property now handles that. When the module is first loaded, it will build up a list of system fonts in order to be usable by Freetype. It was quite painful to program this because font files can contain multiple localized versions of their face names, and then there was the issue where windows likes to mangle custom style types to the font name. Regardless, it all seems to have worked out pretty well. Minor issues: - Truetype/Opentype fonts sometimes do not automatically have italic and/or bold styles available, it seems that the system applies transformations manually in those cases. We don't do this yet, however, so right now a user might select a font with italic/bold only to discover that italic/bold doesn't always work. Not entirely sure what to do about this yet. There's probably a freetype function to do something like that somehow, This also requires that iconv be used for non-windows systems to be able to look up localized font names within font files. Windows will use the win32 API and code page IDs to translate font names.
59 lines
1.3 KiB
Objective-C
59 lines
1.3 KiB
Objective-C
#include <util/darray.h>
|
|
#include "find-font.h"
|
|
#include "text-freetype2.h"
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
static inline void add_path_font(const char *path)
|
|
{
|
|
FT_Face face;
|
|
FT_Long idx = 0;
|
|
FT_Long max_faces = 1;
|
|
|
|
while (idx < max_faces) {
|
|
if (FT_New_Face(ft2_lib, path, idx, &face) != 0)
|
|
break;
|
|
|
|
build_font_path_info(face, idx++, path);
|
|
max_faces = face->num_faces;
|
|
FT_Done_Face(face);
|
|
}
|
|
}
|
|
|
|
static void add_path_fonts(NSFileManager *file_manager, NSString *path)
|
|
{
|
|
NSArray *files = NULL;
|
|
NSError *error = NULL;
|
|
|
|
files = [file_manager contentsOfDirectoryAtPath:path error:&error];
|
|
|
|
for (NSString *file in files) {
|
|
NSString *full_path = [path stringByAppendingPathComponent:file];
|
|
|
|
add_path_font(full_path.fileSystemRepresentation);
|
|
}
|
|
}
|
|
|
|
void load_os_font_list(void)
|
|
{
|
|
@autoreleasepool {
|
|
BOOL is_dir;
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
|
NSLibraryDirectory, NSAllDomainsMask, true);
|
|
|
|
for (NSString *path in paths) {
|
|
NSFileManager *file_manager =
|
|
[NSFileManager defaultManager];
|
|
NSString *font_path =
|
|
[path stringByAppendingPathComponent:@"Fonts"];
|
|
|
|
bool folder_exists = [file_manager
|
|
fileExistsAtPath:font_path
|
|
isDirectory:&is_dir];
|
|
|
|
if (folder_exists && is_dir)
|
|
add_path_fonts(file_manager, font_path);
|
|
}
|
|
}
|
|
}
|