From b222f608ac679b877b984b3645c7a0bb455f582a Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 18 Mar 2012 23:55:21 +0000 Subject: - Rewrite SPFontPreviewTextField to replace previous Colloquy-derived GPL-licensed previous implementation, and amend calls to match --- Source/SPEditorPreferencePane.m | 1 - Source/SPFontPreviewTextField.h | 6 ----- Source/SPFontPreviewTextField.m | 53 ++++++++++++++++++++--------------------- Source/SPTablesPreferencePane.m | 1 - 4 files changed, 26 insertions(+), 35 deletions(-) (limited to 'Source') diff --git a/Source/SPEditorPreferencePane.m b/Source/SPEditorPreferencePane.m index 3c948e74..b84e41ba 100644 --- a/Source/SPEditorPreferencePane.m +++ b/Source/SPEditorPreferencePane.m @@ -329,7 +329,6 @@ static NSString *SPCustomColorSchemeNameLC = @"user-defined"; NSFont *font = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]; [editorFontName setFont:font]; - [editorFontName setStringValue:[NSString stringWithFormat:@"%@, %.1f pt", [font displayName], [font pointSize]]]; [colorSettingTableView reloadData]; } diff --git a/Source/SPFontPreviewTextField.h b/Source/SPFontPreviewTextField.h index f6383f77..edadbab0 100644 --- a/Source/SPFontPreviewTextField.h +++ b/Source/SPFontPreviewTextField.h @@ -4,9 +4,6 @@ // SPFontPreviewTextField.h // sequel-pro // -// This is a heavily modified version of JVFontPreviewField from -// the Colloquy Project -// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or @@ -24,9 +21,6 @@ // More info at @interface SPFontPreviewTextField : NSTextField -{ - NSFont *_actualFont; -} - (void)setFont:(NSFont *)font; diff --git a/Source/SPFontPreviewTextField.m b/Source/SPFontPreviewTextField.m index 90e9f93f..60243233 100644 --- a/Source/SPFontPreviewTextField.m +++ b/Source/SPFontPreviewTextField.m @@ -4,9 +4,6 @@ // SPFontPreviewTextField.m // sequel-pro // -// This is a heavily modified version of JVFontPreviewField from -// the Colloquy Project -// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or @@ -27,37 +24,39 @@ @implementation SPFontPreviewTextField -- (void)setFont:(NSFont *)font +/** + * Add a method to set the font to use for the preview. The font metrics + * are applied to the textField, and the font name is displayed in the textField + * for an easy preview. + */ +- (void)setFont:(NSFont *)theFont { - if (!font) return; - - if (_actualFont) [_actualFont release]; - - _actualFont = [font retain]; - [super setFont:[[NSFontManager sharedFontManager] convertFont:font toSize:11.0f]]; + // If no font was supplied, clear the preview + if (!theFont) { + [self setObjectValue:@""]; + return; + } - NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:[_actualFont displayName]]; - NSMutableParagraphStyle *paraStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + // Take the supplied font and apply all its traits except for a standardised + // font size to the text field + NSFont *displayFont = [[NSFontManager sharedFontManager] convertFont:theFont toSize:11.0f]; + [super setFont:displayFont]; - [paraStyle setMinimumLineHeight:NSHeight([self bounds])]; - [paraStyle setMaximumLineHeight:NSHeight([self bounds])]; - - [text addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, [text length])]; + // Set up a paragraph style for display, setting bounds and display settings + NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle new] autorelease]; + [paragraphStyle setAlignment:NSNaturalTextAlignment]; + [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingMiddle]; + [paragraphStyle setMaximumLineHeight:NSHeight([self bounds]) + [displayFont descender]]; - [self setObjectValue:text]; - - [text release]; - [paraStyle release]; -} + // Set up the text to display - the font display name and the point size. + NSMutableAttributedString *displayString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@, %.1f pt", [theFont displayName], [theFont pointSize]]]; -#pragma mark - + // Apply the paragraph style + [displayString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [displayString length])]; -- (void)dealloc -{ - if (_actualFont) [_actualFont release], _actualFont = nil; - - [super dealloc]; + // Update the display + [self setObjectValue:displayString]; } @end diff --git a/Source/SPTablesPreferencePane.m b/Source/SPTablesPreferencePane.m index 90a1893b..6e009cd8 100644 --- a/Source/SPTablesPreferencePane.m +++ b/Source/SPTablesPreferencePane.m @@ -53,7 +53,6 @@ NSFont *font = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPGlobalResultTableFont]]; [globalResultTableFontName setFont:font]; - [globalResultTableFontName setStringValue:[NSString stringWithFormat:@"%@, %.1f pt", [font displayName], [font pointSize]]]; } #pragma mark - -- cgit v1.2.3