X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=driver%2Fpdf2jpeg.m;h=166826e8122298a29dc4ca319ffdd4ba85df3ff6;hp=60778fe10c472169a07c062314ef2dbbcd9eb594;hb=de460e831dc8578acfa8b72251ab9346c99c1f96;hpb=6b1c86cf395f59389e4ece4ea8f4bea2c332745b diff --git a/driver/pdf2jpeg.m b/driver/pdf2jpeg.m index 60778fe1..166826e8 100644 --- a/driver/pdf2jpeg.m +++ b/driver/pdf2jpeg.m @@ -1,6 +1,6 @@ /* pdf2jpeg -- converts a PDF file to a JPEG file, using Cocoa * - * Copyright (c) 2003 by Jamie Zawinski + * Copyright (c) 2003, 2008 by Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -23,6 +23,7 @@ main (int argc, char** argv) const char *progname = argv[0]; const char *infile = 0, *outfile = 0; double compression = 0.85; + double scale = 1.0; int verbose = 0; int i; @@ -45,6 +46,18 @@ main (int argc, char** argv) } compression = q / 100.0; } + else if (!strcmp (argv[i], "-scale")) + { + float s; + if (1 != sscanf (argv[++i], " %f %c", &s, &c) || + s <= 0 || s > 50) + { + fprintf (stderr, "%s: scale must be 0.0 - 50.0 (%f)\n", + progname, s); + goto USAGE; + } + scale = s; + } else if (!strcmp (argv[i], "-verbose")) verbose++; else if (!strcmp (argv[i], "-v") || @@ -64,7 +77,7 @@ main (int argc, char** argv) { USAGE: fprintf (stderr, - "usage: %s [-verbose] [-quality NN] " + "usage: %s [-verbose] [-scale N] [-quality NN] " "infile.pdf outfile.jpg\n", progname); exit (1); @@ -93,11 +106,16 @@ main (int argc, char** argv) NSPDFImageRep *pdf_rep = [NSPDFImageRep imageRepWithData:pdf_data]; // Create an NSImage instance - NSImage *image = [[NSImage alloc] initWithSize:[pdf_rep size]]; + NSRect rect; + rect.size = [pdf_rep size]; + rect.size.width *= scale; + rect.size.height *= scale; + rect.origin.x = rect.origin.y = 0; + NSImage *image = [[NSImage alloc] initWithSize:rect.size]; // Draw the PDFImageRep in the NSImage [image lockFocus]; - [pdf_rep drawAtPoint:NSMakePoint(0.0,0.0)]; + [pdf_rep drawInRect:rect]; [image unlockFocus]; // Load the NSImage's contents into an NSBitmapImageRep: