]> git.saurik.com Git - winterboard.git/commitdiff
Fix the SBIconLabel drawing code.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 17 Oct 2011 09:35:07 +0000 (09:35 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 17 Oct 2011 09:35:07 +0000 (09:35 +0000)
Library.mm

index b35a2eaae8b1c045ddbc430a2fec289a43deea45..91c9731c5576516ed5b41c40134b840674291437 100644 (file)
@@ -115,6 +115,7 @@ Class $MPMoviePlayerController;
 Class $MPVideoView;
 
 MSClassHook(NSBundle)
+MSClassHook(NSString)
 
 MSClassHook(UIImage)
 MSClassHook(UINavigationBar)
@@ -1302,7 +1303,7 @@ MSInstanceMessageHook2(CGSize, WebCoreFrameBridge, renderedSizeOfNode,constraine
 }
 // }}}
 
-MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
+MSInstanceMessageHook1(void, SBIconLabel, drawRect, CGRect, rect) {
     CGRect bounds = [self bounds];
 
     static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
@@ -1569,10 +1570,26 @@ MSHook(void *, CGImageReadCreateWithFile, NSString *path, int flag) {
 }
 // }}}
 
+extern "C" void WKSetCurrentGraphicsContext(CGContextRef);
+
+static void NSString$drawAtPoint$withStyle$(NSString *self, SEL _cmd, CGPoint point, NSString *style) {
+    WKSetCurrentGraphicsContext(UIGraphicsGetCurrentContext());
+    if (style == nil || [style length] == 0)
+        style = @"font-family: Helvetica; font-size: 12px";
+    return [[WBMarkup sharedMarkup] drawString:self atPoint:point withStyle:style];
+}
+
+static CGSize NSString$sizeWithStyle$forWidth$(NSString *self, SEL _cmd, NSString *style, float width) {
+    if (style == nil || [style length] == 0)
+        style = @"font-family: Helvetica; font-size: 12px";
+    return [[WBMarkup sharedMarkup] sizeOfString:self withStyle:style forWidth:width];
+}
+
 static void SBInitialize() {
-    _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
+    class_addMethod($NSString, @selector(drawAtPoint:withStyle:), (IMP) &NSString$drawAtPoint$withStyle$, "v20@0:4{CGPoint=ff}8@16");
+    class_addMethod($NSString, @selector(sizeWithStyle:forWidth:), (IMP) &NSString$sizeWithStyle$forWidth$, "{CGSize=ff}16@0:4@8f12");
 
-    bool olden(dlsym(RTLD_DEFAULT, "GSLibraryCopyGenerationInfoValueForKey") == NULL);
+    _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
 
     if (SummerBoard_) {
         WBRename(SBApplication, pathForIcon, pathForIcon);
@@ -1591,9 +1608,6 @@ static void SBInitialize() {
     WBRename(SBDockIconListView, setFrame:, setFrame$);
     MSHookMessage(object_getClass($SBDockIconListView), @selector(shouldShowNewDock), &$SBDockIconListView$shouldShowNewDock, &_SBDockIconListView$shouldShowNewDock);
 
-    if (olden)
-        WBRename(SBIconLabel, drawRect:, drawRect$);
-
     WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
     WBRename(SBIconLabel, setInDock:, setInDock$);