Skip to content

Commit

Permalink
Added font preference. Removed rich text related menu items. Implemen…
Browse files Browse the repository at this point in the history
…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
aki-null committed May 6, 2011
1 parent 6ee1101 commit 5187b09
Show file tree
Hide file tree
Showing 13 changed files with 596 additions and 1,321 deletions.
20 changes: 20 additions & 0 deletions EditPaneLayoutManager.h
@@ -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
59 changes: 59 additions & 0 deletions EditPaneLayoutManager.m
@@ -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
16 changes: 16 additions & 0 deletions EditPaneTypesetter.h
@@ -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
29 changes: 29 additions & 0 deletions EditPaneTypesetter.m
@@ -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

0 comments on commit 5187b09

Please sign in to comment.