mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 06:30:38 +00:00
Implemented [readFromURL:options:documentAttributes:]. In
[applyFontTraits:range:] use [NSFontManager convertFont:toHaveTrait:] instead of explicit font creation. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10923 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8dee14989f
commit
6b2f41f67e
1 changed files with 84 additions and 7 deletions
|
@ -33,6 +33,7 @@
|
|||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <AppKit/NSAttributedString.h>
|
||||
#include <AppKit/NSDocumentController.h>
|
||||
#include <AppKit/NSParagraphStyle.h>
|
||||
#include <AppKit/NSTextAttachment.h>
|
||||
#include <AppKit/NSFont.h>
|
||||
|
@ -724,8 +725,7 @@ documentAttributes: (NSDictionary **)dict
|
|||
format: @"RangeError in method -unscriptRange:"];
|
||||
}
|
||||
|
||||
[self addAttribute: NSSuperscriptAttributeName
|
||||
value: [NSNumber numberWithInt: 0]
|
||||
[self removeAttribute: NSSuperscriptAttributeName
|
||||
range: range];
|
||||
}
|
||||
|
||||
|
@ -749,12 +749,10 @@ documentAttributes: (NSDictionary **)dict
|
|||
atIndex: loc
|
||||
effectiveRange: &effRange];
|
||||
|
||||
if (font != nil && [fm traitsOfFont: font] != traitMask)
|
||||
if (font != nil)
|
||||
{
|
||||
font = [fm fontWithFamily: [font familyName]
|
||||
traits: traitMask
|
||||
weight: [fm weightOfFont: font]
|
||||
size: [font pointSize]];
|
||||
font = [fm convertFont: font
|
||||
toHaveTrait: traitMask];
|
||||
|
||||
if (font != nil)
|
||||
{
|
||||
|
@ -973,4 +971,83 @@ documentAttributes: (NSDictionary **)dict
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL) readFromURL: (NSURL *)url
|
||||
options: (NSDictionary *)options
|
||||
documentAttributes: (NSDictionary**)documentAttributes
|
||||
{
|
||||
NSString *extension;
|
||||
NSString *type;
|
||||
|
||||
if (![url isFileURL])
|
||||
return NO;
|
||||
|
||||
extension = [[url path] pathExtension];
|
||||
type = [[NSDocumentController sharedDocumentController]
|
||||
typeFromFileExtension: extension];
|
||||
if (type == nil)
|
||||
return NO;
|
||||
|
||||
if ([type isEqualToString: @"html"])
|
||||
{
|
||||
NSData *data = [url resourceDataUsingCache: YES];
|
||||
NSURL *baseURL = [options objectForKey: @"BaseURL"];
|
||||
NSAttributedString *attr;
|
||||
|
||||
attr = [[NSAttributedString alloc]
|
||||
initWithHTML: data
|
||||
baseURL: baseURL
|
||||
documentAttributes: documentAttributes];
|
||||
[self setAttributedString: attr];
|
||||
RELEASE(attr);
|
||||
|
||||
return YES;
|
||||
}
|
||||
else if ([type isEqualToString: @"rtfd"])
|
||||
{
|
||||
NSData *data = [url resourceDataUsingCache: YES];
|
||||
NSAttributedString *attr;
|
||||
|
||||
attr = [[NSAttributedString alloc]
|
||||
initWithRTFD: data
|
||||
documentAttributes: documentAttributes];
|
||||
[self setAttributedString: attr];
|
||||
RELEASE(attr);
|
||||
|
||||
return YES;
|
||||
}
|
||||
else if ([type isEqualToString: @"rtf"])
|
||||
{
|
||||
NSData *data = [url resourceDataUsingCache: YES];
|
||||
NSAttributedString *attr;
|
||||
|
||||
attr = [[NSAttributedString alloc]
|
||||
initWithRTF: data
|
||||
documentAttributes: documentAttributes];
|
||||
[self setAttributedString: attr];
|
||||
RELEASE(attr);
|
||||
|
||||
return YES;
|
||||
}
|
||||
else if ([type isEqualToString: @"text"])
|
||||
{
|
||||
NSData *data = [url resourceDataUsingCache: YES];
|
||||
NSStringEncoding encoding = [[options objectForKey: @"CharacterEncoding"]
|
||||
intValue];
|
||||
NSDictionary *defaultAttrs = [options objectForKey: @"DefaultAttributes"];
|
||||
NSAttributedString *attr;
|
||||
|
||||
attr = [[NSAttributedString alloc]
|
||||
initWithString: [NSString initWithData: data
|
||||
encoding: encoding]
|
||||
attributes: defaultAttrs];
|
||||
[self setAttributedString: attr];
|
||||
RELEASE(attr);
|
||||
|
||||
return YES;
|
||||
}
|
||||
// FIXME This should also support all converter bundles
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue