Font encodings now specified as descriptive strings. After much fiddling to get fonttexgen to use a PDF for the custom symbols, gave up and generated a big bitmap instead. Generated 1024x1024 Cyrillic font texture, other encodings coming soon.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1358 127b21dd-08f5-0310-b4b7-95ae10353056
master
Jens Ayton 2008-02-10 17:48:08 +00:00
parent 77cde62c7b
commit 03f321da01
13 changed files with 988 additions and 1446 deletions

View File

@ -1,5 +1,16 @@
{
encoding = 12; // NSWindowsCP1252StringEncoding, Windows Latin 1
/*
Currently, Oolite supports the following encodings for fonts:
windows-latin-1 (Windows code page 1252)
windows-latin-2 (Windows code page 1250)
windows-cyrillic (Windows code page 1251)
windows-greek (Windows code page 1253)
windows-turkish (Windows code page 1254)
OXPs with fonts in each encoding (using Helvetica) are available at:
http://svn.berlios.de/svnroot/repos/oolite-linux/trunk/tests/encodings/
*/
encoding = "windows-latin-1";
texture = "oolite-font.png";
substitutions =

View File

@ -49,6 +49,9 @@ SOFTWARE.
*/
#ifndef OOENCODINGCONVERTER_EXCLUDE // For the convenience of fonttexgen
#import "OOCocoa.h"
@class OOCache;
@ -67,3 +70,18 @@ SOFTWARE.
- (NSData *) convertString:(NSString *)string;
@end
#endif OOENCODINGCONVERTER_EXCLUDE
/*
There are a variety of overlapping naming schemes for text encoding.
We ignore them and use a fixed list:
"windows-latin-1" NSWindowsCP1252StringEncoding
"windows-latin-2" NSWindowsCP1250StringEncoding
"windows-cyrillic" NSWindowsCP1251StringEncoding
"windows-greek" NSWindowsCP1253StringEncoding
"windows-turkish" NSWindowsCP1254StringEncoding
*/
NSString *StringFromEncoding(NSStringEncoding encoding); // Returns nil for unknown
NSStringEncoding EncodingFromString(NSString *name); // Returns (NSStringEncoding)NSNotFound for unknown

View File

@ -46,6 +46,8 @@ SOFTWARE.
*/
#ifndef OOENCODINGCONVERTER_EXCLUDE
#import "OOEncodingConverter.h"
#import "OOCache.h"
#import "OOCollectionExtractors.h"
@ -112,7 +114,7 @@ static unsigned sCacheMisses = 0;
- (id) initWithFontPList:(NSDictionary *)fontPList
{
return [self initWithEncoding:[fontPList unsignedIntForKey:@"encoding"] substitutions:[fontPList dictionaryForKey:@"substitutions"]];
return [self initWithEncoding:EncodingFromString([fontPList stringForKey:@"encoding"]) substitutions:[fontPList dictionaryForKey:@"substitutions"]];
}
@ -211,3 +213,58 @@ static unsigned sCacheMisses = 0;
#endif
@end
#endif OOENCODINGCONVERTER_EXCLUDE
/*
There are a variety of overlapping naming schemes for text encoding.
We ignore them and use a fixed list:
"windows-latin-1" NSWindowsCP1252StringEncoding
"windows-latin-2" NSWindowsCP1250StringEncoding
"windows-cyrillic" NSWindowsCP1251StringEncoding
"windows-greek" NSWindowsCP1253StringEncoding
"windows-turkish" NSWindowsCP1254StringEncoding
*/
#define kWindowsLatin1Str @"windows-latin-1"
#define kWindowsLatin2Str @"windows-latin-2"
#define kWindowsCyrillicStr @"windows-cyrillic"
#define kWindowsGreekStr @"windows-greek"
#define kWindowsTurkishStr @"windows-turkish"
NSString *StringFromEncoding(NSStringEncoding encoding)
{
switch (encoding)
{
case NSWindowsCP1252StringEncoding:
return kWindowsLatin1Str;
case NSWindowsCP1250StringEncoding:
return kWindowsLatin2Str;
case NSWindowsCP1251StringEncoding:
return kWindowsCyrillicStr;
case NSWindowsCP1253StringEncoding:
return kWindowsGreekStr;
case NSWindowsCP1254StringEncoding:
return kWindowsTurkishStr;
default:
return nil;
}
}
NSStringEncoding EncodingFromString(NSString *name)
{
if ([name isEqualToString:kWindowsLatin1Str]) return NSWindowsCP1252StringEncoding;
if ([name isEqualToString:kWindowsLatin2Str]) return NSWindowsCP1250StringEncoding;
if ([name isEqualToString:kWindowsCyrillicStr]) return NSWindowsCP1251StringEncoding;
if ([name isEqualToString:kWindowsGreekStr]) return NSWindowsCP1253StringEncoding;
if ([name isEqualToString:kWindowsTurkishStr]) return NSWindowsCP1254StringEncoding;
return (NSStringEncoding)NSNotFound;
}

View File

@ -96,8 +96,8 @@ This code is hereby placed in the public domain.
if (__builtin_expect(
selector != @selector(weakRefDrop) &&
selector != @selector(weakRefObjectStillExists)
&& selector != @selector(weakRefUnderlyingObject), 1))
selector != @selector(weakRefObjectStillExists) &&
selector != @selector(weakRefUnderlyingObject), 1))
{
// Not a proxy method; get signature from _object if it exists, otherwise generic signature for nil calls.
if (__builtin_expect(_object != nil, 1)) result = [(id)_object methodSignatureForSelector:selector];

File diff suppressed because it is too large Load Diff

View File

@ -11,17 +11,20 @@
@interface FontTextureView: NSView
{
int _offsetX, _offsetY;
BOOL _alternatingColors;
NSImage *_topRows;
NSImage *_credits;
NSArray *_widths;
NSDictionary *_template;
int _offsetX, _offsetY;
BOOL _alternatingColors;
NSImage *_topRows;
NSArray *_widths;
NSDictionary *_template;
NSStringEncoding _encoding;
IBOutlet NSPopUpButton *encodingPopUp;
}
@property (nonatomic) int offsetX, offsetY;
@property (nonatomic) BOOL alternatingColors;
- (IBAction) saveImage:(id)sender;
- (IBAction) takeEncodingFromTag:(id)sender;
@end

View File

@ -9,9 +9,37 @@
// Hackerific: it's a view that thinks it's a controller.
#import "FontTextureView.h"
#import <QuartzCore/QuartzCore.h>
#import "OOEncodingConverter.h"
#define ENCODING 11//NSWindowsCP1252StringEncoding
@interface NSImage ()
@property (setter=setFlipped:, getter=isFlipped) BOOL flipped;
@end
static inline NSPoint ScalePoint(NSPoint point, NSPoint scale)
{
point.x *= scale.x;
point.y *= scale.y;
return point;
}
static inline NSSize ScaleSize(NSSize size, NSPoint scale)
{
size.width *= scale.x;
size.height *= scale.y;
return size;
}
static inline NSRect ScaleRect(NSRect rect, NSPoint scale)
{
rect.origin = ScalePoint(rect.origin, scale);
rect.size = ScaleSize(rect.size, scale);
return rect;
}
@interface NSString (StringWithCharacter)
@ -36,6 +64,7 @@
[[NSUserDefaults standardUserDefaults] registerDefaults:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:4], @"offsetX",
[NSNumber numberWithInt:NSWindowsCP1252StringEncoding], @"encoding",
nil]];
}
@ -79,8 +108,11 @@
withKeyPath:@"values.alternatingColors"
options:nil];
_encoding = [[NSUserDefaults standardUserDefaults] integerForKey:@"encoding"];
[encodingPopUp selectItemWithTag:_encoding];
_topRows = [NSImage imageNamed:@"toprows"];
_credits = [NSImage imageNamed:@"credits"];
_topRows.flipped = YES;
_template = [[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"template" ofType:@"plist"]] copy];
}
@ -99,7 +131,10 @@
[[NSColor blackColor] set];
[NSBezierPath fillRect:rect];
NSFont *font = [NSFont fontWithName:@"Helvetica Bold" size:25.0];
// Originally hard-coded at 512x512 pixels, scale is used to transform magic numbers as appropriate.
NSPoint scale = { self.bounds.size.width / 512, self.bounds.size.height / 512 };
NSFont *font = [NSFont fontWithName:@"Helvetica Bold" size:25.0 * scale.y];
if (font == nil) NSLog(@"Failed to find font!");
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil];
@ -112,41 +147,47 @@
{
if (_alternatingColors && ((x % 2) == (y % 2)))
{
NSRect frame = {{ x * 32, y * 32 }, { 32, 32 }};
NSRect frame = {{ x * 32.0 * scale.x, y * 32.0 * scale.y }, { 32.0 * scale.x, 32.0 * scale.y }};
[[NSColor darkGrayColor] set];
[NSBezierPath fillRect:frame];
}
uint8_t value = y * 16 + x;
if (value < 32 && value != '\t' && value != 0x08 && value != 0x18) continue;
if (value == 0x7F) value = '?'; // Substitution glyph for unknown characters
NSString *string = [[NSString alloc] initWithBytes:&value length:1 encoding:ENCODING];
if (value == 0x08) string = [NSString stringWithCharacter:0x2605]; // Black Star
if (value == 0x18) string = [NSString stringWithCharacter:0x2606]; // White Star
// Replace Euro sign with Cruzeiro sign.
if ([string characterAtIndex:0] == 0x20AC) string = [NSString stringWithCharacter:0x20A2];
// Replace tab with space.
if ([string characterAtIndex:0] == '\t') string = [NSString stringWithCharacter:' '];
NSPoint point = NSMakePoint(x * 32 + self.offsetX, y * 32 + self.offsetY);
[string drawAtPoint:point withAttributes:attrs];
NSNumber *width = [NSNumber numberWithFloat:[string sizeWithAttributes:attrs].width / 4.0];
if (value < 32)
if (y >= 2 || value == '\t' || value == 0x08 || value == 0x18)
{
[widths replaceObjectAtIndex:value withObject:width];
}
else
{
[widths addObject:width];
// if (value == 0x7F) value = '?'; // Substitution glyph for unknown characters -- not used
NSString *string = [[NSString alloc] initWithBytes:&value length:1 encoding:_encoding];
if (value == 0x08) string = [NSString stringWithCharacter:0x2605]; // Black Star
if (value == 0x18) string = [NSString stringWithCharacter:0x2606]; // White Star
// Replace Euro sign with Cruzeiro sign.
if ([string characterAtIndex:0] == 0x20AC) string = [NSString stringWithCharacter:0x20A2];
// Replace tab with space.
if ([string characterAtIndex:0] == '\t') string = [NSString stringWithCharacter:' '];
NSPoint point = NSMakePoint((x * 32.0 + self.offsetX) * scale.x, (y * 32.0 + self.offsetY) * scale.y);
[string drawAtPoint:point withAttributes:attrs];
NSNumber *width = [NSNumber numberWithFloat:[string sizeWithAttributes:attrs].width / 4.0];
if (value < 32)
{
[widths replaceObjectAtIndex:value withObject:width];
}
else
{
[widths addObject:width];
}
}
}
}
[_topRows compositeToPoint:NSMakePoint(0, _topRows.size.height) operation:NSCompositePlusLighter];
[NSGraphicsContext currentContext].imageInterpolation = NSImageInterpolationHigh;
NSRect srcRect = {{0, 0}, _topRows.size};
NSRect dstRect = {{0, 0}, {32.0 * scale.x * 8.0, 32.0 * scale.y * 2.0}};
[_topRows drawInRect:dstRect fromRect:srcRect operation:NSCompositePlusLighter fraction:1.0];
_widths = [widths copy];
}
@ -166,13 +207,21 @@
NSMutableDictionary *plist = [_template mutableCopy];
[plist setObject:_widths forKey:@"widths"];
[plist setObject:[NSNumber numberWithInt:ENCODING] forKey:@"encoding"];
[plist setObject:StringFromEncoding(_encoding) forKey:@"encoding"];
path = [[path stringByDeletingPathExtension] stringByAppendingPathExtension:@"plist"];
[plist writeToFile:path atomically:YES];
}
}
- (IBAction) takeEncodingFromTag:(id)sender
{
_encoding = [[sender selectedItem] tag];
[[NSUserDefaults standardUserDefaults] setInteger:_encoding forKey:@"encoding"];
[self setNeedsDisplay:YES];
}
@end

View File

@ -7,9 +7,11 @@
objects = {
/* Begin PBXBuildFile section */
1A88FF7C0D5E393A002E5344 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A88FF7B0D5E393A002E5344 /* QuartzCore.framework */; };
1AC544440D4D01DE00C90E5B /* FontTextureView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AC544430D4D01DE00C90E5B /* FontTextureView.m */; };
1AC544AB0D4D175B00C90E5B /* toprows.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AC544A90D4D175B00C90E5B /* toprows.png */; };
1AC545680D4D362C00C90E5B /* template.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1AC545670D4D362C00C90E5B /* template.plist */; };
1AD3DA280D5F62E700AB473C /* OOEncodingConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AD3DA270D5F62E700AB473C /* OOEncodingConverter.m */; };
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
@ -20,10 +22,13 @@
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
1A88FF7B0D5E393A002E5344 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = SDKs/MacOSX10.5.sdk/System/Library/Frameworks/QuartzCore.framework; sourceTree = DEVELOPER_DIR; };
1AC544420D4D01DE00C90E5B /* FontTextureView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontTextureView.h; sourceTree = "<group>"; };
1AC544430D4D01DE00C90E5B /* FontTextureView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FontTextureView.m; sourceTree = "<group>"; };
1AC544A90D4D175B00C90E5B /* toprows.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = toprows.png; sourceTree = "<group>"; };
1AC545670D4D362C00C90E5B /* template.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = template.plist; sourceTree = "<group>"; };
1AD3DA260D5F62E700AB473C /* OOEncodingConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OOEncodingConverter.h; path = ../../src/Core/OOEncodingConverter.h; sourceTree = SOURCE_ROOT; };
1AD3DA270D5F62E700AB473C /* OOEncodingConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OOEncodingConverter.m; path = ../../src/Core/OOEncodingConverter.m; sourceTree = SOURCE_ROOT; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
@ -39,6 +44,7 @@
buildActionMask = 2147483647;
files = (
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
1A88FF7C0D5E393A002E5344 /* QuartzCore.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -50,6 +56,8 @@
children = (
1AC544420D4D01DE00C90E5B /* FontTextureView.h */,
1AC544430D4D01DE00C90E5B /* FontTextureView.m */,
1AD3DA260D5F62E700AB473C /* OOEncodingConverter.h */,
1AD3DA270D5F62E700AB473C /* OOEncodingConverter.m */,
);
name = Classes;
sourceTree = "<group>";
@ -58,6 +66,7 @@
isa = PBXGroup;
children = (
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
1A88FF7B0D5E393A002E5344 /* QuartzCore.framework */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
@ -181,6 +190,7 @@
files = (
8D11072D0486CEB800E47090 /* main.m in Sources */,
1AC544440D4D01DE00C90E5B /* FontTextureView.m in Sources */,
1AD3DA280D5F62E700AB473C /* OOEncodingConverter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -210,12 +220,18 @@
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(DEVELOPER_DIR)/SDKs/MacOSX10.5.sdk/System/Library/Frameworks\"",
);
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fonttexgen_Prefix.pch;
GCC_PREPROCESSOR_DEFINITIONS = "NS_BUILD_32_LIKE_64=1";
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = OOENCODINGCONVERTER_EXCLUDE;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = fonttexgen;
@ -228,6 +244,10 @@
isa = XCBuildConfiguration;
buildSettings = {
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(DEVELOPER_DIR)/SDKs/MacOSX10.5.sdk/System/Library/Frameworks\"",
);
GCC_ENABLE_OBJC_GC = required;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;

View File

@ -10,5 +10,13 @@
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
@try
{
return NSApplicationMain(argc, (const char **) argv);
}
@catch (id e)
{
NSLog(@"*** Root exception handler: %@: %@", [e name], [e reason]);
}
return -1;
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 12 KiB