RTF Problems
RTF Problems
- Subject: RTF Problems
- From: Mamdouh <email@hidden>
- Date: Sun, 10 Mar 2002 14:37:02 +0100
Hi list...
I4m including a lot of code in this mail so i4ll make this as short as
possible! I4m trying to learn Cocoa by writing a text-editor! Well today
i try4ed implementing saving and opening RTF documents but i got into
some problems:
When the app saves or opens a document it shows all of the RTF tags!
Example:
If i make a new document and type the word "Apple" and save, this is
what the text in the textview is turned into:
{\rtf1\mac\ansicpg10000\cocoartf100
{\fonttbl\f0\fswiss\fcharset77 Helvetica;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\
tx6160\tx6720
\f0\fs24 \cf2 Apple}
Not so fancy huh?
As i understand it ive either:
Ive forgotten to implement some important block of code
Implemented to much code
Please help me cause this is the only thing i need before my app can go
into beta!
The document section of the app source code:
ALL SUGGESTIONS ARE WELCOME BUT PLEASE INCLUDE SOME CODE CAUSE I`M STILL
A NEWBIE!
#import "MyDocument.h"
NSString * kPlainTextDataTypeString = @"Plain Text";
@implementation MyDocument
-(void)dealloc
{
[fTextData release];
[fTextDataType release];
}
- (void)setTextData:(NSData *)theData
{
[theData retain];
[fTextData release];
fTextData = theData;
// If the window is showing, update the text view.
if (documentTextView) {
if ([[self textDataType] isEqualToString:@"RTF Document"])
[documentTextView
replaceCharactersInRange:NSMakeRange(0,[[documentTextView string]
length]) withRTF:[self textData]];
else
[documentTextView
replaceCharactersInRange:NSMakeRange(0,[[documentTextView string]
length]) withString:[NSString stringWithCString:[[self textData] bytes]
length:[[self textData] length]]];
}
}
- (NSData *)textData
{
return [[fTextData copy] autorelease];
}
- (void)setTextDataType:(NSString *)theType
{
[theType retain];
[fTextDataType release];
fTextDataType = theType;
}
- (NSString *)textDataType
{
return [[fTextDataType copy] autorelease];
}
// ==========================================================
// Standard NSDocument methods
// ==========================================================
- (NSString *)windowNibName
{
return @"MyDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
if ([[self textDataType] isEqualToString:@"RTF Document"])
[documentTextView
replaceCharactersInRange:NSMakeRange(0,[[documentTextView string]
length]) withRTF:[self textData]];
else
[documentTextView
replaceCharactersInRange:NSMakeRange(0,[[documentTextView string]
length]) withString:[NSString stringWithCString:[[self textData] bytes]
length:[[self textData] length]]];
[documentWindow makeFirstResponder: documentTextView];
//##############################HER!
}
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
if ([aType isEqualToString:@"RTF Document"])
[self setText
Data:[documentTextView
RTFFromRange:NSMakeRange(0,[[documentTextView string] length])]];
else
[self setText
Data:[NSData dataWithBytes:[[documentTextView
string] cString] length:[[documentTextView string] cStringLength]]];
return [self textData];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType {
// Read the opened file.
[self setText
Data:data];
[self setTextDataType:aType];
return YES;
}
Thanks
ALL SUGGESTIONS ARE WELCOME BUT PLEASE INCLUDE SOME CODE CAUSE I`M STILL
A NEWBIE!
Mamdouh
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.