mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 03:40:47 +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
|
+ (NSData*) produceRTF: (NSAttributedString*) aText
|
||||||
documentAttributes: (NSDictionary*)dict;
|
documentAttributes: (NSDictionary*)dict;
|
||||||
|
+ (NSFileWrapper*) produceRTFD: (NSAttributedString*) aText
|
||||||
|
documentAttributes: (NSDictionary*)dict;
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -95,14 +95,46 @@
|
||||||
|
|
||||||
@implementation RTFProducer
|
@implementation RTFProducer
|
||||||
|
|
||||||
+ (NSData*) RTFDFromAttributedString: (NSAttributedString*) aText
|
+ (NSFileWrapper*) produceRTFD: (NSAttributedString*) aText
|
||||||
documentAttributes: (NSDictionary*)dict
|
documentAttributes: (NSDictionary*)dict
|
||||||
{
|
{
|
||||||
RTFProducer *new = [self new];
|
RTFProducer *new = [self new];
|
||||||
NSData *data = [[new RTFDStringFromAttributedString: aText
|
NSData *data;
|
||||||
documentAttributes: dict]
|
NSFileWrapper *wrapper;
|
||||||
dataUsingEncoding: NSISOLatin1StringEncoding];
|
|
||||||
|
|
||||||
|
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);
|
RELEASE(new);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,17 +206,10 @@ readNSString(StringContext *ctxt)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface RTFConsumer: NSObject
|
@interface RTFConsumer (Private)
|
||||||
{
|
|
||||||
@public
|
|
||||||
NSMutableDictionary *documentAttributes;
|
|
||||||
NSMutableDictionary *fonts;
|
|
||||||
NSMutableArray *colours;
|
|
||||||
NSMutableArray *attrs;
|
|
||||||
NSMutableAttributedString *result;
|
|
||||||
int ignore;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
- (NSAttributedString*) parseRTF: (NSData *)rtfData
|
||||||
|
documentAttributes: (NSDictionary **)dict;
|
||||||
- (NSDictionary*) documentAttributes;
|
- (NSDictionary*) documentAttributes;
|
||||||
- (NSAttributedString*) result;
|
- (NSAttributedString*) result;
|
||||||
|
|
||||||
|
@ -228,6 +221,45 @@ readNSString(StringContext *ctxt)
|
||||||
|
|
||||||
@implementation RTFConsumer
|
@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
|
- (id) init
|
||||||
{
|
{
|
||||||
ignore = 0;
|
ignore = 0;
|
||||||
|
@ -250,6 +282,10 @@ readNSString(StringContext *ctxt)
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation RTFConsumer (Private)
|
||||||
|
|
||||||
- (NSDictionary*) documentAttributes
|
- (NSDictionary*) documentAttributes
|
||||||
{
|
{
|
||||||
RETAIN(documentAttributes);
|
RETAIN(documentAttributes);
|
||||||
|
@ -777,15 +813,3 @@ void GSRTFparagraph(void *ctxt)
|
||||||
GSRTFmangleText(ctxt, "\n");
|
GSRTFmangleText(ctxt, "\n");
|
||||||
CTXT->tabChanged = NO;
|
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
|
#ifndef _rtfConsumer_h_INCLUDE
|
||||||
#define _rtfConsumer_h_INCLUDE
|
#define _rtfConsumer_h_INCLUDE
|
||||||
|
|
||||||
NSAttributedString *parseRTFintoAttributedString(NSData *rtfData,
|
@interface RTFConsumer: NSObject
|
||||||
NSDictionary **dict);
|
{
|
||||||
|
@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
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue