Skip to content
Browse files

Clean up dead code

  • Loading branch information...
1 parent e742f81 commit 6c19ec8dc036234ab671a5ddd9da15c076262d37 @jjgod committed Jan 6, 2011
Showing with 3 additions and 242 deletions.
  1. +0 −2 AppController.m
  2. +0 −1 ExtendedAttributes.m
  3. +1 −1 TTDocument.h
  4. +2 −58 TTDocument.mm
  5. +0 −29 TTPage.h
  6. +0 −67 TTPage.m
  7. +0 −1 TTTextView.h
  8. +0 −83 TTTextView.mm
View
2 AppController.m
@@ -115,8 +115,6 @@ - (void) changeFont: (id) sender
NSFont *newFont = [sender convertFont: oldFont];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSLog(@"changeFont = %@", newFont);
-
if ([oldFont fontName] != [newFont fontName])
[defaults setValue: [newFont fontName] forKey: @"fontName"];
View
1 ExtendedAttributes.m
@@ -71,7 +71,6 @@ - (NSStringEncoding) textEncoding
if (! encodingStr)
return 0;
- NSLog(@"encodingStr = %@", encodingStr);
CFStringEncoding cfenc = CFStringConvertIANACharSetNameToEncoding((CFStringRef) encodingStr);
return CFStringConvertEncodingToNSStringEncoding(cfenc);
}
View
2 TTDocument.h
@@ -1,5 +1,5 @@
//
-// MyDocument.h
+// TTDocument.h
// Textus
//
// Created by Jjgod Jiang on 2/16/09.
View
60 TTDocument.mm
@@ -12,35 +12,6 @@
#import <CommonCrypto/CommonDigest.h>
#define kLastReadLineKey @"org.jjgod.textus.lastReadLine"
-#define kLastLayoutHeight @"org.jjgod.textus.lastLayoutHeight"
-#define kHashKey @"org.jjgod.textus.hash"
-
-@interface NSData (NSData_MD5Extensions)
-
-- (NSString *) MD5Hash;
-
-@end
-
-@implementation NSData (NSData_MD5Extensions)
-
-- (NSString *) MD5Hash
-{
- CC_MD5_CTX theContext;
- int i;
- unsigned char digest[CC_MD5_DIGEST_LENGTH];
-
- CC_MD5_Init(&theContext);
- CC_MD5_Update(&theContext, [self bytes], [self length]);
- CC_MD5_Final(digest, &theContext);
-
- NSMutableString *hash = [NSMutableString stringWithCapacity: CC_MD5_DIGEST_LENGTH * 2];
- for (i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
- [hash appendFormat: @"%02x", digest[i]];
-
- return hash;
-}
-
-@end
@implementation TTDocument
@@ -91,7 +62,6 @@ - (void) dealloc
- (void) saveMetaData
{
- NSLog(@"saveMetaData");
NSURL *fileURL = [self fileURL];
[fileURL setUnsignedInteger: lastReadLine forXattrKey: kLastReadLineKey];
}
@@ -108,21 +78,8 @@ - (void) windowControllerDidLoadNib: (NSWindowController *) aController
[textView setDocument: self];
if (fileContents)
{
-#ifdef ENABLE_PARTIAL_LAYOUT
- if (lastLayoutHeight > 0)
- {
- [textView doPartialLayoutWithMaximumHeight: (CGFloat) lastLayoutHeight
- aroundLine: lastReadLine];
- } else
- {
-#endif
- [textView invalidateLayout];
- [[self fileURL] setUnsignedInteger: (NSUInteger) [textView frame].size.height
- forXattrKey: kLastLayoutHeight];
- [textView scrollToLine: lastReadLine];
-#ifdef ENABLE_PARTIAL_LAYOUT
- }
-#endif
+ [textView invalidateLayout];
+ [textView scrollToLine: lastReadLine];
}
}
@@ -182,20 +139,9 @@ - (BOOL) readFromURL: (NSURL *) absoluteURL
[contents release];
NSArray *keys = [absoluteURL allXattrKeys];
- NSString *hash = [data MD5Hash];
-
if ([keys containsObject: kLastReadLineKey])
lastReadLine = [absoluteURL unsignedIntegerFromXattrKey: kLastReadLineKey];
- if ([keys containsObject: kHashKey] && [[absoluteURL stringFromXattrKey: kHashKey] isEqual: hash])
- {
- NSLog(@"loading previous layout results...");
- lastLayoutHeight = [absoluteURL unsignedIntegerFromXattrKey: kLastLayoutHeight];
- }
- else
- [absoluteURL setString: hash forXattrKey: kHashKey];
-
- NSLog(@"lastReadLine = %d", lastReadLine);
readSuccess = YES;
}
@@ -207,8 +153,6 @@ - (void) observeValueForKeyPath: (NSString *) keyPath
change: (NSDictionary *) change
context: (void *) context
{
- NSLog(@"keyPath = %@", keyPath);
-
if ([keyPath isEqual: @"lineHeight"] ||
[keyPath isEqual: @"fontName"] ||
[keyPath isEqual: @"fontSize"])
View
29 TTPage.h
@@ -1,29 +0,0 @@
-//
-// TTPage.h
-// Textus
-//
-// Created by Jiang Jiang on 4/20/10.
-// Copyright 2010 Jjgod Jiang. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-@interface TTPage : NSObject {
- CGRect frame;
- CFRange textRange;
- CTFramesetterRef framesetter;
- CFArrayRef lines;
- CGFloat lineHeight, lineAscent;
- BOOL drawn;
-}
-
-- (id) initWithContents: (CFAttributedStringRef) contents atRange: (CFRange) initialRange inFrame: (CGRect) theFrame;
-
-- (CGFloat) height;
-
-@property (readonly) CFRange textRange;
-@property (readonly) CFArrayRef lines;
-@property (readonly) CGFloat lineHeight, lineAscent;
-@property (assign) BOOL drawn;
-
-@end
View
67 TTPage.m
@@ -1,67 +0,0 @@
-//
-// TTPage.m
-// Textus
-//
-// Created by Jiang Jiang on 4/20/10.
-// Copyright 2010 Jjgod Jiang. All rights reserved.
-//
-
-#import "TTPage.h"
-
-@implementation TTPage
-
-@synthesize textRange, lines, lineHeight, lineAscent, drawn;
-
-- (id) initWithContents: (CFAttributedStringRef) contents
- atRange: (CFRange) initialRange
- inFrame: (CGRect) theFrame
-{
- if (self = [super init])
- {
- NSLog(@"Creating page with range: %d, %d (%gx%g)", initialRange.location, initialRange.length,
- theFrame.size.width, theFrame.size.height);
- CFAttributedStringRef substring = CFAttributedStringCreateWithSubstring(0, contents, initialRange);
- CTFontRef font = CFAttributedStringGetAttribute(contents, 0, kCTFontAttributeName, NULL);
- lineHeight = CTFontGetAscent(font) + CTFontGetDescent(font) + CTFontGetLeading(font);
- lineHeight *= [[NSUserDefaults standardUserDefaults] doubleForKey: @"lineHeight"];
- lineHeight = ceil(lineHeight);
- NSLog(@"lineHeight = %g", lineHeight);
-
- lineAscent = CTFontGetAscent(font);
- drawn = NO;
-
- framesetter = CTFramesetterCreateWithAttributedString(substring);
- CFRelease(substring);
-
- frame = theFrame;
- if (framesetter)
- {
- CGMutablePathRef path = CGPathCreateMutable();
- CGPathAddRect(path, NULL, frame);
- CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
- lines = CFRetain(CTFrameGetLines(textFrame));
-
- CFRelease(path);
- textRange = CTFrameGetVisibleStringRange(textFrame);
- // NSLog(@"textRange: %d, %d", textRange.location, textRange.length);
- textRange.location = initialRange.location;
- CFRelease(textFrame);
- CFRelease(framesetter);
- }
- }
- return self;
-}
-
-- (CGFloat) height
-{
- return lineHeight * CFArrayGetCount(lines);
-}
-
-- (void) dealloc
-{
- if (lines)
- CFRelease(lines);
- [super dealloc];
-}
-
-@end
View
1 TTTextView.h
@@ -29,6 +29,5 @@ typedef struct LineData {
- (void) invalidateLayout;
- (void) scrollToLine: (NSUInteger) line;
-- (void) doPartialLayoutWithMaximumHeight: (CGFloat) height aroundLine: (NSUInteger) line;
@end
View
83 TTTextView.mm
@@ -33,8 +33,6 @@ - (void) removeAllLines
{
NSUInteger i, count = textLines.size();
- NSLog(@"total lines: %u", count);
-
for (i = 0; i < count; i++)
CFRelease(textLines[i].line);
@@ -50,13 +48,11 @@ - (void) dealloc
- (void) invalidateLayout
{
NSAttributedString *text = [document fileContents];
- clock_t startTime = clock(), duration;
if (! text)
return;
NSSize contentSize = [[self enclosingScrollView] contentSize];
- NSLog(@"Original content size: %@", NSStringFromSize(contentSize));
CTFontRef font = (CTFontRef) [text attribute: (NSString *) kCTFontAttributeName
atIndex: 0
effectiveRange: NULL];
@@ -91,16 +87,10 @@ - (void) invalidateLayout
for (i = 0; i < total; i++)
{
lineData.line = (CTLineRef) CFRetain(CFArrayGetValueAtIndex(lines, i));
- // NSLog(@"y = %g\n", y);
lineData.origin = CGPointMake(frameRect.origin.x, y + lineAscent);
y += lineHeight;
textLines.push_back(lineData);
}
-#if 0
- NSLog(@"frameRange: %ld, %ld, %@",
- frameRange.location, frameRange.length,
- NSStringFromRect(NSRectFromCGRect(frameRect)));
-#endif
frameRect.origin.y = y;
frameRect.size.height = contentSize.height;
CFRelease(path);
@@ -109,81 +99,13 @@ - (void) invalidateLayout
CFRelease(framesetter);
- duration = clock() - startTime;
- NSLog(@"layout time = %g secs", (double) duration / (double) CLOCKS_PER_SEC);
-
NSRect newFrame = [self frame];
newFrame.size.height = frameRect.origin.y + textInset.height;
[self setFrame: newFrame];
[self setNeedsDisplay: YES];
}
-- (void) doPartialLayoutWithMaximumHeight: (CGFloat) height aroundLine: (NSUInteger) line
-{
- NSString *plainText = [document fileContentsInPlainText];
- NSAttributedString *text = [document fileContents];
- clock_t startTime = clock(), duration;
-
- if (! text)
- return;
-
- NSSize contentSize = [[self enclosingScrollView] contentSize];
- NSDictionary *attributes = [document attributesForText];
- CTFontRef font = (CTFontRef) [attributes objectForKey: (NSString *) kCTFontAttributeName];
- CGFloat lineHeight = CTFontGetAscent(font) + CTFontGetDescent(font) + CTFontGetLeading(font);
- CGFloat lineAscent = CTFontGetAscent(font);
- lineHeight *= [[NSUserDefaults standardUserDefaults] doubleForKey: @"lineHeight"];
-
- NSRange partRange = NSMakeRange(0, 2048);
- NSRange lineRange = [plainText lineRangeForRange: partRange];
-
- NSLog(@"lineRange: %@", NSStringFromRange(lineRange));
-
- // Create the framesetter with the attributed string.
- CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)
- [text attributedSubstringFromRange: lineRange]);
-
- CGRect frameRect = CGRectMake(textInset.width, textInset.height,
- contentSize.width - 2 * textInset.width - [NSScroller scrollerWidth],
- contentSize.height);
-
- CFRange range, frameRange;
- JJLineData lineData = { NULL, CGPointMake(0, 0) };
-
- [self removeAllLines];
-
- range = frameRange = CFRangeMake(0, 0);
- CGMutablePathRef path = CGPathCreateMutable();
- CGPathAddRect(path, NULL, frameRect);
-
- CTFrameRef frame = CTFramesetterCreateFrame(framesetter, range, path, NULL);
- frameRange = CTFrameGetVisibleStringRange(frame);
- CFArrayRef lines = CTFrameGetLines(frame);
- CFIndex i, total = CFArrayGetCount(lines);
- CGFloat y = frameRect.origin.y;
- for (i = 0; i < total; i++)
- {
- lineData.line = (CTLineRef) CFRetain(CFArrayGetValueAtIndex(lines, i));
- lineData.origin = CGPointMake(frameRect.origin.x, y + lineAscent);
- y += lineHeight;
- textLines.push_back(lineData);
- }
-
- CFRelease(path);
- CFRelease(frame);
- CFRelease(framesetter);
-
- duration = clock() - startTime;
- NSLog(@"layout time = %g secs", (double) duration / (double) CLOCKS_PER_SEC);
-
- NSRect newFrame = [self frame];
- newFrame.size.height = height;
-
- [self setFrame: newFrame];
- [self setNeedsDisplay: YES];
-}
-
- (BOOL) isFlipped
{
return YES;
@@ -207,8 +129,6 @@ - (void) drawRect: (NSRect) rect
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
- // NSLog(@"drawRect: %@", NSStringFromRect(rect));
-
NSUInteger i, from, total = textLines.size();
JJLineData lineData = { NULL, CGPointZero };
CGFloat bottom = rect.origin.y + rect.size.height;
@@ -217,14 +137,11 @@ - (void) drawRect: (NSRect) rect
for (i = from; i < total && lineData.origin.y <= bottom; i++)
{
lineData = textLines[i];
-
- // NSRectFill(NSMakeRect(lineData.origin.x, lineData.origin.y, 20, 1.5));
CGContextSetTextPosition(context, lineData.origin.x, lineData.origin.y);
CTLineDraw(lineData.line, context);
}
[document setLastReadLine: [self lineBefore: [[self enclosingScrollView] documentVisibleRect].origin.y]];
- // NSLog(@"drawLines from: %u to %u", from, i);
}
- (void) scrollTo: (float) y

0 comments on commit 6c19ec8

Please sign in to comment.
Something went wrong with that request. Please try again.