-static void get_trait(CFDictionaryRef traits, CFStringRef attribute,
- double *trait)
-{
- CFNumberRef cftrait = CFDictionaryGetValue(traits, attribute);
- *trait = 0.0;
- CFNumberGetValue(cftrait, kCFNumberDoubleType, trait);
-}
-
-// These are available as kCTFontWeightUltraLight, etc. in newer SDKs.
-// For some reason they switched the terms "ultra light" and "thin"
-#define FontWeightUltraLight -0.8
-#define FontWeightThin -0.6
-#define FontWeightLight -0.4
-#define FontWeightRegular 0
-#define FontWeightMedium 0.23
-#define FontWeightSemibold 0.3
-#define FontWeightBold 0.4
-#define FontWeightHeavy 0.56
-#define FontWeightBlack 0.62
-
-#define AVG(x, y) ((x + y) / 2.)
-
-static void get_font_traits(CTFontDescriptorRef fontd,
- ASS_FontProviderMetaData *meta)
-{
- double weight, slant, width;
-
- CFDictionaryRef traits =
- CTFontDescriptorCopyAttribute(fontd, kCTFontTraitsAttribute);
-
- get_trait(traits, kCTFontWeightTrait, &weight);
- get_trait(traits, kCTFontSlantTrait, &slant);
- get_trait(traits, kCTFontWidthTrait, &width);
-
- SAFE_CFRelease(traits);
-
- // Printed all of my system fonts (see if'deffed code below). Here is how
- // CoreText 'normalized' weights maps to CSS/libass:
-
- // opentype: 0 100 200 300 400 500 600 700 800 900
- // css: LIGHT REG MED SBOLD BOLD BLACK EXTRABL
- // libass: LIGHT MEDIUM BOLD
- // coretext: -0.4 0.0 0.23 0.3 0.4 0.62
-
- if (weight >= AVG(FontWeightHeavy, FontWeightBlack))
- meta->weight = 900;
- else if (weight >= AVG(FontWeightBold, FontWeightHeavy))
- meta->weight = 800;
- else if (weight >= AVG(FontWeightSemibold, FontWeightBold))
- meta->weight = 700;
- else if (weight >= AVG(FontWeightMedium, FontWeightSemibold))
- meta->weight = 600;
- else if (weight >= AVG(FontWeightRegular, FontWeightMedium))
- meta->weight = 500;
- else if (weight >= AVG(FontWeightLight, FontWeightMedium))
- meta->weight = 400;
- else if (weight >= AVG(FontWeightThin, FontWeightLight))
- meta->weight = 300;
- else if (weight >= AVG(FontWeightUltraLight, FontWeightThin))
- meta->weight = 200;
- else
- meta->weight = 100;
-
- if (slant > 0.03)
- meta->slant = FONT_SLANT_ITALIC;
- else
- meta->slant = FONT_SLANT_NONE;
-
- if (width <= -0.2)
- meta->width = FONT_WIDTH_CONDENSED;
- else if (width >= 0.2)
- meta->width = FONT_WIDTH_EXPANDED;
- else
- meta->width = FONT_WIDTH_NORMAL;
-
-#if 0
- char *name[1];
- int idx = 0;
- get_name(fontd, kCTFontDisplayNameAttribute, name, &idx);
- char *file = get_font_file(fontd);
- printf(
- "Font traits for: %-40s [%-50s] "
- "<slant: %f, %03d>, <weight: (%f, %03d)>, <width: %f, %03d>\n",
- name[0], file,
- slant, meta->slant, weight, meta->weight, width, meta->width);
- free(name[0]);
- free(file);
-#endif
-}
-
-static void process_descriptors(ASS_FontProvider *provider, CFArrayRef fontsd)