diff --git a/djvu.c b/djvu.c index f7b244755..7429b92fd 100644 --- a/djvu.c +++ b/djvu.c @@ -238,34 +238,17 @@ static int getPageSize(lua_State *L) { return 2; } -/*static int getUsedBBox(lua_State *L) {*/ - /*fz_bbox result;*/ - /*fz_matrix ctm;*/ - /*fz_device *dev;*/ - /*DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");*/ - - /*[> returned BBox is in centi-point (n * 0.01 pt) <]*/ - /*ctm = fz_scale(100, 100);*/ - /*ctm = fz_concat(ctm, fz_rotate(page->page->rotate));*/ - - /*fz_try(page->doc->context) {*/ - /*dev = fz_new_bbox_device(page->doc->context, &result);*/ - /*pdf_run_page(page->doc->xref, page->page, dev, ctm, NULL);*/ - /*}*/ - /*fz_always(page->doc->context) {*/ - /*fz_free_device(dev);*/ - /*}*/ - /*fz_catch(page->doc->context) {*/ - /*return luaL_error(L, "cannot calculate bbox for page");*/ - /*}*/ - - /*lua_pushnumber(L, ((double)result.x0)/100);*/ - /*lua_pushnumber(L, ((double)result.y0)/100);*/ - /*lua_pushnumber(L, ((double)result.x1)/100);*/ - /*lua_pushnumber(L, ((double)result.y1)/100);*/ - - /*return 4;*/ -/*}*/ +/* unsupported so fake it */ +static int getUsedBBox(lua_State *L) { + DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage"); + + lua_pushnumber(L, (double)0.01); + lua_pushnumber(L, (double)0.01); + lua_pushnumber(L, (double)-0.01); + lua_pushnumber(L, (double)-0.01); + + return 4; +} static int closePage(lua_State *L) { DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage"); @@ -384,7 +367,7 @@ static const struct luaL_reg djvudocument_meth[] = { static const struct luaL_reg djvupage_meth[] = { {"getSize", getPageSize}, - /*{"getUsedBBox", getUsedBBox},*/ + {"getUsedBBox", getUsedBBox}, {"close", closePage}, {"__gc", closePage}, {"draw", drawPage}, diff --git a/pdfreader.lua b/pdfreader.lua index b40d6218e..9db9d0f1d 100644 --- a/pdfreader.lua +++ b/pdfreader.lua @@ -51,7 +51,8 @@ PDFReader = { settings = nil, -- we will use this one often, so keep it "static": - nulldc = pdf.newDC(), + nulldc = nil, + newDC = nil, -- tile cache configuration: cache_max_memsize = 1024*1024*5, -- 5MB tile cache @@ -125,7 +126,22 @@ end -- open a PDF file and its settings store function PDFReader:open(filename, password) - self.doc = pdf.openDocument(filename, password or "") + if string.match(filename, ".+%.[dD][jJ][vV][uU]$") then + self.doc = djvu.openDocument(filename) + self.newDC = function() + print("djvu.newDC") + return djvu.newDC() + end + else + self.doc = pdf.openDocument(filename, password or "") + self.newDC = function() + print("pdf.newDC") + return pdf.newDC() + end + end + + self.nulldc = self.newDC(); + if self.doc ~= nil then self.settings = DocSettings:open(filename) local gamma = self.settings:readsetting("gamma") @@ -139,7 +155,7 @@ end -- set viewer state according to zoom state function PDFReader:setzoom(page) - local dc = pdf.newDC() + local dc = self.newDC() local pwidth, pheight = page:getSize(self.nulldc) print("# page::getSize "..pwidth.."*"..pheight); local x0, y0, x1, y1 = page:getUsedBBox()