[xiph-commits] r15312 - in trunk: . pngxpdf

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Mon Sep 15 22:21:16 PDT 2008


Author: xiphmont
Date: 2008-09-15 22:21:15 -0700 (Mon, 15 Sep 2008)
New Revision: 15312

Added:
   trunk/pngxpdf/
   trunk/pngxpdf/Makefile
   trunk/pngxpdf/main.c
   trunk/pngxpdf/main.d
   trunk/pngxpdf/pngxpdf
   trunk/pngxpdf/test.pdf
Log:
Cute little app for making many PNGs into a multipage PDF.  Yes, been done many times but 
usually for some other purpose.



Added: trunk/pngxpdf/Makefile
===================================================================
--- trunk/pngxpdf/Makefile	                        (rev 0)
+++ trunk/pngxpdf/Makefile	2008-09-16 05:21:15 UTC (rev 15312)
@@ -0,0 +1,66 @@
+# Fuck Automake
+# Fuck the horse it rode in on
+# and Fuck its little dog Libtool too
+
+PREFIX    = /usr/local
+NAME      = pngxpdf
+MAJOR     = 0
+MINOR     = 0
+SUBMINOR  = 0
+
+CC        = gcc 
+LD        = gcc
+INSTALL   = install
+STRIP     = strip
+LDCONFIG  = /sbin/ldconfig
+
+VERSION   = $(MAJOR).$(MINOR).$(SUBMINOR)
+TARGET    = $(NAME)
+BINDIR    = $(PREFIX)/bin
+INCDIR    = $(PREFIX)/include
+LIBDIR    = $(PREFIX)/lib
+MANDIR    = $(PREFIX)/man
+
+SRC       = main.c
+MAN	  =
+OBJ       = main.o
+CAIROVER  =  >= 1.4.1
+PKGARG	  = "cairo $(CAIROVER) cairo-ft $(CAIROVER) "
+GCF       = -std=gnu99 `pkg-config --cflags $(PKGARG)` -DVERSION="\"$(VERSION)\""
+LDF       = -L/lib `pkg-config --libs $(PKGARG)`
+
+all:    
+	pkg-config --cflags $(PKGARG) 1>/dev/null
+	$(MAKE) target CFLAGS='-O2 -g $(GCF) '
+
+debug:
+	pkg-config --cflags $(PKGARG) 1>/dev/null
+	$(MAKE) target CFLAGS='-g -Wall -W -Wno-unused-parameter -D__NO_MATH_INLINES $(GCF) '
+
+profile:
+	pkg-config --cflags $(PKGARG) 1>/dev/null
+	$(MAKE) target CFLAGS='-g -pg -O2 $(GCF) '
+
+clean:
+	rm -f *.o *.d *.d.* *.pc gmon.out $(TARGET)
+
+distclean: clean
+	rm -f core core.* *~ 
+
+%.d: %.c
+	$(CC) -M $(CFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm -f $@.$$$$
+
+ifeq ($(MAKECMDGOALS),target)
+include $(SRC:.c=.d)
+endif
+
+target:  $(OBJ) 
+	$(LD) $(OBJ) $(CFLAGS) -o $(TARGET) $(LIBS) $(LDF)
+
+$(TARGET): all
+
+install: $(TARGET)
+#	$(INSTALL) -d -m 0755 $(MANDIR)
+#	$(INSTALL) -m 0644 $(MAN) $(MANDIR)
+	$(INSTALL) -d -m 0755 $(BINDIR)
+	$(INSTALL) -m 0755 $(TARGET) $(BINDIR)

Added: trunk/pngxpdf/main.c
===================================================================
--- trunk/pngxpdf/main.c	                        (rev 0)
+++ trunk/pngxpdf/main.c	2008-09-16 05:21:15 UTC (rev 15312)
@@ -0,0 +1,184 @@
+/*
+ *
+ *     pngxpdf copyright (C) 2008 Monty <monty at xiph.org>
+ *
+ *  pngxpdf is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *   
+ *  pngxpdf is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *   
+ *  You should have received a copy of the GNU General Public License
+ *  along with pngxpdf; see the file COPYING.  If not, write to the
+ *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * 
+ */
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <cairo.h>
+#include <cairo-ft.h>
+#include <cairo-pdf.h>
+
+const char *optstring = "w:h:d:t:mhv";
+
+struct option options [] = {
+  {"width",required_argument,NULL,'W'},
+  {"height",required_argument,NULL,'H'},
+  {"resolution",required_argument,NULL,'r'},
+  {"text",required_argument,NULL,'t'},
+  {"help",no_argument,NULL,'h'},
+  {"version",no_argument,NULL,'v'},
+
+  {NULL,0,NULL,0}
+};
+
+cairo_status_t pdf_write(void *closure,
+			 const unsigned char *data,
+			 unsigned int length){
+  if(fwrite(data, 1, length, stdout)<length)
+    return CAIRO_STATUS_WRITE_ERROR;
+  return CAIRO_STATUS_SUCCESS;
+}
+
+void usage(FILE *f){
+  fprintf(f,"pngxpdf "VERSION"\n"
+	  "(C) 2008 Monty <monty at xiph.org>\n\n"
+	  "USAGE:\n\n"
+	  "  pnxpdf [options] file1.png [file2.png...] > output.pdf\n\n"
+	  "OPTIONS:\n\n"
+	  "  -h --help           : Display this usage information\n\n"
+	  "  -H --height <n>     : Height of each output page; suffix with mm, cm,\n"
+	  "                        in or pt to use various units. default is 11.0in\n\n"
+	  "  -r --resolution <n> : Specify input resolution of each image.  Each\n"
+	  "                        image is centered on the page and either cropped\n"
+	  "                        to fit or placed within a border.  Suffix with\n"
+	  "                        dpi, dpcm, dpmm, or dpp to specify different\n"
+	  "                        units.  150dpi default.\n\n"
+	  "  -t --text <string>  : string comment to add as a footer to each page\n\n"
+	  "  -v --version        : Output version string and exit\n\n"
+	  "  -W --width <n>      : Width of each output page; suffix with mm, cm,\n"
+	  "                        in or pt to use various units. default is 8.5in\n\n");
+}
+
+int main(int argc, char **argv){
+  float width=8.5*72.0;
+  float height=11.0*72.0;
+  float dpp=300.0/72.0;
+  char *text=NULL;
+
+  int c,long_option_index;
+
+  cairo_surface_t *cs;
+  cairo_t *ct;
+  cairo_text_extents_t extents;
+
+  while((c=getopt_long(argc,argv,optstring,options,&long_option_index))!=EOF){
+    switch(c){
+    case 'W':
+    case 'H':
+      {
+	float temp;
+	if(strstr(optarg,"cm")){
+	  temp=atof(optarg)*28.3464566929;
+	}else if (strstr(optarg,"mm")){
+	  temp=atof(optarg)*2.83464566929;
+	}else if (strstr(optarg,"pt")){
+	  temp=atof(optarg);
+	}else{
+	  temp=atof(optarg)*72.0;
+	}
+	if(c=='W'){
+	  width=temp;
+	}else{
+	  height=temp;
+	}
+      }
+      break;
+    case 'r':
+      if(strstr(optarg,"dpcm")){
+	dpp=atof(optarg)*.03527777777778;
+      }else if (strstr(optarg,"dpmm")){
+	dpp=atof(optarg)*.35277777777778;
+      }else if (strstr(optarg,"dpp")){
+	dpp=atof(optarg);
+      }else{
+	dpp=atof(optarg)*.01388888888889;
+      }
+      break;
+    case 't':
+      text=strdup(optarg);
+      break;
+    case 'h':
+      usage(stdout);
+      exit(0);
+    case 'v':
+      fprintf(stderr,"pngxpdf "VERSION"\n");
+    default:
+      usage(stderr);
+    }
+  }
+
+  /* set up our surface */
+  cs = cairo_pdf_surface_create_for_stream (pdf_write, NULL, width, height);
+  if(!cs || cairo_surface_status(cs)!=CAIRO_STATUS_SUCCESS){
+    fprintf(stderr,"CAIRO ERROR: Unable to create PDF surface.\n\n");
+    exit(1);
+  }
+  ct = cairo_create(cs);
+  cairo_set_font_size(ct, height*15./792);
+  if(text)
+    cairo_text_extents(ct, text, &extents);
+
+  /* Iterate through PNG files inline */
+  while(optind<argc){
+    int ww, hh;
+    char *filename = argv[optind];
+    cairo_pattern_t *pattern;
+    cairo_surface_t *ps=cairo_image_surface_create_from_png(filename);
+    if(!ps || cairo_surface_status(ps)!=CAIRO_STATUS_SUCCESS){
+      fprintf(stderr,"CAIRO ERROR: Unable to load PNG file %s.\n\n",filename);
+      exit(1);
+    }
+    ww = cairo_image_surface_get_width(ps);
+    hh = cairo_image_surface_get_height(ps);
+
+    cairo_save(ct);
+    cairo_scale(ct, 1./dpp, 1./dpp);
+    pattern = cairo_pattern_create_for_surface(ps);
+    if(text)
+      cairo_translate(ct,(width*dpp - ww)*.5,((height-extents.height-36)*dpp - hh)*.5);
+    else
+      cairo_translate(ct,(width*dpp - ww)*.5,(height*dpp - hh)*.5);
+    cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST);
+    cairo_set_source(ct,pattern);
+    cairo_paint(ct);
+    cairo_restore(ct);
+
+    /* draw comment text */
+    if(text){
+      cairo_set_source_rgb(ct, 0,0,0);
+      cairo_move_to(ct, width-extents.width-36, height-36);
+      cairo_show_text(ct, text);  
+    }
+
+
+    cairo_surface_show_page(cs);
+
+
+    cairo_surface_destroy(ps);
+    optind++;
+  }
+
+  cairo_destroy(ct);
+  cairo_surface_destroy(cs);
+}

Added: trunk/pngxpdf/main.d
===================================================================
--- trunk/pngxpdf/main.d	                        (rev 0)
+++ trunk/pngxpdf/main.d	2008-09-16 05:21:15 UTC (rev 15312)
@@ -0,0 +1,40 @@
+main.o main.d : main.c /usr/include/string.h /usr/include/features.h \
+  /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
+  /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \
+  /usr/lib/gcc/x86_64-linux-gnu/4.3.1/include/stddef.h \
+  /usr/include/xlocale.h /usr/include/stdio.h /usr/include/bits/types.h \
+  /usr/include/bits/typesizes.h /usr/include/libio.h \
+  /usr/include/_G_config.h /usr/include/wchar.h \
+  /usr/lib/gcc/x86_64-linux-gnu/4.3.1/include/stdarg.h \
+  /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
+  /usr/include/stdlib.h /usr/include/bits/waitflags.h \
+  /usr/include/bits/waitstatus.h /usr/include/endian.h \
+  /usr/include/bits/endian.h /usr/include/sys/types.h /usr/include/time.h \
+  /usr/include/sys/select.h /usr/include/bits/select.h \
+  /usr/include/bits/sigset.h /usr/include/bits/time.h \
+  /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \
+  /usr/include/alloca.h /usr/include/unistd.h \
+  /usr/include/bits/posix_opt.h /usr/include/bits/environments.h \
+  /usr/include/bits/confname.h /usr/include/getopt.h \
+  /usr/include/cairo/cairo.h /usr/include/cairo/cairo-features.h \
+  /usr/include/cairo/cairo-deprecated.h /usr/include/cairo/cairo-ft.h \
+  /usr/include/fontconfig/fontconfig.h /usr/include/sys/stat.h \
+  /usr/include/bits/stat.h /usr/include/ft2build.h \
+  /usr/include/freetype2/freetype/config/ftheader.h \
+  /usr/include/freetype2/freetype/freetype.h \
+  /usr/include/freetype2/freetype/config/ftconfig.h \
+  /usr/include/freetype2/freetype/config/ftoption.h \
+  /usr/include/freetype2/freetype/config/ftstdlib.h \
+  /usr/lib/gcc/x86_64-linux-gnu/4.3.1/include-fixed/limits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/4.3.1/include-fixed/syslimits.h \
+  /usr/include/limits.h /usr/include/bits/posix1_lim.h \
+  /usr/include/bits/local_lim.h /usr/include/linux/limits.h \
+  /usr/include/bits/posix2_lim.h /usr/include/bits/xopen_lim.h \
+  /usr/include/setjmp.h /usr/include/bits/setjmp.h \
+  /usr/include/freetype2/freetype/fterrors.h \
+  /usr/include/freetype2/freetype/ftmoderr.h \
+  /usr/include/freetype2/freetype/fterrdef.h \
+  /usr/include/freetype2/freetype/fttypes.h \
+  /usr/include/freetype2/freetype/ftsystem.h \
+  /usr/include/freetype2/freetype/ftimage.h \
+  /usr/include/cairo/cairo-pdf.h

Added: trunk/pngxpdf/pngxpdf
===================================================================
(Binary files differ)


Property changes on: trunk/pngxpdf/pngxpdf
___________________________________________________________________
Name: svn:executable
   + 
Name: svn:mime-type
   + application/octet-stream

Added: trunk/pngxpdf/test.pdf
===================================================================
(Binary files differ)


Property changes on: trunk/pngxpdf/test.pdf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the commits mailing list