Permalink
Browse files

Added an NSTextView category to disable blurriness issues when scrolling

  • Loading branch information...
1 parent 36c8c38 commit b36c83e922ebb1bb30c4490586ff823580dd2780 @jspahrsummers jspahrsummers committed Jul 18, 2012
Showing with 68 additions and 0 deletions.
  1. +10 −0 TwUI.xcodeproj/project.pbxproj
  2. +15 −0 lib/Support/NSTextView+TUIExtensions.h
  3. +43 −0 lib/Support/NSTextView+TUIExtensions.m
@@ -269,6 +269,9 @@
D040610D15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; };
D040610E15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; };
D040610F15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; };
+ D040611615B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */; };
+ D040611715B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */; };
+ D040611815B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */; };
D0C764EB15B611C200E7AC2C /* TUIBridgedView.h in Headers */ = {isa = PBXBuildFile; fileRef = D0C764EA15B611C200E7AC2C /* TUIBridgedView.h */; settings = {ATTRIBUTES = (Public, ); }; };
D0C764EC15B611C200E7AC2C /* TUIBridgedView.h in Headers */ = {isa = PBXBuildFile; fileRef = D0C764EA15B611C200E7AC2C /* TUIBridgedView.h */; settings = {ATTRIBUTES = (Public, ); }; };
D0C764ED15B611C200E7AC2C /* TUIBridgedView.h in Headers */ = {isa = PBXBuildFile; fileRef = D0C764EA15B611C200E7AC2C /* TUIBridgedView.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -465,6 +468,8 @@
CBB74C9013BE6E1900C85CB5 /* TUIViewNSViewContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIViewNSViewContainer.m; sourceTree = "<group>"; };
D040610815B6A77500F753ED /* TUIAnimationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIAnimationManager.h; sourceTree = "<group>"; };
D040610915B6A77500F753ED /* TUIAnimationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIAnimationManager.m; sourceTree = "<group>"; };
+ D040611115B6A7CC00F753ED /* NSTextView+TUIExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSTextView+TUIExtensions.h"; sourceTree = "<group>"; };
+ D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSTextView+TUIExtensions.m"; sourceTree = "<group>"; };
D0C764EA15B611C200E7AC2C /* TUIBridgedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIBridgedView.h; sourceTree = "<group>"; };
D0C7650415B6156A00E7AC2C /* TUIHostView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIHostView.h; sourceTree = "<group>"; };
D0C7650C15B6189D00E7AC2C /* TUINSHostView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUINSHostView.h; sourceTree = "<group>"; };
@@ -638,6 +643,8 @@
D0C7652115B6232100E7AC2C /* CALayer+TUIExtensions.m */,
D0C7652215B6232100E7AC2C /* CATransaction+TUIExtensions.h */,
D0C7652315B6232100E7AC2C /* CATransaction+TUIExtensions.m */,
+ D040611115B6A7CC00F753ED /* NSTextView+TUIExtensions.h */,
+ D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */,
D040610815B6A77500F753ED /* TUIAnimationManager.h */,
D040610915B6A77500F753ED /* TUIAnimationManager.m */,
D0C7656F15B6341800E7AC2C /* TUICAAction.h */,
@@ -1107,6 +1114,7 @@
D0C7656815B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */,
D0C7657615B6341800E7AC2C /* TUICAAction.m in Sources */,
D040610F15B6A77500F753ED /* TUIAnimationManager.m in Sources */,
+ D040611815B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1182,6 +1190,7 @@
D0C7656615B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */,
D0C7657415B6341800E7AC2C /* TUICAAction.m in Sources */,
D040610D15B6A77500F753ED /* TUIAnimationManager.m in Sources */,
+ D040611615B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1263,6 +1272,7 @@
D0C7656715B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */,
D0C7657515B6341800E7AC2C /* TUICAAction.m in Sources */,
D040610E15B6A77500F753ED /* TUIAnimationManager.m in Sources */,
+ D040611715B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,15 @@
+//
+// NSTextView+TUIExtensions.h
+//
+// Created by Justin Spahr-Summers on 10.03.12.
+// Copyright (c) 2012 Bitswift. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+/**
+ * This private category fixes blurry text in layer-backed text views and text
+ * fields.
+ */
+@interface NSTextView (TUIExtensions)
+@end
@@ -0,0 +1,43 @@
+//
+// NSTextView+TUIExtensions.m
+//
+// Created by Justin Spahr-Summers on 10.03.12.
+// Copyright (c) 2012 Bitswift. All rights reserved.
+//
+
+#import "NSTextView+TUIExtensions.h"
+#import <objc/runtime.h>
+
+static void (*originalDrawRectIMP)(id, SEL, NSRect);
+
+static void fixedDrawRect (NSTextView *self, SEL _cmd, NSRect rect) {
+ CGContextRef context = [NSGraphicsContext currentContext].graphicsPort;
+
+ CGContextSetAllowsAntialiasing(context, YES);
+ CGContextSetAllowsFontSmoothing(context, YES);
+ CGContextSetAllowsFontSubpixelPositioning(context, YES);
+ CGContextSetAllowsFontSubpixelQuantization(context, YES);
+
+ CGContextSetShouldAntialias(context, YES);
+ CGContextSetShouldSmoothFonts(context, YES);
+ CGContextSetShouldSubpixelPositionFonts(context, YES);
+ CGContextSetShouldSubpixelQuantizeFonts(context, YES);
+
+ if (self.superview) {
+ // NSTextView likes to fall on non-integral points sometimes -- fix that
+ self.frame = [self.superview backingAlignedRect:self.frame options:NSAlignAllEdgesNearest];
+ }
+
+ originalDrawRectIMP(self, _cmd, rect);
+}
+
+@implementation NSTextView (TUIExtensions)
+
++ (void)load {
+ Method drawRect = class_getInstanceMethod(self, @selector(drawRect:));
+ originalDrawRectIMP = (void (*)(id, SEL, NSRect))method_getImplementation(drawRect);
+
+ class_replaceMethod(self, method_getName(drawRect), (IMP)&fixedDrawRect, method_getTypeEncoding(drawRect));
+}
+
+@end

0 comments on commit b36c83e

Please sign in to comment.