integrate djvu into PDFReader, alternative to #26

This code is based on current master but doesn't include unireader, but
leaves all names to old PDFReader to preserve compatilbity
pull/2/merge
Dobrica Pavlinusic 12 years ago
parent 1b1fc2b3ae
commit efe2ef7efe

@ -238,34 +238,17 @@ static int getPageSize(lua_State *L) {
return 2; return 2;
} }
/*static int getUsedBBox(lua_State *L) {*/ /* unsupported so fake it */
/*fz_bbox result;*/ static int getUsedBBox(lua_State *L) {
/*fz_matrix ctm;*/ DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
/*fz_device *dev;*/
/*DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");*/ lua_pushnumber(L, (double)0.01);
lua_pushnumber(L, (double)0.01);
/*[> returned BBox is in centi-point (n * 0.01 pt) <]*/ lua_pushnumber(L, (double)-0.01);
/*ctm = fz_scale(100, 100);*/ lua_pushnumber(L, (double)-0.01);
/*ctm = fz_concat(ctm, fz_rotate(page->page->rotate));*/
return 4;
/*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;*/
/*}*/
static int closePage(lua_State *L) { static int closePage(lua_State *L) {
DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage"); 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[] = { static const struct luaL_reg djvupage_meth[] = {
{"getSize", getPageSize}, {"getSize", getPageSize},
/*{"getUsedBBox", getUsedBBox},*/ {"getUsedBBox", getUsedBBox},
{"close", closePage}, {"close", closePage},
{"__gc", closePage}, {"__gc", closePage},
{"draw", drawPage}, {"draw", drawPage},

@ -51,7 +51,8 @@ PDFReader = {
settings = nil, settings = nil,
-- we will use this one often, so keep it "static": -- we will use this one often, so keep it "static":
nulldc = pdf.newDC(), nulldc = nil,
newDC = nil,
-- tile cache configuration: -- tile cache configuration:
cache_max_memsize = 1024*1024*5, -- 5MB tile cache cache_max_memsize = 1024*1024*5, -- 5MB tile cache
@ -125,7 +126,22 @@ end
-- open a PDF file and its settings store -- open a PDF file and its settings store
function PDFReader:open(filename, password) 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 if self.doc ~= nil then
self.settings = DocSettings:open(filename) self.settings = DocSettings:open(filename)
local gamma = self.settings:readsetting("gamma") local gamma = self.settings:readsetting("gamma")
@ -139,7 +155,7 @@ end
-- set viewer state according to zoom state -- set viewer state according to zoom state
function PDFReader:setzoom(page) function PDFReader:setzoom(page)
local dc = pdf.newDC() local dc = self.newDC()
local pwidth, pheight = page:getSize(self.nulldc) local pwidth, pheight = page:getSize(self.nulldc)
print("# page::getSize "..pwidth.."*"..pheight); print("# page::getSize "..pwidth.."*"..pheight);
local x0, y0, x1, y1 = page:getUsedBBox() local x0, y0, x1, y1 = page:getUsedBBox()

Loading…
Cancel
Save