From d806256e4ac8a0f9812b8cd98bc7ab28022548d9 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 3 Jan 2009 20:24:50 +0000 Subject: [PATCH] Released font hooking and stuff. --- Library.mm | 76 +++++++++++++++++++++++++++++++++++++---- Saurik.theme/Info.plist | 3 ++ control | 2 +- makefile | 2 +- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/Library.mm b/Library.mm index 6015fd8..dccc219 100644 --- a/Library.mm +++ b/Library.mm @@ -42,6 +42,10 @@ #import #import +#import +#import +#import + #include #import @@ -65,6 +69,7 @@ #import +#import #import #import @@ -76,6 +81,7 @@ extern "C" void __clear_cache (char *beg, char *end); - (void *) _node; @end +Class $MPMoviePlayerController; Class $MPVideoView; Class $WebCoreFrameBridge; @@ -335,9 +341,11 @@ MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) { } MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) { - if (NSString *path = $pathForIcon$([self application])) + if (Debug_) + NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]); + if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]])) return [UIImage imageWithContentsOfFile:path]; - return _SBApplicationIcon$icon(self, sel); + return _SBWidgetApplicationIcon$icon(self, sel); } MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) { @@ -579,12 +587,38 @@ MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize s if (NSString *theme = $getTheme$(Wallpapers_, true)) { NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"]; if ([Manager_ fileExistsAtPath:mp4]) { +#if UseAVController + NSError *error; + + static AVController *controller_(nil); + if (controller_ == nil) { + AVQueue *queue([AVQueue avQueue]); + controller_ = [[AVController avControllerWithQueue:queue error:&error] retain]; + } + + AVQueue *queue([controller_ queue]); + + UIView *video([[[UIView alloc] initWithFrame:[self bounds]] autorelease]); + [controller_ setLayer:[video _layer]]; + + AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]); + [queue appendItem:item error:&error]; + + [controller_ play:&error]; +#elif UseMPMoviePlayerController + NSURL *url([NSURL fileURLWithPath:mp4]); + MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url]; + controller.movieControlMode = MPMovieControlModeHidden; + [controller play]; +#else MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease]; [video setMovieWithPath:mp4]; [video setRepeatMode:1]; - [video setRepeatGap:0]; - [self addSubview:video]; + [video setRepeatGap:-1]; [video playFromBeginning];; +#endif + + [self addSubview:video]; } NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"]; @@ -897,9 +931,28 @@ MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) { if (docked) style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "]; - float max = 75, width = [label sizeWithStyle:style forWidth:320].width; - if (width > max) - style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", ((width - max) / ([label length] - 1))]]; + + bool ellipsis(false); + float max = 75, 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]; @@ -963,6 +1016,12 @@ MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) { return image; } +MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) { + if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]]) + name = [font UTF8String]; + return _GSFontCreateWithName(name, traits, size); +} + #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox" #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit" @@ -1052,6 +1111,8 @@ extern "C" void WBInitialize() { MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName); MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain); + MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName); + if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) { struct nlist nl[2]; memset(nl, 0, sizeof(nl)); @@ -1150,6 +1211,7 @@ extern "C" void WBInitialize() { if (MediaPlayer != nil) [MediaPlayer load]; + $MPMoviePlayerController = objc_getClass("MPMoviePlayerController"); $MPVideoView = objc_getClass("MPVideoView"); $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge"); diff --git a/Saurik.theme/Info.plist b/Saurik.theme/Info.plist index 4315217..a62553c 100644 --- a/Saurik.theme/Info.plist +++ b/Saurik.theme/Info.plist @@ -2,6 +2,9 @@ +FontName-Helvetica +Courier New + UndockedIconLabelStyle /*font-family: monospace; font-size: 13px;*/ color: white diff --git a/control b/control index 92c207b..dc08c5d 100644 --- a/control +++ b/control @@ -3,7 +3,7 @@ Priority: optional Section: System Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.2691-1 +Version: 0.9.2692-1 Description: more powerful, open-source SummerBoard Name: WinterBoard Depends: mobilesubstrate (>= 0.9.2660-1) diff --git a/makefile b/makefile index ed1c9b9..b23bf2c 100644 --- a/makefile +++ b/makefile @@ -10,7 +10,7 @@ clean: rm -f WinterBoard WinterBoard.dylib UIImages WinterBoard.dylib: Library.mm makefile ../mobilesubstrate/substrate.h - $(target)g++ -dynamiclib -g0 -O2 -Wall -o $@ $(filter %.mm,$^) -framework CoreFoundation -framework Foundation -lobjc -init _WBInitialize -I/apl/inc/iPhoneOS-2.0 -framework CoreGraphics -I../mobilesubstrate -L../mobilesubstrate -lsubstrate -framework UIKit -multiply_defined suppress + $(target)g++ -dynamiclib -g0 -O2 -Wall -o $@ $(filter %.mm,$^) -framework CoreFoundation -framework Foundation -lobjc -init _WBInitialize -I/apl/inc/iPhoneOS-2.0 -framework CoreGraphics -framework GraphicsServices -framework Celestial -I../mobilesubstrate -L../mobilesubstrate -lsubstrate -framework UIKit -multiply_defined suppress -F$(PKG_ROOT)/System/Library/PrivateFrameworks UIImages: UIImages.mm makefile $(target)g++ -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework Foundation -framework CoreFoundation -lobjc -I/apl/inc/iPhoneOS-2.0 -multiply_defined suppress -- 2.47.2