vlc | branch: master | Felix Paul Kühne <fkue...@videolan.org> | Sun Nov 22 21:22:14 2015 +0100| [55a47ea3474dd7ba462192cb34bfbf7be92e463b] | committer: Felix Paul Kühne
freetype: drop CoreText specific Select in favor of the generic implementation and add family lookup No fallback yet > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=55a47ea3474dd7ba462192cb34bfbf7be92e463b --- modules/text_renderer/fonts/darwin.c | 76 +++++++++++++++++++++++++------- modules/text_renderer/freetype.c | 8 +++- modules/text_renderer/platform_fonts.h | 9 ++-- 3 files changed, 70 insertions(+), 23 deletions(-) diff --git a/modules/text_renderer/fonts/darwin.c b/modules/text_renderer/fonts/darwin.c index a56ee3d..209b241 100644 --- a/modules/text_renderer/fonts/darwin.c +++ b/modules/text_renderer/fonts/darwin.c @@ -55,18 +55,33 @@ char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor) return retPath; } -char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, - bool b_bold, bool b_italic, - int *i_idx, uni_char_t codepoint ) +const vlc_family_t *CoreText_GetFamily(filter_t *p_filter, const char *psz_family) { - VLC_UNUSED( i_idx ); - VLC_UNUSED( b_bold ); - VLC_UNUSED( b_italic ); - VLC_UNUSED( codepoint ); + filter_sys_t *p_sys = p_filter->p_sys; - if( psz_fontname == NULL ) + if (unlikely(psz_family == NULL)) { return NULL; + } + + char *psz_lc = ToLower(psz_family); + if (unlikely(!psz_lc)) { + return NULL; + } + + /* let's double check if we have parsed this family already */ + vlc_family_t *p_family = vlc_dictionary_value_for_key(&p_sys->family_map, psz_lc); + if (p_family) { + free(psz_lc); + return p_family; + } + + /* create a new family object */ + p_family = NewFamily(p_filter, psz_lc, &p_sys->p_families, &p_sys->family_map, psz_lc); + if (unlikely(!p_family)) { + return NULL; + } + /* we search for family name, display name and name to find them all */ const size_t numberOfAttributes = 3; CTFontDescriptorRef coreTextFontDescriptors[numberOfAttributes]; CFMutableDictionaryRef coreTextAttributes[numberOfAttributes]; @@ -76,12 +91,16 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, kCTFontNameAttribute, }; - CFStringRef fontName = CFStringCreateWithCString(kCFAllocatorDefault, - psz_fontname, - kCFStringEncodingUTF8); +#ifndef NDEBUG + msg_Dbg(p_filter, "Creating new family for '%s'", psz_family); +#endif + + CFStringRef familyName = CFStringCreateWithCString(kCFAllocatorDefault, + psz_family, + kCFStringEncodingUTF8); for (size_t x = 0; x < numberOfAttributes; x++) { coreTextAttributes[x] = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL); - CFDictionaryAddValue(coreTextAttributes[x], attributeNames[x], fontName); + CFDictionaryAddValue(coreTextAttributes[x], attributeNames[x], familyName); coreTextFontDescriptors[x] = CTFontDescriptorCreateWithAttributes(coreTextAttributes[x]); } @@ -94,6 +113,8 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, CFIndex numberOfFoundFontDescriptions = CFArrayGetCount(matchedFontDescriptions); char *path = NULL; + bool b_bold = false; + bool b_italic = false; for (CFIndex i = 0; i < numberOfFoundFontDescriptions; i++) { CTFontDescriptorRef iter = CFArrayGetValueAtIndex(matchedFontDescriptions, i); @@ -107,10 +128,23 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, } } - break; - } + CFDictionaryRef fontTraits = CTFontDescriptorCopyAttribute(iter, kCTFontTraitsAttribute); + CFNumberRef trait = CFDictionaryGetValue(fontTraits, kCTFontWeightTrait); + float traitValue = 0.; + CFNumberGetValue(trait, kCFNumberFloatType, &traitValue); + b_bold = traitValue > 0.23; + trait = CFDictionaryGetValue(fontTraits, kCTFontSlantTrait); + traitValue = 0.; + CFNumberGetValue(trait, kCFNumberFloatType, &traitValue); + b_italic = traitValue > 0.03; + +#ifndef NDEBUG + msg_Dbg(p_filter, "New font for family '%s' bold %i italic %i path '%s'", psz_family, b_bold, b_italic, path); +#endif + NewFont(path, 0, b_bold, b_italic, p_family); - msg_Dbg( p_filter, "found '%s'", path ); + CFRelease(fontTraits); + } CFRelease(matchedFontDescriptions); CFRelease(coreTextFontCollection); @@ -121,7 +155,15 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, } CFRelease(coreTextFontDescriptorsArray); - CFRelease(fontName); + CFRelease(familyName); + + return p_family; +} - return path; +vlc_family_t *CoreText_GetFallbacks(filter_t *p_filter, const char *psz_family, uni_char_t codepoint) +{ + VLC_UNUSED(p_filter); + VLC_UNUSED(psz_family); + VLC_UNUSED(codepoint); + return NULL; } diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c index 251e841..307c7b4 100644 --- a/modules/text_renderer/freetype.c +++ b/modules/text_renderer/freetype.c @@ -1263,7 +1263,13 @@ static int Create( vlc_object_t *p_this ) p_sys->pf_get_fallbacks = FontConfig_GetFallbacks; FontConfig_Prepare( p_filter ); #elif defined( __APPLE__ ) - p_sys->pf_select = CoreText_Select; + const char *const ppsz_darwin_default[] = + { "Helvetica Neue", "Arial", "GungSeo", "Arial Unicode MS", "PingFang SC", "MalayalamMN" }; + p_sys->pf_select = Generic_Select; + p_sys->pf_get_family = CoreText_GetFamily; + p_sys->pf_get_fallbacks = CoreText_GetFallbacks; + InitDefaultList( p_filter, ppsz_darwin_default, + sizeof( ppsz_darwin_default ) / sizeof( *ppsz_darwin_default ) ); #elif defined( _WIN32 ) && defined( HAVE_GET_FONT_BY_FAMILY_NAME ) const char *const ppsz_win32_default[] = { "Tahoma", "FangSong", "SimHei", "KaiTi" }; diff --git a/modules/text_renderer/platform_fonts.h b/modules/text_renderer/platform_fonts.h index 7c9e051..204ca39 100644 --- a/modules/text_renderer/platform_fonts.h +++ b/modules/text_renderer/platform_fonts.h @@ -49,8 +49,8 @@ /* Default fonts */ #ifdef __APPLE__ -# define SYSTEM_DEFAULT_FONT_FILE "/Library/Fonts/Arial Unicode.ttf" -# define SYSTEM_DEFAULT_FAMILY "Arial Unicode MS" +# define SYSTEM_DEFAULT_FONT_FILE "/System/Library/Fonts/HelveticaNeue.dfont" +# define SYSTEM_DEFAULT_FAMILY "Helvetica Neue" # define SYSTEM_DEFAULT_MONOSPACE_FONT_FILE "/System/Library/Fonts/Monaco.dfont" # define SYSTEM_DEFAULT_MONOSPACE_FAMILY "Monaco" #elif defined( _WIN32 ) @@ -151,9 +151,8 @@ const vlc_family_t *Win32_GetFamily( filter_t *p_filter, const char *psz_family #endif /* _WIN32 */ #ifdef __APPLE__ -char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, - bool b_bold, bool b_italic, - int *i_idx, uni_char_t codepoint ); +vlc_family_t *CoreText_GetFallbacks(filter_t *p_filter, const char *psz_family, uni_char_t codepoint); +const vlc_family_t *CoreText_GetFamily(filter_t *p_filter, const char *psz_family); #endif /* __APPLE__ */ #ifdef __ANDROID__ _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits