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
ce0466b729
commit
d1f7108b4c
4 changed files with 105 additions and 31 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue