Skip to content

Commit

Permalink
Clean up dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgod committed Jan 6, 2011
1 parent e742f81 commit 6c19ec8
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 242 deletions.
2 changes: 0 additions & 2 deletions AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down
1 change: 0 additions & 1 deletion ExtendedAttributes.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ - (NSStringEncoding) textEncoding
if (! encodingStr)
return 0;

NSLog(@"encodingStr = %@", encodingStr);
CFStringEncoding cfenc = CFStringConvertIANACharSetNameToEncoding((CFStringRef) encodingStr);
return CFStringConvertEncodingToNSStringEncoding(cfenc);
}
Expand Down
2 changes: 1 addition & 1 deletion TTDocument.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MyDocument.h
// TTDocument.h
// Textus
//
// Created by Jjgod Jiang on 2/16/09.
Expand Down
60 changes: 2 additions & 58 deletions TTDocument.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -91,7 +62,6 @@ - (void) dealloc

- (void) saveMetaData
{
NSLog(@"saveMetaData");
NSURL *fileURL = [self fileURL];
[fileURL setUnsignedInteger: lastReadLine forXattrKey: kLastReadLineKey];
}
Expand All @@ -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];
}
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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"])
Expand Down
29 changes: 0 additions & 29 deletions TTPage.h

This file was deleted.

67 changes: 0 additions & 67 deletions TTPage.m

This file was deleted.

1 change: 0 additions & 1 deletion TTTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ typedef struct LineData {

- (void) invalidateLayout;
- (void) scrollToLine: (NSUInteger) line;
- (void) doPartialLayoutWithMaximumHeight: (CGFloat) height aroundLine: (NSUInteger) line;

@end
83 changes: 0 additions & 83 deletions TTTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 6c19ec8

Please sign in to comment.