]> granicus.if.org Git - libass/commitdiff
coretext: fix reading weights of some fonts
authorRodger Combs <rodger.combs@gmail.com>
Thu, 11 Oct 2018 07:32:50 +0000 (02:32 -0500)
committerOleg Oshmyan <chortos@inbox.lv>
Thu, 26 Sep 2019 13:48:42 +0000 (16:48 +0300)
Some fonts have weights that can be expressed more precisely as doubles than
as floats. In these cases, when writing to a float, CFNumberGetValue will set
the value to the closest approximation, but return false (so we'd just clobber
whatever it set with 0). Easy fix: just store to a double instead.

libass/ass_coretext.c

index 661b95c2a952d849b7905cf49b5d4ed530efc01b..ebcf61fbfaf1431881a727cee3ceb30c85b3f23c 100644 (file)
@@ -116,17 +116,17 @@ static void get_name(CTFontDescriptorRef fontd, CFStringRef attr,
 }
 
 static void get_trait(CFDictionaryRef traits, CFStringRef attribute,
-                      float *trait)
+                      double *trait)
 {
     CFNumberRef cftrait = CFDictionaryGetValue(traits, attribute);
-    if (!CFNumberGetValue(cftrait, kCFNumberFloatType, trait))
-        *trait = 0.0;
+    *trait = 0.0;
+    CFNumberGetValue(cftrait, kCFNumberDoubleType, trait);
 }
 
 static void get_font_traits(CTFontDescriptorRef fontd,
                             ASS_FontProviderMetaData *meta)
 {
-    float weight, slant, width;
+    double weight, slant, width;
 
     CFDictionaryRef traits =
         CTFontDescriptorCopyAttribute(fontd, kCTFontTraitsAttribute);