X-Git-Url: https://git.saurik.com/winterboard.git/blobdiff_plain/c8fa3a187ac4e61a523aa664f01c618746a290b9..c570f7cb4b125942a79cbfaab14fc763ea24a75e:/Library.mm diff --git a/Library.mm b/Library.mm index 72311b8..918978a 100644 --- a/Library.mm +++ b/Library.mm @@ -676,6 +676,35 @@ MSInstanceMessageHook2(NSString *, NSBundle, pathForResource,ofType, NSString *, } // }}} +static void $drawLabel$(NSString *label, CGRect rect, NSString *style, NSString *custom) { + bool ellipsis(false); + float max = rect.size.width - 11, width; + width: + width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width; + + if (width > max) { + size_t length([label length]); + float spacing((width - max) / (length - 1)); + + if (spacing > 1.25) { + ellipsis = true; + label = [label substringToIndex:(length - 1)]; + goto width; + } + + style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]]; + } + + if (ellipsis) + label = [label stringByAppendingString:@"..."]; + + if (custom != nil) + style = [style stringByAppendingString:custom]; + + CGSize size = [label sizeWithStyle:style forWidth:rect.size.width]; + [label drawAtPoint:CGPointMake((rect.size.width - size.width) / 2 + rect.origin.x, rect.origin.y) withStyle:style]; +} + static struct WBStringDrawingState { WBStringDrawingState *next_; unsigned count_; @@ -733,7 +762,12 @@ MSInstanceMessageHook7(CGSize, NSString, _drawInRect,withFont,lineBreakMode,alig NSString *base(state->base_ ?: @""); NSString *extra([NSString stringWithFormat:@"text-align: %@", textAlign]); - [self drawInRect:rect withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], extra, base, info]]; + + if (true) + $drawLabel$(self, rect, [NSString stringWithFormat:@"%@;%@", [font markupDescription], base], info); + else + [self drawInRect:rect withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], extra, base, info]]; + return CGSizeZero; } @@ -1539,8 +1573,6 @@ MSInstanceMessageHook2(CGSize, WebCoreFrameBridge, renderedSizeOfNode,constraine // }}} MSInstanceMessage1(void, SBIconLabel, drawRect, CGRect, rect) { - CGRect bounds = [self bounds]; - static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL); int docked; @@ -1563,32 +1595,9 @@ MSInstanceMessage1(void, SBIconLabel, drawRect, CGRect, rect) { else if (docked) style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "]; - bool ellipsis(false); - float max = [self frame].size.width - 11, width; - width: - width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width; - - if (width > max) { - size_t length([label length]); - float spacing((width - max) / (length - 1)); - - if (spacing > 1.25) { - ellipsis = true; - label = [label substringToIndex:(length - 1)]; - goto width; - } - - style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]]; - } - - if (ellipsis) - label = [label stringByAppendingString:@"..."]; - - if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")]) - style = [style stringByAppendingString:custom]; + NSString *custom([Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")]); - CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width]; - [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style]; + $drawLabel$(label, [self bounds], style, custom); } MSInstanceMessage0(CGImageRef, SBIconLabel, buildLabelImage) {