-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPQFontDocument.m
executable file
·188 lines (156 loc) · 4.09 KB
/
PQFontDocument.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* PQFontDocument.m - Font Manager
*
* Class which represents a font document.
*
* Copyright 2007 Isaiah Beerbower.
*
* Author: Isaiah Beerbower
* Created: 11/30/07
* License: 3-Clause BSD license (see file COPYING)
*/
#import "PQFontDocument.h"
#import "PQFontManager.h"
#import "PQCompat.h"
@implementation PQFontDocument
- (id) init
{
[super init];
fontInfo = [[NSMutableDictionary alloc] init];
fontInfoIndex = [[NSMutableArray alloc] init];
fontName = [[NSString alloc] initWithString: @"Bitstream Vera Sans"];
return self;
}
- (void) awakeFromNib
{
/* Values that should be set in FontDocument.gorm, but aren't */
NSTableColumn *keyColumn = [[infoView tableColumns] objectAtIndex: 0];
NSTableColumn *valueColumn = [[infoView tableColumns] objectAtIndex: 1];
[[keyColumn headerCell] setTitle: @"Key"];
[[valueColumn headerCell] setTitle: @"Value"];
[keyColumn setEditable: NO];
[valueColumn setEditable: NO];
[keyColumn setWidth: 128.0];
[infoView sizeLastColumnToFit];
// FIXME:
[facePopUpButton setEnabled: NO];
[facePopUpButton setHidden: YES];
[installAllButton setEnabled: NO];
[installAllButton setHidden: YES];
[sampleController setFonts: [NSArray arrayWithObject: fontName]];
[charactersController setFont: fontName];
}
- (void) dealloc
{
RELEASE(fontName);
RELEASE(fontInfo);
RELEASE(fontInfoIndex);
[super dealloc];
}
- (void) setFont: (NSString *)newFont
{
ASSIGN(fontName, newFont);
[sampleController setFonts: [NSArray arrayWithObject: fontName]];
[charactersController setFont: fontName];
}
- (void) selectFace: (id)sender
{
}
- (void) installAll: (id)sender
{
if ([[installButton title] isEqualToString:@"Install All"])
{
[installButton setTitle:@"Uninstall All"];
}
else
{
[installButton setTitle:@"Install All"];
}
}
- (void) install: (id)sender
{
if ([[installButton title] isEqualToString:@"Install"])
{
[installButton setTitle:@"Uninstall"];
}
else
{
[installButton setTitle:@"Install"];
}
}
- (int) numberOfRowsInTableView: (NSTableView *)aTableView
{
return [fontInfoIndex count];
}
- (id) tableView: (NSTableView *)aTableView
objectValueForTableColumn: (NSTableColumn *)aTableColumn
row: (int)rowIndex
{
if ([[[aTableColumn headerCell] title] isEqualToString: @"Key"])
{
return [fontInfoIndex objectAtIndex: rowIndex];
}
else
{
return [fontInfo objectForKey: [fontInfoIndex objectAtIndex: rowIndex]];
}
return nil;
}
- (NSString *) windowNibName
{
return @"FontDocument";
}
- (NSString *)displayName
{
return [[NSFont fontWithName: fontName size: 0] displayName];
}
- (BOOL) readFromFile: (NSString *)fileName ofType: (NSString *)docType
{
#ifdef GNUSTEP
/*ASSIGN(fontName,
[[[(PQFontManager *)[PQFontManager sharedFontManager] makeAvailableFontAtPath: fileName]
objectAtIndex: 0] objectAtIndex: 0]);*/
//ASSIGN(fontName, @"Luxi Sans Roman"); //TEMP
fontName = @"Bitstream Vera Sans";
#else
// In theory this code should make the font available, I'm not sure if it
// works though. Any way, after it's activated I'm not sure how to find out
// it's postscript name.
//FSRef iFile;
//char *path = [fileName UTF8String];
//
//if (! FSPathMakeRef((UInt8 *)path, &iFile, NO))
//{
// return NO;
//}
//
//if (ATSFontActivateFromFileSpecification(&iFile, kATSFontContextLocal,
// kATSFontFormatUnspecified, NULL, kATSOptionFlagsDefault, &fontContainer) !=
// kATSIterationCompleted)
//{
// return NO;
//}
// Just so it runs we'll use Helvetica instead.
ASSIGN(fontName, @"Helvetica"); //TEMP
#endif
if (fontName == nil)
{
return NO;
}
NSFont *font = [NSFont fontWithName: fontName size: 0];
[fontInfoIndex addObject:@"Name"];
[fontInfo setObject:[font displayName] forKey:@"Name"];
[fontInfoIndex addObject:@"Family Name"];
[fontInfo setObject:[font familyName] forKey:@"Family Name"];
[fontInfoIndex addObject:@"Postscript Name"];
[fontInfo setObject:[font fontName] forKey:@"Postscript Name"];
[fontInfoIndex addObject:@"File"];
[fontInfo setObject:fileName forKey:@"File"];
return YES;
}
- (void) close
{
// [[GSFontEnumerator sharedEnumerator] makeFontUnvailable: font]
[super close];
}
@end