Commit 55a47ea3 authored by Felix Paul Kühne's avatar Felix Paul Kühne

freetype: drop CoreText specific Select in favor of the generic implementation...

freetype: drop CoreText specific Select in favor of the generic implementation and add family lookup

No fallback yet
parent 0d13b823
...@@ -55,18 +55,33 @@ char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor) ...@@ -55,18 +55,33 @@ char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor)
return retPath; return retPath;
} }
char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, const vlc_family_t *CoreText_GetFamily(filter_t *p_filter, const char *psz_family)
bool b_bold, bool b_italic,
int *i_idx, uni_char_t codepoint )
{ {
VLC_UNUSED( i_idx ); filter_sys_t *p_sys = p_filter->p_sys;
VLC_UNUSED( b_bold );
VLC_UNUSED( b_italic );
VLC_UNUSED( codepoint );
if( psz_fontname == NULL ) if (unlikely(psz_family == NULL)) {
return 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; const size_t numberOfAttributes = 3;
CTFontDescriptorRef coreTextFontDescriptors[numberOfAttributes]; CTFontDescriptorRef coreTextFontDescriptors[numberOfAttributes];
CFMutableDictionaryRef coreTextAttributes[numberOfAttributes]; CFMutableDictionaryRef coreTextAttributes[numberOfAttributes];
...@@ -76,12 +91,16 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, ...@@ -76,12 +91,16 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname,
kCTFontNameAttribute, kCTFontNameAttribute,
}; };
CFStringRef fontName = CFStringCreateWithCString(kCFAllocatorDefault, #ifndef NDEBUG
psz_fontname, msg_Dbg(p_filter, "Creating new family for '%s'", psz_family);
#endif
CFStringRef familyName = CFStringCreateWithCString(kCFAllocatorDefault,
psz_family,
kCFStringEncodingUTF8); kCFStringEncodingUTF8);
for (size_t x = 0; x < numberOfAttributes; x++) { for (size_t x = 0; x < numberOfAttributes; x++) {
coreTextAttributes[x] = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL); coreTextAttributes[x] = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL);
CFDictionaryAddValue(coreTextAttributes[x], attributeNames[x], fontName); CFDictionaryAddValue(coreTextAttributes[x], attributeNames[x], familyName);
coreTextFontDescriptors[x] = CTFontDescriptorCreateWithAttributes(coreTextAttributes[x]); coreTextFontDescriptors[x] = CTFontDescriptorCreateWithAttributes(coreTextAttributes[x]);
} }
...@@ -94,6 +113,8 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, ...@@ -94,6 +113,8 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname,
CFIndex numberOfFoundFontDescriptions = CFArrayGetCount(matchedFontDescriptions); CFIndex numberOfFoundFontDescriptions = CFArrayGetCount(matchedFontDescriptions);
char *path = NULL; char *path = NULL;
bool b_bold = false;
bool b_italic = false;
for (CFIndex i = 0; i < numberOfFoundFontDescriptions; i++) { for (CFIndex i = 0; i < numberOfFoundFontDescriptions; i++) {
CTFontDescriptorRef iter = CFArrayGetValueAtIndex(matchedFontDescriptions, i); CTFontDescriptorRef iter = CFArrayGetValueAtIndex(matchedFontDescriptions, i);
...@@ -107,10 +128,23 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, ...@@ -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(matchedFontDescriptions);
CFRelease(coreTextFontCollection); CFRelease(coreTextFontCollection);
...@@ -121,7 +155,15 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, ...@@ -121,7 +155,15 @@ char* CoreText_Select( filter_t *p_filter, const char* psz_fontname,
} }
CFRelease(coreTextFontDescriptorsArray); CFRelease(coreTextFontDescriptorsArray);
CFRelease(fontName); CFRelease(familyName);
return path; return p_family;
}
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;
} }
...@@ -1263,7 +1263,13 @@ static int Create( vlc_object_t *p_this ) ...@@ -1263,7 +1263,13 @@ static int Create( vlc_object_t *p_this )
p_sys->pf_get_fallbacks = FontConfig_GetFallbacks; p_sys->pf_get_fallbacks = FontConfig_GetFallbacks;
FontConfig_Prepare( p_filter ); FontConfig_Prepare( p_filter );
#elif defined( __APPLE__ ) #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 ) #elif defined( _WIN32 ) && defined( HAVE_GET_FONT_BY_FAMILY_NAME )
const char *const ppsz_win32_default[] = const char *const ppsz_win32_default[] =
{ "Tahoma", "FangSong", "SimHei", "KaiTi" }; { "Tahoma", "FangSong", "SimHei", "KaiTi" };
......
...@@ -49,8 +49,8 @@ ...@@ -49,8 +49,8 @@
/* Default fonts */ /* Default fonts */
#ifdef __APPLE__ #ifdef __APPLE__
# define SYSTEM_DEFAULT_FONT_FILE "/Library/Fonts/Arial Unicode.ttf" # define SYSTEM_DEFAULT_FONT_FILE "/System/Library/Fonts/HelveticaNeue.dfont"
# define SYSTEM_DEFAULT_FAMILY "Arial Unicode MS" # define SYSTEM_DEFAULT_FAMILY "Helvetica Neue"
# define SYSTEM_DEFAULT_MONOSPACE_FONT_FILE "/System/Library/Fonts/Monaco.dfont" # define SYSTEM_DEFAULT_MONOSPACE_FONT_FILE "/System/Library/Fonts/Monaco.dfont"
# define SYSTEM_DEFAULT_MONOSPACE_FAMILY "Monaco" # define SYSTEM_DEFAULT_MONOSPACE_FAMILY "Monaco"
#elif defined( _WIN32 ) #elif defined( _WIN32 )
...@@ -151,9 +151,8 @@ const vlc_family_t *Win32_GetFamily( filter_t *p_filter, const char *psz_family ...@@ -151,9 +151,8 @@ const vlc_family_t *Win32_GetFamily( filter_t *p_filter, const char *psz_family
#endif /* _WIN32 */ #endif /* _WIN32 */
#ifdef __APPLE__ #ifdef __APPLE__
char* CoreText_Select( filter_t *p_filter, const char* psz_fontname, vlc_family_t *CoreText_GetFallbacks(filter_t *p_filter, const char *psz_family, uni_char_t codepoint);
bool b_bold, bool b_italic, const vlc_family_t *CoreText_GetFamily(filter_t *p_filter, const char *psz_family);
int *i_idx, uni_char_t codepoint );
#endif /* __APPLE__ */ #endif /* __APPLE__ */
#ifdef __ANDROID__ #ifdef __ANDROID__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment