mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 03:00:37 +00:00
Added new methods to read/write RTFD and resturctured the methods
for RTF. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6857 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
96056f9785
commit
1ab1e78975
4 changed files with 105 additions and 31 deletions
|
@ -43,7 +43,10 @@
|
|||
*/
|
||||
}
|
||||
|
||||
+ (NSData*) RTFDFromAttributedString: (NSAttributedString*) aText
|
||||
documentAttributes: (NSDictionary*)dict;
|
||||
+ (NSData*) produceRTF: (NSAttributedString*) aText
|
||||
documentAttributes: (NSDictionary*)dict;
|
||||
+ (NSFileWrapper*) produceRTFD: (NSAttributedString*) aText
|
||||
documentAttributes: (NSDictionary*)dict;
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -95,14 +95,46 @@
|
|||
|
||||
@implementation RTFProducer
|
||||
|
||||
+ (NSData*) RTFDFromAttributedString: (NSAttributedString*) aText
|
||||
documentAttributes: (NSDictionary*)dict
|
||||
+ (NSFileWrapper*) produceRTFD: (NSAttributedString*) aText
|
||||
documentAttributes: (NSDictionary*)dict
|
||||
{
|
||||
RTFProducer *new = [self new];
|
||||
NSData *data = [[new RTFDStringFromAttributedString: aText
|
||||
documentAttributes: dict]
|
||||
dataUsingEncoding: NSISOLatin1StringEncoding];
|
||||
NSData *data;
|
||||
NSFileWrapper *wrapper;
|
||||
|
||||
data = [[new RTFDStringFromAttributedString: aText
|
||||
documentAttributes: dict]
|
||||
dataUsingEncoding: NSISOLatin1StringEncoding];
|
||||
|
||||
if ([aText containsAttachments])
|
||||
{
|
||||
NSMutableDictionary *fileDict = [NSMutableDictionary dictionary];
|
||||
NSFileWrapper *txt = [[NSFileWrapper alloc]
|
||||
initRegularFileWithContents: data];
|
||||
|
||||
[fileDict setObject: txt forKey: @"TXT.rtf"];
|
||||
RELEASE(txt);
|
||||
// FIXME: We have to add the attachments to the directory file wrapper
|
||||
|
||||
wrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers: fileDict];
|
||||
}
|
||||
else
|
||||
wrapper = [[NSFileWrapper alloc] initRegularFileWithContents: data];
|
||||
|
||||
|
||||
RELEASE(new);
|
||||
return AUTORELEASE(wrapper);
|
||||
}
|
||||
|
||||
+ (NSData*) produceRTF: (NSAttributedString*) aText
|
||||
documentAttributes: (NSDictionary*)dict
|
||||
{
|
||||
RTFProducer *new = [self new];
|
||||
NSData *data;
|
||||
|
||||
data = [[new RTFDStringFromAttributedString: aText
|
||||
documentAttributes: dict]
|
||||
dataUsingEncoding: NSISOLatin1StringEncoding];
|
||||
RELEASE(new);
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -206,17 +206,10 @@ readNSString(StringContext *ctxt)
|
|||
|
||||
@end
|
||||
|
||||
@interface RTFConsumer: NSObject
|
||||
{
|
||||
@public
|
||||
NSMutableDictionary *documentAttributes;
|
||||
NSMutableDictionary *fonts;
|
||||
NSMutableArray *colours;
|
||||
NSMutableArray *attrs;
|
||||
NSMutableAttributedString *result;
|
||||
int ignore;
|
||||
}
|
||||
@interface RTFConsumer (Private)
|
||||
|
||||
- (NSAttributedString*) parseRTF: (NSData *)rtfData
|
||||
documentAttributes: (NSDictionary **)dict;
|
||||
- (NSDictionary*) documentAttributes;
|
||||
- (NSAttributedString*) result;
|
||||
|
||||
|
@ -228,6 +221,45 @@ readNSString(StringContext *ctxt)
|
|||
|
||||
@implementation RTFConsumer
|
||||
|
||||
+ (NSAttributedString*) parseRTFD: (NSFileWrapper *)wrapper
|
||||
documentAttributes: (NSDictionary **)dict
|
||||
{
|
||||
RTFConsumer *consumer = [RTFConsumer new];
|
||||
NSAttributedString *text = nil;
|
||||
|
||||
if ([wrapper isRegularFile])
|
||||
text = [consumer parseRTF: [wrapper regularFileContents]
|
||||
documentAttributes: dict];
|
||||
else if ([wrapper isDirectory])
|
||||
{
|
||||
NSDictionary *files = [wrapper fileWrappers];
|
||||
NSFileWrapper *contents;
|
||||
|
||||
//FIXME: We should store the files in the consumer
|
||||
// We try to read the main file in the directory
|
||||
if ((contents = [files objectForKey: @"TXT.rtf"]) != nil)
|
||||
text = [consumer parseRTF: [contents regularFileContents]
|
||||
documentAttributes: dict];
|
||||
}
|
||||
|
||||
RELEASE(consumer);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
+ (NSAttributedString*) parseRTF: (NSData *)rtfData
|
||||
documentAttributes: (NSDictionary **)dict
|
||||
{
|
||||
RTFConsumer *consumer = [RTFConsumer new];
|
||||
NSAttributedString *text;
|
||||
|
||||
text = [consumer parseRTF: rtfData
|
||||
documentAttributes: dict];
|
||||
RELEASE(consumer);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
ignore = 0;
|
||||
|
@ -250,6 +282,10 @@ readNSString(StringContext *ctxt)
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RTFConsumer (Private)
|
||||
|
||||
- (NSDictionary*) documentAttributes
|
||||
{
|
||||
RETAIN(documentAttributes);
|
||||
|
@ -777,15 +813,3 @@ void GSRTFparagraph(void *ctxt)
|
|||
GSRTFmangleText(ctxt, "\n");
|
||||
CTXT->tabChanged = NO;
|
||||
}
|
||||
|
||||
NSAttributedString *parseRTFintoAttributedString(NSData *rtfData,
|
||||
NSDictionary **dict)
|
||||
{
|
||||
RTFConsumer *consumer = [RTFConsumer new];
|
||||
NSAttributedString *result;
|
||||
|
||||
result = [consumer parseRTF: rtfData documentAttributes: dict];
|
||||
RELEASE(consumer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,22 @@
|
|||
#ifndef _rtfConsumer_h_INCLUDE
|
||||
#define _rtfConsumer_h_INCLUDE
|
||||
|
||||
NSAttributedString *parseRTFintoAttributedString(NSData *rtfData,
|
||||
NSDictionary **dict);
|
||||
@interface RTFConsumer: NSObject
|
||||
{
|
||||
@public
|
||||
NSMutableDictionary *documentAttributes;
|
||||
NSMutableDictionary *fonts;
|
||||
NSMutableArray *colours;
|
||||
NSMutableArray *attrs;
|
||||
NSMutableAttributedString *result;
|
||||
int ignore;
|
||||
}
|
||||
|
||||
+ (NSAttributedString*) parseRTF: (NSData *)rtfData
|
||||
documentAttributes: (NSDictionary **)dict;
|
||||
+ (NSAttributedString*) parseRTFD: (NSFileWrapper *)rtfFile
|
||||
documentAttributes: (NSDictionary **)dict;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue