Commit 8fba7c58 authored by Felix Paul Kühne's avatar Felix Paul Kühne

freetype: replace legacy Mac selector with a re-write based on CoreText

This removes a Carbon dependency and adds support for tvOS and iOS
parent cc0d1977
...@@ -28,7 +28,7 @@ libfreetype_plugin_la_SOURCES += text_renderer/fonts/android.c ...@@ -28,7 +28,7 @@ libfreetype_plugin_la_SOURCES += text_renderer/fonts/android.c
endif endif
if HAVE_DARWIN if HAVE_DARWIN
libfreetype_plugin_la_SOURCES += text_renderer/fonts/darwin.c libfreetype_plugin_la_SOURCES += text_renderer/fonts/darwin.c
libfreetype_plugin_la_LDFLAGS += -Wl,-framework,Carbon libfreetype_plugin_la_LDFLAGS += -Wl,-framework,CoreFoundation -Wl,-framework,CoreText
endif endif
if HAVE_FRIBIDI if HAVE_FRIBIDI
libfreetype_plugin_la_CPPFLAGS += $(FRIBIDI_CFLAGS) -DHAVE_FRIBIDI libfreetype_plugin_la_CPPFLAGS += $(FRIBIDI_CFLAGS) -DHAVE_FRIBIDI
......
/***************************************************************************** /*****************************************************************************
* freetype.c : Put text on the video, using freetype2 * darwin.c : Put text on the video, using freetype2
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 - 2015 VLC authors and VideoLAN * Copyright (C) 2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Sigmund Augdal Helberg <dnumgis@videolan.org> * Authors: Felix Paul Kühne <fkuehne@videolan.org>
* Gildas Bazin <gbazin@videolan.org>
* Bernie Purcell <bitmap@videolan.org>
* Jean-Baptiste Kempf <jb@videolan.org> * Jean-Baptiste Kempf <jb@videolan.org>
* Felix Paul Kühne <fkuehne@videolan.org>
* Salah-Eddin Shaban <salshaaban@gmail.com> * Salah-Eddin Shaban <salshaaban@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
...@@ -37,92 +34,94 @@ ...@@ -37,92 +34,94 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_filter.h> /* filter_sys_t */ #include <vlc_filter.h> /* filter_sys_t */
#include <TargetConditionals.h> #include <CoreFoundation/CoreFoundation.h>
#if !TARGET_OS_IPHONE #include <CoreText/CoreText.h>
# include <Carbon/Carbon.h>
#endif
#include <sys/param.h> /* for MAXPATHLEN */
#include "../platform_fonts.h" #include "../platform_fonts.h"
#if !TARGET_OS_IPHONE char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor);
char* MacLegacy_Select( filter_t *p_filter, const char* psz_fontname,
char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor)
{
CFURLRef url = CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontURLAttribute);
CFStringRef path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
char *cpath = (char *)CFStringGetCStringPtr(path, kCFStringEncodingUTF8);
char *retPath = NULL;
if (cpath) {
retPath = strdup(cpath);
}
CFRelease(path);
CFRelease(url);
return retPath;
}
char* CoreText_Select( filter_t *p_filter, const char* psz_fontname,
bool b_bold, bool b_italic, bool b_bold, bool b_italic,
int *i_idx, uni_char_t codepoint ) int *i_idx, uni_char_t codepoint )
{ {
VLC_UNUSED( i_idx );
VLC_UNUSED( b_bold ); VLC_UNUSED( b_bold );
VLC_UNUSED( b_italic ); VLC_UNUSED( b_italic );
VLC_UNUSED( codepoint ); VLC_UNUSED( codepoint );
FSRef ref;
unsigned char path[MAXPATHLEN];
char * psz_path;
CFStringRef cf_fontName;
ATSFontRef ats_font_id;
*i_idx = 0;
if( psz_fontname == NULL ) if( psz_fontname == NULL )
return NULL; return NULL;
msg_Dbg( p_filter, "looking for %s", psz_fontname ); const size_t numberOfAttributes = 3;
cf_fontName = CFStringCreateWithCString( kCFAllocatorDefault, psz_fontname, kCFStringEncodingUTF8 ); CTFontDescriptorRef coreTextFontDescriptors[numberOfAttributes];
CFMutableDictionaryRef coreTextAttributes[numberOfAttributes];
CFStringRef attributeNames[numberOfAttributes] = {
kCTFontFamilyNameAttribute,
kCTFontDisplayNameAttribute,
kCTFontNameAttribute,
};
CFStringRef fontName = CFStringCreateWithCString(kCFAllocatorDefault,
psz_fontname,
kCFStringEncodingUTF8);
for (size_t x = 0; x < numberOfAttributes; x++) {
coreTextAttributes[x] = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL);
CFDictionaryAddValue(coreTextAttributes[x], attributeNames[x], fontName);
coreTextFontDescriptors[x] = CTFontDescriptorCreateWithAttributes(coreTextAttributes[x]);
}
CFArrayRef coreTextFontDescriptorsArray = CFArrayCreate(kCFAllocatorDefault, (const void **)&coreTextFontDescriptors, numberOfAttributes, NULL);
ats_font_id = ATSFontFindFromName( cf_fontName, kATSOptionFlagsIncludeDisabledMask ); CTFontCollectionRef coreTextFontCollection = CTFontCollectionCreateWithFontDescriptors(coreTextFontDescriptorsArray, 0);
if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) CFArrayRef matchedFontDescriptions = CTFontCollectionCreateMatchingFontDescriptors(coreTextFontCollection);
{
msg_Dbg( p_filter, "ATS couldn't find %s by name, checking family", psz_fontname );
ats_font_id = ATSFontFamilyFindFromName( cf_fontName, kATSOptionFlagsDefault );
if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) CFIndex numberOfFoundFontDescriptions = CFArrayGetCount(matchedFontDescriptions);
{
msg_Dbg( p_filter, "ATS couldn't find either %s nor its family, checking PS name", psz_fontname );
ats_font_id = ATSFontFindFromPostScriptName( cf_fontName, kATSOptionFlagsDefault );
if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) char *path = NULL;
{
msg_Err( p_filter, "ATS couldn't find %s (no font name, family or PS name)", psz_fontname ); for (CFIndex i = 0; i < numberOfFoundFontDescriptions; i++) {
CFRelease( cf_fontName ); CTFontDescriptorRef iter = CFArrayGetValueAtIndex(matchedFontDescriptions, i);
return NULL; path = getPathForFontDescription(iter);
}
/* check if the path is empty, which can happen in rare circumstances */
if (path != NULL) {
if (strcmp("", path) == 0) {
FREENULL(path);
continue;
} }
} }
CFRelease( cf_fontName );
if ( noErr != ATSFontGetFileReference( ats_font_id, &ref ) ) break;
{
msg_Err( p_filter, "ATS couldn't get file ref for %s", psz_fontname );
return NULL;
} }
/* i_idx calculation by searching preceding fontIDs */ msg_Dbg( p_filter, "found '%s'", path );
/* with same FSRef */
{
ATSFontRef id2 = ats_font_id - 1;
FSRef ref2;
while ( id2 > 0 ) CFRelease(matchedFontDescriptions);
{ CFRelease(coreTextFontCollection);
if ( noErr != ATSFontGetFileReference( id2, &ref2 ) )
break;
if ( noErr != FSCompareFSRefs( &ref, &ref2 ) )
break;
id2 --; for (size_t x = 0; x < numberOfAttributes; x++) {
} CFRelease(coreTextAttributes[x]);
*i_idx = ats_font_id - ( id2 + 1 ); CFRelease(coreTextFontDescriptors[x]);
} }
if ( noErr != FSRefMakePath( &ref, path, sizeof(path) ) ) CFRelease(coreTextFontDescriptorsArray);
{ CFRelease(fontName);
msg_Err( p_filter, "failure when getting path from FSRef" );
return NULL;
}
msg_Dbg( p_filter, "found %s", path );
psz_path = strdup( (char *)path ); return path;
return psz_path;
} }
#endif
...@@ -1263,9 +1263,7 @@ static int Create( vlc_object_t *p_this ) ...@@ -1263,9 +1263,7 @@ 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__ )
#if !TARGET_OS_IPHONE p_sys->pf_select = CoreText_Select;
p_sys->pf_select = MacLegacy_Select;
#endif
#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" };
......
...@@ -151,11 +151,9 @@ const vlc_family_t *Win32_GetFamily( filter_t *p_filter, const char *psz_family ...@@ -151,11 +151,9 @@ const vlc_family_t *Win32_GetFamily( filter_t *p_filter, const char *psz_family
#endif /* _WIN32 */ #endif /* _WIN32 */
#ifdef __APPLE__ #ifdef __APPLE__
#if !TARGET_OS_IPHONE char* CoreText_Select( filter_t *p_filter, const char* psz_fontname,
char* MacLegacy_Select( filter_t *p_filter, const char* psz_fontname,
bool b_bold, bool b_italic, bool b_bold, bool b_italic,
int *i_idx, uni_char_t codepoint ); int *i_idx, uni_char_t codepoint );
#endif
#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