mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 11:00:59 +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>
|
||||
|
||||
* Source/NSDocumentController.m: Remove now unused override helper
|
||||
|
|
|
@ -625,19 +625,14 @@ static Class converter_class(NSString *format, BOOL producer)
|
|||
- (id) initWithURL: (NSURL *)url
|
||||
documentAttributes: (NSDictionary **)dict
|
||||
{
|
||||
NSData *data = [url resourceDataUsingCache: YES];
|
||||
NSError *error;
|
||||
NSDictionary *options = [NSDictionary dictionaryWithObject: [url baseURL]
|
||||
forKey: NSBaseURLDocumentOption];
|
||||
|
||||
if (data == nil)
|
||||
{
|
||||
RELEASE (self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
// FIXME: This expects the URL to point to a HTML page
|
||||
return [self initWithHTML: data
|
||||
baseURL: [url baseURL]
|
||||
documentAttributes: dict];
|
||||
return [self initWithURL: url
|
||||
options: options
|
||||
documentAttributes: dict
|
||||
error: &error];
|
||||
}
|
||||
|
||||
- (id) initWithRTFDFileWrapper: (NSFileWrapper *)wrapper
|
||||
|
@ -752,18 +747,32 @@ documentAttributes: (NSDictionary **)dict
|
|||
- (id) initWithDocFormat: (NSData *)data
|
||||
documentAttributes: (NSDictionary **)dict
|
||||
{
|
||||
// FIXME
|
||||
NSAttributedString *new;
|
||||
|
||||
if (data == nil)
|
||||
{
|
||||
RELEASE (self);
|
||||
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
|
||||
options: (NSDictionary *)options
|
||||
documentAttributes: (NSDictionary **)dict
|
||||
{
|
||||
// FIXME
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
NSURL *baseURL = [options objectForKey: NSBaseURLDocumentOption];
|
||||
|
||||
return [self initWithHTML: data
|
||||
baseURL: baseURL
|
||||
documentAttributes: dict];
|
||||
}
|
||||
|
||||
- (id) initWithData: (NSData *)data
|
||||
|
@ -771,7 +780,49 @@ documentAttributes: (NSDictionary **)dict
|
|||
documentAttributes: (NSDictionary **)dict
|
||||
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);
|
||||
return nil;
|
||||
}
|
||||
|
@ -781,11 +832,21 @@ documentAttributes: (NSDictionary **)dict
|
|||
documentAttributes: (NSDictionary **)dict
|
||||
error: (NSError **)error
|
||||
{
|
||||
// FIXME
|
||||
NSData *data = [url resourceDataUsingCache: YES];
|
||||
|
||||
if (data == nil)
|
||||
{
|
||||
// FIXME: Set error
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [self initWithData: data
|
||||
options: options
|
||||
documentAttributes: dict
|
||||
error: error];
|
||||
}
|
||||
|
||||
- (NSData *) docFormatFromRange: (NSRange)range
|
||||
documentAttributes: (NSDictionary *)dict
|
||||
{
|
||||
|
@ -1380,12 +1441,11 @@ static NSMutableDictionary *cachedCSets = nil;
|
|||
if ([type isEqualToString: @"html"])
|
||||
{
|
||||
NSData *data = [url resourceDataUsingCache: YES];
|
||||
NSURL *baseURL = [options objectForKey: @"BaseURL"];
|
||||
NSAttributedString *attr;
|
||||
|
||||
attr = [[NSAttributedString alloc]
|
||||
initWithHTML: data
|
||||
baseURL: baseURL
|
||||
options: options
|
||||
documentAttributes: documentAttributes];
|
||||
[self setAttributedString: attr];
|
||||
RELEASE(attr);
|
||||
|
@ -1457,7 +1517,20 @@ static NSMutableDictionary *cachedCSets = nil;
|
|||
documentAttributes: (NSDictionary **)documentAttributes
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue