Commit 962f11c2 authored by Felix Paul Kühne's avatar Felix Paul Kühne

freetype: use Apple Type Services to get the font file location instead of libfontconfig

This API was deprecated in 10.6, but still works correctly on 10.7. CoreText is the modern replacement, but doesn't provide the needed functionality so far.

(cherry picked from commit 9cee736f)

(cherry picked from commit 76313965)

(cherry picked from commit 6938a98a)

(cherry picked from commit 780bc869)
parent 6abf2937
/*****************************************************************************
* freetype.c : Put text on the video, using freetype2
*****************************************************************************
* Copyright (C) 2002 - 2011 the VideoLAN team
* Copyright (C) 2002 - 2012 the VideoLAN team
* $Id$
*
* Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
* Gildas Bazin <gbazin@videolan.org>
* Bernie Purcell <bitmap@videolan.org>
* Jean-Baptiste Kempf <jb@videolan.org>
* Felix Paul Kühne <fkuehne@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -74,6 +75,14 @@
#define FT_MulFix(v, s) (((v)*(s))>>16)
#endif
/* apple stuff */
#ifdef __APPLE__
#include <Carbon/Carbon.h>
#include <sys/param.h> /* for MAXPATHLEN */
#undef HAVE_FONTCONFIG
#define HAVE_STYLES
#endif
/* RTL */
#if defined(HAVE_FRIBIDI)
# include <fribidi/fribidi.h>
......@@ -696,6 +705,82 @@ fail:
}
#endif /* HAVE_WIN32 */
#ifdef __APPLE__
static char* MacLegacy_Select( filter_t *p_filter, const char* psz_fontname,
bool b_bold, bool b_italic, int i_size, int *i_idx )
{
VLC_UNUSED( b_bold );
VLC_UNUSED( b_italic );
VLC_UNUSED( i_size );
FSRef ref;
unsigned char path[MAXPATHLEN];
char * psz_path;
CFStringRef cf_fontName;
ATSFontRef ats_font_id;
*i_idx = 0;
msg_Dbg( p_filter, "looking for %s", psz_fontname );
cf_fontName = CFStringCreateWithCString( kCFAllocatorDefault, psz_fontname, kCFStringEncodingUTF8 );
ats_font_id = ATSFontFindFromName( cf_fontName, kATSOptionFlagsIncludeDisabledMask );
CFRelease( cf_fontName );
if ( ats_font_id == 0xFFFFFFFFUL )
{
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 )
{
msg_Err( p_filter, "ATS couldn't find either %s nor its family", psz_fontname );
return NULL;
}
}
else if( ats_font_id == 0 )
{
msg_Err( p_filter, "ATS couldn't find %s by name, won't check family", psz_fontname );
return NULL;
}
if ( noErr != ATSFontGetFileReference( ats_font_id, &ref ) )
{
msg_Err( p_filter, "ATS couldn't get file ref for %s", psz_fontname );
return NULL;
}
/* i_idx calculation by searching preceding fontIDs */
/* with same FSRef */
{
ATSFontRef id2 = ats_font_id - 1;
FSRef ref2;
while ( id2 > 0 )
{
if ( noErr != ATSFontGetFileReference( id2, &ref2 ) )
break;
if ( noErr != FSCompareFSRefs( &ref, &ref2 ) )
break;
id2 --;
}
*i_idx = ats_font_id - ( id2 + 1 );
}
if ( noErr != FSRefMakePath( &ref, path, sizeof(path) ) )
{
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 psz_path;
}
#endif
#endif /* HAVE_STYLES */
......@@ -1726,7 +1811,7 @@ static FT_Face LoadFace( filter_t *p_filter,
if( !p_face )
{
int i_idx = 0;
char *psz_fontfile;
char *psz_fontfile = NULL;
#ifdef HAVE_FONTCONFIG
psz_fontfile = FontConfig_Select( NULL,
p_style->psz_fontname,
......@@ -1734,6 +1819,8 @@ static FT_Face LoadFace( filter_t *p_filter,
(p_style->i_style_flags & STYLE_ITALIC) != 0,
-1,
&i_idx );
#elif defined( __APPLE__ )
psz_fontfile = MacLegacy_Select( p_filter, p_style->psz_fontname, false, false, -1, &i_idx );
#elif defined( WIN32 )
psz_fontfile = Win32_Select( p_filter,
p_style->psz_fontname,
......@@ -2624,6 +2711,8 @@ static int Create( vlc_object_t *p_this )
/* */
psz_fontfile = FontConfig_Select( NULL, psz_fontfamily, false, false,
p_sys->i_default_font_size, &fontindex );
#elif defined(__APPLE__)
psz_fontfile = MacLegacy_Select( p_filter, psz_fontfamily, false, false, 0, &fontindex );
#elif defined(WIN32)
psz_fontfile = Win32_Select( p_filter, psz_fontfamily, false, false,
p_sys->i_default_font_size, &fontindex );
......
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