summaryrefslogtreecommitdiffstats
path: root/libass
diff options
context:
space:
mode:
authorRodger Combs <rodger.combs@gmail.com>2018-10-12 00:58:04 -0500
committerOleg Oshmyan <chortos@inbox.lv>2019-09-26 16:48:42 +0300
commitd0852911b7a91ee7e6653958419009912a7ad3e8 (patch)
treefeebcc8966b61cf8cdf14de5b0d7ef5d54fcc9fa /libass
parentd9c1df24c148fb6f6a19d6563c3f6abe8653264b (diff)
downloadlibass-d0852911b7a91ee7e6653958419009912a7ad3e8.tar.bz2
libass-d0852911b7a91ee7e6653958419009912a7ad3e8.tar.xz
coretext: use weight steps from macOS SDK
Diffstat (limited to 'libass')
-rw-r--r--libass/ass_coretext.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c
index ebcf61f..5885477 100644
--- a/libass/ass_coretext.c
+++ b/libass/ass_coretext.c
@@ -123,6 +123,20 @@ static void get_trait(CFDictionaryRef traits, CFStringRef attribute,
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)
{
@@ -145,18 +159,24 @@ static void get_font_traits(CTFontDescriptorRef fontd,
// libass: LIGHT MEDIUM BOLD
// coretext: -0.4 0.0 0.23 0.3 0.4 0.62
- if (weight >= 0.62)
+ if (weight >= AVG(FontWeightHeavy, FontWeightBlack))
+ meta->weight = 900;
+ else if (weight >= AVG(FontWeightBold, FontWeightHeavy))
meta->weight = 800;
- else if (weight >= 0.4)
+ else if (weight >= AVG(FontWeightSemibold, FontWeightBold))
meta->weight = 700;
- else if (weight >= 0.3)
+ else if (weight >= AVG(FontWeightMedium, FontWeightSemibold))
meta->weight = 600;
- else if (weight >= 0.23)
+ else if (weight >= AVG(FontWeightRegular, FontWeightMedium))
meta->weight = 500;
- else if (weight >= -0.4)
+ else if (weight >= AVG(FontWeightLight, FontWeightMedium))
meta->weight = 400;
- else
+ 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;