Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: a wider chosen font no longer breaks words mid-line
My-Name-Is-Jeff0a395e6276b6
diff --git a/tweak/Sources/Shared/Fonts/Fonts.x b/tweak/Sources/Shared/Fonts/Fonts.xindex c39b40b0..c1967d0b 100644--- a/tweak/Sources/Shared/Fonts/Fonts.x+++ b/tweak/Sources/Shared/Fonts/Fonts.x@@ -72,17 +72,51 @@ static UIFont *systemFor(NSString *name, CGFloat size) {return designed([UIFont systemFontOfSize:size weight:weightOf(name)]);}+// Spotify sizes its text boxes for Spotify Mix, so a wider font in its place breaks words mid-line ("BABYMONSTE" over+// "R" in Georgia's bold). Its text is set smaller by Spotify Mix's width over the chosen font's, measured once on a+// sample line for the regular and the bold face, each never above 1, so a font only as wide keeps its size.+// Georgia: regular 432 against 440, kept; bold 498 against 449, set at 90%.+static CGFloat fitScale(UIFontWeight weight) {+ static CGFloat regular = 1, bold = 1;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ NSString *sample = @"The quick brown fox jumps over the lazy dog 0123456789";+ NSMutableArray<NSString *> *seen = [NSMutableArray array];+ for (NSString *face in @[@"SpotifyMixUI-Regular", @"SpotifyMixUI-Bold"]) {+ // Core Text, which these hooks do not reach: Spotify's own face, once Spotify has registered it.+ CTFontRef spotify = CTFontCreateWithName((__bridge CFStringRef)face, 17, NULL);+ NSString *made = spotify ? (__bridge_transfer NSString *)CTFontCopyPostScriptName(spotify) : nil;+ UIFont *chosen = systemFor(face, 17);+ CGFloat scale = 1;+ if ([made isEqualToString:face] && chosen) {+ CGFloat theirs = [sample sizeWithAttributes:@{NSFontAttributeName: (__bridge UIFont *)spotify}].width;+ CGFloat ours = [sample sizeWithAttributes:@{NSFontAttributeName: chosen}].width;+ if (theirs > 0 && ours > theirs) scale = theirs / ours;+ [seen addObject:[NSString stringWithFormat:@"%@ %.0f against %.0f, %.0f%%", face, ours, theirs, scale * 100]];+ } else {+ [seen addObject:[NSString stringWithFormat:@"%@ not found (%@)", face, made]];+ }+ if (spotify) CFRelease(spotify);+ if ([face hasSuffix:@"Bold"]) bold = scale;+ else regular = scale;+ }+ SGLog(@"fonts: Spotify's text set to keep its width: %@", [seen componentsJoinedByString:@"; "]);+ });+ // Semibold and up take the bold face's measure.+ return weight >= UIFontWeightSemibold ? bold : regular;+}+%hook UIFont+ (UIFont *)fontWithName:(NSString *)name size:(CGFloat)size {- UIFont *font = spotifys(name) ? systemFor(name, size) : nil;+ UIFont *font = spotifys(name) ? systemFor(name, size * fitScale(weightOf(name))) : nil;return font ?: %orig;}+ (UIFont *)fontWithDescriptor:(UIFontDescriptor *)descriptor size:(CGFloat)size {NSString *name = descriptor.fontAttributes[UIFontDescriptorNameAttribute] ?: descriptor.fontAttributes[UIFontDescriptorFamilyAttribute];if (!spotifys(name)) return %orig;- CGFloat points = size > 0 ? size : descriptor.pointSize;NSNumber *weight = weightAsked(descriptor);+ CGFloat points = (size > 0 ? size : descriptor.pointSize) * fitScale(weight ? weight.doubleValue : weightOf(name));UIFont *font = !weight ? systemFor(name, points): sg_font >= SGAppFontCustom ? family(points, weight.doubleValue): designed([UIFont systemFontOfSize:points weight:weight.doubleValue]);