mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-04 03:50:41 +00:00
Basic implementation of the initWithData:.. methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27437 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b842490265
commit
d0f3a643c4
2 changed files with 122 additions and 42 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2008-12-26 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSAttributedString.m (-initWithData:...,
|
||||||
|
-initWithURL:...): Basic implementation.
|
||||||
|
* Source/NSAttributedString.m
|
||||||
|
(NSMutableAttributedString-readFromData:...): Implement.
|
||||||
|
|
||||||
2008-12-26 Fred Kiefer <FredKiefer@gmx.de>
|
2008-12-26 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSDocumentController.m: Remove now unused override helper
|
* Source/NSDocumentController.m: Remove now unused override helper
|
||||||
|
|
|
@ -625,19 +625,14 @@ static Class converter_class(NSString *format, BOOL producer)
|
||||||
- (id) initWithURL: (NSURL *)url
|
- (id) initWithURL: (NSURL *)url
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
{
|
{
|
||||||
NSData *data = [url resourceDataUsingCache: YES];
|
NSError *error;
|
||||||
|
NSDictionary *options = [NSDictionary dictionaryWithObject: [url baseURL]
|
||||||
|
forKey: NSBaseURLDocumentOption];
|
||||||
|
|
||||||
if (data == nil)
|
return [self initWithURL: url
|
||||||
{
|
options: options
|
||||||
RELEASE (self);
|
documentAttributes: dict
|
||||||
return nil;
|
error: &error];
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME: This expects the URL to point to a HTML page
|
|
||||||
return [self initWithHTML: data
|
|
||||||
baseURL: [url baseURL]
|
|
||||||
documentAttributes: dict];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithRTFDFileWrapper: (NSFileWrapper *)wrapper
|
- (id) initWithRTFDFileWrapper: (NSFileWrapper *)wrapper
|
||||||
|
@ -752,18 +747,32 @@ documentAttributes: (NSDictionary **)dict
|
||||||
- (id) initWithDocFormat: (NSData *)data
|
- (id) initWithDocFormat: (NSData *)data
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
{
|
{
|
||||||
// FIXME
|
NSAttributedString *new;
|
||||||
RELEASE(self);
|
|
||||||
|
if (data == nil)
|
||||||
|
{
|
||||||
|
RELEASE (self);
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
new = [converter_class(@"DOC", NO)
|
||||||
|
parseData: data
|
||||||
|
documentAttributes: dict
|
||||||
|
class: [self class]];
|
||||||
|
// We do not return self but the newly created object
|
||||||
|
RELEASE (self);
|
||||||
|
return RETAIN (new);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithHTML: (NSData *)data
|
- (id) initWithHTML: (NSData *)data
|
||||||
options: (NSDictionary *)options
|
options: (NSDictionary *)options
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
{
|
{
|
||||||
// FIXME
|
NSURL *baseURL = [options objectForKey: NSBaseURLDocumentOption];
|
||||||
RELEASE(self);
|
|
||||||
return nil;
|
return [self initWithHTML: data
|
||||||
|
baseURL: baseURL
|
||||||
|
documentAttributes: dict];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithData: (NSData *)data
|
- (id) initWithData: (NSData *)data
|
||||||
|
@ -771,7 +780,49 @@ documentAttributes: (NSDictionary **)dict
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
error: (NSError **)error
|
error: (NSError **)error
|
||||||
{
|
{
|
||||||
// FIXME
|
NSString *type = [options objectForKey: NSDocumentTypeDocumentOption];
|
||||||
|
|
||||||
|
if (type == nil)
|
||||||
|
{
|
||||||
|
// FIXME: try to determine type
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([type isEqualToString: NSDocFormatTextDocumentType])
|
||||||
|
{
|
||||||
|
return [self initWithDocFormat: data
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString: NSHTMLTextDocumentType])
|
||||||
|
{
|
||||||
|
return [self initWithHTML: data
|
||||||
|
options: options
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString: NSRTFDTextDocumentType])
|
||||||
|
{
|
||||||
|
return [self initWithRTFD: data
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString: NSRTFTextDocumentType])
|
||||||
|
{
|
||||||
|
return [self initWithRTF: data
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString: NSPlainTextDocumentType])
|
||||||
|
{
|
||||||
|
NSStringEncoding encoding = [[options objectForKey: @"CharacterEncoding"]
|
||||||
|
intValue];
|
||||||
|
NSDictionary *defaultAttrs = [options objectForKey: @"DefaultAttributes"];
|
||||||
|
NSString *str = [[NSString alloc] initWithData: data
|
||||||
|
encoding: encoding];
|
||||||
|
|
||||||
|
self = [self initWithString: str
|
||||||
|
attributes: defaultAttrs];
|
||||||
|
RELEASE(str);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Set error
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -781,9 +832,19 @@ documentAttributes: (NSDictionary **)dict
|
||||||
documentAttributes: (NSDictionary **)dict
|
documentAttributes: (NSDictionary **)dict
|
||||||
error: (NSError **)error
|
error: (NSError **)error
|
||||||
{
|
{
|
||||||
// FIXME
|
NSData *data = [url resourceDataUsingCache: YES];
|
||||||
|
|
||||||
|
if (data == nil)
|
||||||
|
{
|
||||||
|
// FIXME: Set error
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [self initWithData: data
|
||||||
|
options: options
|
||||||
|
documentAttributes: dict
|
||||||
|
error: error];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *) docFormatFromRange: (NSRange)range
|
- (NSData *) docFormatFromRange: (NSRange)range
|
||||||
|
@ -1380,12 +1441,11 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
if ([type isEqualToString: @"html"])
|
if ([type isEqualToString: @"html"])
|
||||||
{
|
{
|
||||||
NSData *data = [url resourceDataUsingCache: YES];
|
NSData *data = [url resourceDataUsingCache: YES];
|
||||||
NSURL *baseURL = [options objectForKey: @"BaseURL"];
|
|
||||||
NSAttributedString *attr;
|
NSAttributedString *attr;
|
||||||
|
|
||||||
attr = [[NSAttributedString alloc]
|
attr = [[NSAttributedString alloc]
|
||||||
initWithHTML: data
|
initWithHTML: data
|
||||||
baseURL: baseURL
|
options: options
|
||||||
documentAttributes: documentAttributes];
|
documentAttributes: documentAttributes];
|
||||||
[self setAttributedString: attr];
|
[self setAttributedString: attr];
|
||||||
RELEASE(attr);
|
RELEASE(attr);
|
||||||
|
@ -1457,7 +1517,20 @@ static NSMutableDictionary *cachedCSets = nil;
|
||||||
documentAttributes: (NSDictionary **)documentAttributes
|
documentAttributes: (NSDictionary **)documentAttributes
|
||||||
error: (NSError **)error
|
error: (NSError **)error
|
||||||
{
|
{
|
||||||
// FIXME
|
NSAttributedString *attr;
|
||||||
|
|
||||||
|
attr = [[NSAttributedString alloc]
|
||||||
|
initWithData: data
|
||||||
|
options: options
|
||||||
|
documentAttributes: documentAttributes
|
||||||
|
error: error];
|
||||||
|
if (attr)
|
||||||
|
{
|
||||||
|
[self setAttributedString: attr];
|
||||||
|
RELEASE(attr);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue