Disable font smoothing for dark themes

If you wish to always have font smoothing enabled you can run:

    defaults write com.macromates.TextMate.preview fontSmoothing 1

Setting the value to 0 causes it to always be disabled and deleting the key (or setting it to 2) has it disabled only for dark themes.
This commit is contained in:
Allan Odgaard
2013-04-21 10:59:57 +07:00
parent ced23336de
commit fe400c1487
2 changed files with 17 additions and 0 deletions

View File

@@ -14,6 +14,13 @@ namespace bundles { struct item_t; typedef std::shared_ptr<item_t> item_ptr; }
enum folding_state_t { kFoldingNone, kFoldingTop, kFoldingCollapsed, kFoldingBottom };
enum OTVFontSmoothing : NSUInteger
{
OTVFontSmoothingDisabled = 0,
OTVFontSmoothingEnabled = 1,
OTVFontSmoothingAuto = 2,
};
@protocol OakTextViewDelegate <NSObject>
@optional
- (NSString*)scopeAttributes;
@@ -27,6 +34,7 @@ PUBLIC @interface OakTextView : OakView <NSTextInput, NSTextFieldDelegate>
@property (nonatomic) NSCursor* ibeamCursor;
@property (nonatomic) NSFont* font;
@property (nonatomic) BOOL antiAlias;
@property (nonatomic) OTVFontSmoothing fontSmoothing;
@property (nonatomic) size_t tabSize;
@property (nonatomic) BOOL showInvisibles;
@property (nonatomic) BOOL softWrap;

View File

@@ -47,6 +47,7 @@ OAK_DEBUG_VAR(OakTextView_Macros);
int32_t const NSWrapColumnWindowWidth = 0;
int32_t const NSWrapColumnAskUser = -1;
NSString* const kUserDefaultsFontSmoothingKey = @"fontSmoothing";
NSString* const kUserDefaultsDisableAntiAliasKey = @"disableAntiAlias";
NSString* const kUserDefaultsDisableTypingPairsKey = @"disableTypingPairs";
NSString* const kUserDefaultsScrollPastEndKey = @"scrollPastEnd";
@@ -517,6 +518,7 @@ static std::string shell_quote (std::vector<std::string> paths)
_showInvisibles = settings.get(kSettingsShowInvisiblesKey, false);
_scrollPastEnd = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsScrollPastEndKey];
_antiAlias = ![[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableAntiAliasKey];
_fontSmoothing = (OTVFontSmoothing)[[NSUserDefaults standardUserDefaults] integerForKey:kUserDefaultsFontSmoothingKey];
spellingDotImage = [NSImage imageNamed:@"SpellingDot" inSameBundleAsClass:[self class]];
foldingDotsImage = [NSImage imageNamed:@"FoldingDots" inSameBundleAsClass:[self class]];
@@ -700,6 +702,8 @@ doScroll:
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
if(!self.antiAlias)
CGContextSetShouldAntialias(context, false);
if(self.fontSmoothing == OTVFontSmoothingAuto && theme->is_dark() || self.fontSmoothing == OTVFontSmoothingDisabled)
CGContextSetShouldSmoothFonts(context, false);
NSImage* pdfImage = foldingDotsImage;
auto foldingDotsFactory = [&pdfImage](double width, double height) -> CGImageRef
@@ -1187,6 +1191,10 @@ static void update_menu_key_equivalents (NSMenu* menu, action_to_key_t const& ac
}
update_menu_key_equivalents([NSApp mainMenu], actionToKey);
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
kUserDefaultsFontSmoothingKey : @(OTVFontSmoothingAuto),
}];
}
[NSApp registerServicesMenuSendTypes:@[ NSStringPboardType ] returnTypes:@[ NSStringPboardType ]];
@@ -2792,6 +2800,7 @@ static char const* kOakMenuItemTitle = "OakMenuItemTitle";
- (void)userDefaultsDidChange:(id)sender
{
self.antiAlias = ![[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableAntiAliasKey];
self.fontSmoothing = (OTVFontSmoothing)[[NSUserDefaults standardUserDefaults] integerForKey:kUserDefaultsFontSmoothingKey];
self.scrollPastEnd = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsScrollPastEndKey];
}