Permalink
Browse files

Refactor file names

  • Loading branch information...
1 parent 1b6fc03 commit e742f81458b900699e7b94e746e916d1afcf6b7e @jjgod committed Nov 15, 2010
View
@@ -1,3 +1,4 @@
*.pbxuser
*.perspectivev3
+.DS_Store
build/
View
@@ -7,7 +7,6 @@
//
#import "AppController.h"
-#import "TextDocument.h"
int hexNum(char ch)
{
@@ -2,35 +2,29 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">10B504</string>
- <string key="IBDocument.InterfaceBuilderVersion">732</string>
- <string key="IBDocument.AppKitVersion">1038.2</string>
- <string key="IBDocument.HIToolboxVersion">437.00</string>
+ <string key="IBDocument.SystemVersion">10H574</string>
+ <string key="IBDocument.InterfaceBuilderVersion">804</string>
+ <string key="IBDocument.AppKitVersion">1038.35</string>
+ <string key="IBDocument.HIToolboxVersion">461.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string key="NS.object.0">732</string>
+ <string key="NS.object.0">804</string>
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="5"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys" id="0">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
+ <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+ <integer value="1" key="NS.object.0"/>
</object>
<object class="NSMutableArray" key="IBDocument.RootObjects" id="580458321">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSCustomObject" id="512844837">
- <string key="NSClassName">TextDocument</string>
+ <string key="NSClassName">TTDocument</string>
</object>
<object class="NSCustomObject" id="613418571">
<string key="NSClassName">FirstResponder</string>
@@ -46,7 +40,7 @@
<string key="NSWindowContentMaxSize">{1.79769e+308, 1.79769e+308}</string>
<string key="NSWindowContentMinSize">{94, 86}</string>
<object class="NSView" key="NSWindowView" id="568628114">
- <reference key="NSNextResponder"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -65,7 +59,7 @@
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{800, 679}</string>
<reference key="NSSuperview" ref="479699895"/>
- <string key="NSClassName">JJTextView</string>
+ <string key="NSClassName">TTTextView</string>
</object>
</object>
<string key="NSFrame">{{1, 1}, {800, 679}}</string>
@@ -114,7 +108,6 @@
</object>
</object>
<string key="NSFrameSize">{800, 700}</string>
- <reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{94, 108}</string>
@@ -160,7 +153,9 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBObjectRecord">
<int key="objectID">0</int>
- <reference key="object" ref="0"/>
+ <object class="NSArray" key="object" id="0">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
<reference key="children" ref="580458321"/>
<nil key="parent"/>
</object>
@@ -295,38 +290,27 @@
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
- <string key="className">JJTextView</string>
- <string key="superclassName">NSView</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier" id="368465059">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">JJTextView.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
- <string key="className">JJTextView</string>
- <string key="superclassName">NSView</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier" id="109171031">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">TextDocument.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
- <string key="className">TextDocument</string>
- <string key="superclassName">NSDocument</string>
- <reference key="sourceIdentifier" ref="368465059"/>
- </object>
- <object class="IBPartialClassDescription">
- <string key="className">TextDocument</string>
+ <string key="className">TTDocument</string>
<string key="superclassName">NSDocument</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">textView</string>
- <string key="NS.object.0">JJTextView</string>
+ <string key="NS.object.0">TTTextView</string>
+ </object>
+ <object class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <string key="NS.key.0">textView</string>
+ <object class="IBToOneOutletInfo" key="NS.object.0">
+ <string key="name">textView</string>
+ <string key="candidateClassName">TTTextView</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBUserSource</string>
+ <string key="minorKey"/>
</object>
- <reference key="sourceIdentifier" ref="109171031"/>
</object>
<object class="IBPartialClassDescription">
- <string key="className">TextDocument</string>
- <string key="superclassName">NSDocument</string>
+ <string key="className">TTTextView</string>
+ <string key="superclassName">NSView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBUserSource</string>
<string key="minorKey"/>
@@ -418,6 +402,45 @@
<string>id</string>
</object>
</object>
+ <object class="NSMutableDictionary" key="actionInfosByName">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>printDocument:</string>
+ <string>revertDocumentToSaved:</string>
+ <string>runPageLayout:</string>
+ <string>saveDocument:</string>
+ <string>saveDocumentAs:</string>
+ <string>saveDocumentTo:</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBActionInfo">
+ <string key="name">printDocument:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo">
+ <string key="name">revertDocumentToSaved:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo">
+ <string key="name">runPageLayout:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo">
+ <string key="name">saveDocument:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo">
+ <string key="name">saveDocumentAs:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo">
+ <string key="name">saveDocumentTo:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ </object>
+ </object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">AppKit.framework/Headers/NSDocument.h</string>
@@ -780,6 +803,7 @@
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
<integer value="1050" key="NS.object.0"/>
View
@@ -22,7 +22,7 @@
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>NSDocumentClass</key>
- <string>TextDocument</string>
+ <string>TTDocument</string>
<key>NSTypeName</key>
<string>Plain Text Format</string>
</dict>
@@ -7,24 +7,11 @@
//
#import <Cocoa/Cocoa.h>
+#import "TTTextView.h"
-@class TextDocument;
-
-@interface JJTextView : NSView
-
-@property (assign) NSSize textInset;
-@property (retain) NSColor *backgroundColor;
-@property (assign) TextDocument *document;
-
-- (void) invalidateLayout;
-- (void) scrollToLine: (NSUInteger) line;
-- (void) doPartialLayoutWithMaximumHeight: (CGFloat) height aroundLine: (NSUInteger) line;
-
-@end
-
-@interface TextDocument : NSDocument
+@interface TTDocument : NSDocument
{
- IBOutlet JJTextView *textView;
+ IBOutlet TTTextView *textView;
NSStringEncoding GB18030Encoding;
NSMutableAttributedString *fileContents;
NSString *fileContentsInPlainText;
@@ -1,13 +1,13 @@
//
-// MyDocument.m
+// TTDocument.m
// Textus
//
// Created by Jjgod Jiang on 2/16/09.
// Copyright Jjgod Jiang 2009 . All rights reserved.
//
#import "AppController.h"
-#import "TextDocument.h"
+#import "TTDocument.h"
#import "ExtendedAttributes.h"
#import <CommonCrypto/CommonDigest.h>
@@ -42,7 +42,7 @@ - (NSString *) MD5Hash
@end
-@implementation TextDocument
+@implementation TTDocument
@synthesize fileContents, fileContentsInPlainText;
@synthesize lastReadLine, lastLayoutHeight;
@@ -98,7 +98,7 @@ - (void) saveMetaData
- (NSString *) windowNibName
{
- return @"TextDocument";
+ return @"TTDocument";
}
- (void) windowControllerDidLoadNib: (NSWindowController *) aController
View
@@ -0,0 +1,29 @@
+//
+// 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
@@ -0,0 +1,67 @@
+//
+// 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
Oops, something went wrong.

0 comments on commit e742f81

Please sign in to comment.