Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added font preference. Removed rich text related menu items. Implemen…
…ted custom layout manager for edit pane to fix the issue with line height change when mixed font behavior of OS X is provoked. This is an common issue with NSLayoutManager when using foreign characters that are not included in the specified font.
- Loading branch information
Showing
13 changed files
with
596 additions
and
1,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// TCLayoutManager.h | ||
// MarkdownLive | ||
// | ||
// Created by Akihiro Noguchi on 7/05/11. | ||
// Copyright 2011 Aki. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface EditPaneLayoutManager : NSLayoutManager { | ||
NSFont *font; | ||
} | ||
|
||
@property (nonatomic, retain) NSFont *font; | ||
|
||
- (CGFloat)lineHeight; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// TCLayoutManager.m | ||
// MarkdownLive | ||
// | ||
// Created by Akihiro Noguchi on 7/05/11. | ||
// Copyright 2011 Aki. All rights reserved. | ||
// | ||
|
||
#import "EditPaneLayoutManager.h" | ||
#import "EditPaneTypesetter.h" | ||
|
||
|
||
@implementation EditPaneLayoutManager | ||
|
||
@synthesize font; | ||
|
||
- (id)init { | ||
if ((self = [super init])) { | ||
EditPaneTypesetter *typeSetter = [[EditPaneTypesetter alloc] init]; | ||
[self setTypesetter:typeSetter]; | ||
[typeSetter release]; | ||
[self setUsesFontLeading:NO]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
self.font = nil; | ||
[super dealloc]; | ||
} | ||
|
||
- (CGFloat)lineHeight { | ||
return floor([self defaultLineHeightForFont:font] + 1.5); | ||
} | ||
|
||
- (void)setLineFragmentRect:(NSRect)inFragmentRect forGlyphRange:(NSRange)inGlyphRange | ||
usedRect:(NSRect)inUsedRect { | ||
inFragmentRect.size.height = [self lineHeight]; | ||
inUsedRect.size.height = [self lineHeight]; | ||
|
||
(void)[super setLineFragmentRect:(NSRect)inFragmentRect | ||
forGlyphRange:(NSRange)inGlyphRange | ||
usedRect:(NSRect)inUsedRect]; | ||
} | ||
|
||
- (void)setExtraLineFragmentRect:(NSRect)inFragmentRect usedRect:(NSRect)inUsedRect | ||
textContainer:(NSTextContainer *)inTextContainer { | ||
inFragmentRect.size.height = [self lineHeight]; | ||
[super setExtraLineFragmentRect:inFragmentRect usedRect:inUsedRect | ||
textContainer:inTextContainer]; | ||
} | ||
|
||
- (NSPoint)locationForGlyphAtIndex:(NSUInteger)inGlyphIndex { | ||
NSPoint outPoint = [super locationForGlyphAtIndex:inGlyphIndex]; | ||
outPoint.y = [font pointSize]; | ||
return outPoint; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// TCTypeSetter.h | ||
// MarkdownLive | ||
// | ||
// Created by Akihiro Noguchi on 7/05/11. | ||
// Copyright 2011 Aki. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface EditPaneTypesetter : NSATSTypesetter { | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// TCTypeSetter.m | ||
// MarkdownLive | ||
// | ||
// Created by Akihiro Noguchi on 7/05/11. | ||
// Copyright 2011 Aki. All rights reserved. | ||
// | ||
|
||
#import "EditPaneTypesetter.h" | ||
#import "EditPaneLayoutManager.h" | ||
|
||
|
||
@implementation EditPaneTypesetter | ||
|
||
- (id)init { | ||
if ((self = [super init])) { | ||
[self setUsesFontLeading:YES]; | ||
} | ||
return self; | ||
} | ||
|
||
- (CGFloat)lineSpacingAfterGlyphAtIndex:(NSUInteger)inGlyphIndex | ||
withProposedLineFragmentRect:(NSRect)inRect { | ||
EditPaneLayoutManager *theManager = (EditPaneLayoutManager *)[self layoutManager]; | ||
CGFloat theDefaultLineHeight = [theManager defaultLineHeightForFont:theManager.font]; | ||
return floor(theDefaultLineHeight - inRect.size.height + 1.5); | ||
} | ||
|
||
@end |
Oops, something went wrong.