Post

Replies

Boosts

Views

Activity

Reply to NSAttributedString draw in rect
This is what I have so far: CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)self); if (line) { CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; CTLineDraw(line, context); CFRelease(line); } Looks quite good… Just have to figure out how to align it horizontally and vertically in the rect.
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’24
Reply to NSAttributedString draw in rect
Ok, I figured it out. The following code gives me the correct bounds of the attributed string: - (CGRect)typographicBounds { CGRect usedRect = CGRectZero; CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)self); if (line) { CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; usedRect = CTLineGetImageBounds(line, context); CFRelease(line); } return usedRect; } and the following code draws it exactly into the view: NSRect stringRect = [_attributedString typographicBounds]; // draw the string CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)_attributedString); if (line) { CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; CGContextSetTextPosition( context, ((NSWidth([self frame]) - NSWidth(stringRect)) / 2) - stringRect.origin.x, ((NSHeight([self frame]) - NSHeight(stringRect)) / 2) - stringRect.origin.y ); CTLineDraw(line, context); CFRelease(line); } @DTS Engineer Thank you for your patience and for showing me the right direction.
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’24
Reply to Dock tile plugin and app groups
I ended up setting a com.apple.security.temporary-exception.shared-preference.read-write sandbox exception for my app so that it could write to the ~/Library/Preferences folder. The Dock tile plugin can access this location by default.
Topic: UI Frameworks SubTopic: General Tags:
May ’25
Reply to NSAttributedString draw in rect
Ok. I think I also have to use Core Text for drawing the string. Right? Would be something like CGContextShowGlyphsAtPositions a good way to go?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’24
Reply to NSAttributedString draw in rect
This is what I have so far: CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)self); if (line) { CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; CTLineDraw(line, context); CFRelease(line); } Looks quite good… Just have to figure out how to align it horizontally and vertically in the rect.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’24
Reply to NSAttributedString draw in rect
Ok, I figured it out. The following code gives me the correct bounds of the attributed string: - (CGRect)typographicBounds { CGRect usedRect = CGRectZero; CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)self); if (line) { CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; usedRect = CTLineGetImageBounds(line, context); CFRelease(line); } return usedRect; } and the following code draws it exactly into the view: NSRect stringRect = [_attributedString typographicBounds]; // draw the string CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)_attributedString); if (line) { CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; CGContextSetTextPosition( context, ((NSWidth([self frame]) - NSWidth(stringRect)) / 2) - stringRect.origin.x, ((NSHeight([self frame]) - NSHeight(stringRect)) / 2) - stringRect.origin.y ); CTLineDraw(line, context); CFRelease(line); } @DTS Engineer Thank you for your patience and for showing me the right direction.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’24
Reply to Dock tile plugin and app groups
If it's not possible to access a group container from a Dock Tile plugin, what would be a supported way to share data between a sandboxed app and its Dock Tile plugin? Thans, Marc
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’24
Reply to Dock tile plugin and app groups
I ended up setting a com.apple.security.temporary-exception.shared-preference.read-write sandbox exception for my app so that it could write to the ~/Library/Preferences folder. The Dock tile plugin can access this location by default.
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’25
Reply to Dock tile plugin and app groups
Sure. You could use DistributedNotificationCenter to send a notification.
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’25