X-Git-Url: https://git.saurik.com/winterboard.git/blobdiff_plain/2a606c6c8279781217a5b74be66ecbee548576d7..7327178388c65f34619d4b5f7875a4ca49fb658c:/Library.mm?ds=inline diff --git a/Library.mm b/Library.mm index d03ec83..223b681 100644 --- a/Library.mm +++ b/Library.mm @@ -121,6 +121,8 @@ MSClassHook(UIImage) MSMetaClassHook(UIImage) MSClassHook(UINavigationBar) MSClassHook(UIToolbar) +MSClassHook(UIStatusBarTimeItemView) +MSClassHook(UIWebDocumentView) MSClassHook(CKBalloonView) MSClassHook(CKMessageCell) @@ -161,6 +163,7 @@ MSClassHook(SBWidgetApplicationIcon) extern "C" void WKSetCurrentGraphicsContext(CGContextRef); static struct MSFixClass { MSFixClass() { + $UIWebDocumentView = objc_getClass("UIWebBrowserView") ?: $UIWebDocumentView; $SBIcon = objc_getClass("SBIconView") ?: $SBIcon; if ($SBIconList == nil) @@ -714,6 +717,52 @@ static struct WBStringDrawingState { NSString *info_; } *stringDrawingState_; +extern "C" CGColorSpaceRef CGContextGetFillColorSpace(CGContextRef); +extern "C" void CGContextGetFillColor(CGContextRef, CGFloat[]); + +static NSString *WBColorMarkup() { + CGContextRef context(UIGraphicsGetCurrentContext()); + //NSLog(@"XXX:1:%p", context); + if (context == NULL) + return @""; + + CGColorSpaceRef space(CGContextGetFillColorSpace(context)); + //NSLog(@"XXX:2:%p", space); + if (space == NULL) + return @""; + + size_t number(CGColorSpaceGetNumberOfComponents(space)); + //NSLog(@"XXX:3:%u", number); + if (number == 0) + return @""; + + CGFloat components[number + 1]; + CGContextGetFillColor(context, components); + + CGFloat r, g, b, a; + + switch (number) { + case 1: + r = components[0]; + g = components[0]; + b = components[0]; + a = components[1]; + break; + + case 3: + r = components[0]; + g = components[1]; + b = components[2]; + a = components[3]; + break; + + default: + return @""; + } + + return [NSString stringWithFormat:@"color: rgba(%g, %g, %g, %g)", r * 255, g * 255, b * 255, a]; +} + MSInstanceMessageHook6(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreakMode,letterSpacing,includeEmoji, CGPoint, point, float, width, UIFont *, font, UILineBreakMode, mode, float, spacing, BOOL, emoji) { //NSLog(@"XXX: @\"%@\" %g", self, spacing); @@ -732,7 +781,7 @@ MSInstanceMessageHook6(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreak NSString *base(state->base_ ?: @""); NSString *extra([NSString stringWithFormat:@"letter-spacing: %gpx", spacing]); - [self drawAtPoint:point withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], extra, base, info]]; + [self drawAtPoint:point withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@;%@", [font markupDescription], WBColorMarkup(), extra, base, info]]; return CGSizeZero; } @@ -772,9 +821,9 @@ MSInstanceMessageHook7(CGSize, NSString, _drawInRect,withFont,lineBreakMode,alig NSString *extra([NSString stringWithFormat:@"text-align: %@", textAlign]); if (true) - $drawLabel$(self, rect, [NSString stringWithFormat:@"%@;%@", [font markupDescription], base], info); + $drawLabel$(self, rect, [NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], WBColorMarkup(), base], info); else - [self drawInRect:rect withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], extra, base, info]]; + [self drawInRect:rect withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@;%@", [font markupDescription], WBColorMarkup(), extra, base, info]]; return CGSizeZero; } @@ -797,7 +846,7 @@ MSInstanceMessageHook4(CGSize, NSString, sizeWithFont,forWidth,lineBreakMode,let NSString *base(state->base_ ?: @""); NSString *extra([NSString stringWithFormat:@"letter-spacing: %gpx", spacing]); - return [self sizeWithStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], extra, base, info] forWidth:width]; + return [self sizeWithStyle:[NSString stringWithFormat:@"%@;%@;%@;%@;%@", [font markupDescription], WBColorMarkup(), extra, base, info] forWidth:width]; } MSInstanceMessageHook1(CGSize, NSString, sizeWithFont, UIFont *, font) { @@ -817,12 +866,11 @@ MSInstanceMessageHook1(CGSize, NSString, sizeWithFont, UIFont *, font) { return MSOldCall(font); NSString *base(state->base_ ?: @""); - return [self sizeWithStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info] forWidth:65535]; + return [self sizeWithStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], WBColorMarkup(), base, info] forWidth:65535]; } MSInstanceMessageHook1(UIImage *, SBIconBadgeFactory, checkoutBadgeImageForText, NSString *, text) { - WBStringDrawingState badgeState = {NULL, 1, @"" - "color: white;" + WBStringDrawingState badgeState = {NULL, -1, @"" , @"BadgeStyle"}; stringDrawingState_ = &badgeState; @@ -835,7 +883,6 @@ MSInstanceMessageHook1(UIImage *, SBIconBadgeFactory, checkoutBadgeImageForText, MSInstanceMessageHook1(UIImage *, SBCalendarApplicationIcon, generateIconImage, int, type) { WBStringDrawingState dayState = {NULL, 2, @"" - "color: white;" // XXX: this is only correct on an iPod dock "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px;" , @"CalendarIconDayStyle"}; @@ -843,7 +890,6 @@ MSInstanceMessageHook1(UIImage *, SBCalendarApplicationIcon, generateIconImage, WBStringDrawingState sizeState = {&dayState, 7, nil, nil}; WBStringDrawingState dateState = {&sizeState, 2, @"" - "color: #333333;" , @"CalendarIconDateStyle"}; stringDrawingState_ = &dateState; @@ -854,6 +900,18 @@ MSInstanceMessageHook1(UIImage *, SBCalendarApplicationIcon, generateIconImage, return image; } +MSInstanceMessageHook1(UIImage *, UIStatusBarTimeItemView, contentsImageForStyle, int, style) { + WBStringDrawingState timeState = {NULL, 0, @"" + , @"TimeStyle"}; + + stringDrawingState_ = &timeState; + + UIImage *image(MSOldCall(style)); + + stringDrawingState_ = NULL; + return image; +} + MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) { NSBundle *bundle([NSBundle mainBundle]); @@ -1146,7 +1204,7 @@ MSInstanceMessageHook0(id, SBUIController, init) { if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.html"], themes)) { CGRect bounds = [indirect bounds]; - UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]); + UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]); [view setAutoresizes:true]; WallpaperPage_ = [view retain]; @@ -1169,7 +1227,7 @@ MSInstanceMessageHook0(id, SBUIController, init) { if ([Manager_ fileExistsAtPath:html]) { CGRect bounds = [indirect bounds]; - UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]); + UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]); [view setAutoresizes:true]; NSURL *url = [NSURL fileURLWithPath:html]; @@ -1200,7 +1258,7 @@ MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage if (path != nil) { CGRect bounds = [self bounds]; - UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]); + UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]); [view setAutoresizes:true]; if (WallpaperPage_ != nil) @@ -1337,8 +1395,12 @@ MSInstanceMessageHook0(id, SBIcon, initWithDefaultSize) { if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"]) { // XXX: note: this is overridden above, which is silly float alpha([number floatValue]); - [self setIconImageAlpha:alpha]; - [self setIconLabelAlpha:alpha]; + if ([self respondsToSelector:@selector(setIconImageAlpha:)]) + [self setIconImageAlpha:alpha]; + if ([self respondsToSelector:@selector(setIconLabelAlpha:)]) + [self setIconLabelAlpha:alpha]; + if ([self respondsToSelector:@selector(setAlpha:)]) + [self setAlpha:alpha]; } } return self; } @@ -1638,7 +1700,6 @@ MSInstanceMessage0(CGImageRef, SBIconLabel, buildLabelImage) { bool docked((MSHookIvar(self, "_inDock") & 0x2) != 0); WBStringDrawingState labelState = {NULL, 0, @"" - "color: white;" , docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle"}; stringDrawingState_ = &labelState; @@ -1923,10 +1984,6 @@ static CGSize NSString$sizeWithStyle$forWidth$(NSString *self, SEL _cmd, NSStrin } static void SBInitialize() { - class_addMethod($NSString, @selector(drawAtPoint:withStyle:), (IMP) &NSString$drawAtPoint$withStyle$, "v20@0:4{CGPoint=ff}8@16"); - class_addMethod($NSString, @selector(drawInRect:withStyle:), (IMP) &NSString$drawInRect$withStyle$, "v28@0:4{CGRect={CGSize=ff}{CGSize=ff}}8@24"); - class_addMethod($NSString, @selector(sizeWithStyle:forWidth:), (IMP) &NSString$sizeWithStyle$forWidth$, "{CGSize=ff}16@0:4@8f12"); - if (SummerBoard_) { WBRename(SBApplication, pathForIcon, pathForIcon); WBRename(SBApplicationIcon, icon, icon); @@ -2091,6 +2148,10 @@ MSInitialize { // }}} // UIKit {{{ if ([NSBundle bundleWithIdentifier:@"com.apple.UIKit"] != nil) { + class_addMethod($NSString, @selector(drawAtPoint:withStyle:), (IMP) &NSString$drawAtPoint$withStyle$, "v20@0:4{CGPoint=ff}8@16"); + class_addMethod($NSString, @selector(drawInRect:withStyle:), (IMP) &NSString$drawInRect$withStyle$, "v28@0:4{CGRect={CGSize=ff}{CGSize=ff}}8@24"); + class_addMethod($NSString, @selector(sizeWithStyle:forWidth:), (IMP) &NSString$sizeWithStyle$forWidth$, "{CGSize=ff}16@0:4@8f12"); + struct nlist nl[6]; memset(nl, 0, sizeof(nl)); nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";