diff --git a/.gitignore b/.gitignore index 5cfbb4d84..5f09485ed 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ Demos ./Aristo WebSite .push-package +*.xcodeproj/*.pbxuser +*.xcodeproj/*.perspectivev3 +xcuserdata/ +!*.xcodeproj/project.pbxproj diff --git a/CommonJS/lib/cappuccino/fontinfo.j b/CommonJS/lib/cappuccino/fontinfo.j new file mode 100644 index 000000000..2b7b8d9ba --- /dev/null +++ b/CommonJS/lib/cappuccino/fontinfo.j @@ -0,0 +1,12 @@ + +var OS = require("os"); + +exports.fontinfo = function(name, size) +{ + var p = OS.popen(["fontinfo", "-n", name, size || 12]); + + if (p.wait() === 0) + return JSON.parse(p.stdout.read()); + else + return null; +} diff --git a/Tools/Jakefile b/Tools/Jakefile index e9e0f5fc9..e468d8c69 100644 --- a/Tools/Jakefile +++ b/Tools/Jakefile @@ -1,5 +1,7 @@ require("../common.jake"); -// nib2cib has to come before capp since capp uses nib2cib -subtasks(["nib2cib", "capp", "NativeHost"], ["build"/*, "clean", "clobber"*/]); +// nib2cib uses fontinfo and capp uses nib2cib +subtasks(["fontinfo", "nib2cib", "capp", "NativeHost"], ["build"/*, "clean", "clobber"*/]); + +subtasks(["fontinfo"], ["clean", "clobber"]); diff --git a/Tools/fontinfo/.gitignore b/Tools/fontinfo/.gitignore new file mode 100644 index 000000000..567609b12 --- /dev/null +++ b/Tools/fontinfo/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/Tools/fontinfo/Jakefile b/Tools/fontinfo/Jakefile new file mode 100644 index 000000000..e00299e34 --- /dev/null +++ b/Tools/fontinfo/Jakefile @@ -0,0 +1,45 @@ + +require ("../../common.jake"); + +var OS = require("os"), + task = require("jake").task; + +task ("build", function() +{ + if (executableExists("xcodebuild")) + { + var args = "-alltargets -configuration Release"; + + if (FILE.exists(FILE.join("/", "Developer", "SDKs", "MacOSX10.5.sdk"))) + args = "-sdk macosx10.5 " + args; + + else + args = "-sdk macosx " + args; + + if (OS.system("xcodebuild " + args)) + OS.exit(1); + + var binPath = FILE.join($BUILD_CJS_CAPPUCCINO_BIN, "fontinfo"); + + FILE.copy(FILE.join("build", "Release", "fontinfo"), binPath); + FILE.chmod(binPath, 0755); + } + else + { + print("Building fontinfo requires Xcode."); + } +}); + +task ("clean", function() +{ + if (OS.system("xcodebuild clean")) + OS.exit(1); +}); + +task ("clobber", function() +{ + if (OS.system("xcodebuild clean")) + OS.exit(1); +}); + +task ("default", ["build"]); diff --git a/Tools/fontinfo/README b/Tools/fontinfo/README new file mode 100644 index 000000000..1850c27d2 --- /dev/null +++ b/Tools/fontinfo/README @@ -0,0 +1,47 @@ +NAME + fontinfo -- retrieve information about a font + +SYNOPSIS + fontinfo [-n] font [size] + +DESCRIPTION + fontinfo is a tiny utility that returns information about a font. + The font name must be a full PostScript name, not a display name. So you would use something + like "LucidaGrande-Bold", not "Lucida Grande Bold". The size can be any floating point number + greater than zero. If no size is given, it defaults to 12. + + If the -n option is passed, the output will not be terminated with a linefeed. + +EXIT STATUS + fontinfo exits with a return status of zero if there are no errors. + fontinfo exits with a return status of 1 if any arguments are invalid, or a status of 2 if the font + cannot be found. + +OUTPUT + fontinfo outputs a stringified JSON object with the following structure: + + { + familyName: , + bold: , + italic: , + ascender: , + descender: , + line-height: + } + + If -n is not passed, the JSON is terminated with a linefeed. The fields of the object are as follows: + + familyName: The display name of the font's family + bold: Whether the font's stylistic traits are considered bold + italic: Whether the font's stylistic traits are considered italic + ascender: The offset from the baseline in points (not pixels!) of the longest ascender of the given font at + the given size. + descender: The negative offset from the baseline in points (not pixels!) + of the longest descender of the given font at the given size. + lineHeight: The height in points (not pixels!) of the largest glyph in the given font at the given size. + Note that glyphs include diacritical marks that may appear above and below the largest ascender + and descender, so the line height will almost always be greater than ascender + descender. + +AUTHORS + Aparajita Fishman, Victory-Heart Productions + http://www.aparajita.com diff --git a/Tools/fontinfo/fontinfo.m b/Tools/fontinfo/fontinfo.m new file mode 100644 index 000000000..f6523d4ed --- /dev/null +++ b/Tools/fontinfo/fontinfo.m @@ -0,0 +1,94 @@ +/* + font_info + + Copyright 2010 Aparajita Fishman +*/ + +#import +#import + +enum { + kErrInvalidArguments = 1, + kErrInvalidFontName +}; + + +int main (int argc, const char * argv[]) +{ + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + int exitCode = 0; + + if (argc >= 2) + { + BOOL appendLineFeed = YES; + int nextArgument = 1; + + if (argv[1][0] == '-') + { + if (argv[1][1] == 'n') + { + appendLineFeed = NO; + ++nextArgument; + --argc; + } + else + exitCode = kErrInvalidArguments; + } + + if (exitCode == 0) + { + CGFloat fontSize = 12; + + NSString* fontName = [NSString stringWithUTF8String:argv[nextArgument++]]; + + if (argc > 2) + fontSize = atof(argv[nextArgument]); + + if (fontSize > 0.0) + { + NSFont* font = [NSFont fontWithName:fontName size:fontSize]; + + if (font) + { + NSString* familyName = [font familyName]; + NSFontDescriptor* descriptor = [font fontDescriptor]; + NSFontSymbolicTraits traits = [descriptor symbolicTraits]; + BOOL isBold = traits & NSFontBoldTrait; + BOOL isItalic = traits & NSFontItalicTrait; + CGFloat ascender = [font ascender]; + CGFloat descender = [font descender]; + NSRect box = [font boundingRectForFont]; + NSMutableString* result = [NSMutableString stringWithFormat:@"{\"familyName\": \"%@\", \"bold\": %@, \"italic\": %@, \"ascender\": %g, \"descender\": %g, \"lineHeight\": %g}", + familyName, + isBold ? @"true" : @"false", isItalic ? @"true" : @"false", + ascender, descender, box.size.height]; + + if (appendLineFeed) + [result appendString:@"\n"]; + + printf("%s", [result UTF8String]); + + [familyName release]; + [font release]; + } + else + { + exitCode = kErrInvalidFontName; + } + } + else + { + exitCode = kErrInvalidArguments; + } + + [fontName release]; + } + } + else + { + exitCode = kErrInvalidArguments; + } + + [pool drain]; + return exitCode; +} diff --git a/Tools/fontinfo/fontinfo.xcodeproj/project.pbxproj b/Tools/fontinfo/fontinfo.xcodeproj/project.pbxproj new file mode 100644 index 000000000..b5dd193cf --- /dev/null +++ b/Tools/fontinfo/fontinfo.xcodeproj/project.pbxproj @@ -0,0 +1,215 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 45; + objects = { + +/* Begin PBXBuildFile section */ + E1C392BC133D513B0092D7CA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E1C392BB133D513B0092D7CA /* Cocoa.framework */; }; + E1D3CFAA12AFFB7F00CBB79E /* fontinfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* fontinfo.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 08FB7796FE84155DC02AAC07 /* fontinfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = fontinfo.m; sourceTree = ""; }; + 08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; + 32A70AAB03705E1F00C91783 /* fontinfo_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fontinfo_Prefix.pch; sourceTree = ""; }; + E11C89CC1277CECE0012609B /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; + E18587D81279B93100FB6A47 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = ""; }; + E1C392BB133D513B0092D7CA /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; + E1E20D0B12B09283005A6A64 /* fontinfo */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fontinfo; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E1D3CF6912AFEE3800CBB79E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + E1C392BC133D513B0092D7CA /* Cocoa.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 08FB7794FE84155DC02AAC07 /* font_info */ = { + isa = PBXGroup; + children = ( + 08FB7795FE84155DC02AAC07 /* Source */, + E18587DD1279B93600FB6A47 /* Documentation */, + 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */, + 1AB674ADFE9D54B511CA2CBB /* Products */, + ); + name = font_info; + sourceTree = ""; + }; + 08FB7795FE84155DC02AAC07 /* Source */ = { + isa = PBXGroup; + children = ( + 32A70AAB03705E1F00C91783 /* fontinfo_Prefix.pch */, + 08FB7796FE84155DC02AAC07 /* fontinfo.m */, + ); + name = Source; + sourceTree = ""; + }; + 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = { + isa = PBXGroup; + children = ( + 08FB779EFE84155DC02AAC07 /* Foundation.framework */, + E11C89CC1277CECE0012609B /* AppKit.framework */, + E1C392BB133D513B0092D7CA /* Cocoa.framework */, + ); + name = "External Frameworks and Libraries"; + sourceTree = ""; + }; + 1AB674ADFE9D54B511CA2CBB /* Products */ = { + isa = PBXGroup; + children = ( + E1E20D0B12B09283005A6A64 /* fontinfo */, + ); + name = Products; + sourceTree = ""; + }; + E18587DD1279B93600FB6A47 /* Documentation */ = { + isa = PBXGroup; + children = ( + E18587D81279B93100FB6A47 /* README */, + ); + name = Documentation; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E1D3CF6A12AFEE3800CBB79E /* fontinfo */ = { + isa = PBXNativeTarget; + buildConfigurationList = E1D3CF6F12AFEE3B00CBB79E /* Build configuration list for PBXNativeTarget "fontinfo" */; + buildPhases = ( + E1D3CF6812AFEE3800CBB79E /* Sources */, + E1D3CF6912AFEE3800CBB79E /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = fontinfo; + productName = font_info; + productReference = E1E20D0B12B09283005A6A64 /* fontinfo */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 08FB7793FE84155DC02AAC07 /* Project object */ = { + isa = PBXProject; + buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "fontinfo" */; + compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; + hasScannedForEncodings = 1; + knownRegions = ( + English, + Japanese, + French, + German, + ); + mainGroup = 08FB7794FE84155DC02AAC07 /* font_info */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + E1D3CF6A12AFEE3800CBB79E /* fontinfo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + E1D3CF6812AFEE3800CBB79E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E1D3CFAA12AFFB7F00CBB79E /* fontinfo.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 1DEB927908733DD40010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(NATIVE_ARCH_ACTUAL)"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = fontinfo_Prefix.pch; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = fontinfo; + SDKROOT = macosx10.5; + }; + name = Debug; + }; + 1DEB927A08733DD40010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(NATIVE_ARCH_ACTUAL)"; + DEPLOYMENT_LOCATION = NO; + DEPLOYMENT_POSTPROCESSING = NO; + DSTROOT = "/tmp/$(PROJECT_NAME).dst"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INSTALL_PATH = ""; + ONLY_ACTIVE_ARCH = NO; + PREBINDING = NO; + PRODUCT_NAME = fontinfo; + SDKROOT = macosx10.5; + }; + name = Release; + }; + E1D3CF6D12AFEE3900CBB79E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + E1D3CF6E12AFEE3900CBB79E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + MACOSX_DEPLOYMENT_TARGET = 10.5; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "fontinfo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB927908733DD40010E9CD /* Debug */, + 1DEB927A08733DD40010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E1D3CF6F12AFEE3B00CBB79E /* Build configuration list for PBXNativeTarget "fontinfo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E1D3CF6D12AFEE3900CBB79E /* Debug */, + E1D3CF6E12AFEE3900CBB79E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 08FB7793FE84155DC02AAC07 /* Project object */; +} diff --git a/Tools/fontinfo/fontinfo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tools/fontinfo/fontinfo.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..a3fe95833 --- /dev/null +++ b/Tools/fontinfo/fontinfo.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Tools/fontinfo/fontinfo_Prefix.pch b/Tools/fontinfo/fontinfo_Prefix.pch new file mode 100644 index 000000000..8a571c50e --- /dev/null +++ b/Tools/fontinfo/fontinfo_Prefix.pch @@ -0,0 +1,8 @@ +// +// Prefix header for all source files of the 'font_info' target in the 'font_info' project. +// + +#ifdef __OBJC__ + #import + #import +#endif diff --git a/Tools/nib2cib/NSFont.j b/Tools/nib2cib/NSFont.j index 93433eecf..cb26ca353 100644 --- a/Tools/nib2cib/NSFont.j +++ b/Tools/nib2cib/NSFont.j @@ -23,7 +23,7 @@ @import var OS = require("os"), - fontinfo = require("fontinfo").fontinfo; + fontinfo = require("cappuccino/fontinfo").fontinfo; var IBDefaultFontFace = @"Lucida Grande", IBDefaultFontSize = 13.0;