File: PQCharactersController.m

package info (click to toggle)
fontmanager.app 0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 564 kB
  • sloc: objc: 1,618; makefile: 19
file content (116 lines) | stat: -rw-r--r-- 2,432 bytes parent folder | download | duplicates (2)
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
/*
 * PQCharactersController.m - Font Manager
 *
 * Copyright 2007 Isaiah Beerbower.
 *
 * Author: Isaiah Beerbower
 * Created: 12/02/07
 * License: 3-Clause BSD license (see file COPYING)
 */


#import "PQCharactersController.h"
#import "PQCompat.h"


@implementation PQCharactersController

- (id) init
{
	[super init];
	
	fontName = [[NSString alloc] init];
	
	unicodeBlocks =
		[NSDictionary dictionaryWithContentsOfFile:
			[[NSBundle mainBundle] pathForResource: @"UnicodeBlocks"
																			ofType: @"plist"]];
	
	characterRange = NSMakeRange(0, 128);
	
	RETAIN(unicodeBlocks);
	RETAIN(fontName);
	
	return self;
}

- (void) dealloc
{
	RELEASE(unicodeBlocks);
	RELEASE(fontName);
	
	[super dealloc];
}

- (void) awakeFromNib
{
	[unicodeBlockPopUpButton removeAllItems];

	NSArray *unicodeBlockNames =
		[NSArray arrayWithContentsOfFile:
			[[NSBundle mainBundle] pathForResource: @"UnicodeBlockNames"
																			ofType: @"plist"]];

	[unicodeBlockPopUpButton addItemsWithTitles: unicodeBlockNames];

	/*
	[unicodeBlockPopUpButton addItemsWithTitles:
		[[unicodeBlocks allKeys]
			sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)]];
	*/
	
	[unicodeBlockPopUpButton selectItemWithTitle: @"Basic Latin"];

	[charsView setSelectedIndex: 65];
}

- (void) changeCharSize: (id)sender
{
  [charView setFontSize: [sender intValue]];
}

- (void) changeUnicodeBlock: (id)sender
{
	NSArray *unicodeBlock =
		[unicodeBlocks objectForKey: [sender titleOfSelectedItem]];
	
	unsigned int lowerBound = [[unicodeBlock objectAtIndex: 0] intValue];
	unsigned int upperBound = [[unicodeBlock objectAtIndex: 1] intValue];
	
	characterRange = NSMakeRange(lowerBound, (upperBound - lowerBound));
	
	[charsView setSelectedIndex: 0];
	[charsView setNeedsDisplay: YES];
}

- (void) setFont: (NSString *)newFontName
{
	ASSIGN(fontName, newFontName);
	
	[charView setFont: fontName];
	
	[charsView setFont: [NSFont fontWithName: fontName size: 24.0]];
}

- (NSString *) font
{
	return fontName;
}

- (int) numberOfCharactersInCharactersView: (PQCharactersView *)aCharactersView
{
	return characterRange.length;
}

- (unichar) charactersView: (PQCharactersView *)aCharactersView
					characterAtIndex: (int)index
{
	return index + characterRange.location;
}

- (void) selectionDidChangeInCharactersView: (PQCharactersView *)charactersView
{
	[charView setCharacter: characterRange.location + [charsView selectedIndex]];
}

@end