forked from kimasendorf/ExtraFile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XFImageDocumentController.m
142 lines (110 loc) · 3.57 KB
/
XFImageDocumentController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// XFImageDocumentController.m
// ExtraFile
//
// Created by Kim Asendorf on 06.05.11.
//
#import "XFImageDocumentController.h"
static NSString* ImageIOLocalizedString(NSString* key)
{
static NSBundle* b = nil;
if (b == nil)
b = [NSBundle bundleWithIdentifier:@"com.apple.ImageIO.framework"];
return [b localizedStringForKey:key value:key table: @"CGImageSource"];
}
static NSString* XFTypeNameRoot = @"org.extrafile";
static NSString* XFTypeNameXFF = @"org.extrafile.xff";
static NSString* XFTypeNameCCI = @"org.extrafile.cci";
static NSString* XFTypeNameMCF = @"org.extrafile.mcf";
static NSString* XFTypeName4BC = @"org.extrafile.4bc";
static NSString* XFTypeNameBASCII = @"org.extrafile.bascii";
static NSString* XFTypeNameBLINX = @"org.extrafile.blinx";
static NSString* XFTypeNameUSPEC = @"org.extrafile.uspec";
static NSString* XFIOLocalizedString(NSString* key)
{
static NSString* type = nil;
if ([key isEqualToString:XFTypeNameXFF]) {
type = @"XFF";
} else if ([key isEqualToString:XFTypeNameCCI]) {
type = @"CCI";
} else if ([key isEqualToString:XFTypeNameMCF]) {
type = @"MCF";
} else if ([key isEqualToString:XFTypeName4BC]) {
type = @"4BC";
} else if ([key isEqualToString:XFTypeNameBASCII]) {
type = @"BASCII";
} else if ([key isEqualToString:XFTypeNameBLINX]) {
type = @"BLINX";
} else if ([key isEqualToString:XFTypeNameUSPEC]) {
type = @"USPEC";
}
return type;
}
@implementation XFImageDocumentController
- (NSString *)defaultType
{
return @"public.tiff";
}
- (NSArray *)documentClassNames
{
return [NSArray arrayWithObject:@"XFImageDocument"];
}
- (Class)documentClassForType:(NSString *)typeName
{
return [[NSBundle mainBundle] classNamed:@"XFImageDocument"];
}
- (NSString *)displayNameForType:(NSString *)typeName;
{
NSString* displayName = nil;
if ([typeName rangeOfString:XFTypeNameRoot].location != NSNotFound) {
displayName = XFIOLocalizedString(typeName);
} else {
displayName = ImageIOLocalizedString(typeName);
}
return displayName;
}
// Return the name of the document type that should be used when opening a URL
// In this app, we return the UTI type returned by CGImageSourceGetType.
//
/*
- (NSString *)typeForContentsOfURL:(NSURL *)absURL error:(NSError **)outError
{
NSLog(@"TYPE CONTENT URL");
NSLog(@"%@", absURL);
NSString* type = nil;
CGImageSourceRef isrc = CGImageSourceCreateWithURL((CFURLRef)absURL, nil);
NSLog(@"%@", isrc);
if (isrc)
{
NSLog(@"TYPE CGI");
type = [[(NSString *)CGImageSourceGetType(isrc) retain] autorelease];
NSLog(@"%@", type);
CFRelease(isrc);
}
return type;
}
*/
// Given a document type, return an array of corresponding file name extensions
// and HFS file type strings of the sort returned by NSFileTypeForHFSTypeCode().
// In this app, 'typeName' is a UTI type so we can call UTTypeCopyDeclaration().
//
- (NSArray *)fileExtensionsFromType:(NSString *)typeName;
{
NSArray* readExts = nil;
CFDictionaryRef utiDecl = UTTypeCopyDeclaration((CFStringRef)typeName);
if (utiDecl)
{
CFDictionaryRef utiSpec = CFDictionaryGetValue(utiDecl, kUTTypeTagSpecificationKey);
if (utiSpec)
{
CFTypeRef ext = CFDictionaryGetValue(utiSpec, kUTTagClassFilenameExtension);
if (ext && CFGetTypeID(ext) == CFStringGetTypeID())
readExts = [NSArray arrayWithObject:(id)ext];
if (ext && CFGetTypeID(ext) == CFArrayGetTypeID())
readExts = [NSArray arrayWithArray:(id)ext];
}
CFRelease(utiDecl);
}
return readExts;
}
@end