[vlc-commits] [Git][videolan/vlc][master] 2 commits: text_renderer: improve code style in darwin.c

Marvin Scholz (@ePirat) gitlab at videolan.org
Sun May 5 23:28:28 UTC 2024



Marvin Scholz pushed to branch master at VideoLAN / VLC


Commits:
96ae876d by Jiepeng Huang at 2024-05-05T23:07:57+00:00
text_renderer: improve code style in darwin.c

- - - - -
6497bee4 by Jiepeng Huang at 2024-05-05T23:07:57+00:00
text_renderer: change -1 to kCFNotFound

- - - - -


1 changed file:

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


Changes:

=====================================
modules/text_renderer/freetype/fonts/darwin.c
=====================================
@@ -56,62 +56,48 @@ static char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor)
     return retPath;
 }
 
-int getFontIndexInFontFile(const char* psz_filePath, const char* psz_family) {
-    CFStringRef cfFilePath = CFStringCreateWithCString(kCFAllocatorDefault, psz_filePath, kCFStringEncodingUTF8);
-    if (cfFilePath == NULL) {
-        return -1;
-    }
-    CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfFilePath, kCFURLPOSIXPathStyle, false);
+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) {
-        CFRelease(cfFilePath);
-        return -1;
+        return kCFNotFound;
     }
     CFArrayRef fontDescriptors = CTFontManagerCreateFontDescriptorsFromURL(url);
     if (fontDescriptors == NULL) {
-        CFRelease(cfFilePath);
         CFRelease(url);
-        return -1;
+        return kCFNotFound;
     }
     CFIndex numberOfFontDescriptors = CFArrayGetCount(fontDescriptors);
-
-    int index = 0;
+    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);
-        char* familyNameStr = FromCFString(familyName, kCFStringEncodingUTF8);
-        char* fontNameStr = FromCFString(fontName, kCFStringEncodingUTF8);
-        char* displayNameStr = FromCFString(displayName, kCFStringEncodingUTF8);
 
-        if (!strcasecmp(familyNameStr, psz_family) || !strcasecmp(fontNameStr, psz_family) || !strcasecmp(displayNameStr, psz_family)) {
+        if (CFStringCompare(targetFontName, familyName, kCFCompareCaseInsensitive) == kCFCompareEqualTo ||
+            CFStringCompare(targetFontName, fontName, kCFCompareCaseInsensitive) == kCFCompareEqualTo ||
+            CFStringCompare(targetFontName, displayName, kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
             index = i;
-            FREENULL(familyNameStr);
-            FREENULL(fontNameStr);
-            FREENULL(displayNameStr);
-            CFRelease(familyName);
-            CFRelease(fontName);
-            CFRelease(displayName);
-            break;
         }
 
-        FREENULL(familyNameStr);
-        FREENULL(fontNameStr);
-        FREENULL(displayNameStr);
         CFRelease(familyName);
         CFRelease(fontName);
         CFRelease(displayName);
+
+        if (index != kCFNotFound) {
+            break;
+        }
     }
-    if (fontDescriptors != NULL) {
-        CFRelease(fontDescriptors);
-    }
-    if (url != NULL) {
-        CFRelease(url);
-    }
-    if (cfFilePath != NULL) {
-        CFRelease(cfFilePath);
-    }
+    CFRelease(targetFontName);
+    CFRelease(fontDescriptors);
+    CFRelease(url);
     return index;
 }
 
@@ -301,8 +287,8 @@ int CoreText_GetFamily(vlc_font_select_t *fs, const char *psz_lcname,
         }
 
         /* get the index of the font family in the font file */
-        int fontIndex = getFontIndexInFontFile(path, psz_lcname);
-        if (fontIndex < 0) {
+        CFIndex fontIndex = getFontIndexInFontFile(path, psz_lcname);
+        if (fontIndex == kCFNotFound) {
             FREENULL(path);
             continue;
         }
@@ -395,8 +381,8 @@ int CoreText_GetFallbacks(vlc_font_select_t *fs, const char *psz_lcname,
     }
 
     /* get the index of the font family in the font file */
-    int fontIndex = getFontIndexInFontFile(psz_fontPath, psz_fallbackFamilyName);
-    if (fontIndex < 0) {
+    CFIndex fontIndex = getFontIndexInFontFile(psz_fontPath, psz_fallbackFamilyName);
+    if (fontIndex == kCFNotFound) {
         goto done;
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/259c50c2bdb6a27c8d3319832f155fd2d3e448cb...6497bee48a9d7844532a715759b0b65a1bae7363

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/259c50c2bdb6a27c8d3319832f155fd2d3e448cb...6497bee48a9d7844532a715759b0b65a1bae7363
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