diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 9c07f0c780e..0ebb0f777a9 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -233,22 +233,22 @@ static ofPath makeContoursForCharacter(FT_Face face){ #include //------------------------------------------------------------------ -static string osxFontPathByName(const of::filesystem::path & fileName){ +static of::filesystem::path osxFontPathByName(const of::filesystem::path & fileName) { CFStringRef targetName = CFStringCreateWithCString(nullptr, fileName.c_str(), kCFStringEncodingUTF8); CTFontDescriptorRef targetDescriptor = CTFontDescriptorCreateWithNameAndSize(targetName, 0.0); CFURLRef targetURL = (CFURLRef) CTFontDescriptorCopyAttribute(targetDescriptor, kCTFontURLAttribute); - string fontPath = ""; + string fontDir = ""; if(targetURL) { UInt8 buffer[PATH_MAX]; CFURLGetFileSystemRepresentation(targetURL, true, buffer, PATH_MAX); - fontPath = string((char *)buffer); + fontDir = string((char *)buffer); CFRelease(targetURL); } CFRelease(targetName); CFRelease(targetDescriptor); - + of::filesystem::path fontPath = { fontDir }; return fontPath; } #endif @@ -256,8 +256,7 @@ static string osxFontPathByName(const of::filesystem::path & fileName){ #ifdef TARGET_WIN32 #include // font font face -> file name name mapping -// FIXME: second -> fs::path -static std::unordered_map fonts_table; +static std::unordered_map fonts_table; // read font linking information from registry, and store in std::map //------------------------------------------------------------------ void initWindows(){ @@ -277,7 +276,6 @@ void initWindows(){ wchar_t value_name[2048]; BYTE *value_data; - // get font_file_name -> font_face mapping from the "Fonts" registry key l_ret = RegQueryInfoKeyW(key_ft, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &value_count, nullptr, &max_data_len, nullptr, nullptr); @@ -298,47 +296,40 @@ void initWindows(){ char value_name_char[2048]; char value_data_char[2048]; - /*char ppidl[2048]; - char fontsPath[2048]; - SHGetKnownFolderIDList(FOLDERID_Fonts, 0, nullptr, &ppidl); - SHGetPathFromIDList(ppidl,&fontsPath);*/ string fontsDir = ofGetEnv("windir"); fontsDir += "\\Fonts\\"; + for (DWORD i = 0; i < value_count; ++i) { DWORD name_len = 2048; DWORD data_len = max_data_len; - l_ret = RegEnumValueW(key_ft, i, value_name, &name_len, nullptr, nullptr, value_data, &data_len); if(l_ret != ERROR_SUCCESS){ ofLogError("ofTrueTypeFont") << "initWindows(): couldn't read registry key for font type"; continue; } - wcstombs(value_name_char,value_name,2048); wcstombs(value_data_char,reinterpret_cast(value_data),2048); string curr_face = value_name_char; string font_file = value_data_char; curr_face = curr_face.substr(0, curr_face.find('(') - 1); curr_face = ofToLower(curr_face); - fonts_table[curr_face] = fontsDir + font_file; + of::filesystem::path fontPath = { fontsDir + font_file }; + fonts_table[curr_face] = fontPath; } - - HeapFree(GetProcessHeap(), 0, value_data); - l_ret = RegCloseKey(key_ft); } -static string winFontPathByName(const string & fontname){ +static of::filesystem::path winFontPathByName(const string & fontname) { return fonts_table[fontname]; } #endif #ifdef TARGET_LINUX //------------------------------------------------------------------ -static string linuxFontPathByName(const string & fontname){ +static of::filesystem::path linuxFontPathByName(const string & fontname) { string filename; FcPattern * pattern = FcNameParse((const FcChar8*)fontname.c_str()); FcBool ret = FcConfigSubstitute(0,pattern,FcMatchPattern); @@ -368,21 +359,21 @@ static string linuxFontPathByName(const string & fontname){ } FcPatternDestroy(fontMatch); FcPatternDestroy(pattern); - return filename; + of::filesystem::path fontPath = { filename }; + return fontPath; } #endif //----------------------------------------------------------- -// FIXME: it seems first parameter is string because it represents the font name only -static bool loadFontFace(const string & _fontname, FT_Face & face, +// FIXME: it seems first parameter is string because it represents the font name only / can be +static bool loadFontFace(const string & _fontname, FT_Face & face, of::filesystem::path & _filename, int index){ auto fontname = _fontname; - auto filename = ofToDataPath(_filename); + auto filename = ofToDataPath(fontname); int fontID = index; if(!of::filesystem::exists(filename)){ #ifdef TARGET_LINUX - // FIXME: fs::path in input and output - filename = linuxFontPathByName(_fontname); + filename = linuxFontPathByName(fontname); #elif defined(TARGET_OSX) if(fontname==OF_TTF_SANS){ fontname = "Helvetica Neue"; @@ -396,18 +387,16 @@ static bool loadFontFace(const string & _fontname, FT_Face & face, }else if(fontname==OF_TTF_MONO){ fontname = "Menlo Regular"; } - // FIXME: fs::path in input and output - filename = osxFontPathByName(_fontname); + filename = osxFontPathByName(fontname); #elif defined(TARGET_WIN32) if(fontname==OF_TTF_SANS){ - fontname = "Arial"; + fontname = "arial"; }else if(fontname==OF_TTF_SERIF){ - fontname = "Times New Roman"; + fontname = "times new roman"; }else if(fontname==OF_TTF_MONO){ - fontname = "Courier New"; + fontname = "courier new"; } - // FIXME: fs::path in input and output - filename = winFontPathByName(_fontname); + filename = winFontPathByName(fontname); #endif if(filename == "" ){ ofLogError("ofTrueTypeFont") << "loadFontFace(): couldn't find font " << fontname;