--- /dev/null
+/*
+ * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <WebCore+SVG/DrawDocumentPrivate.h>
+#import <WebCore+SVG/DrawView.h>
+
+extern const double svg2pngVersionNumber;
+extern const unsigned char svg2pngVersionString[];
+
+void usage(const char *name)
+{
+ printf("Usage: %s [options] file[s]\n", name);
+ printf("Options:\n");
+ printf(" --version\t\t\tPrints full version (%.1f) information and exits.\n", svg2pngVersionNumber);
+ printf(" --output <outputfile> dump a png copy of a single svg input file to the named path\n");
+ printf(" --suffix <suffix> append <suffix> to each output file e.g. <inputname><suffix>.png\n");
+ printf("When --output is not specified, output files are created in the same directory\n");
+ printf("as the original source files e.g. <source directory>/<filename><suffix>.png");
+ exit(1);
+};
+
+void outputPNG(NSString *svgPath, NSString *pngPath)
+{
+ // load the given document
+ DrawDocument *document = [[DrawDocument alloc] initWithContentsOfFile:svgPath];
+
+ // create a view
+ DrawView *view = [[DrawView alloc] initWithFrame:NSZeroRect]; // could be static...
+ [view setDocument:document];
+ [view sizeToFitViewBox];
+
+ // My maximum 500x500 size hack:
+ NSSize boundsSize = [view bounds].size;
+ if (boundsSize.width > 500)
+ boundsSize.width = 500;
+ if (boundsSize.height > 500)
+ boundsSize.height = 500;
+ [view setFrameSize:boundsSize];
+
+ // tell that view to render
+ NSBitmapImageRep *imageRep = [view bitmapImageRepForCachingDisplayInRect:[view bounds]];
+ [view cacheDisplayInRect:[view bounds] toBitmapImageRep:imageRep];
+
+ // output the resulting image
+ NSData *pngData = [imageRep representationUsingType:NSPNGFileType properties:nil];
+ [pngData writeToFile:svgPath atomically:YES];
+
+ [view release]; // should be singleton.
+ [document release];
+}
+
+int main (int argc, const char *argv[])
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ // deal with args
+ NSMutableArray *svgs = [NSMutableArray array];
+ const char *name = [[[NSString stringWithUTF8String:argv[0]] lastPathComponent] UTF8String];
+ NSString *explicitOutputPath = nil;
+ NSString *outputSuffix = nil;
+
+ for(int x = 1; x < argc; x++) {
+ const char *arg = argv[x];
+ NSString *argString = [NSString stringWithUTF8String:arg];
+
+ if ([argString hasPrefix:@"--"]) { // this is an option
+ if ([argString isEqualToString:@"--help"])
+ usage(name);
+ else if ([argString isEqualToString:@"--version"]) {
+ printf((char *)svg2pngVersionString);
+ exit(0);
+ } else if ([argString isEqualToString:@"--output"]) {
+ if (x + 1 < argc) {
+ explicitOutputPath = [NSString stringWithUTF8String:argv[x+1]];
+ if ([explicitOutputPath hasPrefix:@"--"])
+ NSLog(@"WARNING: did you really mean to output to: %@ Or did you just forget the --output <filename> argument?", explicitOutputPath);
+ x++; // to skip the next arg
+ } else {
+ NSLog(@"--output requires an argument.");
+ usage(name);
+ }
+ } else if ([argString isEqualToString:@"--suffix"]) {
+ if (x + 1 < argc) {
+ outputSuffix = [NSString stringWithUTF8String:argv[x+1]];
+ x++; // to skip the next arg
+ } else {
+ NSLog(@"--suffix requires an argument.");
+ usage(name);
+ }
+ } else {
+ printf("Unrecognized option %@\n", argString);
+ usage(name);
+ }
+ } else {
+ if (![[NSFileManager defaultManager] fileExistsAtPath:[argString stringByStandardizingPath]]) {
+ printf("SVG does not exist at path: %@\n", argString);
+ exit(1);
+ }
+ [svgs addObject:argString];
+ }
+ }
+
+ if (![svgs count]) {
+ printf("No svgs specified.\n");
+ usage(name);
+ }
+
+ if ( ([svgs count] > 1) && explicitOutputPath) {
+ printf("--output name specifed, yet more than one input file was given!\n\n");
+ usage(name);
+ }
+
+ NSString *svgPath = nil;
+ foreacharray(svgPath, svgs) {
+ NSString *pngPath = nil;
+ if (explicitOutputPath)
+ pngPath = explicitOutputPath;
+ else {
+ pngPath = [svgPath stringByDeletingPathExtension];
+ if (outputSuffix)
+ pngPath = [pngPath stringByAppendingString:outputSuffix];
+ pngPath = [pngPath stringByAppendingPathExtension:@"png"];
+ }
+ outputPNG(svgPath, pngPath);
+ }
+
+ [pool drain];
+
+ return 0;
+}
+
+
--- /dev/null
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 42;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 8DD76F9A0486AA7600D96B5E /* svg2png.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* svg2png.m */; settings = {ATTRIBUTES = (); }; };
+ 8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
+ A898F79508824B4A0075EFB2 /* WebCore+SVG.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A898F79408824B4A0075EFB2 /* WebCore+SVG.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXBuildStyle section */
+ 014CEA4F0018CE4811CA2923 /* Development */ = {
+ isa = PBXBuildStyle;
+ buildSettings = {
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 014CEA500018CE4811CA2923 /* Deployment */ = {
+ isa = PBXBuildStyle;
+ buildSettings = {
+ COPY_PHASE_STRIP = YES;
+ GCC_ENABLE_FIX_AND_CONTINUE = NO;
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+/* End PBXBuildStyle section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ 8DD76F9E0486AA7600D96B5E /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 8;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ 08FB7796FE84155DC02AAC07 /* svg2png.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = svg2png.m; sourceTree = "<group>"; };
+ 08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
+ 32A70AAB03705E1F00C91783 /* svg2png_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = svg2png_Prefix.pch; sourceTree = "<group>"; };
+ 8DD76FA10486AA7600D96B5E /* svg2png */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = svg2png; sourceTree = BUILT_PRODUCTS_DIR; };
+ A898F79408824B4A0075EFB2 /* WebCore+SVG.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = "WebCore+SVG.framework"; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 8DD76F9B0486AA7600D96B5E /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */,
+ A898F79508824B4A0075EFB2 /* WebCore+SVG.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 08FB7794FE84155DC02AAC07 /* svg2png */ = {
+ isa = PBXGroup;
+ children = (
+ 08FB7795FE84155DC02AAC07 /* Source */,
+ 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
+ 1AB674ADFE9D54B511CA2CBB /* Products */,
+ );
+ name = svg2png;
+ sourceTree = "<group>";
+ };
+ 08FB7795FE84155DC02AAC07 /* Source */ = {
+ isa = PBXGroup;
+ children = (
+ 32A70AAB03705E1F00C91783 /* svg2png_Prefix.pch */,
+ 08FB7796FE84155DC02AAC07 /* svg2png.m */,
+ );
+ name = Source;
+ sourceTree = "<group>";
+ };
+ 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = {
+ isa = PBXGroup;
+ children = (
+ A898F79408824B4A0075EFB2 /* WebCore+SVG.framework */,
+ 08FB779EFE84155DC02AAC07 /* Foundation.framework */,
+ );
+ name = "External Frameworks and Libraries";
+ sourceTree = "<group>";
+ };
+ 1AB674ADFE9D54B511CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 8DD76FA10486AA7600D96B5E /* svg2png */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 8DD76F960486AA7600D96B5E /* svg2png */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = A8C006250897569A00BA5114 /* Build configuration list for PBXNativeTarget "svg2png" */;
+ buildPhases = (
+ 8DD76F990486AA7600D96B5E /* Sources */,
+ 8DD76F9B0486AA7600D96B5E /* Frameworks */,
+ 8DD76F9E0486AA7600D96B5E /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ buildSettings = {
+ GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = svg2png_Prefix.pch;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ INSTALL_PATH = "$(HOME)/bin";
+ PREBINDING = NO;
+ PRODUCT_NAME = svg2png;
+ VERSIONING_SYSTEM = "apple-generic";
+ };
+ dependencies = (
+ );
+ name = svg2png;
+ productInstallPath = "$(HOME)/bin";
+ productName = svg2png;
+ productReference = 8DD76FA10486AA7600D96B5E /* svg2png */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 08FB7793FE84155DC02AAC07 /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = A8C006290897569A00BA5114 /* Build configuration list for PBXProject "svg2png" */;
+ buildSettings = {
+ };
+ buildStyles = (
+ 014CEA4F0018CE4811CA2923 /* Development */,
+ 014CEA500018CE4811CA2923 /* Deployment */,
+ );
+ hasScannedForEncodings = 1;
+ mainGroup = 08FB7794FE84155DC02AAC07 /* svg2png */;
+ projectDirPath = "";
+ targets = (
+ 8DD76F960486AA7600D96B5E /* svg2png */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 8DD76F990486AA7600D96B5E /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8DD76F9A0486AA7600D96B5E /* svg2png.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ A8C006260897569A00BA5114 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = svg2png_Prefix.pch;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ INSTALL_PATH = "$(HOME)/bin";
+ PREBINDING = NO;
+ PRODUCT_NAME = svg2png;
+ VERSIONING_SYSTEM = "apple-generic";
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ A8C006270897569A00BA5114 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COPY_PHASE_STRIP = YES;
+ GCC_ENABLE_FIX_AND_CONTINUE = NO;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = svg2png_Prefix.pch;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ INSTALL_PATH = "$(HOME)/bin";
+ PREBINDING = NO;
+ PRODUCT_NAME = svg2png;
+ VERSIONING_SYSTEM = "apple-generic";
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+ A8C006280897569A00BA5114 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = svg2png_Prefix.pch;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ INSTALL_PATH = "$(HOME)/bin";
+ PREBINDING = NO;
+ PRODUCT_NAME = svg2png;
+ VERSIONING_SYSTEM = "apple-generic";
+ };
+ name = Default;
+ };
+ A8C0062A0897569A00BA5114 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ VERSIONING_SYSTEM = "apple-generic";
+ };
+ name = Development;
+ };
+ A8C0062B0897569A00BA5114 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ VERSIONING_SYSTEM = "apple-generic";
+ };
+ name = Deployment;
+ };
+ A8C0062C0897569A00BA5114 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ VERSIONING_SYSTEM = "apple-generic";
+ };
+ name = Default;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ A8C006250897569A00BA5114 /* Build configuration list for PBXNativeTarget "svg2png" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ A8C006260897569A00BA5114 /* Development */,
+ A8C006270897569A00BA5114 /* Deployment */,
+ A8C006280897569A00BA5114 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+ A8C006290897569A00BA5114 /* Build configuration list for PBXProject "svg2png" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ A8C0062A0897569A00BA5114 /* Development */,
+ A8C0062B0897569A00BA5114 /* Deployment */,
+ A8C0062C0897569A00BA5114 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
+}
--- /dev/null
+/*
+ * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+//
+// Prefix header for all source files of the 'svg2png' target in the 'svg2png' project.
+//
+
+#ifdef __OBJC__
+#import <Foundation/Foundation.h>
+
+#define foreacharray(__variable, __container) \
+ for (int __variable##__i=0, __variable##__n=[__container count]; \
+ __variable##__i < __variable##__n && (__variable = [__container objectAtIndex:__variable##__i]); \
+ ++__variable##__i)
+#endif