From ecb5bd1166278d8d8fcd6012cd037c29bdff0661 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Tue, 19 Jan 2016 12:03:53 +0100 Subject: [PATCH] Optimize the monospace font attribute. --- Classes/SBDocument.h | 2 ++ Classes/SBDocument.m | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Classes/SBDocument.h b/Classes/SBDocument.h index dcebd84..3f87e0b 100755 --- a/Classes/SBDocument.h +++ b/Classes/SBDocument.h @@ -47,6 +47,8 @@ NS_ASSUME_NONNULL_BEGIN IBOutlet NSButton *_64bit_data; IBOutlet NSButton *_64bit_time; BOOL _optimize; + + NSDictionary *_detailMonospacedAttr; } - (instancetype)initWithMP4:(MP42File *)mp4File error:(NSError **)outError; diff --git a/Classes/SBDocument.m b/Classes/SBDocument.m index 889fd20..8d76d2e 100755 --- a/Classes/SBDocument.m +++ b/Classes/SBDocument.m @@ -66,6 +66,17 @@ [documentWindow setFrameUsingName:@"documentSave"]; [splitView setAutosaveName:@"splitViewSave"]; } + + if ([[NSFont class] respondsToSelector:@selector(monospacedDigitSystemFontOfSize:weight:)]) { + NSFont *font = [NSFont monospacedDigitSystemFontOfSize:[NSFont systemFontSize] weight:NSFontWeightRegular]; + NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + ps.alignment = NSTextAlignmentRight; + + _detailMonospacedAttr = [@{NSFontAttributeName: font, + NSParagraphStyleAttributeName: ps} retain]; + + [ps release]; + } } - (instancetype)initWithMP4:(MP42File *)mp4File error:(NSError **)outError @@ -463,17 +474,8 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn if ([tableColumn.identifier isEqualToString:@"trackDuration"]) { - if ([[NSFont class] respondsToSelector:@selector(monospacedDigitSystemFontOfSize:weight:)]) { - NSFont *font = [NSFont monospacedDigitSystemFontOfSize:[NSFont systemFontSize] weight:NSFontWeightRegular]; - NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; - ps.alignment = NSTextAlignmentRight; - - NSDictionary *monospacedAttr = @{NSFontAttributeName: font, - NSParagraphStyleAttributeName: ps}; - - [ps release]; - - return [[[NSAttributedString alloc] initWithString:track.timeString attributes:monospacedAttr] autorelease]; + if (_detailMonospacedAttr) { + return [[[NSAttributedString alloc] initWithString:track.timeString attributes:_detailMonospacedAttr] autorelease]; } else { return track.timeString; @@ -1099,6 +1101,9 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn [_mp4File release]; _mp4File = nil; + [_detailMonospacedAttr release]; + _detailMonospacedAttr = nil; + [super dealloc]; }