diff --git a/.gitmodules b/.gitmodules index ead63e79f..45ae3eaf5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "kpvcrlib/crengine"] path = kpvcrlib/crengine url = git://crengine.git.sourceforge.net/gitroot/crengine/crengine +[submodule "luajit-2.0"] + path = luajit-2.0 + url = http://luajit.org/git/luajit-2.0.git diff --git a/Makefile b/Makefile index be0929009..d58ac18d1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # you can probably leave these settings alone: -LUADIR=lua +LUADIR=luajit-2.0 MUPDFDIR=mupdf MUPDFTARGET=build/debug MUPDFLIBDIR=$(MUPDFDIR)/$(MUPDFTARGET) @@ -8,7 +8,7 @@ DJVUDIR=djvulibre KPVCRLIGDIR=kpvcrlib CRENGINEDIR=$(KPVCRLIGDIR)/crengine -FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.8 +FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.9 LFSDIR=luafilesystem # must point to directory with *.ttf fonts for crengine @@ -82,7 +82,7 @@ THIRDPARTYLIBS := $(MUPDFLIBDIR)/libfreetype.a \ #$(MUPDFLIBDIR)/libjpeg.a \ #$(CRENGINEDIR)/thirdparty/libjpeg/libjpeg.a \ -LUALIB := $(LUADIR)/src/liblua.a +LUALIB := $(LUADIR)/src/libluajit.a all:kpdfview @@ -111,7 +111,7 @@ kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft slider_watcher: slider_watcher.c $(CC) $(CFLAGS) $< -o $@ -ft.o: %.o: %.c +ft.o: %.o: %.c $(THIRDPARTYLIBS) $(CC) -c $(KPDFREADER_CFLAGS) -I$(FREETYPEDIR)/include -I$(MUPDFDIR)/fitz $< -o $@ kpdfview.o pdf.o blitbuffer.o util.o drawcontext.o einkfb.o input.o mupdfimg.o: %.o: %.c @@ -127,12 +127,13 @@ lfs.o: $(LFSDIR)/src/lfs.c $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ fetchthirdparty: - -rm -Rf lua lua-5.1.4 -rm -Rf mupdf/thirdparty test -d mupdf && (cd mupdf; git checkout .) || echo warn: mupdf folder not found + test -d $(LUADIR) && (cd $(LUADIR); git checkout .) || echo warn: $(LUADIR) folder not found git submodule init git submodule update ln -sf kpvcrlib/crengine/cr3gui/data data + test -e data/cr3.css || ln kpvcrlib/cr3.css data/ test -d fonts || ln -sf $(TTF_FONTS_DIR) fonts # CREngine patch: disable fontconfig grep USE_FONTCONFIG $(CRENGINEDIR)/crengine/include/crsetup.h && grep -v USE_FONTCONFIG $(CRENGINEDIR)/crengine/include/crsetup.h > /tmp/new && mv /tmp/new $(CRENGINEDIR)/crengine/include/crsetup.h || echo "USE_FONTCONFIG already disabled" @@ -148,16 +149,14 @@ fetchthirdparty: patch -N -p0 < ../../../kpvcrlib/jpeg_decompress_struct_size.patch # MuPDF patch: use external fonts cd mupdf && patch -N -p1 < ../mupdf.patch - test -f lua-5.1.4.tar.gz || wget http://www.lua.org/ftp/lua-5.1.4.tar.gz - tar xvzf lua-5.1.4.tar.gz && ln -s lua-5.1.4 lua clean: -rm -f *.o kpdfview slider_watcher cleanthirdparty: - make -C $(LUADIR) clean - make -C $(MUPDFDIR) clean - #make -C $(CRENGINEDIR)/thirdparty/antiword clean + -make -C $(LUADIR) clean + -make -C $(MUPDFDIR) clean + -make -C $(CRENGINEDIR)/thirdparty/antiword clean test -d $(CRENGINEDIR)/thirdparty/chmlib && make -C $(CRENGINEDIR)/thirdparty/chmlib clean || echo warn: chmlib folder not found test -d $(CRENGINEDIR)/thirdparty/libpng && (make -C $(CRENGINEDIR)/thirdparty/libpng clean) || echo warn: chmlib folder not found test -d $(CRENGINEDIR)/crengine && (make -C $(CRENGINEDIR)/crengine clean) || echo warn: chmlib folder not found @@ -195,17 +194,16 @@ $(CRENGINELIBS): make $(LUALIB): - make -C lua/src CC="$(CC)" CFLAGS="$(CFLAGS)" MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E" liblua.a +ifdef EMULATE_READER + make -C $(LUADIR) +else + make -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CROSS="$(HOST)-" TARGET_FLAGS="$(SYSROOT) -DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2" +endif thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) $(CRENGINELIBS) INSTALL_DIR=kindlepdfviewer -install: - # install to kindle using USB networking - scp kpdfview *.lua root@192.168.2.2:/mnt/us/$(INSTALL_DIR)/ - scp launchpad/* root@192.168.2.2:/mnt/us/launchpad/ - VERSION?=$(shell git rev-parse --short HEAD) customupdate: all # ensure that build binary is for ARM @@ -221,6 +219,6 @@ customupdate: all cp -r resources $(INSTALL_DIR) cp -r frontend $(INSTALL_DIR) mkdir $(INSTALL_DIR)/fonts/host - zip -9 -r kindlepdfviewer-$(VERSION).zip $(INSTALL_DIR) launchpad/ + zip -9 -r kindlepdfviewer-$(VERSION).zip $(INSTALL_DIR) launchpad/ kite/ rm -Rf $(INSTALL_DIR) @echo "copy kindlepdfviewer-$(VERSION).zip to /mnt/us/customupdates and install with shift+shift+I" diff --git a/README.TXT b/README.TXT index a06c75335..f05e506f8 100644 --- a/README.TXT +++ b/README.TXT @@ -18,9 +18,12 @@ Follow these steps: - install muPDF third-party sources (see muPDF homepage) into a new subfolder "mupdf/thirdparty" -- install Lua sources into subfolder "lua" +- install libDjvuLibre sources into subfolder "djvulibre" +- install CREngine sources into subfolder "kpvcrlib/crengine" -=> note that there's a make target to do this. You need wget, unzip and git +- install LuaJit sources into subfolder "luajit-2.0" + +=> note that there's a make target to do all the above. You need wget, unzip and git installed. Then just run "make fetchthirdparty". - adapt Makefile to your needs @@ -57,10 +60,8 @@ To build in "emulation mode", you need to run make like this: make clean cleanthirdparty EMULATE_READER=1 make thirdparty kpdfview -The reader.lua script needs a device argument in order to cope with some -slight differences between actual readers and the emulation. Run it like -this: - ./reader.lua -d emu /PATH/TO/PDF.pdf +And run the emulator like this: + ./reader.lua /PATH/TO/PDF.pdf By default emulation will provide DXG resolution of 824*1200. It can be specified at compile time, this is example for Kindle 3: diff --git a/cre.cpp b/cre.cpp index ac9a9fbd9..a60bbae83 100644 --- a/cre.cpp +++ b/cre.cpp @@ -117,28 +117,29 @@ static int getPageFromXPointer(lua_State *L) { return 1; } -static int getCurrentPos(lua_State *L) { +static int getPosFromXPointer(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + const char *xpointer_str = luaL_checkstring(L, 2); - lua_pushinteger(L, doc->text_view->GetPos()); + int pos = 0; + ldomXPointer xp = doc->dom_doc->createXPointer(lString16(xpointer_str)); + + lvPoint pt = xp.toPoint(); + if (pt.y > 0) { + pos = pt.y; + } + lua_pushinteger(L, pos); return 1; } -//static int getPosFromXPointer(lua_State *L) { - //CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); - //const char *xpointer_str = luaL_checkstring(L, 2); - - //lvRect rc; - //int pos; +static int getCurrentPos(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); - //ldomXPointer *xp = NULL; - //xp = doc->dom_doc->createXPointer(lString16(xpointer_str)); - //getCursorDocRect(*xp, rc); - //pos = + lua_pushinteger(L, doc->text_view->GetPos()); - //return 1; -//} + return 1; +} static int getCurrentPercent(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); @@ -440,6 +441,7 @@ static const struct luaL_Reg credocument_meth[] = { {"getPages", getNumberOfPages}, {"getCurrentPage", getCurrentPage}, {"getPageFromXPointer", getPageFromXPointer}, + {"getPosFromXPointer", getPosFromXPointer}, {"getCurrentPos", getCurrentPos}, {"getCurrentPercent", getCurrentPercent}, {"getXPointer", getXPointer}, diff --git a/einkfb.c b/einkfb.c index cea9bd923..fdd058aae 100644 --- a/einkfb.c +++ b/einkfb.c @@ -78,6 +78,8 @@ static int openFrameBuffer(lua_State *L) { if(fb->buf->data == MAP_FAILED) { return luaL_error(L, "cannot mmap framebuffer"); } + memset(fb->buf->data, 0, fb->finfo.smem_len); + fb->buf->pitch = fb->finfo.line_length; #else if(SDL_Init(SDL_INIT_VIDEO) < 0) { return luaL_error(L, "cannot initialize SDL."); @@ -86,26 +88,17 @@ static int openFrameBuffer(lua_State *L) { return luaL_error(L, "can't get video surface %dx%d for 32bpp.", EMULATE_READER_W, EMULATE_READER_H); } - memset(&fb->finfo, 0, sizeof(fb->finfo)); - memset(&fb->vinfo, 0, sizeof(fb->vinfo)); fb->vinfo.xres = EMULATE_READER_W; fb->vinfo.yres = EMULATE_READER_H; - fb->vinfo.grayscale = 1; - fb->vinfo.bits_per_pixel = 4; - fb->finfo.smem_len = ((EMULATE_READER_W + 1) / 2) * EMULATE_READER_H; - fb->finfo.line_length = (EMULATE_READER_W + 1) / 2; - fb->finfo.type = FB_TYPE_PACKED_PIXELS; - fb->buf->data = malloc(fb->finfo.smem_len); + fb->buf->pitch = (EMULATE_READER_W + 1) / 2; + fb->buf->data = calloc(fb->buf->pitch * EMULATE_READER_H, sizeof(char)); if(fb->buf->data == NULL) { return luaL_error(L, "cannot get framebuffer emu memory"); } #endif - memset(fb->buf->data, 0, fb->finfo.smem_len); fb->buf->w = fb->vinfo.xres; fb->buf->h = fb->vinfo.yres; - fb->buf->pitch = fb->finfo.line_length; fb->buf->allocated = 0; - return 1; } diff --git a/einkfb.h b/einkfb.h index 883619021..d3c0ca933 100644 --- a/einkfb.h +++ b/einkfb.h @@ -18,10 +18,14 @@ #ifndef _PDF_EINKFB_H #define _PDF_EINKFB_H -#include #ifdef EMULATE_READER #include +struct fb_var_screeninfo { + uint32_t xres; + uint32_t yres; +}; #else +#include #include "include/einkfb.h" #endif @@ -34,11 +38,12 @@ typedef struct FBInfo { int fd; BlitBuffer *buf; - struct fb_fix_screeninfo finfo; - struct fb_var_screeninfo vinfo; #ifdef EMULATE_READER SDL_Surface *screen; +#else + struct fb_fix_screeninfo finfo; #endif + struct fb_var_screeninfo vinfo; } FBInfo; int luaopen_einkfb(lua_State *L); diff --git a/frontend/settings.lua b/frontend/settings.lua index 260cb185a..757b14b3a 100644 --- a/frontend/settings.lua +++ b/frontend/settings.lua @@ -29,7 +29,7 @@ end function DEBUG(...) local line = "" - for i,v in ipairs(arg) do + for i,v in ipairs({...}) do if type(v) == "table" then line = line .. " " .. dump(v) else diff --git a/input.c b/input.c index 1bf7f9ba5..6dce14f50 100644 --- a/input.c +++ b/input.c @@ -27,8 +27,12 @@ #include #define OUTPUT_SIZE 21 -#define CODE_IN_SAVER 10000 -#define CODE_OUT_SAVER 10001 +#define CODE_IN_SAVER 10000 +#define CODE_OUT_SAVER 10001 +#define CODE_USB_PLUG_IN 10010 +#define CODE_USB_PLUG_OUT 10011 +#define CODE_CHARGING 10020 +#define CODE_NOT_CHARGING 10021 #define NUM_FDS 4 int inputfds[4] = { -1, -1, -1, -1 }; @@ -78,7 +82,11 @@ static int openInputDevice(lua_State *L) { /* listen power slider events */ while(1) { - fp = popen("exec lipc-wait-event com.lab126.powerd goingToScreenSaver,outOfScreenSaver", "r"); + fp = popen("exec lipc-wait-event com.lab126.powerd goingToScreenSaver,outOfScreenSaver,charging,notCharging", "r"); + /* @TODO 07.06 2012 (houqp) + * plugin and out event can only be watched by: + lipc-wait-event com.lab126.hal usbPlugOut,usbPlugIn + */ if(fgets(std_out, OUTPUT_SIZE, fp) == NULL) { break; } @@ -87,6 +95,14 @@ static int openInputDevice(lua_State *L) { ev.code = CODE_IN_SAVER; } else if(std_out[0] == 'o') { ev.code = CODE_OUT_SAVER; + } else if((std_out[0] == 'u') && (std_out[7] == 'I')) { + ev.code = CODE_USB_PLUG_IN; + } else if((std_out[0] == 'u') && (std_out[7] == 'O')) { + ev.code = CODE_USB_PLUG_OUT; + } else if(std_out[0] == 'c') { + ev.code = CODE_CHARGING; + } else if(std_out[0] == 'n') { + ev.code = CODE_NOT_CHARGING; } else { printf("Unrecognized event.\n"); } diff --git a/kite/KPDFviewer (last file) b/kite/KPDFviewer (last file) new file mode 100755 index 000000000..5d9acab14 --- /dev/null +++ b/kite/KPDFviewer (last file) @@ -0,0 +1,3 @@ +#!/bin/sh + +/mnt/us/launchpad/kpdf.sh diff --git a/kite/KPDFviewer File Manager b/kite/KPDFviewer File Manager new file mode 100755 index 000000000..3374ef3ae --- /dev/null +++ b/kite/KPDFviewer File Manager @@ -0,0 +1,3 @@ +#!/bin/sh + +/mnt/us/launchpad/kpdf.sh /mnt/us/documents diff --git a/kpdfview.c b/kpdfview.c index d0003ae7f..4fa85e940 100644 --- a/kpdfview.c +++ b/kpdfview.c @@ -38,6 +38,46 @@ lua_State *L; +/* from luajit-2.0/src/luajit.c : */ +static int traceback(lua_State *L) +{ + if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */ + if (lua_isnoneornil(L, 1) || + !luaL_callmeta(L, 1, "__tostring") || + !lua_isstring(L, -1)) + return 1; /* Return non-string error object. */ + lua_remove(L, 1); /* Replace object by result of __tostring metamethod. */ + } + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* Push error message. */ + lua_pushinteger(L, 2); /* Skip this function and debug.traceback(). */ + lua_call(L, 2, 1); /* Call debug.traceback(). */ + return 1; +} + +/* from luajit-2.0/src/luajit.c : */ +static int docall(lua_State *L, int narg, int clear) +{ + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + int main(int argc, char **argv) { int i, err; @@ -71,7 +111,7 @@ int main(int argc, char **argv) { } lua_setglobal(L, "ARGV"); - if(luaL_dofile(L, argv[1])) { + if(luaL_loadfile(L, argv[1]) || docall(L, 0, 1)) { fprintf(stderr, "lua config error: %s\n", lua_tostring(L, -1)); lua_close(L); L=NULL; diff --git a/kpvcrlib/CMakeLists.txt b/kpvcrlib/CMakeLists.txt index 43dc7563a..dae382518 100644 --- a/kpvcrlib/CMakeLists.txt +++ b/kpvcrlib/CMakeLists.txt @@ -9,7 +9,7 @@ SET(CR_3RDPARTY_DIR crengine/thirdparty) SET(CR3_PNG 1) #SET(CR3_JPEG 1) -SET(FREETYPE_INCLUDE_DIRS ${MUPDF_3RDPARTY_DIR}/freetype-2.4.8/include) +SET(FREETYPE_INCLUDE_DIRS ${MUPDF_3RDPARTY_DIR}/freetype-2.4.9/include) #SET(FREETYPE_INCLUDE_DIRS ${CR_3RDPARTY_DIR}/freetype/include) SET(ANTIWORD_INCLUDE_DIR ${CR_3RDPARTY_DIR}/antiword) SET(CHM_INCLUDE_DIRS ${CR_3RDPARTY_DIR}/chmlib) diff --git a/kpvcrlib/crengine b/kpvcrlib/crengine index 7a73d1666..b62d054cc 160000 --- a/kpvcrlib/crengine +++ b/kpvcrlib/crengine @@ -1 +1 @@ -Subproject commit 7a73d1666538fe9dd7d84d7e18135b03c21be2ca +Subproject commit b62d054cca57366bc1ba2fa249c5bbf5c5234346 diff --git a/luajit-2.0 b/luajit-2.0 new file mode 160000 index 000000000..5bd133d6c --- /dev/null +++ b/luajit-2.0 @@ -0,0 +1 @@ +Subproject commit 5bd133d6c89fb9ef5c501eb27d2d6221ec44d11d diff --git a/mupdfimg.c b/mupdfimg.c index dcda3e8fa..fe14e5ad6 100644 --- a/mupdfimg.c +++ b/mupdfimg.c @@ -53,6 +53,7 @@ static int loadPNGData(lua_State *L) { fz_catch(img->context) { return luaL_error(L, "cannot load PNG data"); } + return 0; } static int loadJPEGData(lua_State *L) { @@ -65,6 +66,7 @@ static int loadJPEGData(lua_State *L) { fz_catch(img->context) { return luaL_error(L, "cannot open JPEG data"); } + return 0; } static int toBlitBuffer(lua_State *L) {