+ return MSOldCall(resource, type);
+}
+// }}}
+
+static struct WBStringDrawingState {
+ WBStringDrawingState *next_;
+ NSString *base_;
+ NSString *info_;
+} *stringDrawingState_;
+
+MSInstanceMessageHook4(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreakMode, CGPoint, point, float, width, UIFont *, font, int, mode) {
+ if (stringDrawingState_ == NULL || stringDrawingState_->info_ == nil)
+ return MSOldCall(point, width, font, mode);
+
+ NSString *info([Info_ objectForKey:stringDrawingState_->info_]);
+ if (info == nil)
+ return MSOldCall(point, width, font, mode);
+
+ NSString *base(stringDrawingState_->base_ ?: @"");
+ stringDrawingState_ = stringDrawingState_->next_;
+
+ [self drawAtPoint:point withStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info]];
+ return CGSizeZero;
+}
+
+MSInstanceMessageHook2(CGSize, NSString, drawAtPoint,withFont, CGPoint, point, UIFont *, font) {
+ if (stringDrawingState_ == NULL || stringDrawingState_->info_ == nil)
+ return MSOldCall(point, font);
+
+ NSString *info([Info_ objectForKey:stringDrawingState_->info_]);
+ if (info == nil)
+ return MSOldCall(point, font);
+
+ NSString *base(stringDrawingState_->base_ ?: @"");
+ stringDrawingState_ = stringDrawingState_->next_;
+
+ [self drawAtPoint:point withStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info]];
+ return CGSizeZero;
+}
+
+MSInstanceMessageHook1(UIImage *, SBIconBadgeFactory, checkoutBadgeImageForText, NSString *, text) {
+ WBStringDrawingState badgeState = {NULL, @""
+ "color: white;"
+ , @"BadgeStyle"};
+
+ stringDrawingState_ = &badgeState;
+
+ UIImage *image(MSOldCall(text));
+
+ stringDrawingState_ = NULL;
+ return image;
+}
+
+MSInstanceMessageHook1(UIImage *, SBCalendarApplicationIcon, generateIconImage, int, type) {
+ WBStringDrawingState dayState = {NULL, @""
+ "color: white;"
+ // XXX: this is only correct on an iPod dock
+ "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px;"
+ , @"CalendarIconDayStyle"};
+
+ WBStringDrawingState dateState = {&dayState, @""
+ "color: #333333;"
+ , @"CalendarIconDateStyle"};
+
+ stringDrawingState_ = &dateState;
+
+ UIImage *image(MSOldCall(type));
+
+ stringDrawingState_ = NULL;
+ return image;
+}
+
+MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
+ NSBundle *bundle([NSBundle mainBundle]);
+
+ CFLocaleRef locale(CFLocaleCopyCurrent());
+ CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
+ CFRelease(locale);
+
+ CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
+
+ CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"d" table:@"SpringBoard"]);
+ CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
+ CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
+ CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
+
+ CFRelease(now);
+
+ CFRelease(formatter);
+
+ NSString *datestyle([@""
+ "font-family: Helvetica; "
+ "font-weight: bold; "
+ "color: #333333; "
+ "alpha: 1.0; "
+ "" stringByAppendingString:(IsWild_
+ ? @"font-size: 54px; "
+ : @"font-size: 39px; "
+ )]);
+
+ NSString *daystyle([@""
+ "font-family: Helvetica; "
+ "font-weight: bold; "
+ "color: white; "
+ "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
+ "" stringByAppendingString:(IsWild_
+ ? @"font-size: 11px; "
+ : @"font-size: 9px; "
+ )]);
+
+ if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
+ datestyle = [datestyle stringByAppendingString:style];
+ if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
+ daystyle = [daystyle stringByAppendingString:style];
+
+ float width([self bounds].size.width);
+ float leeway(10);
+ CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
+ CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
+
+ unsigned base0(IsWild_ ? 89 : 70);
+ if ($GSFontGetUseLegacyFontMetrics())
+ base0 = base0 + 1;
+ unsigned base1(IsWild_ ? 18 : 16);
+
+ if (Four_) {
+ ++base0;
+ ++base1;
+ }
+
+ [(NSString *)date drawAtPoint:CGPointMake(
+ (width + 1 - datesize.width) / 2, (base0 - datesize.height) / 2
+ ) withStyle:datestyle];
+
+ [(NSString *)day drawAtPoint:CGPointMake(
+ (width + 1 - daysize.width) / 2, (base1 - daysize.height) / 2
+ ) withStyle:daystyle];
+
+ CFRelease(date);
+ CFRelease(day);