From 94ee852cfe2489187402faac689b8f8930a4ac3d Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Fri, 23 Jul 2010 17:56:21 -0400 Subject: [PATCH] Implemented method of setting the default system font face. See http://groups.google.com/group/objectivej/browse_thread/thread/64f6a42d74d68386 --- AppKit/CPFont.j | 17 +++++++++++++++++ Tools/nib2cib/Converter.j | 12 ++++++++++++ Tools/nib2cib/NSFont.j | 8 +++++--- Tools/nib2cib/main.j | 24 ++++++++++++++++++------ 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/AppKit/CPFont.j b/AppKit/CPFont.j index 4f5e5f3a4..fbdf5cdd1 100644 --- a/AppKit/CPFont.j +++ b/AppKit/CPFont.j @@ -43,6 +43,14 @@ var _CPFonts = {}, CPString _cssString; } ++ (void)initialize +{ + var systemFont = [[CPBundle mainBundle] objectForInfoDictionaryKey:"CPSystemFontFace"]; + + if (systemFont) + _CPFontSystemFontFace = systemFont; +} + /*! Returns a font with the specified name and size. @param aName the name of the font @@ -65,6 +73,15 @@ var _CPFonts = {}, return _CPCachedFont(aName, aSize, YES) || [[CPFont alloc] _initWithName:aName size:aSize bold:YES]; } +/*! + Returns the name of the system font + @return the configured system font +*/ ++ (CPString)systemFontFace +{ + return _CPFontSystemFontFace; +} + /*! Returns the system font scaled to the specified size @param aSize the size of the font (in points) diff --git a/Tools/nib2cib/Converter.j b/Tools/nib2cib/Converter.j index 88175bb48..e4159e05c 100644 --- a/Tools/nib2cib/Converter.j +++ b/Tools/nib2cib/Converter.j @@ -33,12 +33,24 @@ NibFormatIPhone = 2; ConverterConversionException = @"ConverterConversionException"; +SharedConverterInstance = nil; + + @implementation Converter : CPObject { NibFormat format @accessors; CPString inputPath @accessors; CPString outputPath @accessors; CPString resourcesPath @accessors; + CPString systemFontFace @accessors; +} + ++ (Converter)sharedConverterInstance +{ + if (!SharedConverterInstance) + SharedConverterInstance = [[Converter alloc] init]; + + return SharedConverterInstance; } - (id)init diff --git a/Tools/nib2cib/NSFont.j b/Tools/nib2cib/NSFont.j index 41643eb22..1dc84d3b3 100644 --- a/Tools/nib2cib/NSFont.j +++ b/Tools/nib2cib/NSFont.j @@ -22,6 +22,8 @@ @import +@import "Converter.j" + @implementation CPFont (NSCoding) @@ -37,12 +39,12 @@ return nil; } - // FIXME: Is this alwasy true? + // FIXME: Is this always true? if (fontName.indexOf("-Bold") === fontName.length - "-Bold".length) isBold = YES; - + if (fontName === "LucidaGrande" || fontName === "LucidaGrande-Bold") - fontName = "Arial"; + fontName = [[Converter sharedConverterInstance] systemFontFace]; return [self _initWithName:fontName size:size bold:isBold]; } diff --git a/Tools/nib2cib/main.j b/Tools/nib2cib/main.j index ccb1a9f29..cf93e8b68 100644 --- a/Tools/nib2cib/main.j +++ b/Tools/nib2cib/main.j @@ -30,6 +30,8 @@ @import "Nib2CibKeyedUnarchiver.j" @import "Converter.j" +var DefaultSystemFontFace = "Arial, sans-serif"; + var FILE = require("file"); var OS = require("os"); @@ -45,6 +47,10 @@ parser.option("-R", "resources") .set() .help("Set the Resources directory"); +parser.option("--systemFontFace", "systemFontFace") + .set() + .help("Set the default system font"); + parser.option("--mac", "format") .set(NibFormatMac) .def(NibFormatUndetermined) @@ -91,6 +97,9 @@ function main(args) parser.printUsage(options); OS.exit(1); } + + if (!options.systemFontFace) + options.systemFontFace = [CPFont systemFontFace]; if (options.quiet) {} else if (options.verbose === 0) @@ -100,18 +109,21 @@ function main(args) else CPLogRegister(CPLogPrint); - CPLog.debug("Input: " + options.args[0]); - CPLog.debug("Output: " + (options.args[1]||"")); - CPLog.debug("Format: " + ["Auto","Mac","iPhone"][options.format]); - CPLog.debug("Resources: " + (options.resources||"")); - CPLog.debug("Frameworks: " + options.frameworks); + CPLog.debug("Input: " + options.args[0]); + CPLog.debug("Output: " + (options.args[1]||"")); + CPLog.debug("Format: " + ["Auto","Mac","iPhone"][options.format]); + CPLog.debug("Resources: " + (options.resources||"")); + CPLog.debug("Frameworks: " + options.frameworks); + CPLog.debug("System font: " + options.systemFontFace); - var converter = [[Converter alloc] init]; + var converter = [Converter sharedConverterInstance]; if (options.resources) [converter setResourcesPath:options.resources]; [converter setFormat:options.format]; + + [converter setSystemFontFace:options.systemFontFace]; [converter setInputPath:options.args[0]];