top_srcdir = @top_srcdir@
include ../Makefile.common
-all: librfxswf$(A) libpdf$(A) libbase$(A) libgfx$(A) libgfxswf$(A) libocr$(A)
+all: librfxswf$(A) libgfxpdf$(A) libbase$(A) libgfx$(A) libgfxswf$(A) libocr$(A)
lame_objects = lame/psymodel.$(O) lame/fft.$(O) lame/newmdct.$(O) lame/quantize.$(O) lame/takehiro.$(O) lame/reservoir.$(O) lame/quantize_pvt.$(O) lame/vbrquantize.$(O) lame/encoder.$(O) lame/id3tag.$(O) lame/version.$(O) lame/tables.$(O) lame/util.$(O) lame/bitstream.$(O) lame/set_get.$(O) lame/VbrTag.$(O) lame/lame.$(O)
lame_in_source = @lame_in_source@
rfxswf_modules = modules/swfbits.c modules/swfaction.c modules/swfdump.c modules/swfcgi.c modules/swfbutton.c modules/swftext.c modules/swffont.c modules/swftools.c modules/swfsound.c modules/swfshape.c modules/swfobject.c modules/swfdraw.c modules/swffilter.c modules/swfrender.c h.263/swfvideo.c modules/swfalignzones.c
-base_objects=q.$(O) utf8.$(O) png.$(O) jpeg.$(O) wav.$(O) mp3.$(O) os.$(O) bitio.$(O) log.$(O) mem.$(O)
+base_objects=q.$(O) utf8.$(O) png.$(O) jpeg.$(O) wav.$(O) mp3.$(O) os.$(O) bitio.$(O) log.$(O) mem.$(O) MD5.$(O)
gfx_objects=gfxtools.$(O) gfxfont.$(O) devices/dummy.$(O) devices/file.$(O) devices/render.$(O) devices/text.$(O) devices/record.$(O) devices/ops.$(O) devices/polyops.$(O) devices/bbox.$(O) devices/rescale.$(O) @DEVICE_OPENGL@ @DEVICE_PDF@
rfxswf_objects=modules/swfaction.$(O) modules/swfbits.$(O) modules/swfbutton.$(O) modules/swfcgi.$(O) modules/swfdraw.$(O) modules/swfdump.$(O) modules/swffilter.$(O) modules/swffont.$(O) modules/swfobject.$(O) modules/swfrender.$(O) modules/swfshape.$(O) modules/swfsound.$(O) modules/swftext.$(O) modules/swftools.$(O) modules/swfalignzones.$(O)
$(C) MD5.c -o $@
log.$(O): log.c log.h
$(C) log.c -o $@
+
rfxswf.$(O): rfxswf.c rfxswf.h drawer.h bitio.h log.h MD5.h $(top_builddir)/config.h
$(C) rfxswf.c -o $@
$(AR) r libgfx$(A) $(gfx_objects) $(gfxpoly_objects)
$(RANLIB) libgfx$(A)
-librfxswf$(A): Makefile $(rfxswf_objects) rfxswf.$(O) drawer.$(O) MD5.$(O) $(lame_in_source) $(h263_objects) $(as12compiler_in_source) $(as3compiler_objects) Makefile
- $(AR) r librfxswf$(A) $(rfxswf_objects) rfxswf.$(O) drawer.$(O) MD5.$(O) $(lame_in_source) $(h263_objects) $(as12compiler_in_source) $(as3compiler_objects)
+librfxswf$(A): Makefile $(rfxswf_objects) rfxswf.$(O) drawer.$(O) $(lame_in_source) $(h263_objects) $(as12compiler_in_source) $(as3compiler_objects) Makefile
+ $(AR) r librfxswf$(A) $(rfxswf_objects) rfxswf.$(O) drawer.$(O) $(lame_in_source) $(h263_objects) $(as12compiler_in_source) $(as3compiler_objects)
$(RANLIB) librfxswf$(A)
-libpdf$(A): pdf/GFXOutputDev.cc pdf/GFXOutputDev.h pdf/pdf.cc pdf/pdf.h
- cd pdf;$(MAKE) libpdf
+libgfxpdf$(A): pdf/GFXOutputDev.cc pdf/GFXOutputDev.h pdf/pdf.cc pdf/pdf.h
+ cd pdf;$(MAKE) libgfxpdf
tests: png.test.c
$(L) png.test.c -o png.test $(LIBS)
top_srcdir = @top_srcdir@
include ../../Makefile.common
-all: ../libpdf$(A) pdf2swf$(E)
+all: ../libgfxpdf$(A) pdf2swf$(E)
-libpdf: ../libpdf$(A)
+libgfxpdf: ../libgfxpdf$(A)
-libpdf_objects = GFXOutputDev.$(O) InfoOutputDev.$(O) BitmapOutputDev.$(O) FullBitmapOutputDev.$(O) XMLOutputDev.$(O) pdf.$(O) fonts.$(O)
+libgfxpdf_objects = GFXOutputDev.$(O) InfoOutputDev.$(O) BitmapOutputDev.$(O) FullBitmapOutputDev.$(O) XMLOutputDev.$(O) pdf.$(O) fonts.$(O)
xpdf_in_source = @xpdf_in_source@
$(CC) -I ./ -I xpdf $< -o $@
-../libpdf$(A): $(XPDFOK) $(libpdf_objects) $(xpdf_in_source) $(splash_in_source)
- $(AR) r ../libpdf$(A) $(libpdf_objects) $(xpdf_in_source) $(splash_in_source)
- $(RANLIB) ../libpdf$(A)
+../libgfxpdf$(A): $(XPDFOK) $(libgfxpdf_objects) $(xpdf_in_source) $(splash_in_source)
+ $(AR) r ../libgfxpdf$(A) $(libgfxpdf_objects) $(xpdf_in_source) $(splash_in_source)
+ $(RANLIB) ../libgfxpdf$(A)
xpdfapp_sources=xpdf/XPDFApp.cc xpdf/XPDFCore.cc xpdf/XPDFTree.cc xpdf/XPDFViewer.cc xpdf/PDFCore.cc xpdf/TextOutputDev.cc xpdf/xpdf.cc xpdf/CoreOutputDev.cc xpdf/UnicodeTypeTable.cc xpdf/PSOutputDev.cc
splash_sources=xpdf/Splash.cc xpdf/SplashBitmap.cc xpdf/SplashClip.cc xpdf/SplashFTFont.cc xpdf/SplashFTFontEngine.cc xpdf/SplashFTFontFile.cc xpdf/SplashFont.cc xpdf/SplashFontEngine.cc xpdf/SplashFontFile.cc xpdf/SplashFontFileID.cc xpdf/SplashOutputDev.cc xpdf/SplashPath.cc xpdf/SplashPattern.cc xpdf/SplashScreen.cc xpdf/SplashState.cc xpdf/SplashT1Font.cc xpdf/SplashT1FontEngine.cc xpdf/SplashT1FontFile.cc xpdf/SplashXPath.cc xpdf/SplashXPathScanner.cc
gfx_objects = ../libgfxswf$(A) ../libgfx$(A) ../librfxswf$(A) ../libbase$(A)
gfx_objects2 = $(gfx_objects) ../devices/lrf.$(O) ../libocr$(A)
-pdf2swf$(E): $(XPDFOK) ../../src/pdf2swf.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects)
- $(LL) $(CPPFLAGS) -g ../../src/pdf2swf.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects) -o pdf2swf$(E) $(LIBS)
-gfx2gfx$(E): $(XPDFOK) ../../src/gfx2gfx.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects2)
- $(LL) $(CPPFLAGS) -g ../../src/gfx2gfx.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects2) -o gfx2gfx$(E) $(LIBS)
+pdf2swf$(E): $(XPDFOK) ../../src/pdf2swf.c $(libgfxpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects)
+ $(LL) $(CPPFLAGS) -g ../../src/pdf2swf.c $(libgfxpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects) -o pdf2swf$(E) $(LIBS)
+gfx2gfx$(E): $(XPDFOK) ../../src/gfx2gfx.c $(libgfxpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects2)
+ $(LL) $(CPPFLAGS) -g ../../src/gfx2gfx.c $(libgfxpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects2) -o gfx2gfx$(E) $(LIBS)
install:
$(mkinstalldirs) $(bindir)
--- /dev/null
+#include <ruby.h>
+#include "../gfxdevice.h"
+#include "../gfxsource.h"
+#include "../devices/pdf.h"
+#include "../readers/swf.h"
+#include "../readers/image.h"
+#include "../pdf/pdf.h"
+#include "../types.h"
+
+#define RUBY_GFX_VERSION "0.9.0"
+
+static VALUE GFX;
+static VALUE Document, DocumentPage, PDFClass, SWFClass, ImageClass, Device;
+static ID id_doc;
+
+typedef struct doc_internal {
+ gfxsource_t*driver; // filled by alloc
+ gfxdocument_t*doc;
+} doc_internal_t;
+
+typedef struct page_internal {
+ gfxpage_t*page;
+} page_internal_t;
+
+static gfxsource_t* pdfdriver = 0;
+static gfxsource_t* imagedriver = 0;
+static gfxsource_t* swfdriver = 0;
+
+#define Get_Doc(doc,cls) doc_internal_t*doc=0;Data_Get_Struct(cls, doc_internal_t, doc);
+#define Get_Page(page,cls) page_internal_t*page=0;Data_Get_Struct(cls, page_internal_t, page);
+
+static VALUE doc_allocate(VALUE cls, gfxsource_t*driver);
+static VALUE page_allocate(VALUE cls);
+
+// ------------------------ documents ---------------------------------------
+
+static VALUE doc_initialize(VALUE cls, VALUE _filename)
+{
+ Check_Type(_filename, T_STRING);
+ Get_Doc(doc,cls);
+ const char*filename = StringValuePtr(_filename);
+ doc->doc = pdfdriver->open(pdfdriver, filename);
+ return cls;
+}
+
+static VALUE doc_num_pages(VALUE cls)
+{
+ Get_Doc(doc,cls)
+ return INT2FIX(doc->doc->num_pages);
+}
+
+
+static VALUE doc_get_page(VALUE cls, VALUE _nr)
+{
+ Check_Type(_nr, T_FIXNUM);
+ int nr = FIX2INT(_nr);
+ Get_Doc(doc,cls);
+
+ VALUE v = page_allocate(DocumentPage);
+ Get_Page(page,v)
+ page->page = doc->doc->getpage(doc->doc, nr);
+ return v;
+}
+
+static VALUE doc_each_page(VALUE cls)
+{
+ Get_Doc(doc,cls);
+ int t;
+ for(t=1;t<=doc->doc->num_pages;t++) {
+ VALUE v = page_allocate(DocumentPage);
+ Get_Page(page,v)
+ page->page = doc->doc->getpage(doc->doc, t);
+ rb_yield(v);
+ }
+ return cls;
+}
+
+static void doc_mark(doc_internal_t*doc)
+{
+ // e.g. rb_gc_mark(z->page);
+}
+
+static void doc_free(doc_internal_t*doc)
+{
+ doc->doc->destroy(doc->doc);
+ free(doc);
+}
+
+static VALUE doc_allocate(VALUE cls, gfxsource_t*driver)
+{
+ doc_internal_t*doc = 0;
+ VALUE v = Data_Make_Struct(cls, doc_internal_t, 0, doc_free, doc);
+ memset(doc, 0, sizeof(doc_internal_t));
+ doc->driver = driver;
+ return v;
+}
+
+static VALUE pdf_allocate(VALUE cls) {return doc_allocate(cls, pdfdriver);}
+static VALUE swf_allocate(VALUE cls) {return doc_allocate(cls, swfdriver);}
+static VALUE image_allocate(VALUE cls) {return doc_allocate(cls, imagedriver);}
+
+// ------------------------ doc pages ---------------------------------------
+
+static VALUE page_free(VALUE cls)
+{
+ Get_Page(page, cls);
+ page->page->destroy(page->page);
+ free(page);
+ return cls;
+}
+
+static VALUE page_allocate(VALUE cls)
+{
+ page_internal_t*page = 0;
+ VALUE v = Data_Make_Struct(cls, page_internal_t, 0, page_free, page);
+ memset(page, 0, sizeof(page_internal_t));
+ return v;
+}
+
+static VALUE page_render(VALUE cls, VALUE device)
+{
+ Check_Type(device, T_CLASS);
+ Get_Page(page,cls)
+
+ gfxdevice_t dev;
+ dev.internal = (void*)(ptroff_t)device;
+
+ page->page->render(page->page, 0);//device);
+ //rb_yield(v);
+}
+
+static VALUE page_nr(VALUE cls)
+{
+ Get_Page(page,cls)
+ return INT2FIX(page->page->nr);
+}
+
+static VALUE page_width(VALUE cls)
+{
+ Get_Page(page,cls)
+ return INT2FIX(page->page->width);
+}
+
+static VALUE page_height(VALUE cls)
+{
+ Get_Page(page,cls)
+ return INT2FIX(page->page->height);
+}
+
+// ------------------------ gfx device --------------------------------------
+
+static VALUE noop(int argc, VALUE *argv, VALUE obj) {return obj;}
+
+// --------------------------------------------------------------------------
+
+void Init_gfx()
+{
+ initLog(0,0,0,0,0,2);
+ pdfdriver = gfxsource_pdf_create();
+ swfdriver = gfxsource_swf_create();
+ imagedriver = gfxsource_image_create();
+
+ GFX = rb_define_module("GFX");
+
+ DocumentPage = rb_define_class_under(GFX, "DocumentPage", rb_cObject);
+ rb_define_alloc_func(DocumentPage, page_allocate);
+ rb_define_method(DocumentPage, "width", page_width, 0);
+ rb_define_method(DocumentPage, "height", page_height, 0);
+ rb_define_method(DocumentPage, "nr", page_nr, 0);
+ rb_define_method(DocumentPage, "render", page_render, 0);
+
+ Document = rb_define_class_under(GFX, "Document", rb_cObject);
+ rb_define_method(Document, "initialize", doc_initialize, 1);
+ rb_define_method(Document, "page", doc_get_page, 1);
+ rb_define_method(Document, "each_page", doc_each_page, 0);
+
+ Device = rb_define_class_under(GFX, "Device", rb_cObject);
+ rb_define_method(Device, "startpage", noop, -1);
+ rb_define_method(Device, "endpage", noop, -1);
+ rb_define_method(Device, "startclip", noop, -1);
+ rb_define_method(Device, "endclip", noop, -1);
+ rb_define_method(Device, "stroke", noop, -1);
+ rb_define_method(Device, "fill", noop, -1);
+ rb_define_method(Device, "fillbitmap", noop, -1);
+ rb_define_method(Device, "fillgradient", noop, -1);
+ rb_define_method(Device, "addfont", noop, -1);
+ rb_define_method(Device, "drawchar", noop, -1);
+ rb_define_method(Device, "drawlink", noop, -1);
+ rb_define_method(Device, "endpage", noop, -1);
+
+ PDFClass = rb_define_class_under(GFX, "PDF", Document);
+ rb_define_alloc_func(PDFClass, pdf_allocate);
+
+ SWFClass = rb_define_class_under(GFX, "SWF", Document);
+ rb_define_alloc_func(SWFClass, swf_allocate);
+
+ ImageClass = rb_define_class_under(GFX, "Image", Document);
+ rb_define_alloc_func(ImageClass, image_allocate);
+
+ //id_doc = rb_intern("doc");
+}
+