+static struct WBStringDrawingState {
+ WBStringDrawingState *next_;
+ unsigned count_;
+ NSString *base_;
+ NSString *info_;
+} *stringDrawingState_;
+
+MSInstanceMessageHook4(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreakMode, CGPoint, point, float, width, UIFont *, font, int, mode) {
+ WBStringDrawingState *state(stringDrawingState_);
+ if (state == NULL)
+ return MSOldCall(point, width, font, mode);
+
+ if (--state->count_ == 0)
+ stringDrawingState_ = state->next_;
+ if (state->info_ == nil)
+ return MSOldCall(point, width, font, mode);
+
+ NSString *info([Info_ objectForKey:state->info_]);
+ if (info == nil)
+ return MSOldCall(point, width, font, mode);
+
+ NSString *base(state->base_ ?: @"");
+ [self drawAtPoint:point withStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info]];
+ return CGSizeZero;
+}
+
+MSInstanceMessageHook2(CGSize, NSString, drawAtPoint,withFont, CGPoint, point, UIFont *, font) {
+ WBStringDrawingState *state(stringDrawingState_);
+ if (state == NULL)
+ return MSOldCall(point, font);
+
+ if (--state->count_ == 0)
+ stringDrawingState_ = state->next_;
+ if (state->info_ == nil)
+ return MSOldCall(point, font);
+
+ NSString *info([Info_ objectForKey:state->info_]);
+ if (info == nil)
+ return MSOldCall(point, font);
+
+ NSString *base(state->base_ ?: @"");
+ [self drawAtPoint:point withStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info]];
+ return CGSizeZero;
+}
+
+MSInstanceMessageHook1(CGSize, NSString, sizeWithFont, UIFont *, font) {
+ WBStringDrawingState *state(stringDrawingState_);
+ if (state == NULL)
+ return MSOldCall(font);
+
+ if (--state->count_ == 0)
+ stringDrawingState_ = state->next_;
+ if (state->info_ == nil)
+ return MSOldCall(font);
+
+ NSString *info([Info_ objectForKey:state->info_]);
+ if (info == nil)
+ return MSOldCall(font);
+
+ NSString *base(state->base_ ?: @"");
+ return [self sizeWithStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info] forWidth:65535];
+}
+
+MSInstanceMessageHook1(UIImage *, SBIconBadgeFactory, checkoutBadgeImageForText, NSString *, text) {
+ WBStringDrawingState badgeState = {NULL, 1, @""
+ "color: white;"
+ , @"BadgeStyle"};
+
+ stringDrawingState_ = &badgeState;
+
+ UIImage *image(MSOldCall(text));
+
+ stringDrawingState_ = NULL;
+ return image;
+}
+
+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"};
+
+ WBStringDrawingState sizeState = {&dayState, 7, nil, nil};
+
+ WBStringDrawingState dateState = {&sizeState, 2, @""
+ "color: #333333;"
+ , @"CalendarIconDateStyle"};
+
+ stringDrawingState_ = &dateState;
+
+ UIImage *image(MSOldCall(type));
+
+ stringDrawingState_ = NULL;
+ return image;