Skip to content

Commit

Permalink
Add a pref for whether to use non-ascii font and turn it off by defau…
Browse files Browse the repository at this point in the history
…lt for new bookmarks (but leave on for compatibility with existing bookmarks)
  • Loading branch information
gnachman committed Dec 26, 2013
1 parent 4377be4 commit 666e506
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 142 deletions.
2 changes: 2 additions & 0 deletions DefaultBookmark.plist
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@
<key>Red Component</key>
<real>0.70980000495910645</real>
</dict>
<key>Use Non-ASCII Font</key>
<false/>
<key>Non-ASCII Anti Aliased</key>
<true/>
<key>ASCII Anti Aliased</key>
Expand Down
120 changes: 70 additions & 50 deletions English.lproj/PreferencePanel.xib

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ITAddressBookMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
#define KEY_BLUR_RADIUS @"Blur Radius"
#define KEY_ANTI_ALIASING @"Anti Aliasing" // DEPRECATED
#define KEY_ASCII_ANTI_ALIASED @"ASCII Anti Aliased"
#define KEY_USE_NONASCII_FONT @"Use Non-ASCII Font"
#define KEY_NONASCII_ANTI_ALIASED @"Non-ASCII Anti Aliased"
#define KEY_BACKGROUND_IMAGE_LOCATION @"Background Image Location"
#define KEY_BACKGROUND_IMAGE_TILED @"Background Image Is Tiled"
Expand Down
2 changes: 1 addition & 1 deletion PTYSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ - (void)setPreferencesFromAddressBookEntry:(NSDictionary *)aePrefs
}
[TEXTVIEW setSmartSelectionRules:[aDict objectForKey:KEY_SMART_SELECTION_RULES]];
[TEXTVIEW setTrouterPrefs:[aDict objectForKey:KEY_TROUTER]];

[TEXTVIEW setUseNonAsciiFont:[[aDict objectForKey:KEY_USE_NONASCII_FONT] boolValue]];
[TEXTVIEW setAntiAlias:asciiAA nonAscii:nonasciiAA];
[self setEncoding:[[aDict objectForKey:KEY_CHARACTER_ENCODING] unsignedIntValue]];
[self setTERM_VALUE:[aDict objectForKey:KEY_TERMINAL_TYPE]];
Expand Down
6 changes: 4 additions & 2 deletions PTYTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ enum {

// anti-alias flags
BOOL asciiAntiAlias;
BOOL nonasciiAntiAlias;
BOOL nonasciiAntiAlias; // Only used if useNonAsciiFont_ is set.
BOOL useNonAsciiFont_;

// option to not render in bold
BOOL useBoldFont;
Expand Down Expand Up @@ -146,7 +147,7 @@ enum {
double verticalSpacing_;

PTYFontInfo *primaryFont;
PTYFontInfo *secondaryFont;
PTYFontInfo *secondaryFont; // non-ascii font, only used if useNonAsciiFont_ is set.

NSColor* colorTable[256];
NSColor* defaultFGColor;
Expand Down Expand Up @@ -498,6 +499,7 @@ enum {
- (void)setFont:(NSFont*)aFont nafont:(NSFont *)naFont horizontalSpacing:(double)horizontalSpacing verticalSpacing:(double)verticalSpacing;
- (NSRect)scrollViewContentSize;
- (void)setAntiAlias:(BOOL)asciiAA nonAscii:(BOOL)nonAsciiAA;
- (void)setUseNonAsciiFont:(BOOL)useNonAsciiFont;
- (BOOL)useBoldFont;
- (void)setUseBoldFont:(BOOL)boldFlag;
- (void)setUseBrightBold:(BOOL)flag;
Expand Down
183 changes: 94 additions & 89 deletions PTYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -312,94 +312,100 @@ - (void)viewDidChangeBackingProperties {
_antiAliasedShift = [[[self window] screen] backingScaleFactor] > 1 ? 0.5 : 0;
}

- (id)initWithFrame:(NSRect)aRect
{
self = [super initWithFrame: aRect];
firstMouseEventNumber_ = -1;

dimmedColorCache_ = [[NSMutableDictionary alloc] init];
- (void)updateMarkedTextAttributes {
[self setMarkedTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
defaultBGColor, NSBackgroundColorAttributeName,
defaultFGColor, NSForegroundColorAttributeName,
secondaryFont.font, NSFontAttributeName,
[self nafont], NSFontAttributeName,
[NSNumber numberWithInt:(NSUnderlineStyleSingle|NSUnderlineByWordMask)],
NSUnderlineStyleAttributeName,
NULL]];
CURSOR=YES;
lastFindStartX = lastFindEndX = oldStartX = startX = -1;
_underlineStartX = _underlineStartY = _underlineEndX = _underlineEndY = -1;
markedText = nil;
gettimeofday(&lastBlink, NULL);
[[self window] useOptimizedDrawing:YES];
}

// register for drag and drop
[self registerForDraggedTypes: [NSArray arrayWithObjects:
NSFilenamesPboardType,
NSStringPboardType,
nil]];
- (id)initWithFrame:(NSRect)aRect
{
self = [super initWithFrame: aRect];
if (self) {
firstMouseEventNumber_ = -1;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_useBackgroundIndicatorChanged:)
name:kUseBackgroundPatternIndicatorChangedNotification
object:nil];
[self _useBackgroundIndicatorChanged:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_settingsChanged:)
name:@"iTermRefreshTerminal"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_pointerSettingsChanged:)
name:kPointerPrefsChangedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(flagsChangedNotification:)
name:@"iTermFlagsChanged"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hostnameLookupFailed:)
name:kHostnameLookupFailed
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hostnameLookupSucceeded:)
name:kHostnameLookupSucceeded
object:nil];

advancedFontRendering = [[PreferencePanel sharedInstance] advancedFontRendering];
strokeThickness = [[PreferencePanel sharedInstance] strokeThickness];
imeOffset = 0;
resultMap_ = [[NSMutableDictionary alloc] init];
dimmedColorCache_ = [[NSMutableDictionary alloc] init];
[self updateMarkedTextAttributes];
CURSOR=YES;
lastFindStartX = lastFindEndX = oldStartX = startX = -1;
_underlineStartX = _underlineStartY = _underlineEndX = _underlineEndY = -1;
markedText = nil;
gettimeofday(&lastBlink, NULL);
[[self window] useOptimizedDrawing:YES];

// register for drag and drop
[self registerForDraggedTypes: [NSArray arrayWithObjects:
NSFilenamesPboardType,
NSStringPboardType,
nil]];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_useBackgroundIndicatorChanged:)
name:kUseBackgroundPatternIndicatorChangedNotification
object:nil];
[self _useBackgroundIndicatorChanged:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_settingsChanged:)
name:@"iTermRefreshTerminal"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_pointerSettingsChanged:)
name:kPointerPrefsChangedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(flagsChangedNotification:)
name:@"iTermFlagsChanged"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hostnameLookupFailed:)
name:kHostnameLookupFailed
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hostnameLookupSucceeded:)
name:kHostnameLookupSucceeded
object:nil];

advancedFontRendering = [[PreferencePanel sharedInstance] advancedFontRendering];
strokeThickness = [[PreferencePanel sharedInstance] strokeThickness];
imeOffset = 0;
resultMap_ = [[NSMutableDictionary alloc] init];

trouter = [[Trouter alloc] init];
trouter.delegate = self;
trouterDragged = NO;
workingDirectoryAtLines = [[NSMutableArray alloc] init];

pointer_ = [[PointerController alloc] init];
pointer_.delegate = self;
primaryFont = [[PTYFontInfo alloc] init];
secondaryFont = [[PTYFontInfo alloc] init];

initialFindContext_ = [[FindContext alloc] init];
if ([pointer_ viewShouldTrackTouches]) {
DLog(@"Begin tracking touches in view %@", self);
[self setAcceptsTouchEvents:YES];
[self setWantsRestingTouches:YES];
if ([self useThreeFingerTapGestureRecognizer]) {
threeFingerTapGestureRecognizer_ = [[ThreeFingerTapGestureRecognizer alloc] initWithTarget:self
selector:@selector(threeFingerTap:)];
trouter = [[Trouter alloc] init];
trouter.delegate = self;
trouterDragged = NO;
workingDirectoryAtLines = [[NSMutableArray alloc] init];

pointer_ = [[PointerController alloc] init];
pointer_.delegate = self;
primaryFont = [[PTYFontInfo alloc] init];
secondaryFont = [[PTYFontInfo alloc] init];

initialFindContext_ = [[FindContext alloc] init];
if ([pointer_ viewShouldTrackTouches]) {
DLog(@"Begin tracking touches in view %@", self);
[self setAcceptsTouchEvents:YES];
[self setWantsRestingTouches:YES];
if ([self useThreeFingerTapGestureRecognizer]) {
threeFingerTapGestureRecognizer_ = [[ThreeFingerTapGestureRecognizer alloc] initWithTarget:self
selector:@selector(threeFingerTap:)];
}
} else {
DLog(@"Not tracking touches in view %@", self);
}
} else {
DLog(@"Not tracking touches in view %@", self);
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LogDrawingPerformance"]) {
NSLog(@"** Drawing performance timing enabled **");
drawRectDuration_ = [[MovingAverage alloc] init];
drawRectInterval_ = [[MovingAverage alloc] init];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LogDrawingPerformance"]) {
NSLog(@"** Drawing performance timing enabled **");
drawRectDuration_ = [[MovingAverage alloc] init];
drawRectInterval_ = [[MovingAverage alloc] init];
}
[self viewDidChangeBackingProperties];
markImage_ = [NSImage imageNamed:@"mark"];
}
[self viewDidChangeBackingProperties];
markImage_ = [NSImage imageNamed:@"mark"];


return self;
}

Expand Down Expand Up @@ -590,6 +596,12 @@ - (BOOL)isOpaque
return YES;
}

- (void)setUseNonAsciiFont:(BOOL)useNonAsciiFont {
useNonAsciiFont_ = useNonAsciiFont;
[self setNeedsDisplay:YES];
[self updateMarkedTextAttributes];
}

- (void)setAntiAlias:(BOOL)asciiAA nonAscii:(BOOL)nonAsciiAA
{
asciiAntiAlias = asciiAA;
Expand Down Expand Up @@ -675,9 +687,9 @@ - (NSDictionary*)markedTextAttributes

- (void)setMarkedTextAttributes:(NSDictionary *)attr
{
[markedTextAttributes release];
[markedTextAttributes autorelease];
[attr retain];
markedTextAttributes=attr;
markedTextAttributes = attr;
}

- (int)selectionStartX
Expand Down Expand Up @@ -1052,7 +1064,7 @@ - (NSFont *)font

- (NSFont *)nafont
{
return secondaryFont.font;
return useNonAsciiFont_ ? secondaryFont.font : primaryFont.font;
}

+ (NSSize)charSizeForFont:(NSFont*)aFont horizontalSpacing:(double)hspace verticalSpacing:(double)vspace baseline:(double*)baseline
Expand Down Expand Up @@ -1129,14 +1141,7 @@ - (void)setFont:(NSFont*)aFont
}
}

[self setMarkedTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
defaultBGColor, NSBackgroundColorAttributeName,
defaultFGColor, NSForegroundColorAttributeName,
secondaryFont.font, NSFontAttributeName,
[NSNumber numberWithInt:(NSUnderlineStyleSingle|NSUnderlineByWordMask)],
NSUnderlineStyleAttributeName,
NULL]];
[self updateMarkedTextAttributes];
[self setNeedsDisplay:YES];

NSScrollView* scrollview = [self enclosingScrollView];
Expand Down Expand Up @@ -6801,7 +6806,7 @@ - (PTYFontInfo*)getFontForChar:(UniChar)ch
*renderBold = NO;
*renderItalic = NO;
PTYFontInfo* theFont;
BOOL usePrimary = !complex && (ch < 128);
BOOL usePrimary = !useNonAsciiFont_ || (!complex && (ch < 128));

PTYFontInfo *rootFontInfo = usePrimary ? primaryFont : secondaryFont;
theFont = rootFontInfo;
Expand Down Expand Up @@ -7085,7 +7090,7 @@ - (CRun *)_constructRuns:(NSPoint)initialPoint
NSString* thisCharString = nil;
CGFloat thisCharAdvance;

if (theLine[i].code < 128 && !theLine[i].complexChar) {
if (!useNonAsciiFont_ || (theLine[i].code < 128 && !theLine[i].complexChar)) {
attrs.antiAlias = asciiAntiAlias;
} else {
attrs.antiAlias = nonasciiAntiAlias;
Expand Down
2 changes: 2 additions & 0 deletions PreferencePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@
IBOutlet NSButton* blur;
IBOutlet NSSlider *blurRadius;
IBOutlet NSButton* asciiAntiAliased;
IBOutlet NSButton* useNonAsciiFont;
IBOutlet NSView* nonAsciiFontView; // Hide this view to hide all non-ascii font settings
IBOutlet NSButton* nonasciiAntiAliased;
IBOutlet NSButton* backgroundImage;
NSString* backgroundImageFilename;
Expand Down
11 changes: 11 additions & 0 deletions PreferencePanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,13 @@ - (IBAction)bookmarkSettingChanged:(id)sender
[newDict setObject:[NSNumber numberWithFloat:[blend floatValue]] forKey:KEY_BLEND];
[newDict setObject:[NSNumber numberWithFloat:[blurRadius floatValue]] forKey:KEY_BLUR_RADIUS];
[newDict setObject:[NSNumber numberWithBool:([blur state]==NSOnState)] forKey:KEY_BLUR];
[newDict setObject:[NSNumber numberWithBool:([useNonAsciiFont state]==NSOnState)] forKey:KEY_USE_NONASCII_FONT];
[newDict setObject:[NSNumber numberWithBool:([asciiAntiAliased state]==NSOnState)] forKey:KEY_ASCII_ANTI_ALIASED];
[newDict setObject:[NSNumber numberWithBool:([nonasciiAntiAliased state]==NSOnState)] forKey:KEY_NONASCII_ANTI_ALIASED];
[self _updateFontsDisplay];

[nonAsciiFontView setHidden:(useNonAsciiFont.state == NSOffState)];

if (sender == backgroundImage) {
NSString* filename = nil;
if ([sender state] == NSOnState) {
Expand Down Expand Up @@ -2783,6 +2786,7 @@ - (void)copyAttributes:(BulkCopySettings)attributes fromBookmark:(NSString*)guid
KEY_USE_ITALIC_FONT,
KEY_ASCII_ANTI_ALIASED,
KEY_NONASCII_ANTI_ALIASED,
KEY_USE_NONASCII_FONT,
KEY_ANTI_ALIASING,
KEY_AMBIGUOUS_DOUBLE_WIDTH,
nil
Expand Down Expand Up @@ -4015,11 +4019,18 @@ - (void)updateBookmarkFields:(NSDictionary *)dict
}
[blurRadius setFloatValue:[dict objectForKey:KEY_BLUR_RADIUS] ? [[dict objectForKey:KEY_BLUR_RADIUS] floatValue] : 2.0];
[blur setState:[[dict objectForKey:KEY_BLUR] boolValue] ? NSOnState : NSOffState];
if ([dict objectForKey:KEY_USE_NONASCII_FONT]) {
[useNonAsciiFont setState:[[dict objectForKey:KEY_USE_NONASCII_FONT] boolValue] ? NSOnState : NSOffState];
} else {
// Default to ON for backward compatibility
[useNonAsciiFont setState:NSOnState];
}
if ([dict objectForKey:KEY_ASCII_ANTI_ALIASED]) {
[asciiAntiAliased setState:[[dict objectForKey:KEY_ASCII_ANTI_ALIASED] boolValue] ? NSOnState : NSOffState];
} else {
[asciiAntiAliased setState:[[dict objectForKey:KEY_ANTI_ALIASING] boolValue] ? NSOnState : NSOffState];
}
[nonAsciiFontView setHidden:(useNonAsciiFont.state == NSOffState)];
if ([dict objectForKey:KEY_NONASCII_ANTI_ALIASED]) {
[nonasciiAntiAliased setState:[[dict objectForKey:KEY_NONASCII_ANTI_ALIASED] boolValue] ? NSOnState : NSOffState];
} else {
Expand Down

0 comments on commit 666e506

Please sign in to comment.