From a52aee2f9aa469702f04f6712c63988d19531fc1 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Mon, 27 Aug 2012 12:57:26 +0100 Subject: [PATCH 01/27] Set up to compile with arm-kindle-linux-x-tools-glibc2.5-gcc4.2.4.tar.gz toolchain. --- Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index b1366924c..61d0f286d 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ TTF_FONTS_DIR=$(MUPDFDIR)/fonts # set this to your ARM cross compiler: -HOST:=arm-none-linux-gnueabi +HOST:=arm-kindle-linux-gnueabi CC:=$(HOST)-gcc CXX:=$(HOST)-g++ STRIP:=$(HOST)-strip @@ -27,14 +27,16 @@ endif HOSTCC:=gcc HOSTCXX:=g++ -CFLAGS:=-O3 $(SYSROOT) -CXXFLAGS:=-O3 $(SYSROOT) -LDFLAGS:= $(SYSROOT) +SYSROOT=/usr/local/arm/$(HOST)/$(HOST)/sysroot/ +CFLAGS:=-O3 --sysroot=$(SYSROOT) +CXXFLAGS:=-O3 --sysroot=$(SYSROOT) +LDFLAGS:= --sysroot=$(SYSROOT) ARM_CFLAGS:=-march=armv6 # use this for debugging: #CFLAGS:=-O0 -g $(SYSROOT) DYNAMICLIBSTDCPP:=-lstdc++ +STATICLIBSTDCPP=$(SYSROOT)lib/libstdc++.a ifdef STATICLIBSTDCPP DYNAMICLIBSTDCPP:= endif @@ -124,7 +126,7 @@ djvu.o: %.o: %.c $(CC) -c $(KPDFREADER_CFLAGS) -I$(DJVUDIR)/ $< -o $@ cre.o: %.o: %.cpp - $(CC) -c -I$(CRENGINEDIR)/crengine/include/ -I$(LUADIR)/src $< -o $@ -lstdc++ + $(CC) -c -I$(CRENGINEDIR)/crengine/include/ -I$(LUADIR)/src $< -o $@ lfs.o: $(LFSDIR)/src/lfs.c $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ @@ -204,7 +206,7 @@ $(LUALIB): 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" + make -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CROSS="$(HOST)-" TARGET_FLAGS="--sysroot=$(SYSROOT) -DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2" endif thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) $(CRENGINELIBS) From bcb85d7c073db03b124c5fb5bf5e48c6e2b88e9f Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Mon, 27 Aug 2012 14:39:42 +0100 Subject: [PATCH 02/27] Fix the Makefile to use freetype-2.4.10 and kpvcrlib/CMakeLists.txt to do the same and also zlib 1.2.5->1.2.7 and libjpeg 8d->9. --- Makefile | 2 +- kpvcrlib/CMakeLists.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 61d0f286d..8a5af214e 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ DJVUDIR=djvulibre KPVCRLIBDIR=kpvcrlib CRENGINEDIR=$(KPVCRLIBDIR)/crengine -FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.9 +FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.10 LFSDIR=luafilesystem # must point to directory with *.ttf fonts for crengine diff --git a/kpvcrlib/CMakeLists.txt b/kpvcrlib/CMakeLists.txt index dae382518..d36200925 100644 --- a/kpvcrlib/CMakeLists.txt +++ b/kpvcrlib/CMakeLists.txt @@ -9,14 +9,14 @@ SET(CR_3RDPARTY_DIR crengine/thirdparty) SET(CR3_PNG 1) #SET(CR3_JPEG 1) -SET(FREETYPE_INCLUDE_DIRS ${MUPDF_3RDPARTY_DIR}/freetype-2.4.9/include) +SET(FREETYPE_INCLUDE_DIRS ${MUPDF_3RDPARTY_DIR}/freetype-2.4.10/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) SET(PNG_INCLUDE_DIR ${CR_3RDPARTY_DIR}/libpng) -SET(ZLIB_INCLUDE_DIR ${MUPDF_3RDPARTY_DIR}/zlib-1.2.5) +SET(ZLIB_INCLUDE_DIR ${MUPDF_3RDPARTY_DIR}/zlib-1.2.7) #SET(ZLIB_INCLUDE_DIR ${CR_3RDPARTY_DIR}/zlib) -SET(JPEGLIB_INCLUDE_DIR ${MUPDF_3RDPARTY_DIR}/jpeg-8d) +SET(JPEGLIB_INCLUDE_DIR ${MUPDF_3RDPARTY_DIR}/jpeg-9) #SET(JPEGLIB_INCLUDE_DIR ${CR_3RDPARTY_DIR}/libjpeg) SET(JCONFIG_INCLUDE_DIR ${MUPDF_DIR}/scripts) From 144f5c637ac75f996bbab4be37654b67bf9c4cac Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Mon, 27 Aug 2012 15:33:32 +0100 Subject: [PATCH 03/27] DjVu enhancements: a) add support for switching the rendering mode between B&W (default, 1) and COLOUR (0) values. b) handle the gamma values correctly. Conflicts: unireader.lua --- djvu.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/djvu.c b/djvu.c index 53b1298ab..9253b404e 100644 --- a/djvu.c +++ b/djvu.c @@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include #include #include @@ -185,7 +186,7 @@ static int openPage(lua_State *L) { luaL_getmetatable(L, "djvupage"); lua_setmetatable(L, -2); - /* djvulibre counts page starts form 0 */ + /* djvulibre counts page starts from 0 */ page->page_ref = ddjvu_page_create_by_pageno(doc->doc_ref, pageno - 1); while (! ddjvu_page_decoding_done(page->page_ref)) handle(L, doc->context, TRUE); @@ -196,7 +197,7 @@ static int openPage(lua_State *L) { page->doc = doc; page->num = pageno; - /* djvulibre counts page starts form 0 */ + /* djvulibre counts page starts from 0 */ while((r=ddjvu_document_get_pageinfo(doc->doc_ref, pageno - 1, &(page->info)))context, TRUE); @@ -376,6 +377,15 @@ static int drawPage(lua_State *L) { DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); BlitBuffer *bb = (BlitBuffer*) luaL_checkudata(L, 3, "blitbuffer"); + int render_mode = (int) luaL_checkint(L, 6); + ddjvu_render_mode_t djvu_render_mode; + unsigned char adjusted_low[16], adjusted_high[16]; + int i, adjust_pixels = 0; + + if (render_mode) + djvu_render_mode = DDJVU_RENDER_BLACK; + else + djvu_render_mode = DDJVU_RENDER_COLOR; ddjvu_format_t *pixelformat; ddjvu_rect_t pagerect, renderrect; @@ -422,7 +432,7 @@ static int drawPage(lua_State *L) { */ ddjvu_page_render(page->page_ref, - DDJVU_RENDER_COLOR, + djvu_render_mode, &pagerect, &renderrect, pixelformat, @@ -436,12 +446,26 @@ static int drawPage(lua_State *L) { int x_offset = MAX(0, dc->offset_x); int y_offset = MAX(0, dc->offset_y); + /* prepare the tables for adjusting the intensity of pixels */ + if (dc->gamma != -1.0) { + for (i=0; i<16; i++) { + adjusted_low[i] = MIN(15, (unsigned char)floorf(dc->gamma * (float)i)); + adjusted_high[i] = adjusted_low[i] << 4; + } + adjust_pixels = 1; + } + bbptr += bb->pitch * y_offset; for(y = y_offset; y < bb->h; y++) { /* bbptr's line width is half of pmptr's */ for(x = x_offset/2; x < (bb->w / 2); x++) { - bbptr[x] = 255 - (((pmptr[x*2 + 1 - x_offset] & 0xF0) >> 4) | - (pmptr[x*2 - x_offset] & 0xF0)); + int p = x*2 - x_offset; + unsigned char low = 15 - (pmptr[p + 1] >> 4); + unsigned char high = 15 - (pmptr[p] >> 4); + if (adjust_pixels) + bbptr[x] = adjusted_high[high] | adjusted_low[low]; + else + bbptr[x] = (high << 4) | low; } if(bb->w & 1) { bbptr[x] = 255 - (pmptr[x*2] & 0xF0); From cc52ee0a097cefd970e46cdcc9de1fa89e1a5860 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 27 Aug 2012 20:53:14 +0200 Subject: [PATCH 04/27] Revert "Set up to compile with arm-kindle-linux-x-tools-glibc2.5-gcc4.2.4.tar.gz toolchain." This reverts commit 2650faa000631d8e3e7440f7920ddce1f3ea359b as described in #229 --- Makefile | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8a5af214e..f15a1072e 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ TTF_FONTS_DIR=$(MUPDFDIR)/fonts # set this to your ARM cross compiler: -HOST:=arm-kindle-linux-gnueabi +HOST:=arm-none-linux-gnueabi CC:=$(HOST)-gcc CXX:=$(HOST)-g++ STRIP:=$(HOST)-strip @@ -27,16 +27,14 @@ endif HOSTCC:=gcc HOSTCXX:=g++ -SYSROOT=/usr/local/arm/$(HOST)/$(HOST)/sysroot/ -CFLAGS:=-O3 --sysroot=$(SYSROOT) -CXXFLAGS:=-O3 --sysroot=$(SYSROOT) -LDFLAGS:= --sysroot=$(SYSROOT) +CFLAGS:=-O3 $(SYSROOT) +CXXFLAGS:=-O3 $(SYSROOT) +LDFLAGS:= $(SYSROOT) ARM_CFLAGS:=-march=armv6 # use this for debugging: #CFLAGS:=-O0 -g $(SYSROOT) DYNAMICLIBSTDCPP:=-lstdc++ -STATICLIBSTDCPP=$(SYSROOT)lib/libstdc++.a ifdef STATICLIBSTDCPP DYNAMICLIBSTDCPP:= endif @@ -126,7 +124,7 @@ djvu.o: %.o: %.c $(CC) -c $(KPDFREADER_CFLAGS) -I$(DJVUDIR)/ $< -o $@ cre.o: %.o: %.cpp - $(CC) -c -I$(CRENGINEDIR)/crengine/include/ -I$(LUADIR)/src $< -o $@ + $(CC) -c -I$(CRENGINEDIR)/crengine/include/ -I$(LUADIR)/src $< -o $@ -lstdc++ lfs.o: $(LFSDIR)/src/lfs.c $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ @@ -206,7 +204,7 @@ $(LUALIB): ifdef EMULATE_READER make -C $(LUADIR) else - make -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CROSS="$(HOST)-" TARGET_FLAGS="--sysroot=$(SYSROOT) -DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2" + 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) From dadbf000c9d0c6e8bd5cfe275ad3e54f3c473100 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 28 Aug 2012 20:49:11 +0200 Subject: [PATCH 05/27] coolreader search highlight This is rough port of Android code, but seems to work Conflicts: cre.cpp crereader.lua --- cre.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/cre.cpp b/cre.cpp index c2fe620da..5f565941d 100644 --- a/cre.cpp +++ b/cre.cpp @@ -17,6 +17,7 @@ along with this program. If not, see . */ +#define DEBUG_CRENGINE 1 extern "C" { #include "blitbuffer.h" @@ -443,6 +444,73 @@ static int registerFont(lua_State *L) { return 0; } +// ported from Android UI kpvcrlib/crengine/android/jni/docview.cpp + +static int findText(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + const char *l_pattern = luaL_checkstring(L, 2); + lString16 pattern = lString16(l_pattern); + int origin = luaL_checkint(L, 3); + bool reverse = luaL_checkint(L, 4); + bool caseInsensitive = luaL_checkint(L, 5); + const char *l_lastPatt = luaL_checkstring(L, 6); + lString16 _lastPattern = lString16(l_lastPatt); + + if ( pattern.empty() ) + return 0; + if ( pattern!=_lastPattern && origin==1 ) + origin = 0; + _lastPattern = pattern; + LVArray words; + lvRect rc; + doc->text_view->GetPos( rc ); + int pageHeight = rc.height(); + int start = -1; + int end = -1; + if ( reverse ) { + // reverse + if ( origin == 0 ) { + // from end current page to first page + end = rc.bottom; + } else if ( origin == -1 ) { + // from last page to end of current page + start = rc.bottom; + } else { // origin == 1 + // from prev page to first page + end = rc.top; + } + } else { + // forward + if ( origin == 0 ) { + // from current page to last page + start = rc.top; + } else if ( origin == -1 ) { + // from first page to current page + end = rc.top; + } else { // origin == 1 + // from next page to last + start = rc.bottom; + } + } + CRLog::debug("CRViewDialog::findText: Current page: %d .. %d", rc.top, rc.bottom); + CRLog::debug("CRViewDialog::findText: searching for text '%s' from %d to %d origin %d", LCSTR(pattern), start, end, origin ); + if ( doc->text_view->getDocument()->findText( pattern, caseInsensitive, reverse, start, end, words, 200, pageHeight ) ) { + CRLog::debug("CRViewDialog::findText: pattern found"); + doc->text_view->clearSelection(); + doc->text_view->selectWords( words ); + ldomMarkedRangeList * ranges = doc->text_view->getMarkedRanges(); + if ( ranges ) { + if ( ranges->length()>0 ) { + int pos = ranges->get(0)->start.y; + doc->text_view->SetPos(pos); + } + } + return 0; + } + CRLog::debug("CRViewDialog::findText: pattern not found"); + return 0; +} + static const struct luaL_Reg cre_func[] = { {"openDocument", openDocument}, {"getFontFaces", getFontFaces}, @@ -480,6 +548,7 @@ static const struct luaL_Reg credocument_meth[] = { //{"cursorLeft", cursorLeft}, //{"cursorRight", cursorRight}, {"drawCurrentView", drawCurrentView}, + {"findText", findText}, {"close", closeDocument}, {"__gc", closeDocument}, {NULL, NULL} From 09440f600c588266ac46b0912736a40f12b1e4da Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 28 Aug 2012 21:56:46 +0200 Subject: [PATCH 06/27] correctly return first search position and refresh screen Conflicts: crereader.lua --- cre.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cre.cpp b/cre.cpp index 5f565941d..69ecb5499 100644 --- a/cre.cpp +++ b/cre.cpp @@ -453,14 +453,10 @@ static int findText(lua_State *L) { int origin = luaL_checkint(L, 3); bool reverse = luaL_checkint(L, 4); bool caseInsensitive = luaL_checkint(L, 5); - const char *l_lastPatt = luaL_checkstring(L, 6); - lString16 _lastPattern = lString16(l_lastPatt); if ( pattern.empty() ) return 0; - if ( pattern!=_lastPattern && origin==1 ) - origin = 0; - _lastPattern = pattern; + LVArray words; lvRect rc; doc->text_view->GetPos( rc ); @@ -502,7 +498,10 @@ static int findText(lua_State *L) { if ( ranges ) { if ( ranges->length()>0 ) { int pos = ranges->get(0)->start.y; - doc->text_view->SetPos(pos); + //doc->text_view->SetPos(pos); // commented out not to mask lua code which does the same + CRLog::debug("# SetPos = %d", pos); + lua_pushinteger(L, pos); + return 1; } } return 0; From 3cd19db601a6ca46152b8a95954bedb5852416eb Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 28 Aug 2012 22:14:57 +0200 Subject: [PATCH 07/27] showInfoMsgWithDelay with number of results Conflicts: crereader.lua --- cre.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cre.cpp b/cre.cpp index 69ecb5499..c17c83be6 100644 --- a/cre.cpp +++ b/cre.cpp @@ -500,8 +500,9 @@ static int findText(lua_State *L) { int pos = ranges->get(0)->start.y; //doc->text_view->SetPos(pos); // commented out not to mask lua code which does the same CRLog::debug("# SetPos = %d", pos); + lua_pushinteger(L, ranges->length()); // results found lua_pushinteger(L, pos); - return 1; + return 2; } } return 0; From 3d291f52acde1b183640212f2a7b1fb1d054175d Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 28 Aug 2012 23:15:34 +0200 Subject: [PATCH 08/27] disable DEBUG_CRENGINE --- cre.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cre.cpp b/cre.cpp index c17c83be6..609467bbc 100644 --- a/cre.cpp +++ b/cre.cpp @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#define DEBUG_CRENGINE 1 +#define DEBUG_CRENGINE 0 extern "C" { #include "blitbuffer.h" From 0d23340738188e0b30ee668a71a683e9ca0165fd Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Tue, 28 Aug 2012 23:48:56 +0100 Subject: [PATCH 09/27] Move render_mode support out of unireader.lua into djvureader.lua as it is djvu-specific. Also added support for all other rendering modes handled by djvulibre. Also made the message print a human-readable description of the mode rather than just the number. Conflicts: djvureader.lua unireader.lua --- djvu.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/djvu.c b/djvu.c index 9253b404e..2f63940a6 100644 --- a/djvu.c +++ b/djvu.c @@ -378,15 +378,9 @@ static int drawPage(lua_State *L) { DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); BlitBuffer *bb = (BlitBuffer*) luaL_checkudata(L, 3, "blitbuffer"); int render_mode = (int) luaL_checkint(L, 6); - ddjvu_render_mode_t djvu_render_mode; + ddjvu_render_mode_t djvu_render_mode = render_mode; unsigned char adjusted_low[16], adjusted_high[16]; int i, adjust_pixels = 0; - - if (render_mode) - djvu_render_mode = DDJVU_RENDER_BLACK; - else - djvu_render_mode = DDJVU_RENDER_COLOR; - ddjvu_format_t *pixelformat; ddjvu_rect_t pagerect, renderrect; uint8_t *imagebuffer = NULL; From 7f6d3097a20076bc73c5ddea6b168125f4305788 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Wed, 29 Aug 2012 10:02:31 +0100 Subject: [PATCH 10/27] Remove the local variable render_mode from drawPage() (although it would be optimized away by gcc anyway). --- djvu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/djvu.c b/djvu.c index 2f63940a6..4d6dcd7a5 100644 --- a/djvu.c +++ b/djvu.c @@ -377,8 +377,7 @@ static int drawPage(lua_State *L) { DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); BlitBuffer *bb = (BlitBuffer*) luaL_checkudata(L, 3, "blitbuffer"); - int render_mode = (int) luaL_checkint(L, 6); - ddjvu_render_mode_t djvu_render_mode = render_mode; + ddjvu_render_mode_t djvu_render_mode = (int) luaL_checkint(L, 6); unsigned char adjusted_low[16], adjusted_high[16]; int i, adjust_pixels = 0; ddjvu_format_t *pixelformat; From b761418236c1422de122f741d01acb1e78d02efe Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sun, 2 Sep 2012 18:22:15 +0100 Subject: [PATCH 11/27] Small optimization in djvu.c:drawPage() --- there is no need to create and destroy djvu pixel format on each redraw of the page as this can be done once on open and close of the document. Also, set dither bits to 4 to help djvulibre choose the most optimal dithering algorithm for the Kindle. Also, make coding style of "if(" -> "if (" consistent (both instances were used, but "if (" was more frequent). Conflicts: djvu.c --- djvu.c | 113 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 38 deletions(-) diff --git a/djvu.c b/djvu.c index 4d6dcd7a5..7772c41f1 100644 --- a/djvu.c +++ b/djvu.c @@ -31,6 +31,7 @@ typedef struct DjvuDocument { ddjvu_context_t *context; ddjvu_document_t *doc_ref; + ddjvu_format_t *pixelformat; } DjvuDocument; typedef struct DjvuPage { @@ -92,6 +93,14 @@ static int openDocument(lua_State *L) { return luaL_error(L, "cannot open DJVU file <%s>", filename); } + doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL); + if (! doc->pixelformat) { + return luaL_error(L, "cannot create DJVU pixelformat for <%s>", filename); + } + ddjvu_format_set_row_order(doc->pixelformat, 1); + ddjvu_format_set_y_direction(doc->pixelformat, 1); + ddjvu_format_set_ditherbits(doc->pixelformat, 4); + return 1; } @@ -99,14 +108,18 @@ static int closeDocument(lua_State *L) { DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); // should be save if called twice - if(doc->doc_ref != NULL) { + if (doc->doc_ref != NULL) { ddjvu_document_release(doc->doc_ref); doc->doc_ref = NULL; } - if(doc->context != NULL) { + if (doc->context != NULL) { ddjvu_context_release(doc->context); doc->context = NULL; } + if (doc->pixelformat != NULL) { + ddjvu_format_release(doc->pixelformat); + doc->pixelformat = NULL; + } return 0; } @@ -178,7 +191,7 @@ static int openPage(lua_State *L) { DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); int pageno = luaL_checkint(L, 2); - if(pageno < 1 || pageno > ddjvu_document_get_pagenum(doc->doc_ref)) { + if (pageno < 1 || pageno > ddjvu_document_get_pagenum(doc->doc_ref)) { return luaL_error(L, "cannot open page #%d, out of range (1-%d)", pageno, ddjvu_document_get_pagenum(doc->doc_ref)); } @@ -190,7 +203,7 @@ static int openPage(lua_State *L) { page->page_ref = ddjvu_page_create_by_pageno(doc->doc_ref, pageno - 1); while (! ddjvu_page_decoding_done(page->page_ref)) handle(L, doc->context, TRUE); - if(! page->page_ref) { + if (! page->page_ref) { return luaL_error(L, "cannot open page #%d", pageno); } @@ -230,6 +243,23 @@ static int getUsedBBox(lua_State *L) { return 4; } +static int getOriginalPageSize(lua_State *L) { + DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); + int pageno = luaL_checkint(L, 2); + + ddjvu_status_t r; + ddjvu_pageinfo_t info; + + while ((r=ddjvu_document_get_pageinfo( + doc->doc_ref, pageno-1, &info))context, TRUE); + } + + lua_pushnumber(L, info.width); + lua_pushnumber(L, info.height); + + return 2; +} /* * Return a table like following: @@ -255,6 +285,17 @@ static int getPageText(lua_State *L) { DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); int pageno = luaL_checkint(L, 2); + /* get page height for coordinates transform */ + ddjvu_pageinfo_t info; + ddjvu_status_t r; + while ((r=ddjvu_document_get_pageinfo( + doc->doc_ref, pageno-1, &info))context, TRUE); + } + if (r>=DDJVU_JOB_FAILED) + return luaL_error(L, "cannot get page #%d information", pageno); + + /* start retrieving page text */ miniexp_t sexp, se_line, se_word; int i = 1, j = 1, counter_l = 1, counter_w=1, nr_line = 0, nr_word = 0; @@ -278,7 +319,7 @@ static int getPageText(lua_State *L) { /* retrive one line entry */ se_line = miniexp_nth(i, sexp); nr_word = miniexp_length(se_line); - if(nr_word == 0) { + if (nr_word == 0) { continue; } @@ -292,16 +333,18 @@ static int getPageText(lua_State *L) { lua_pushnumber(L, miniexp_to_int(miniexp_nth(1, se_line))); lua_settable(L, -3); - lua_pushstring(L, "y0"); - lua_pushnumber(L, miniexp_to_int(miniexp_nth(2, se_line))); + lua_pushstring(L, "y1"); + lua_pushnumber(L, + info.height - miniexp_to_int(miniexp_nth(2, se_line))); lua_settable(L, -3); lua_pushstring(L, "x1"); lua_pushnumber(L, miniexp_to_int(miniexp_nth(3, se_line))); lua_settable(L, -3); - lua_pushstring(L, "y1"); - lua_pushnumber(L, miniexp_to_int(miniexp_nth(4, se_line))); + lua_pushstring(L, "y0"); + lua_pushnumber(L, + info.height - miniexp_to_int(miniexp_nth(4, se_line))); lua_settable(L, -3); /* now loop through each word in the line */ @@ -325,16 +368,18 @@ static int getPageText(lua_State *L) { lua_pushnumber(L, miniexp_to_int(miniexp_nth(1, se_word))); lua_settable(L, -3); - lua_pushstring(L, "y0"); - lua_pushnumber(L, miniexp_to_int(miniexp_nth(2, se_word))); + lua_pushstring(L, "y1"); + lua_pushnumber(L, + info.height - miniexp_to_int(miniexp_nth(2, se_word))); lua_settable(L, -3); lua_pushstring(L, "x1"); lua_pushnumber(L, miniexp_to_int(miniexp_nth(3, se_word))); lua_settable(L, -3); - lua_pushstring(L, "y1"); - lua_pushnumber(L, miniexp_to_int(miniexp_nth(4, se_word))); + lua_pushstring(L, "y0"); + lua_pushnumber(L, + info.height - miniexp_to_int(miniexp_nth(4, se_word))); lua_settable(L, -3); lua_pushstring(L, "word"); @@ -355,8 +400,8 @@ static int getPageText(lua_State *L) { static int closePage(lua_State *L) { DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage"); - // should be save if called twice - if(page->page_ref != NULL) { + // should be safe if called twice + if (page->page_ref != NULL) { ddjvu_page_release(page->page_ref); page->page_ref = NULL; } @@ -380,47 +425,41 @@ static int drawPage(lua_State *L) { ddjvu_render_mode_t djvu_render_mode = (int) luaL_checkint(L, 6); unsigned char adjusted_low[16], adjusted_high[16]; int i, adjust_pixels = 0; - ddjvu_format_t *pixelformat; ddjvu_rect_t pagerect, renderrect; - uint8_t *imagebuffer = NULL; + uint8_t *imagebuffer = malloc((bb->w)*(bb->h)+1); + + /*printf("@page %d, @@zoom:%f, offset: (%d, %d)\n", page->num, dc->zoom, dc->offset_x, dc->offset_y);*/ - imagebuffer = malloc((bb->w)*(bb->h)+1); /* fill pixel map with white color */ memset(imagebuffer, 0xFF, (bb->w)*(bb->h)+1); - pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL); - ddjvu_format_set_row_order(pixelformat, 1); - ddjvu_format_set_y_direction(pixelformat, 1); - ddjvu_format_set_gamma(pixelformat, dc->gamma); - /*ddjvu_format_set_ditherbits(dc->pixelformat, 2);*/ - /* render full page into rectangle specified by pagerect */ pagerect.x = 0; pagerect.y = 0; pagerect.w = page->info.width * dc->zoom; pagerect.h = page->info.height * dc->zoom; + /*printf("--pagerect--- (x: %d, y: %d), w: %d, h: %d.\n", 0, 0, pagerect.w, pagerect.h);*/ /* copy pixels area from pagerect specified by renderrect. - + * * ddjvulibre library does not support negative offset, positive offset * means moving towards right and down. * - * However, djvureader.lua handles offset differently. It use negative + * However, djvureader.lua handles offset differently. It uses negative * offset to move right and down while positive offset to move left * and up. So we need to handle positive offset manually when copying * imagebuffer to blitbuffer (framebuffer). */ - renderrect.x = luaL_checkint(L, 4); - renderrect.y = luaL_checkint(L, 5); - /*renderrect.x = MAX(-dc->offset_x, 0);*/ - /*renderrect.y = MAX(-dc->offset_y, 0);*/ + renderrect.x = MAX(-dc->offset_x, 0); + renderrect.y = MAX(-dc->offset_y, 0); renderrect.w = MIN(pagerect.w - renderrect.x, bb->w); renderrect.h = MIN(pagerect.h - renderrect.y, bb->h); + /*printf("--renderrect--- (%d, %d), w:%d, h:%d\n", renderrect.x, renderrect.y, renderrect.w, renderrect.h);*/ /* ddjvulibre library only supports rotation of 0, 90, 180 and 270 degrees. - * This four kinds of rotations can already be achieved by native system. + * These four kinds of rotations can already be achieved by native system. * So we don't set rotation here. */ @@ -428,12 +467,12 @@ static int drawPage(lua_State *L) { djvu_render_mode, &pagerect, &renderrect, - pixelformat, + page->doc->pixelformat, bb->w, imagebuffer); - uint8_t *bbptr = (uint8_t*)bb->data; - uint8_t *pmptr = (uint8_t*)imagebuffer; + uint8_t *bbptr = bb->data; + uint8_t *pmptr = imagebuffer; int x, y; /* if offset is positive, we are moving towards up and left. */ int x_offset = MAX(0, dc->offset_x); @@ -460,7 +499,7 @@ static int drawPage(lua_State *L) { else bbptr[x] = (high << 4) | low; } - if(bb->w & 1) { + if (bb->w & 1) { bbptr[x] = 255 - (pmptr[x*2] & 0xF0); } /* go to next line */ @@ -469,9 +508,6 @@ static int drawPage(lua_State *L) { } free(imagebuffer); - pmptr = imagebuffer = NULL; - ddjvu_format_release(pixelformat); - return 0; } @@ -500,6 +536,7 @@ static const struct luaL_Reg djvudocument_meth[] = { {"getPages", getNumberOfPages}, {"getToc", getTableOfContent}, {"getPageText", getPageText}, + {"getOriginalPageSize", getOriginalPageSize}, {"close", closeDocument}, {"getCacheSize", getCacheSize}, {"cleanCache", cleanCache}, From bbbd64d96eb896ad29a8776002e456c042bd3ec4 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sun, 2 Sep 2012 18:57:37 +0100 Subject: [PATCH 12/27] Comment out the setting of dithering bits because djvulibre ignores anything less than 8 bits anyway. --- djvu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/djvu.c b/djvu.c index 7772c41f1..fa882c462 100644 --- a/djvu.c +++ b/djvu.c @@ -99,7 +99,8 @@ static int openDocument(lua_State *L) { } ddjvu_format_set_row_order(doc->pixelformat, 1); ddjvu_format_set_y_direction(doc->pixelformat, 1); - ddjvu_format_set_ditherbits(doc->pixelformat, 4); + /* dithering bits <8 are ignored by djvulibre */ + /* ddjvu_format_set_ditherbits(doc->pixelformat, 4); */ return 1; } From 3278ef5a293184162b68aad23ee89e1b713c564c Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sat, 8 Sep 2012 22:21:26 +0100 Subject: [PATCH 13/27] Correct the comment (the existing text was referring to a different file). --- util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util.h b/util.h index e18c5f092..23bf52c2d 100644 --- a/util.h +++ b/util.h @@ -1,5 +1,5 @@ /* - KindlePDFViewer: buffer for blitting muPDF data to framebuffer (blitbuffer) + KindlePDFViewer: miscellaneous utility functions for Lua Copyright (C) 2011 Hans-Werner Hilse This program is free software: you can redistribute it and/or modify From 04e6df1fd00d53c69f2029fca8fcc4f842a48add Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 9 Sep 2012 12:58:04 +0200 Subject: [PATCH 14/27] use ldomDocCache::init to cache crengine DOM This should improve performance of crengine #206 --- cre.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cre.cpp b/cre.cpp index 609467bbc..9326c5ae5 100644 --- a/cre.cpp +++ b/cre.cpp @@ -567,6 +567,8 @@ int luaopen_cre(lua_State *L) { /* initialize font manager for CREngine */ InitFontManager(lString8()); + ldomDocCache::init(lString16("./cr3cache"), 100); + #ifdef DEBUG_CRENGINE CRLog::setStdoutLogger(); CRLog::setLogLevel(CRLog::LL_DEBUG); From e23cc2a1deb93cd89e3c161d1e558c47d7356dc1 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 10 Sep 2012 13:41:44 +0200 Subject: [PATCH 15/27] use 64Mb for on disk DOM cache for crengine Previously we had cache size limit of 100 bytes, so crengine would erase all on-disk cache on each file open as described in #206 --- cre.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cre.cpp b/cre.cpp index 9326c5ae5..e9d592b2d 100644 --- a/cre.cpp +++ b/cre.cpp @@ -567,7 +567,7 @@ int luaopen_cre(lua_State *L) { /* initialize font manager for CREngine */ InitFontManager(lString8()); - ldomDocCache::init(lString16("./cr3cache"), 100); + ldomDocCache::init(lString16("./cr3cache"), 1024 * 1024 * 64); // 64Mb on disk cache for DOM #ifdef DEBUG_CRENGINE CRLog::setStdoutLogger(); From 619f5a0f348e3881117c9200be9efef7c3a446f0 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 10 Sep 2012 21:45:05 +0800 Subject: [PATCH 16/27] set crengine cache size in lua code Conflicts: crereader.lua --- cre.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cre.cpp b/cre.cpp index e9d592b2d..ef3aca8b1 100644 --- a/cre.cpp +++ b/cre.cpp @@ -33,6 +33,13 @@ typedef struct CreDocument { ldomDocument *dom_doc; } CreDocument; +static int initCache(lua_State *L) { + int cache_size = luaL_optint(L, 1, (2 << 20) * 64); // 64Mb on disk cache for DOM + + ldomDocCache::init(lString16("./cr3cache"), cache_size); + + return 0; +} static int openDocument(lua_State *L) { const char *file_name = luaL_checkstring(L, 1); @@ -512,6 +519,7 @@ static int findText(lua_State *L) { } static const struct luaL_Reg cre_func[] = { + {"initCache", initCache}, {"openDocument", openDocument}, {"getFontFaces", getFontFaces}, {"getGammaIndex", getGammaIndex}, @@ -567,8 +575,6 @@ int luaopen_cre(lua_State *L) { /* initialize font manager for CREngine */ InitFontManager(lString8()); - ldomDocCache::init(lString16("./cr3cache"), 1024 * 1024 * 64); // 64Mb on disk cache for DOM - #ifdef DEBUG_CRENGINE CRLog::setStdoutLogger(); CRLog::setLogLevel(CRLog::LL_DEBUG); From 25af917170cc7a8021163323feb154abc1e01404 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 17 Sep 2012 20:12:33 -0400 Subject: [PATCH 17/27] call cre.initCache() in CreDocument:engineInit() --- frontend/document/credocument.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 8f9e0b48a..2828ad1d4 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -25,6 +25,9 @@ end function CreDocument:engineInit() if not engine_initilized then + -- initialize cache + cre.initCache(1024*1024*64) + -- we need to initialize the CRE font list local fonts = Font:getFontList() for _k, _v in ipairs(fonts) do From dfff1906fdb557d3a4f727b2adb786f8b08780c0 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 17 Sep 2012 20:21:03 -0400 Subject: [PATCH 18/27] return only one value in ReaderToc:cleanUpTocTitle(title) --- frontend/ui/reader/readertoc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/ui/reader/readertoc.lua b/frontend/ui/reader/readertoc.lua index 8528891dd..9671154c2 100644 --- a/frontend/ui/reader/readertoc.lua +++ b/frontend/ui/reader/readertoc.lua @@ -8,7 +8,7 @@ ReaderToc = InputContainer:new{ } function ReaderToc:cleanUpTocTitle(title) - return title:gsub("\13", "") + return (title:gsub("\13", "")) end function ReaderToc:onSetDimensions(dimen) From 97f59ed07c63328a61e62bc59fe254346d7c1718 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Fri, 14 Sep 2012 23:22:19 +0100 Subject: [PATCH 19/27] 1. It is customary to call DjVu context by the name of the program. 2. When changing DjVu page rendering mode there is no need to clear DjVu cache, only our own tile cache. Conflicts: djvureader.lua --- djvu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/djvu.c b/djvu.c index fa882c462..fe6758288 100644 --- a/djvu.c +++ b/djvu.c @@ -78,9 +78,9 @@ static int openDocument(lua_State *L) { luaL_getmetatable(L, "djvudocument"); lua_setmetatable(L, -2); - doc->context = ddjvu_context_create("DJVUReader"); + doc->context = ddjvu_context_create("kindlepdfviewer"); if (! doc->context) { - return luaL_error(L, "cannot create context."); + return luaL_error(L, "cannot create context"); } printf("## cache_size = %d\n", cache_size); @@ -90,12 +90,12 @@ static int openDocument(lua_State *L) { while (! ddjvu_document_decoding_done(doc->doc_ref)) handle(L, doc->context, True); if (! doc->doc_ref) { - return luaL_error(L, "cannot open DJVU file <%s>", filename); + return luaL_error(L, "cannot open DjVu file <%s>", filename); } doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL); if (! doc->pixelformat) { - return luaL_error(L, "cannot create DJVU pixelformat for <%s>", filename); + return luaL_error(L, "cannot create DjVu pixelformat for <%s>", filename); } ddjvu_format_set_row_order(doc->pixelformat, 1); ddjvu_format_set_y_direction(doc->pixelformat, 1); From e6a8f5558c64da783ac9fc2a96700589e93547b9 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 16 Sep 2012 12:17:47 -0400 Subject: [PATCH 20/27] move -l argument to the end of GCC call --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f15a1072e..e9929c7e8 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,7 @@ LUALIB := $(LUADIR)/src/libluajit.a all:kpdfview kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS) - $(CC) -lm -ldl -lpthread $(EMU_LDFLAGS) $(DYNAMICLIBSTDCPP) \ + $(CC) \ kpdfview.o \ einkfb.o \ pdf.o \ @@ -109,7 +109,7 @@ kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft cre.o \ $(CRENGINELIBS) \ $(STATICLIBSTDCPP) \ - -o kpdfview + -o kpdfview -lm -ldl -lpthread $(EMU_LDFLAGS) $(DYNAMICLIBSTDCPP) slider_watcher: slider_watcher.c $(CC) $(CFLAGS) $< -o $@ From cc78a43b92584a3a9018625981c285f722ac340b Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 17 Sep 2012 00:27:54 +0800 Subject: [PATCH 21/27] update readme --- README.TXT | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/README.TXT b/README.TXT index f05e506f8..a365d46c2 100644 --- a/README.TXT +++ b/README.TXT @@ -12,24 +12,26 @@ The application is licensed under the GPLv3 (see COPYING file). Building ======== + Follow these steps: -- install muPDF sources into subfolder "mupdf" -- install muPDF third-party sources (see muPDF homepage) into a new subfolder - "mupdf/thirdparty" +- fetch thirdparty sources + - manually fetch all the thirdparty sources: + - install muPDF sources into subfolder "mupdf" + - install muPDF third-party sources (see muPDF homepage) into a new + subfolder "mupdf/thirdparty" + - install libDjvuLibre sources into subfolder "djvulibre" + - install CREngine sources into subfolder "kpvcrlib/crengine" + - install LuaJit sources into subfolder "luajit-2.0" -- install libDjvuLibre sources into subfolder "djvulibre" -- install CREngine sources into subfolder "kpvcrlib/crengine" - -- 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". + - automatically fetch thirdparty sources with Makefile: + - make sure you have wget, unzip and git installed + - run "make fetchthirdparty". - adapt Makefile to your needs - run "make thirdparty". This will build MuPDF (plus the libraries it depends - on) and Lua. + on), libDjvuLibre, CREngine and Lua. - run "make". This will build the kpdfview application @@ -40,12 +42,14 @@ Running The user interface (or what's there yet) is scripted in Lua. See "reader.lua". It uses the Linux feature to run scripts by using a corresponding line at its start. + So you might just call that script. Note that the script and the kpdfview binary currently must be in the same directory. -You would then just call reader.lua, giving the document file path as its first -argument. Run reader.lua without arguments to see usage notes. -The reader.lua script can also show a file chooser: it will do this when you -call it with a directory (instead of a file) as first argument. + +You would then just call reader.lua, giving the document file path, or any +directory path, as its first argument. Run reader.lua without arguments to see +usage notes. The reader.lua script can also show a file chooser: it will do +this when you call it with a directory (instead of a file) as first argument. Device emulation @@ -54,7 +58,9 @@ Device emulation The code also features a device emulation. You need SDL headers and library for this. It allows to develop on a standard PC and saves precious development time. It might also compose the most unfriendly desktop PDF reader, depending -on your view. +on your view. + +If you are using Ubuntu, simply install `libsdl-dev1.2` package. To build in "emulation mode", you need to run make like this: make clean cleanthirdparty @@ -62,6 +68,8 @@ To build in "emulation mode", you need to run make like this: And run the emulator like this: ./reader.lua /PATH/TO/PDF.pdf +or: + ./reader.lua /ANY/PATH By default emulation will provide DXG resolution of 824*1200. It can be specified at compile time, this is example for Kindle 3: From 6ad8afebbb7d4debce3d91e01cb6269e3dd375c8 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 17 Sep 2012 01:56:58 +0800 Subject: [PATCH 22/27] rename README.TXT to README.md for better rendering in Github --- README.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..79e047939 --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +KindlePDFViewer +=============== + +This is a PDF viewer application, created for usage on the Kindle e-ink reader. +It is currently restricted to 4bpp inverse grayscale displays. It's using the +muPDF library (see http://mupdf.com/) and its UI is scripted using Lua (see +http://www.lua.org/). + +The application is licensed under the GPLv3 (see COPYING file). + + +Building +======== + + +Follow these steps: + +* fetch thirdparty sources + * manually fetch all the thirdparty sources: + * install muPDF sources into subfolder "mupdf" + * install muPDF third-party sources (see muPDF homepage) into a new + subfolder "mupdf/thirdparty" + * install libDjvuLibre sources into subfolder "djvulibre" + * install CREngine sources into subfolder "kpvcrlib/crengine" + * install LuaJit sources into subfolder "luajit-2.0" + + * automatically fetch thirdparty sources with Makefile: + * make sure you have wget, unzip and git installed + * run "make fetchthirdparty". + +* adapt Makefile to your needs + +* run `make thirdparty`. This will build MuPDF (plus the libraries it depends + on), libDjvuLibre, CREngine and Lua. + +* run `make`. This will build the kpdfview application + + +Running +======= + +The user interface (or what's there yet) is scripted in Lua. See "reader.lua". +It uses the Linux feature to run scripts by using a corresponding line at its +start. + +So you might just call that script. Note that the script and the kpdfview +binary currently must be in the same directory. + +You would then just call reader.lua, giving the document file path, or any +directory path, as its first argument. Run reader.lua without arguments to see +usage notes. The reader.lua script can also show a file chooser: it will do +this when you call it with a directory (instead of a file) as first argument. + + +Device emulation +================ + +The code also features a device emulation. You need SDL headers and library +for this. It allows to develop on a standard PC and saves precious development +time. It might also compose the most unfriendly desktop PDF reader, depending +on your view. + +If you are using Ubuntu, simply install `libsdl-dev1.2` package. + +To build in "emulation mode", you need to run make like this: + make clean cleanthirdparty + EMULATE_READER=1 make thirdparty kpdfview + +And run the emulator like this: +``` + ./reader.lua /PATH/TO/PDF.pdf +``` +or: +``` + ./reader.lua /ANY/PATH +``` + +By default emulation will provide DXG resolution of 824*1200. It can be +specified at compile time, this is example for Kindle 3: + +``` + EMULATE_READER_W=600 EMULATE_READER_H=800 EMULATE_READER=1 make kpdfview +``` + From 825de1ea4f0541873b69befeeeeed4bf03685d4c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 17 Sep 2012 01:59:19 +0800 Subject: [PATCH 23/27] remove leading tab in command in README --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 79e047939..f46ec04c7 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Follow these steps: * automatically fetch thirdparty sources with Makefile: * make sure you have wget, unzip and git installed - * run "make fetchthirdparty". + * run `make fetchthirdparty`. * adapt Makefile to your needs @@ -68,17 +68,18 @@ To build in "emulation mode", you need to run make like this: And run the emulator like this: ``` - ./reader.lua /PATH/TO/PDF.pdf +./reader.lua /PATH/TO/PDF.pdf ``` + or: ``` - ./reader.lua /ANY/PATH +./reader.lua /ANY/PATH ``` By default emulation will provide DXG resolution of 824*1200. It can be specified at compile time, this is example for Kindle 3: ``` - EMULATE_READER_W=600 EMULATE_READER_H=800 EMULATE_READER=1 make kpdfview +EMULATE_READER_W=600 EMULATE_READER_H=800 EMULATE_READER=1 make kpdfview ``` From 68eeeaa0d2314689602b8c068f99975b3432f161 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 17 Sep 2012 06:04:40 +0800 Subject: [PATCH 24/27] delete README.TXT --- README.TXT | 78 ------------------------------------------------------ 1 file changed, 78 deletions(-) delete mode 100644 README.TXT diff --git a/README.TXT b/README.TXT deleted file mode 100644 index a365d46c2..000000000 --- a/README.TXT +++ /dev/null @@ -1,78 +0,0 @@ -KindlePDFViewer -=============== - -This is a PDF viewer application, created for usage on the Kindle e-ink reader. -It is currently restricted to 4bpp inverse grayscale displays. It's using the -muPDF library (see http://mupdf.com/) and its UI is scripted using Lua (see -http://www.lua.org/). - -The application is licensed under the GPLv3 (see COPYING file). - - -Building -======== - - -Follow these steps: - -- fetch thirdparty sources - - manually fetch all the thirdparty sources: - - install muPDF sources into subfolder "mupdf" - - install muPDF third-party sources (see muPDF homepage) into a new - subfolder "mupdf/thirdparty" - - install libDjvuLibre sources into subfolder "djvulibre" - - install CREngine sources into subfolder "kpvcrlib/crengine" - - install LuaJit sources into subfolder "luajit-2.0" - - - automatically fetch thirdparty sources with Makefile: - - make sure you have wget, unzip and git installed - - run "make fetchthirdparty". - -- adapt Makefile to your needs - -- run "make thirdparty". This will build MuPDF (plus the libraries it depends - on), libDjvuLibre, CREngine and Lua. - -- run "make". This will build the kpdfview application - - -Running -======= - -The user interface (or what's there yet) is scripted in Lua. See "reader.lua". -It uses the Linux feature to run scripts by using a corresponding line at its -start. - -So you might just call that script. Note that the script and the kpdfview -binary currently must be in the same directory. - -You would then just call reader.lua, giving the document file path, or any -directory path, as its first argument. Run reader.lua without arguments to see -usage notes. The reader.lua script can also show a file chooser: it will do -this when you call it with a directory (instead of a file) as first argument. - - -Device emulation -================ - -The code also features a device emulation. You need SDL headers and library -for this. It allows to develop on a standard PC and saves precious development -time. It might also compose the most unfriendly desktop PDF reader, depending -on your view. - -If you are using Ubuntu, simply install `libsdl-dev1.2` package. - -To build in "emulation mode", you need to run make like this: - make clean cleanthirdparty - EMULATE_READER=1 make thirdparty kpdfview - -And run the emulator like this: - ./reader.lua /PATH/TO/PDF.pdf -or: - ./reader.lua /ANY/PATH - -By default emulation will provide DXG resolution of 824*1200. It can be -specified at compile time, this is example for Kindle 3: - - EMULATE_READER_W=600 EMULATE_READER_H=800 EMULATE_READER=1 make kpdfview - From 83d910b7d3b134abb33148d10b254b0d472f7251 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 17 Sep 2012 22:38:05 +0200 Subject: [PATCH 25/27] use README.md in distribution zip Conflicts: Makefile --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e9929c7e8..b0404c75d 100644 --- a/Makefile +++ b/Makefile @@ -211,6 +211,8 @@ thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) $(CRENGINELIBS) INSTALL_DIR=kindlepdfviewer +LUA_FILES=reader.lua + VERSION?=$(shell git rev-parse --short HEAD) customupdate: all # ensure that build binary is for ARM @@ -219,7 +221,7 @@ customupdate: all -rm kindlepdfviewer-$(VERSION).zip rm -Rf $(INSTALL_DIR) mkdir $(INSTALL_DIR) - cp -p README.TXT COPYING kpdfview *.lua $(INSTALL_DIR) + cp -p README.md COPYING kpdfview $(LUA_FILES) $(INSTALL_DIR) mkdir $(INSTALL_DIR)/data cp -rpL data/*.css $(INSTALL_DIR)/data cp -rpL fonts $(INSTALL_DIR) From eb79e1c95ca0a9eb771a9be67cd9222f0828edca Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 17 Sep 2012 20:36:39 -0400 Subject: [PATCH 26/27] handle file with no extension in filechooser --- frontend/document/document.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 89a365607..9a173f183 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -11,7 +11,7 @@ end function DocumentRegistry:getProvider(file) -- TODO: some implementation based on mime types? - local extension = string.lower(string.match(file, ".+%.([^.]+)")) + local extension = string.lower(string.match(file, ".+%.([^.]+)") or "") for _, provider in ipairs(self.providers) do if extension == provider.extension then return provider.provider From 61bc799de4cc4304cda791bb6b781f990aba7a25 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 17 Sep 2012 20:44:09 -0400 Subject: [PATCH 27/27] update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f46ec04c7..0093a9ebd 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ KindlePDFViewer =============== This is a PDF viewer application, created for usage on the Kindle e-ink reader. -It is currently restricted to 4bpp inverse grayscale displays. It's using the -muPDF library (see http://mupdf.com/) and its UI is scripted using Lua (see -http://www.lua.org/). +It currently supports Kindle 2, DXG, 3 and 4, but not Touch. It's using the +muPDF library (see http://mupdf.com/), djvulibre library, CREngine library and +its UI is scripted using Lua (see http://www.lua.org/). The application is licensed under the GPLv3 (see COPYING file).