X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Fgfx.c;h=1d28bc5e64b699260ebc2d771cf16cf88c408f9a;hb=18eb80b698320ccde1f556c894c92b309df4c145;hp=5bc2068064b20a11c0d0296b5ad44a4989a38b91;hpb=cff493c8c3d14392786e3415478faf62423f71b5;p=swftools.git diff --git a/lib/python/gfx.c b/lib/python/gfx.c index 5bc2068..1d28bc5 100644 --- a/lib/python/gfx.c +++ b/lib/python/gfx.c @@ -25,6 +25,7 @@ #undef HAVE_STAT #include "../devices/swf.h" #include "../devices/render.h" +#include "../devices/ocr.h" #include "../devices/rescale.h" #include "../devices/text.h" #include "../pdf/pdf.h" @@ -170,6 +171,27 @@ static PyObject* f_createSWF(PyObject* parent, PyObject* args, PyObject* kwargs) return (PyObject*)self; } +PyDoc_STRVAR(f_createOCR_doc, \ +"OCR()\n\n" +"Creates a device which processes documents using OCR (optical\n" +"character recognition).\n" +"This is handy for e.g. extracting fulltext from PDF documents\n" +"which have broken fonts, and where hence the \"PlainText\"\n" +"device doesn't work.\n" +); +static PyObject* f_createOCR(PyObject* parent, PyObject* args, PyObject* kwargs) +{ + static char *kwlist[] = {NULL}; + if (args && !PyArg_ParseTupleAndKeywords(args, kwargs, "", kwlist)) + return NULL; + OutputObject*self = PyObject_New(OutputObject, &OutputClass); + + self->output_device = malloc(sizeof(gfxdevice_t)); + gfxdevice_ocr_init(self->output_device); + return (PyObject*)self; +} + + PyDoc_STRVAR(f_createImageList_doc, \ "ImageList()\n\n" "Creates a device which renders documents to bitmaps.\n" @@ -726,6 +748,8 @@ static PyObject* f_open(PyObject* parent, PyObject* args, PyObject* kwargs) type = "image"; if(strchr("pP", filename[l-3]) && strchr("nN", filename[l-2]) && strchr("gG", filename[l-1])) type = "image"; + if(strchr("sS", filename[l-3]) && strchr("wW", filename[l-2]) && strchr("fF", filename[l-1])) + type = "swf"; } else if(filename[l-5]=='.') { type = "image"; } @@ -734,9 +758,9 @@ static PyObject* f_open(PyObject* parent, PyObject* args, PyObject* kwargs) if(!strcmp(type,"pdf")) self->doc = pdfdriver->open(pdfdriver,filename); - else if(!strcmp(type, "image")) + else if(!strcmp(type, "image") || !strcmp(type, "img")) self->doc = imagedriver->open(imagedriver, filename); - else if(!strcmp(type, "swf")) + else if(!strcmp(type, "swf") || !strcmp(type, "SWF")) self->doc = swfdriver->open(imagedriver, filename); else return PY_ERROR("Unknown type %s", type); @@ -946,6 +970,7 @@ static PyMethodDef pdf2swf_methods[] = /* devices */ {"SWF", (PyCFunction)f_createSWF, METH_KEYWORDS, f_createSWF_doc}, + {"OCR", (PyCFunction)f_createOCR, METH_KEYWORDS, f_createOCR_doc}, {"ImageList", (PyCFunction)f_createImageList, METH_KEYWORDS, f_createImageList_doc}, {"PlainText", (PyCFunction)f_createPlainText, METH_KEYWORDS, f_createPlainText_doc}, {"PassThrough", (PyCFunction)f_createPassThrough, METH_KEYWORDS, f_createPassThrough_doc},