[vlc-commits] freetype: use Apple Type Services to get the font file location instead of libfontconfig
Felix Paul Kühne
git at videolan.org
Wed May 30 18:54:14 CEST 2012
vlc/vlc-2.0 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon May 28 02:03:00 2012 +0200| [962f11c20cdcd002e10d074a0d9416330c9cf496] | committer: 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 9cee736f1276daa463bc6fa9127dfb9d5f52d957)
(cherry picked from commit 763139653998328284518112904e0e8ec4d9b8d8)
(cherry picked from commit 6938a98a430431a7d8f41228c60dd883b8264e6a)
(cherry picked from commit 780bc86907509205c3d0335350aeed909a427a2b)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=962f11c20cdcd002e10d074a0d9416330c9cf496
---
modules/text_renderer/freetype.c | 93 +++++++++++++++++++++++++++++++++++++-
1 file changed, 91 insertions(+), 2 deletions(-)
diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index a61e18c..f24aa28 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -1,13 +1,14 @@
/*****************************************************************************
* 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 at videolan.org>
* Gildas Bazin <gbazin at videolan.org>
* Bernie Purcell <bitmap at videolan.org>
* Jean-Baptiste Kempf <jb at videolan.org>
+ * Felix Paul Kühne <fkuehne at 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 );
More information about the vlc-commits
mailing list