On Fri, 13 May 2011, Enlightenment SVN wrote:
> Log: > fix pdf loader to > > 1. handle load options for dpi and load size > 2. handle pdf crop region properly > 3. handle landscape oriented pdf's properly and render right. > > > > Author: raster > Date: 2011-05-13 00:45:22 -0700 (Fri, 13 May 2011) > New Revision: 59362 > Trac: http://trac.enlightenment.org/e/changeset/59362 > > Modified: > trunk/evas_generic_loaders/src/bin/pdf/main.cpp > > Modified: trunk/evas_generic_loaders/src/bin/pdf/main.cpp > =================================================================== > --- trunk/evas_generic_loaders/src/bin/pdf/main.cpp 2011-05-13 06:10:13 UTC > (rev 59361) > +++ trunk/evas_generic_loaders/src/bin/pdf/main.cpp 2011-05-13 07:45:22 UTC > (rev 59362) > @@ -31,15 +31,18 @@ > SplashOutputDev *output_dev; > > ::Page *page; > -int width = 0; > -int height = 0; > -void *data; > +int width = 0, height = 0; > +int crop_width = 0, crop_height = 0; > +void *data = NULL; > +double dpi = -1.0; > > static int shm_fd = -1; > static int shm_size = 0; > static void *shm_addr = NULL; > static char shmfile[1024] = ""; > > +#define DEF_DPI 72.0 > + > static void > shm_alloc(int dsize) > { > @@ -93,10 +96,12 @@ > shm_fd = -1; > } > > -Eina_Bool poppler_init(const char *file, int page_nbr, double dpi, int > size_w, int size_h) > +Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int > size_h) > { > Object obj; > SplashColor white; > + double w, h, cw, ch; > + int rot; > > if (!file || !*file) > return EINA_FALSE; > @@ -131,42 +136,49 @@ > if (!page || !page->isOk()) > goto del_pdfdoc; > > - width = page->getMediaWidth(); > - height = page->getMediaHeight(); > - > + w = page->getMediaWidth(); > + h = page->getMediaHeight(); > + cw = page->getCropWidth(); > + ch = page->getCropHeight(); > + rot = page->getRotate(); > + if (cw > w) cw = w; > + if (ch > h) ch = h; > + if ((rot == 90) || (rot == 270)) > + { > + double t; > + // swap width & height > + t = w; w = h; h = t; > + // swap crop width & height > + t = cw; cw = ch; ch = t; > + } > + > if ((size_w > 0) || (size_h > 0)) > { > - /* FIXME: tell poller to render at the new width and height > - unsigned int w2 = width, h2 = height; > - if (size_w > 0) > + double w2 = cw, h2 = ch; > + > + w2 = size_w; > + h2 = (size_w * ch) / cw; > + if (h2 > size_h) > { > - w2 = size_w; > - h2 = (size_w * h) / w; > - if ((size_h > 0) && (h2 > size_h)) > - { > - unsigned int w3; > - h2 = size_h; > - w3 = (size_h * w) / h; > - if (w3 > w2) > - w2 = w3; > - } > - } > - else if (size_h > 0) > - { > h2 = size_h; > - w2 = (size_h * w) / h; > + w2 = (size_h * cw) / ch; > } > - width = w2; > - height = h2; > - */ > + D("XXXXXXXXXXXXXXXXXXXXx %3.3fx%3.3f\n", w2, h2); > + if (w2 > h2) dpi = (w2 * DEF_DPI) / cw; > + else dpi = (h2 * DEF_DPI) / ch; > } > - else if (dpi > 0.0) > + > + if (dpi > 0.0) > { > - /* FIXME: tell poppler to render at this size > - width = (width * dpi) / 72.0; > - height = (height * dpi) / 72.0; > - */ > + cw = (cw * dpi) / DEF_DPI; > + ch = (ch * dpi) / DEF_DPI; > + w = (w * dpi) / DEF_DPI; > + h = (h * dpi) / DEF_DPI; > } > + width = w; > + height = h; > + crop_width = cw; > + crop_height = ch; > > return EINA_TRUE; > > @@ -185,11 +197,13 @@ > delete globalParams; > } > > -void poppler_load_image(double dpi, int size_w, int size_h) > +void poppler_load_image(int size_w, int size_h) > { > SplashOutputDev *output_dev; > SplashColor white; > SplashColorPtr color_ptr; > + DATA32 *src, *dst; > + int y; > > white[0] = 255; > white[1] = 255; > @@ -202,19 +216,25 @@ > > output_dev->startDoc(pdfdoc->getXRef()); > > - if (dpi <= 0.0) dpi = 72.0; > + if (dpi <= 0.0) dpi = DEF_DPI; > > - page->display(output_dev, > - dpi, dpi, 0, > - false, false, false, > - pdfdoc->getCatalog()); > + page->displaySlice(output_dev, dpi, dpi, > + 0, false, false, > + 0, 0, width, height, > + false, pdfdoc->getCatalog()); would it be possible to know whether or not one has to crop ? ::display() is faster than ::displaySlice() (and we would just do a memcpy below, and not a loop). Vincent > color_ptr = output_dev->getBitmap()->getDataPtr(); > > - shm_alloc(width * height * sizeof(DATA32)); > - if (!shm_addr) > - goto del_outpput_dev; > + shm_alloc(crop_width * crop_height * sizeof(DATA32)); > + if (!shm_addr) goto del_outpput_dev; > data = shm_addr; > - memcpy(data, color_ptr, width * height * sizeof(DATA32)); > + src = (DATA32 *)color_ptr; > + dst = (DATA32 *)data; > + for (y = 0; y < crop_height; y++) > + { > + memcpy(dst, src, crop_width * sizeof(DATA32)); > + src += width; > + dst += crop_width; > + } > > del_outpput_dev: > delete output_dev; > @@ -228,7 +248,6 @@ > int size_w = 0, size_h = 0; > int head_only = 0; > int page = 0; > - double dpi = -1.0; > > if (argc < 2) return -1; > // file is ALWAYS first arg, other options come after > @@ -263,24 +282,28 @@ > size_h = atoi(argv[i]); > } > } > + size_w = 400; > + size_h = 400; > > D("poppler_file_init\n"); > D("dpi....: %f\n", dpi); > D("page...: %d\n", page); > > - if (!poppler_init(file, page, dpi, size_w, size_h)) > + if (!poppler_init(file, page, size_w, size_h)) > return -1; > D("poppler_file_init done\n"); > > + D("dpi2...: %f\n", dpi); > if (!head_only) > { > - poppler_load_image(dpi, size_w, size_h); > + poppler_load_image(size_w, size_h); > } > > D("size...: %ix%i\n", width, height); > + D("crop...: %ix%i\n", crop_width, crop_height); > D("alpha..: 1\n"); > > - printf("size %i %i\n", width, height); > + printf("size %i %i\n", crop_width, crop_height); > printf("alpha 0\n"); > > if (!head_only) > @@ -291,7 +314,7 @@ > // could also to "tmpfile %s\n" like shmfile but just > // a mmaped tmp file on the system > printf("data\n"); > - fwrite(data, width * height * sizeof(DATA32), 1, stdout); > + fwrite(data, crop_width * crop_height * sizeof(DATA32), 1, > stdout); > } > shm_free(); > } > > > ------------------------------------------------------------------------------ > Achieve unprecedented app performance and reliability > What every C/C++ and Fortran developer should know. > Learn how Intel has extended the reach of its next-generation tools > to help boost performance applications - inlcuding clusters. > http://p.sf.net/sfu/intel-dev2devmay > _______________________________________________ > enlightenment-svn mailing list > enlightenment-...@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/enlightenment-svn > > ------------------------------------------------------------------------------ Achieve unprecedented app performance and reliability What every C/C++ and Fortran developer should know. Learn how Intel has extended the reach of its next-generation tools to help boost performance applications - inlcuding clusters. http://p.sf.net/sfu/intel-dev2devmay _______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel