Skip to content

Instantly share code, notes, and snippets.

@ccgus
Created February 15, 2012 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccgus/1838008 to your computer and use it in GitHub Desktop.
Save ccgus/1838008 to your computer and use it in GitHub Desktop.
font stuff.
- (void)changeFont:(id)sender {
// by default, the bold menu is hooked up to NSFontManagers' - (void)addFontTrait:(id)sender; Start there to debug.
// isEditable , inputContext
for (TSGraphic *graphic in [[[self document] currentLayer] selectedGraphics]) {
if (![graphic isKindOfClass:[TSTextArea class]]) {
continue;
}
TSTextArea *ta = (id)graphic;
NSTextStorage *contentsCopy = [[[ta contents] mutableCopy] autorelease];
if (![contentsCopy length]) {
continue;
}
[ta fontWillChange];
NSFont *oldFont = [contentsCopy attribute:NSFontAttributeName atIndex:0 effectiveRange:nil];
NSFont *newFont = [sender convertFont:oldFont];
[contentsCopy addAttribute:NSFontAttributeName value:newFont range:NSMakeRange(0, [contentsCopy length])];
[ta setContents:contentsCopy];
[ta didChange];
[ta fontDidChange];
[[NSFontManager sharedFontManager] setSelectedFont:newFont isMultiple:NO];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment