Unify the text converter handling. Plus added a bit of implementation

for the new test block methods.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28713 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2009-09-19 14:55:57 +00:00
parent 420648751a
commit 3b51ebf3fe
7 changed files with 306 additions and 170 deletions

View file

@ -279,22 +279,30 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
if (flag)
{
if ([format isEqual: @"RTFD"])
if (([format isEqual: NSRTFDTextDocumentType]) ||
([format isEqual: @"com.apple.rtfd"]) ||
([format isEqual: @"rtfd"]))
{
cClass = [RTFDProducer class];
}
else if ([format isEqual: @"RTF"])
else if (([format isEqual: NSRTFTextDocumentType]) ||
([format isEqual: @"public.rtf"]) ||
([format isEqual: @"rtf"]))
{
cClass = [RTFProducer class];
}
}
else
{
if ([format isEqual: @"RTFD"])
if (([format isEqual: NSRTFDTextDocumentType]) ||
([format isEqual: @"com.apple.rtfd"]) ||
([format isEqual: @"rtfd"]))
{
cClass = [RTFDConsumer class];
}
else if ([format isEqual: @"RTF"])
else if (([format isEqual: NSRTFTextDocumentType]) ||
([format isEqual: @"public.rtf"]) ||
([format isEqual: @"rtf"]))
{
cClass = [RTFConsumer class];
}
@ -303,7 +311,9 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
}
+ (NSAttributedString*) parseFile: (NSFileWrapper *)wrapper
options: (NSDictionary *)options
documentAttributes: (NSDictionary **)dict
error: (NSError **)error
class: (Class)class
{
NSAttributedString *text = nil;
@ -337,7 +347,9 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
}
+ (NSAttributedString*) parseData: (NSData *)rtfData
options: (NSDictionary *)options
documentAttributes: (NSDictionary **)dict
error: (NSError **)error
class: (Class)class
{
RTFConsumer *consumer = [RTFConsumer new];
@ -406,14 +418,20 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
}
+ (NSAttributedString*) parseData: (NSData *)rtfData
options: (NSDictionary *)options
documentAttributes: (NSDictionary **)dict
error: (NSError **)error
class: (Class)class
{
NSAttributedString *str;
NSFileWrapper *wrapper = [[NSFileWrapper alloc]
initWithSerializedRepresentation: rtfData];
str = [self parseFile: wrapper documentAttributes: dict class: class];
str = [self parseFile: wrapper
options: options
documentAttributes: dict
error: error
class: class];
RELEASE (wrapper);
return str;

View file

@ -60,12 +60,6 @@
int unnamedAttachmentCounter; /*" Count the number of unnamed attachments so we can name them uniquely "*/
}
+ (NSData *)produceDataFrom: (NSAttributedString *)aText
documentAttributes: (NSDictionary *)dict;
+ (NSFileWrapper *)produceFileFrom: (NSAttributedString *)aText
documentAttributes: (NSDictionary *)dict;
@end
@interface RTFProducer: RTFDProducer

View file

@ -69,6 +69,7 @@
+ (NSFileWrapper *)produceFileFrom: (NSAttributedString *)aText
documentAttributes: (NSDictionary *)dict
error: (NSError **)error
{
RTFDProducer *producer;
NSData *encodedText;
@ -122,9 +123,11 @@
+ (NSData *)produceDataFrom: (NSAttributedString *)aText
documentAttributes: (NSDictionary *)dict
error: (NSError **)error
{
return [[self produceFileFrom: aText
documentAttributes: dict] serializedRepresentation];
documentAttributes: dict
error: error] serializedRepresentation];
}
- (id)init
@ -170,6 +173,7 @@
+ (NSData *)produceDataFrom: (NSAttributedString *)aText
documentAttributes: (NSDictionary *)dict
error: (NSError **)error
{
RTFProducer *producer;
NSData *data;
@ -187,10 +191,12 @@
+ (NSFileWrapper *)produceFileFrom: (NSAttributedString *)aText
documentAttributes: (NSDictionary *)dict
error: (NSError **)error
{
return AUTORELEASE([[NSFileWrapper alloc]
initRegularFileWithContents: [self produceDataFrom: aText
documentAttributes: dict]]);
documentAttributes: dict
error: error]]);
}
@end