Re: NSTextContainer exclusionPaths not working on iOS without UITextView
Steve, You should be rendering using NSLayoutManager instead of -drawInRect:. The method is handling NSTextStorage just as a mere NSAttributedString ignoring the rest of objects connected. Check out the documentation for -[NSLayoutManager drawGlyphsInGlyphRange:atPoint:]. Aki > On Sep 21, 2017, at 6:04 AM, Steve Millswrote: > > Didn't work the first time I sent this, because something messed up and > thought the message was too large, when it's less than 2000 characters. > > No bites on apple-dev.groups.io, so I'll try here. > > I'm trying to use exclusionPaths for the first time and am not having any > success. For now, I'm just creating the stuff on the fly in my > drawLayer:inContext: method:. The string draws, but doesn't exclude any path > no matter what I set it to. I'm also not that familiar with the whole > NSTextStorage/NSLayoutManager/NSTextContainer family, other than using > snippets of code in the past, so it could be I'm doing something dumb. Any > ideas? > > BTW, if I instead install a UITextView and set its exclusionPaths, it works. > So does NSTextStorage not know enough to draw with the exclusionPaths, and I > just need to install text views for each one instead? > > -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx > { > if([layer.name isEqualToString:@"balloons"]) { > UIGraphicsPushContext(ctx); > > CGRect box = CGRectMake(0, 0, 400, 400); > NSTextStorage* storage = [[NSTextStorage alloc] > initWithString:@"I like little pigs who run and scurry away from the butcher, > because the butcher is carrying a large cleaver and wants to chop them up > into delicious sandwiches!" attributes:@{NSFontAttributeName:[UIFont > systemFontOfSize:36]}]; > UIBezierPath* bez = [UIBezierPath > bezierPathWithRect:CGRectMake(100, 100, 100, 100)]; > NSLayoutManager* lman = [NSLayoutManager new]; > > [storage addLayoutManager:lman]; > > NSTextContainer* cont = [[NSTextContainer alloc] > initWithSize:box.size]; > > cont.exclusionPaths = @[bez]; > [lman addTextContainer:cont]; > > // Trying different things to see if they make it work - nope. > [lman textContainerChangedGeometry:cont]; > [lman invalidateLayoutForCharacterRange:NSMakeRange(0, > storage.length) actualCharacterRange:nil]; > > [storage drawInRect:box]; > > UIGraphicsPopContext(); > } > } > > -- > Steve Mills > Drummer, Mac geek > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/aki%40apple.com > > This email sent to a...@apple.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSTextContainer exclusionPaths not working on iOS without UITextView
Didn't work the first time I sent this, because something messed up and thought the message was too large, when it's less than 2000 characters. No bites on apple-dev.groups.io, so I'll try here. I'm trying to use exclusionPaths for the first time and am not having any success. For now, I'm just creating the stuff on the fly in my drawLayer:inContext: method:. The string draws, but doesn't exclude any path no matter what I set it to. I'm also not that familiar with the whole NSTextStorage/NSLayoutManager/NSTextContainer family, other than using snippets of code in the past, so it could be I'm doing something dumb. Any ideas? BTW, if I instead install a UITextView and set its exclusionPaths, it works. So does NSTextStorage not know enough to draw with the exclusionPaths, and I just need to install text views for each one instead? -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx { if([layer.name isEqualToString:@"balloons"]) { UIGraphicsPushContext(ctx); CGRect box = CGRectMake(0, 0, 400, 400); NSTextStorage* storage = [[NSTextStorage alloc] initWithString:@"I like little pigs who run and scurry away from the butcher, because the butcher is carrying a large cleaver and wants to chop them up into delicious sandwiches!" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:36]}]; UIBezierPath* bez = [UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 100, 100)]; NSLayoutManager* lman = [NSLayoutManager new]; [storage addLayoutManager:lman]; NSTextContainer* cont = [[NSTextContainer alloc] initWithSize:box.size]; cont.exclusionPaths = @[bez]; [lman addTextContainer:cont]; // Trying different things to see if they make it work - nope. [lman textContainerChangedGeometry:cont]; [lman invalidateLayoutForCharacterRange:NSMakeRange(0, storage.length) actualCharacterRange:nil]; [storage drawInRect:box]; UIGraphicsPopContext(); } } -- Steve Mills Drummer, Mac geek ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Inserting a button into another application's toolbar
Thank you for the suggestions! 2017-09-19 10:36 GMT+03:00 Alastair Houghton: > > On 19 Sep 2017, at 06:01, Jack Brindle wrote: > > > > Actually, there may be a way. It all depends on exactly where in the > menu bar you want to place the menu item. > > I think the OP wanted to inject a *toolbar* item into another app’s > window’s toolbar, not a menu bar item/status item. > > FWIW, a status bar item might be an appropriate alternative, depending on > what the app does and how it works. Other alternatives worth considering > are the Scripts menu (this is AppleScript, so if you go to Script Editor’s > Preferences window, you’ll see you can turn on the Script menu in the > status bar), and making your code run as a system service (so you can > choose it from App > Services). > > > On Sep 18, 2017, at 4:15 PM, Jens Alfke wrote: > > > >> Sorry, there's no reasonable way to do that if the app doesn't already > support plugins. There used to be some awful hacks that patched into the > app-launching mechanism and made it possible to inject code into other > apps, but that approach causes stability problems and is in general > terrible for security. > > There were also quite a number that abused the Input Manager mechanism as > if it was a general purpose way of plugging in to other applications. On > the one hand, some of these extensions were fine, worked nicely, and didn’t > cause problems. On the other, *some* of them did cause trouble on a fairly > routine basis. > > Certainly I’d caution against writing anything other than a > personal-use-only project or some kind of debug tool that does things like > that; at the very least, your users are going to find that many developers > take one look at their crash logs and reply that you’ve got some kind of > system hack installed and that if you can reproduce it without that, > they’ll look at it. That’s a little unfair, of course - many times these > system hacks weren’t to blame at all - but after the handful of cases where > they *are* to blame hit your desk, sending you on a wild goose chase until > you finally realise that some kind of tampering has been going on, you’ll > probably end up as grumpy about them as Jens :-) > > Kind regards, > > Alastair. > > -- > http://alastairs-place.net > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com