Remove CJK font requirement as OS X 10.7 already handles fallback better.

This commit is contained in:
Lukhnos D. Liu 2012-03-29 20:57:16 -07:00
parent b0e7e7032f
commit b0b5dd0233
7 changed files with 13 additions and 26 deletions

View File

@ -42,7 +42,6 @@
NSArray *_keyLabels;
NSFont *_keyLabelFont;
NSFont *_candidateFont;
NSFont *_CJKCandidateFont;
}
- (void)reloadData;
@ -65,5 +64,4 @@
@property (copy, nonatomic) NSArray *keyLabels;
@property (copy, nonatomic) NSFont *keyLabelFont;
@property (copy, nonatomic) NSFont *candidateFont;
@property (copy, nonatomic) NSFont *CJKCandidateFont;
@end

View File

@ -33,14 +33,12 @@
@synthesize keyLabels = _keyLabels;
@synthesize keyLabelFont = _keyLabelFont;
@synthesize candidateFont = _candidateFont;
@synthesize CJKCandidateFont = _CJKCandidateFont;
- (void)dealloc
{
[_keyLabels release];
[_keyLabelFont release];
[_candidateFont release];
[_CJKCandidateFont release];
[super dealloc];
}
@ -52,7 +50,6 @@
_keyLabels = [[NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil] retain];
_keyLabelFont = [[NSFont systemFontOfSize:14.0] retain];
_candidateFont = [[NSFont systemFontOfSize:18.0] retain];
_CJKCandidateFont = [_candidateFont retain];
}
return self;

View File

@ -172,7 +172,7 @@
- (void)layoutCandidateView
{
[_candidateView setKeyLabelFont:_keyLabelFont candidateFont:_candidateFont CJKCandidateFont:_CJKCandidateFont];
[_candidateView setKeyLabelFont:_keyLabelFont candidateFont:_candidateFont];
NSMutableArray *candidates = [NSMutableArray array];
NSUInteger count = [_delegate candidateCountForController:self];

View File

@ -37,7 +37,6 @@
CGFloat _cellPadding;
NSDictionary *_keyLabelAttrDict;
NSDictionary *_candidateAttrDict;
NSDictionary *_CJKCandidateAttrDict;
NSArray *_elementWidths;
NSUInteger _highlightedIndex;
NSUInteger _trackingHighlightedIndex;
@ -46,7 +45,7 @@
}
- (void)setKeyLabels:(NSArray *)labels displayedCandidates:(NSArray *)candidates;
- (void)setKeyLabelFont:(NSFont *)labelFont candidateFont:(NSFont *)candidateFont CJKCandidateFont:(NSFont *)candidateFontCJK;
- (void)setKeyLabelFont:(NSFont *)labelFont candidateFont:(NSFont *)candidateFont;
@property (readonly, nonatomic) NSSize sizeForView;
@property (assign, nonatomic) NSUInteger highlightedIndex;

View File

@ -43,7 +43,6 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
[_displayedCandidates release];
[_keyLabelAttrDict release];
[_candidateAttrDict release];
[_CJKCandidateAttrDict release];
[_elementWidths release];
[super dealloc];
}
@ -67,7 +66,6 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
for (NSUInteger index = 0; index < count; index++) {
NSRect labelRect = [[_keyLabels objectAtIndex:index] boundingRectWithSize:baseSize options:NSStringDrawingUsesLineFragmentOrigin attributes:_keyLabelAttrDict];
// TODO: Handle CJK text drawing
NSRect candidateRect = [[_displayedCandidates objectAtIndex:index] boundingRectWithSize:baseSize options:NSStringDrawingUsesLineFragmentOrigin attributes:_candidateAttrDict];
CGFloat width = max(labelRect.size.width, candidateRect.size.width) + _cellPadding;
@ -79,7 +77,7 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
[tmp release];
}
- (void)setKeyLabelFont:(NSFont *)labelFont candidateFont:(NSFont *)candidateFont CJKCandidateFont:(NSFont *)candidateFontCJK
- (void)setKeyLabelFont:(NSFont *)labelFont candidateFont:(NSFont *)candidateFont
{
NSMutableParagraphStyle *paraStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
[paraStyle setAlignment:NSCenterTextAlignment];
@ -101,17 +99,8 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
nil] retain];
[tmp release];
tmp = _CJKCandidateAttrDict;
_CJKCandidateAttrDict = [[NSDictionary dictionaryWithObjectsAndKeys:
candidateFontCJK, NSFontAttributeName,
paraStyle, NSParagraphStyleAttributeName,
[NSColor textColor], NSForegroundColorAttributeName,
nil] retain];
[tmp release];
CGFloat labelFontSize = [labelFont pointSize];
CGFloat candidateFontSize = max([candidateFont pointSize], [candidateFontCJK pointSize]);
CGFloat candidateFontSize = [candidateFont pointSize];
CGFloat biggestSize = max(labelFontSize, candidateFontSize);
_keyLabelHeight = ceil(labelFontSize * 1.20);

View File

@ -112,7 +112,7 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
- (void)reloadData
{
_maxCandidateAttrStringWidth = ceil(max([_candidateFont pointSize], [_CJKCandidateFont pointSize])) * 2.0 + kCandidateTextPadding;
_maxCandidateAttrStringWidth = ceil([_candidateFont pointSize] * 2.0 + kCandidateTextPadding);
[_tableView reloadData];
[self layoutCandidateView];
@ -199,9 +199,9 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
{
NSString *candidate = [_delegate candidateController:self candidateAtIndex:row];
// TODO: Handle CJK font fallback
NSAttributedString *attrString = [[[NSAttributedString alloc] initWithString:candidate attributes:[NSDictionary dictionaryWithObjectsAndKeys:_candidateFont, NSFontAttributeName, _candidateTextParagraphStyle, NSParagraphStyleAttributeName, nil]] autorelease];
// we do more work than what this method is expected; normally not a good practice, but for the amount of data (9 to 10 rows max), we can afford the overhead
// expand the window width if text overflows
NSRect boundingRect = [attrString boundingRectWithSize:NSMakeSize(10240.0, 10240.0) options:NSStringDrawingUsesLineFragmentOrigin];
@ -236,6 +236,11 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
}
}
// fix a subtle on 10.7 that, since we force the scroller to appear, scrolling sometimes shows a temporarily "broken" scroll bar (but quickly disappears)
if ([_scrollView hasVerticalScroller]) {
[[_scrollView verticalScroller] setNeedsDisplay];
}
return attrString;
}
@ -333,7 +338,7 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
return;
}
CGFloat candidateFontSize = ceil(max([_candidateFont pointSize], [_CJKCandidateFont pointSize]));
CGFloat candidateFontSize = ceil([_candidateFont pointSize]);
CGFloat keyLabelFontSize = ceil([_keyLabelFont pointSize]);
CGFloat fontSize = max(candidateFontSize, keyLabelFontSize);

View File

@ -1024,7 +1024,6 @@ public:
LTCurrentCandidateController.keyLabelFont = [NSFont systemFontOfSize:keyLabelSize];
LTCurrentCandidateController.candidateFont = [NSFont systemFontOfSize:textSize];
LTCurrentCandidateController.CJKCandidateFont = [NSFont systemFontOfSize:textSize];
LTCurrentCandidateController.keyLabels = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil];
[self collectCandidates];