[vlc-commits] [Git][videolan/vlc][3.0.x] 4 commits: freetype: darwin: fix font index issue

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon May 6 05:35:15 UTC 2024



Jean-Baptiste Kempf pushed to branch 3.0.x at VideoLAN / VLC


Commits:
2a2eaf62 by Jiepeng Huang at 2024-05-06T02:07:49+02:00
freetype: darwin: fix font index issue

In macOS/iOS/tvOS, font collection file contains multiple fonts.
The 0 index should not be used by default, but the corresponding
index should be used. This will fix some font rendering bugs and
fallback font bugs.

(manual cherry picked from commit 2e3c0fb6bc38fdad5f894611b3b9eaa0ace2c746)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -
f6f11faf by Jiepeng Huang at 2024-05-06T02:07:49+02:00
freetype: darwin: ignore case whe comparing

The `psz_lcname` is lowercase, so we need to use `strcasecmp`
instead.

(cherry picked from commit c52066f20458165436ff9c8831869fa783d12a30)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -
a072f541 by Jiepeng Huang at 2024-05-06T02:21:10+02:00
text_renderer: improve code style in darwin.c

(cherry picked from commit 96ae876dc8523939a1092bfdbb31138eb8f99e69)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -
6c952047 by Jiepeng Huang at 2024-05-06T02:21:10+02:00
text_renderer: change -1 to kCFNotFound

(cherry picked from commit 6497bee48a9d7844532a715759b0b65a1bae7363)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -


1 changed file:

- modules/text_renderer/freetype/fonts/darwin.c


Changes:

=====================================
modules/text_renderer/freetype/fonts/darwin.c
=====================================
@@ -41,7 +41,7 @@
 #include "../platform_fonts.h"
 
 char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor);
-void addNewFontToFamily(filter_t *p_filter, CTFontDescriptorRef iter, char *path, vlc_family_t *family);
+void addNewFontToFamily(filter_t *p_filter, CTFontDescriptorRef iter, char *path, vlc_family_t *family, int index);
 
 
 char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor)
@@ -60,7 +60,52 @@ char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor)
     return retPath;
 }
 
-void addNewFontToFamily(filter_t *p_filter, CTFontDescriptorRef iter, char *path, vlc_family_t *p_family)
+static CFIndex getFontIndexInFontFile(const char* psz_filePath, const char* psz_family) {
+    CFIndex index = kCFNotFound;
+    CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)psz_filePath, strlen(psz_filePath), false);
+    if (url == NULL) {
+        return kCFNotFound;
+    }
+    CFArrayRef fontDescriptors = CTFontManagerCreateFontDescriptorsFromURL(url);
+    if (fontDescriptors == NULL) {
+        CFRelease(url);
+        return kCFNotFound;
+    }
+    CFIndex numberOfFontDescriptors = CFArrayGetCount(fontDescriptors);
+    CFStringRef targetFontName = CFStringCreateWithCString(kCFAllocatorDefault, psz_family, kCFStringEncodingUTF8);
+    if (targetFontName == NULL) {
+        CFRelease(fontDescriptors);
+        CFRelease(url);
+        return kCFNotFound;
+    }
+
+    for (CFIndex i = 0; i < numberOfFontDescriptors; i++) {
+        CTFontDescriptorRef descriptor = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fontDescriptors, i);
+        CFStringRef familyName = (CFStringRef)CTFontDescriptorCopyAttribute(descriptor, kCTFontFamilyNameAttribute);
+        CFStringRef fontName = (CFStringRef)CTFontDescriptorCopyAttribute(descriptor, kCTFontNameAttribute);
+        CFStringRef displayName = (CFStringRef)CTFontDescriptorCopyAttribute(descriptor, kCTFontDisplayNameAttribute);
+
+        if (CFStringCompare(targetFontName, familyName, kCFCompareCaseInsensitive) == kCFCompareEqualTo ||
+            CFStringCompare(targetFontName, fontName, kCFCompareCaseInsensitive) == kCFCompareEqualTo ||
+            CFStringCompare(targetFontName, displayName, kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
+            index = i;
+        }
+
+        CFRelease(familyName);
+        CFRelease(fontName);
+        CFRelease(displayName);
+
+        if (index != kCFNotFound) {
+            break;
+        }
+    }
+    CFRelease(targetFontName);
+    CFRelease(fontDescriptors);
+    CFRelease(url);
+    return index;
+}
+
+void addNewFontToFamily(filter_t *p_filter, CTFontDescriptorRef iter, char *path, vlc_family_t *family, int index)
 {
     bool b_bold = false;
     bool b_italic = false;
@@ -79,7 +124,7 @@ void addNewFontToFamily(filter_t *p_filter, CTFontDescriptorRef iter, char *path
 #else
     VLC_UNUSED(p_filter);
 #endif
-    NewFont(path, 0, b_bold, b_italic, p_family);
+    NewFont(path, index, b_bold, b_italic, family);
 
     CFRelease(fontTraits);
 }
@@ -166,7 +211,14 @@ const vlc_family_t *CoreText_GetFamily(filter_t *p_filter, const char *psz_famil
             continue;
         }
 
-        addNewFontToFamily(p_filter, iter, path, p_family);
+        /* get the index of the font family in the font file */
+        CFIndex fontIndex = getFontIndexInFontFile(path, psz_lc);
+        if (fontIndex == kCFNotFound) {
+            FREENULL(path);
+            continue;
+        }
+
+        addNewFontToFamily(p_filter, iter, path, p_family, fontIndex);
     }
 
 end:
@@ -246,7 +298,13 @@ vlc_family_t *CoreText_GetFallbacks(filter_t *p_filter, const char *psz_family,
         goto done;
     }
 
-    addNewFontToFamily(p_filter, fallbackFontDescriptor, strdup(psz_fontPath), p_family);
+    /* get the index of the font family in the font file */
+    CFIndex fontIndex = getFontIndexInFontFile(psz_fontPath, psz_fallbackFamilyName);
+    if (fontIndex == kCFNotFound) {
+        goto done;
+    }
+
+    addNewFontToFamily(p_filter, fallbackFontDescriptor, strdup(psz_fontPath), p_family, fontIndex);
 
 done:
     CFRelease(familyName);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/46c24f3a3b25ae0e39724087e1d9ed12226739c7...6c95204716d9fa9c79e7b200821c2d5863f384ef

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/46c24f3a3b25ae0e39724087e1d9ed12226739c7...6c95204716d9fa9c79e7b200821c2d5863f384ef
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list