From 6ad4721f6a1949668117c878c28c7788ac301ffa Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 27 Mar 2012 16:32:41 +0800 Subject: [PATCH 01/40] add: crengine as submodule --- .gitmodules | 3 +++ crengine | 1 + 2 files changed, 4 insertions(+) create mode 160000 crengine diff --git a/.gitmodules b/.gitmodules index 77f6eecd4..6c5c235cf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "djvulibre"] path = djvulibre url = git://djvu.git.sourceforge.net/gitroot/djvu/djvulibre.git +[submodule "crengine"] + path = crengine + url = git://crengine.git.sourceforge.net/gitroot/crengine/crengine diff --git a/crengine b/crengine new file mode 160000 index 000000000..e0a86d85a --- /dev/null +++ b/crengine @@ -0,0 +1 @@ +Subproject commit e0a86d85a3da3bed48a84fd3096ee6040ba1ba34 From 4821f10dda6161dadd65218eef88ab9d59152ad7 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 29 Mar 2012 00:09:26 +0800 Subject: [PATCH 02/40] half done demo for crengine --- Makefile | 40 +++++++++++++++++++++++++++++++++------- filechooser.lua | 2 +- filesearcher.lua | 7 ++++++- kpdfview.c | 3 +++ reader.lua | 4 ++++ unireader.lua | 12 ++++++++---- 6 files changed, 55 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index ce64f0778..24f637bf3 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ MUPDFDIR=mupdf MUPDFTARGET=build/debug MUPDFLIBDIR=$(MUPDFDIR)/$(MUPDFTARGET) DJVUDIR=djvulibre +CRENGINEDIR=crengine FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.8 LFSDIR=luafilesystem @@ -55,16 +56,26 @@ KPDFREADER_CFLAGS=$(CFLAGS) -I$(LUADIR)/src -I$(MUPDFDIR)/ MUPDFLIBS := $(MUPDFLIBDIR)/libfitz.a DJVULIBS := $(DJVUDIR)/build/libdjvu/.libs/libdjvulibre.a +CRENGINELIBS := $(CRENGINEDIR)/crengine/libcrengine.a \ + $(CRENGINEDIR)/thirdparty/chmlib/libchmlib.a \ + $(CRENGINEDIR)/thirdparty/libpng/libpng.a \ + $(CRENGINEDIR)/thirdparty/libjpeg/libjpeg.a \ + $(CRENGINEDIR)/thirdparty/zlib/libz.a \ + $(CRENGINEDIR)/thirdparty/antiword/libantiword.a THIRDPARTYLIBS := $(MUPDFLIBDIR)/libfreetype.a \ - $(MUPDFLIBDIR)/libjpeg.a \ - $(MUPDFLIBDIR)/libopenjpeg.a \ - $(MUPDFLIBDIR)/libjbig2dec.a \ - $(MUPDFLIBDIR)/libz.a + $(MUPDFLIBDIR)/libopenjpeg.a \ + $(MUPDFLIBDIR)/libjbig2dec.a \ + $(MUPDFLIBDIR)/libz.a + +# @TODO the libjpeg used by mupdf is too new for crengine and will cause +# a segment fault when decoding jpeg images in crengine, we need to fix +# this. 28.03 2012 (houqp) + #$(MUPDFLIBDIR)/libjpeg.a LUALIB := $(LUADIR)/src/liblua.a -kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft.o lfs.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) djvu.o - $(CC) -lm -ldl -lpthread $(EMU_LDFLAGS) -lstdc++ \ +kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft.o lfs.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS) + $(CC) -lm -ldl -lpthread $(EMU_LDFLAGS) -lstdc++ \ kpdfview.o \ einkfb.o \ pdf.o \ @@ -79,6 +90,8 @@ kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft $(LUALIB) \ djvu.o \ $(DJVULIBS) \ + cre.o \ + $(CRENGINELIBS) \ -o kpdfview einkfb.o input.o: %.o: %.c @@ -93,6 +106,9 @@ kpdfview.o pdf.o blitbuffer.o util.o drawcontext.o: %.o: %.c djvu.o: %.o: %.c $(CC) -c $(KPDFREADER_CFLAGS) -I$(DJVUDIR)/ $< -o $@ +cre.o: %.o: %.cpp + $(CC) -c -I$(CRENGINEDIR)/crengine/include/ $< -o $@ -lstdc++ + lfs.o: $(LFSDIR)/src/lfs.c $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ @@ -112,6 +128,7 @@ clean: cleanthirdparty: make -C $(LUADIR) clean make -C $(MUPDFDIR) clean + make -C $(CRENGINEDIR) clean -rm -rf $(DJVUDIR)/build -rm -f $(MUPDFDIR)/fontdump.host -rm -f $(MUPDFDIR)/cmapdump.host @@ -139,10 +156,19 @@ else endif make -C $(DJVUDIR)/build +$(CRENGINELIBS): + cd $(CRENGINEDIR) && cmake -D CR3_PNG=1 -D CR3_JPEG=1 . + cd $(CRENGINEDIR)/crengine && make + cd $(CRENGINEDIR)/thirdparty/libjpeg && make + cd $(CRENGINEDIR)/thirdparty/chmlib && make + cd $(CRENGINEDIR)/thirdparty/antiword && make + cd $(CRENGINEDIR)/thirdparty/libpng && make + cd $(CRENGINEDIR)/thirdparty/zlib && make + $(LUALIB): make -C lua/src CC="$(CC)" CFLAGS="$(CFLAGS)" MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E" liblua.a -thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) +thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) $(CRENGINELIBS) INSTALL_DIR=kindlepdfviewer diff --git a/filechooser.lua b/filechooser.lua index c4e2f1378..e1be925cb 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -54,7 +54,7 @@ function FileChooser:readDir() table.insert(self.dirs, f) else local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "") - if file_type == "djvu" or file_type == "pdf" or file_type == "xps" or file_type == "cbz" then + if file_type == "djvu" or file_type == "pdf" or file_type == "xps" or file_type == "cbz" or file_type == "epub" or file_type == "txt" or file_type == "rtf" or file_type == "htm" or file_type == "fb2" or file_type == "chm" then table.insert(self.files, f) end end diff --git a/filesearcher.lua b/filesearcher.lua index f2792c268..097fb5c57 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -30,10 +30,15 @@ function FileSearcher:readDir() for __, d in pairs(self.dirs) do -- handle files in d for f in lfs.dir(d) do + local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "") if lfs.attributes(d.."/"..f, "mode") == "directory" and f ~= "." and f~= ".." and not string.match(f, "^%.[^.]") then table.insert(new_dirs, d.."/"..f) - elseif string.match(f, ".+%.[pP][dD][fF]$") or string.match(f, ".+%.[dD][jJ][vV][uU]$") then + elseif file_type == "djvu" or file_type == "pdf" + or file_type == "xps" or file_type == "cbz" + or file_type == "epub" or file_type == "txt" + or file_type == "rtf" or file_type == "htm" + or file_type == "fb2" or file_type == "chm" then file_entry = {dir=d, name=f,} table.insert(self.files, file_entry) --print("file:"..d.."/"..f) diff --git a/kpdfview.c b/kpdfview.c index d14a38053..a09a9a0ab 100644 --- a/kpdfview.c +++ b/kpdfview.c @@ -26,6 +26,8 @@ #include "blitbuffer.h" #include "drawcontext.h" #include "pdf.h" +#include "djvu.h" +#include "cre.h" #include "einkfb.h" #include "input.h" #include "ft.h" @@ -53,6 +55,7 @@ int main(int argc, char **argv) { luaopen_einkfb(L); luaopen_pdf(L); luaopen_djvu(L); + luaopen_cre(L); luaopen_input(L); luaopen_util(L); luaopen_ft(L); diff --git a/reader.lua b/reader.lua index 0ad9da911..1d4e7bb6e 100755 --- a/reader.lua +++ b/reader.lua @@ -20,6 +20,7 @@ require "alt_getopt" require "pdfreader" require "djvureader" +require "crereader" require "filechooser" require "settings" require "screen" @@ -42,6 +43,8 @@ function openFile(filename) reader = DJVUReader elseif file_type == "pdf" or file_type == "xps" or file_type == "cbz" then reader = PDFReader + elseif file_type == "epub" or file_type == "txt" or file_type == "rtf" or file_type == "htm" or file_type == "fb2" or file_type == "chm" then + reader = CREReader end if reader then local ok, err = reader:open(filename) @@ -133,6 +136,7 @@ UniReader:initGlobalSettings(reader_settings) -- initialize specific readers PDFReader:init() DJVUReader:init() +CREReader:init() -- display directory or open file local patharg = reader_settings:readSetting("lastfile") diff --git a/unireader.lua b/unireader.lua index bf956be15..56f96fbf2 100644 --- a/unireader.lua +++ b/unireader.lua @@ -493,7 +493,7 @@ function UniReader:addJump(pageno, notes) local notes_to_add = notes if not notes_to_add then -- no notes given, auto generate from TOC entry - notes_to_add = self:getTOCTitleByPage(self.pageno) + notes_to_add = self:getTocTitleByPage(self.pageno) if notes_to_add ~= "" then notes_to_add = "in "..notes_to_add end @@ -563,6 +563,10 @@ function UniReader:goto(no) end end +function UniReader:redrawCurrentPage() + self:goto(self.pageno) +end + function UniReader:nextView() local pageno = self.pageno @@ -659,7 +663,7 @@ function UniReader:fillTOC() self.toc = self.doc:getTOC() end -function UniReader:getTOCTitleByPage(pageno) +function UniReader:getTocTitleByPage(pageno) if not self.toc then -- build toc when needed. self:fillTOC() @@ -734,7 +738,7 @@ function UniReader:showMenu() ypos = ypos + 15 local face, fhash = Font:getFaceAndHash(22) - local cur_section = self:getTOCTitleByPage(self.pageno) + local cur_section = self:getTocTitleByPage(self.pageno) if cur_section ~= "" then cur_section = "Section: "..cur_section end @@ -1010,7 +1014,7 @@ function UniReader:addAllCommands() "open menu", function(unireader) unireader:showMenu() - unireader:goto(unireader.pageno) + unireader:redrawCurrentPage() end) -- panning local panning_keys = {Keydef:new(KEY_FW_LEFT,MOD_ANY),Keydef:new(KEY_FW_RIGHT,MOD_ANY),Keydef:new(KEY_FW_UP,MOD_ANY),Keydef:new(KEY_FW_DOWN,MOD_ANY),Keydef:new(KEY_FW_PRESS,MOD_ANY)} From c56516d5d148ca780ebaffa059b98463c58e9ac4 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 29 Mar 2012 00:16:00 +0800 Subject: [PATCH 03/40] add: data from crengine --- Makefile | 1 + cre.cpp | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++ cre.h | 28 +++++++ crereader.lua | 57 +++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 cre.cpp create mode 100644 cre.h create mode 100644 crereader.lua diff --git a/Makefile b/Makefile index 24f637bf3..5744031ce 100644 --- a/Makefile +++ b/Makefile @@ -164,6 +164,7 @@ $(CRENGINELIBS): cd $(CRENGINEDIR)/thirdparty/antiword && make cd $(CRENGINEDIR)/thirdparty/libpng && make cd $(CRENGINEDIR)/thirdparty/zlib && make + 'cp' -ru $(CRENGINELIBS)/cr3gui/data ./ $(LUALIB): make -C lua/src CC="$(CC)" CFLAGS="$(CFLAGS)" MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E" liblua.a diff --git a/cre.cpp b/cre.cpp new file mode 100644 index 000000000..cce2c8884 --- /dev/null +++ b/cre.cpp @@ -0,0 +1,199 @@ +/* + KindlePDFViewer: CREngine abstraction for Lua + Copyright (C) 2012 Hans-Werner Hilse + Qingping Hou + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +extern "C" { +#include "blitbuffer.h" +#include "drawcontext.h" +#include "cre.h" +} + +#include "crengine.h" + +//using namespace std; + +typedef struct CreDocument { + LVDocView *text_view; +} CreDocument; + + +static int openDocument(lua_State *L) { + const char *file_name = luaL_checkstring(L, 1); + const char *style_sheet = luaL_checkstring(L, 2); + int width = luaL_checkint(L, 3); + int height = luaL_checkint(L, 4); + + CreDocument *doc = (CreDocument*) lua_newuserdata(L, sizeof(CreDocument)); + luaL_getmetatable(L, "credocument"); + lua_setmetatable(L, -2); + + doc->text_view = new LVDocView(); + doc->text_view->setStyleSheet(lString8(style_sheet)); + doc->text_view->LoadDocument(file_name); + doc->text_view->setViewMode(DVM_SCROLL, -1); + doc->text_view->Resize(width, height); + doc->text_view->Render(); + + return 1; +} + +static int closeDocument(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + delete doc->text_view; + + return 0; +} + +static int gotoPage(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + int pageno = luaL_checkint(L, 2); + + doc->text_view->goToPage(pageno); + + return 0; +} + +static int gotoPos(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + int pos = luaL_checkint(L, 2); + + doc->text_view->SetPos(pos); + + return 0; +} + +static int getNumberOfPages(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + lua_pushinteger(L, doc->text_view->getPageCount()); + + return 1; +} + +static int getCurrentPage(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + lua_pushinteger(L, doc->text_view->getCurPage()); + + return 1; +} + +static int getPos(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + lua_pushinteger(L, doc->text_view->GetPos()); + + return 1; +} + +static int getFullHeight(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + lua_pushinteger(L, doc->text_view->GetFullHeight()); + + return 1; +} + +static int drawCurrentPage(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); + BlitBuffer *bb = (BlitBuffer*) luaL_checkudata(L, 3, "blitbuffer"); + + int w = bb->w, + h = bb->h; + LVGrayDrawBuf drawBuf(w, h, 8); + + doc->text_view->Resize(w, h); + doc->text_view->Render(); + drawBuf.Clear(0xFFFFFF); + doc->text_view->Draw(drawBuf); + + + uint8_t *bbptr = (uint8_t*)bb->data; + uint8_t *pmptr = (uint8_t*)drawBuf.GetScanLine(0); + int i,x; + + for (i = 0; i < h; i++) { + for (x = 0; x < (bb->w / 2); x++) { + bbptr[x] = 255 - (((pmptr[x*2 + 1] & 0xF0) >> 4) | + (pmptr[x*2] & 0xF0)); + } + if(bb->w & 1) { + bbptr[x] = 255 - (pmptr[x*2] & 0xF0); + } + bbptr += bb->pitch; + pmptr += w; + } +} + + +static const struct luaL_Reg cre_func[] = { + {"openDocument", openDocument}, + {NULL, NULL} +}; + +static const struct luaL_Reg credocument_meth[] = { + {"getPages", getNumberOfPages}, + {"getCurrentPage", getCurrentPage}, + {"getPos", getPos}, + {"GetFullHeight", getFullHeight}, + {"gotoPos", gotoPos}, + {"gotoPage", gotoPage}, + {"drawCurrentPage", drawCurrentPage}, + //{"getTOC", getTableOfContent}, + {"close", closeDocument}, + {"__gc", closeDocument}, + {NULL, NULL} +}; + +int luaopen_cre(lua_State *L) { + luaL_newmetatable(L, "credocument"); + lua_pushstring(L, "__index"); + lua_pushvalue(L, -2); + lua_settable(L, -3); + luaL_register(L, NULL, credocument_meth); + lua_pop(L, 1); + luaL_register(L, "cre", cre_func); + + + /* initialize fonts for CREngine */ + InitFontManager(lString8("./fonts")); + + lString8 fontDir("./fonts"); + LVContainerRef dir = LVOpenDirectory( LocalToUnicode(fontDir).c_str() ); + if ( !dir.isNull() ) + for ( int i=0; iGetObjectCount(); i++ ) { + const LVContainerItemInfo * item = dir->GetObjectInfo(i); + lString16 fileName = item->GetName(); + if ( !item->IsContainer() && fileName.length()>4 && lString16(fileName, fileName.length()-4, 4)==L".ttf" ) { + lString8 fn = UnicodeToLocal(fileName); + printf("loading font: %s\n", fn.c_str()); + if ( !fontMan->RegisterFont(fn) ) { + printf(" failed\n"); + } + } + } + +#ifdef DEBUG_CRENGINE + CRLog::setStdoutLogger(); + CRLog::setLogLevel(CRLog::LL_DEBUG); +#endif + + return 1; +} diff --git a/cre.h b/cre.h new file mode 100644 index 000000000..f4166095e --- /dev/null +++ b/cre.h @@ -0,0 +1,28 @@ +/* + KindlePDFViewer: CREngine abstraction for Lua + Copyright (C) 2012 Hans-Werner Hilse + Qingping Hou + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _CRENGING_H +#define _CRENGING_H + +#include +#include +#include + +int luaopen_cre(lua_State *L); +#endif diff --git a/crereader.lua b/crereader.lua new file mode 100644 index 000000000..eac8ebe37 --- /dev/null +++ b/crereader.lua @@ -0,0 +1,57 @@ +require "unireader" +require "inputbox" + +CREReader = UniReader:new{ + pos = 0, + pan_overlap_vertical = 0, +} + +-- open a CREngine supported file and its settings store +function CREReader:open(filename) + local ok + local file_type = string.lower(string.match(filename, ".+%.([^.]+)")) + local style_sheet = "./data/"..file_type..".css" + ok, self.doc = pcall(cre.openDocument, filename, style_sheet, + width, height) + if not ok then + return false, self.doc -- will contain error message + end + + return true +end + +function CREReader:goto(pos) + local pos = math.min(pos, self.doc:GetFullHeight()) + pos = math.max(pos, 0) + self.doc:gotoPos(pos) + self.doc:drawCurrentPage(self.nulldc, fb.bb) + + if self.rcount == self.rcountmax then + print("full refresh") + self.rcount = 1 + fb:refresh(0) + else + print("partial refresh") + self.rcount = self.rcount + 1 + fb:refresh(1) + end + + self.pos = pos + self.pageno = self.doc:getCurrentPage() +end + +function CREReader:redrawCurrentPage() + self:goto(self.pos) +end + +function CREReader:getTocTitleByPage(page) + return "" +end + +function CREReader:nextView() + return self.pos + height - self.pan_overlap_vertical +end + +function CREReader:prevView() + return self.pos - height + self.pan_overlap_vertical +end From 8bd1cb09ea804f5b870885476bf77ce88174b5ce Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 28 Mar 2012 19:47:10 +0200 Subject: [PATCH 04/40] lua.h dependecy #77 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5744031ce..a84eb7f84 100644 --- a/Makefile +++ b/Makefile @@ -107,7 +107,7 @@ djvu.o: %.o: %.c $(CC) -c $(KPDFREADER_CFLAGS) -I$(DJVUDIR)/ $< -o $@ cre.o: %.o: %.cpp - $(CC) -c -I$(CRENGINEDIR)/crengine/include/ $< -o $@ -lstdc++ + $(CC) -c -I$(CRENGINEDIR)/crengine/include/ -Ilua/src $< -o $@ -lstdc++ lfs.o: $(LFSDIR)/src/lfs.c $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ From ee5b32aced9e59c385335be09348087474937b0b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 28 Mar 2012 20:02:13 +0200 Subject: [PATCH 05/40] build crengine after depenencies #77 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a84eb7f84..369b1e09e 100644 --- a/Makefile +++ b/Makefile @@ -158,12 +158,12 @@ endif $(CRENGINELIBS): cd $(CRENGINEDIR) && cmake -D CR3_PNG=1 -D CR3_JPEG=1 . - cd $(CRENGINEDIR)/crengine && make cd $(CRENGINEDIR)/thirdparty/libjpeg && make cd $(CRENGINEDIR)/thirdparty/chmlib && make cd $(CRENGINEDIR)/thirdparty/antiword && make cd $(CRENGINEDIR)/thirdparty/libpng && make cd $(CRENGINEDIR)/thirdparty/zlib && make + cd $(CRENGINEDIR)/crengine && make 'cp' -ru $(CRENGINELIBS)/cr3gui/data ./ $(LUALIB): From e97cfb91e79480bb9b735bfdef4e16d6dda0f3e1 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 29 Mar 2012 00:20:07 +0200 Subject: [PATCH 06/40] hack crsetup.h using grep #77 --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 369b1e09e..264c26eb9 100644 --- a/Makefile +++ b/Makefile @@ -113,10 +113,12 @@ 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 lua lua-5.1.4 -rm -Rf mupdf/thirdparty git submodule init git submodule update + 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 + test -f $(CRENGINEDIR)/thirdparty/zlib/qconfig.h || touch $(CRENGINEDIR)/thirdparty/zlib/qconfig.h test -f mupdf-thirdparty.zip || wget http://www.mupdf.com/download/mupdf-thirdparty.zip unzip mupdf-thirdparty.zip -d mupdf test -f lua-5.1.4.tar.gz || wget http://www.lua.org/ftp/lua-5.1.4.tar.gz @@ -164,7 +166,6 @@ $(CRENGINELIBS): cd $(CRENGINEDIR)/thirdparty/libpng && make cd $(CRENGINEDIR)/thirdparty/zlib && make cd $(CRENGINEDIR)/crengine && make - 'cp' -ru $(CRENGINELIBS)/cr3gui/data ./ $(LUALIB): make -C lua/src CC="$(CC)" CFLAGS="$(CFLAGS)" MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E" liblua.a From 178e6597e218ba05dbdef6002f5dc4a947e561ba Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 29 Mar 2012 17:49:59 +0800 Subject: [PATCH 07/40] add: TOC support --- cre.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/cre.cpp b/cre.cpp index cce2c8884..b7aa36f4a 100644 --- a/cre.cpp +++ b/cre.cpp @@ -110,6 +110,66 @@ static int getFullHeight(lua_State *L) { return 1; } +/* + * helper function for getTableOfContent() + */ +static int walkTableOfContent(lua_State *L, LVTocItem *toc, int *count) { + LVTocItem *toc_tmp = NULL; + int i = 0, + nr_child = toc->getChildCount(); + + for(i = 0; i < nr_child; i++) { + toc_tmp = toc->getChild(i); + lua_pushnumber(L, (*count)++); + + /* set subtable, Toc entry */ + lua_newtable(L); + lua_pushstring(L, "page"); + lua_pushnumber(L, toc_tmp->getY()); + lua_settable(L, -3); + + lua_pushstring(L, "depth"); + lua_pushnumber(L, toc_tmp->getLevel()); + lua_settable(L, -3); + + lua_pushstring(L, "title"); + lua_pushstring(L, UnicodeToLocal(toc_tmp->getName()).c_str()); + lua_settable(L, -3); + + + /* set Toc entry to Toc table */ + lua_settable(L, -3); + + if (toc_tmp->getChildCount() > 0) { + walkTableOfContent(L, toc_tmp, count); + } + } + return 0; +} + +/* + * Return a table like this: + * { + * {page=12, depth=1, title="chapter1"}, + * {page=54, depth=1, title="chapter2"}, + * } + * + * Warnning: not like pdf or djvu support, page here refers to the + * position(height) within the document, not the real page number. + * + */ +static int getTableOfContent(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + LVTocItem * toc = doc->text_view->getToc(); + int count = 0; + + lua_newtable(L); + walkTableOfContent(L, toc, &count); + + return 1; +} + static int drawCurrentPage(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); @@ -153,10 +213,10 @@ static const struct luaL_Reg credocument_meth[] = { {"getCurrentPage", getCurrentPage}, {"getPos", getPos}, {"GetFullHeight", getFullHeight}, + {"getTOC", getTableOfContent}, {"gotoPos", gotoPos}, {"gotoPage", gotoPage}, {"drawCurrentPage", drawCurrentPage}, - //{"getTOC", getTableOfContent}, {"close", closeDocument}, {"__gc", closeDocument}, {NULL, NULL} From ad9d13a94738c3692856a1f9f2732a45e57a4c52 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 29 Mar 2012 18:17:32 +0800 Subject: [PATCH 08/40] mod: rename TOC to Toc, adapt showMenu to CREReader --- cre.cpp | 2 +- crereader.lua | 26 ++++++++++++++++++++++++-- djvu.c | 2 +- pdf.c | 2 +- unireader.lua | 30 ++++++++++++++++++------------ 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/cre.cpp b/cre.cpp index b7aa36f4a..98cbe286a 100644 --- a/cre.cpp +++ b/cre.cpp @@ -213,7 +213,7 @@ static const struct luaL_Reg credocument_meth[] = { {"getCurrentPage", getCurrentPage}, {"getPos", getPos}, {"GetFullHeight", getFullHeight}, - {"getTOC", getTableOfContent}, + {"getToc", getTableOfContent}, {"gotoPos", gotoPos}, {"gotoPage", gotoPage}, {"drawCurrentPage", drawCurrentPage}, diff --git a/crereader.lua b/crereader.lua index eac8ebe37..04548345e 100644 --- a/crereader.lua +++ b/crereader.lua @@ -20,6 +20,10 @@ function CREReader:open(filename) return true end +function CREReader:setzoom(page, preCache) + return +end + function CREReader:goto(pos) local pos = math.min(pos, self.doc:GetFullHeight()) pos = math.max(pos, 0) @@ -44,8 +48,26 @@ function CREReader:redrawCurrentPage() self:goto(self.pos) end -function CREReader:getTocTitleByPage(page) - return "" +-- used in UniReader:showMenu() +function UniReader:_drawReadingInfo() + local ypos = height - 50 + local load_percent = (self.pos / self.doc:GetFullHeight()) + + fb.bb:paintRect(0, ypos, width, 50, 0) + + ypos = ypos + 15 + local face, fhash = Font:getFaceAndHash(22) + local cur_section = self:getTocTitleByPage(self.pos) + if cur_section ~= "" then + cur_section = "Section: "..cur_section + end + renderUtf8Text(fb.bb, 10, ypos+6, face, fhash, + "Position: "..math.floor((load_percent*100)).."%".. + " "..cur_section, true) + + ypos = ypos + 15 + blitbuffer.progressBar(fb.bb, 10, ypos, width-20, 15, + 5, 4, load_percent, 8) end function CREReader:nextView() diff --git a/djvu.c b/djvu.c index 6bcac2290..5367efb0e 100644 --- a/djvu.c +++ b/djvu.c @@ -455,7 +455,7 @@ static const struct luaL_Reg djvu_func[] = { static const struct luaL_Reg djvudocument_meth[] = { {"openPage", openPage}, {"getPages", getNumberOfPages}, - {"getTOC", getTableOfContent}, + {"getToc", getTableOfContent}, {"getPageText", getPageText}, {"close", closeDocument}, {"__gc", closeDocument}, diff --git a/pdf.c b/pdf.c index b335d65c7..53efff9ba 100644 --- a/pdf.c +++ b/pdf.c @@ -304,7 +304,7 @@ static const struct luaL_Reg pdfdocument_meth[] = { {"authenticatePassword", authenticatePassword}, {"openPage", openPage}, {"getPages", getNumberOfPages}, - {"getTOC", getTableOfContent}, + {"getToc", getTableOfContent}, {"close", closeDocument}, {"__gc", closeDocument}, {NULL, NULL} diff --git a/unireader.lua b/unireader.lua index e6049e1ea..96e833306 100644 --- a/unireader.lua +++ b/unireader.lua @@ -528,7 +528,7 @@ function UniReader:addJump(pageno, notes) local jump_item = nil local notes_to_add = notes if not notes_to_add then - -- no notes given, auto generate from TOC entry + -- no notes given, auto generate from Toc entry notes_to_add = self:getTocTitleByPage(self.pageno) if notes_to_add ~= "" then notes_to_add = "in "..notes_to_add @@ -541,7 +541,7 @@ function UniReader:addJump(pageno, notes) table.remove(self.jump_stack, _t) -- if original notes is not empty, probably defined by users, -- we use the original notes to overwrite auto generated notes - -- from TOC entry + -- from Toc entry if jump_item.notes ~= "" then notes_to_add = jump_item.notes end @@ -691,18 +691,18 @@ function UniReader:screenRotate(orien) self:goto(self.pageno) end -function UniReader:cleanUpTOCTitle(title) +function UniReader:cleanUpTocTitle(title) return title:gsub("\13", "") end -function UniReader:fillTOC() - self.toc = self.doc:getTOC() +function UniReader:fillToc() + self.toc = self.doc:getToc() end function UniReader:getTocTitleByPage(pageno) if not self.toc then -- build toc when needed. - self:fillTOC() + self:fillToc() end -- no table of content @@ -717,20 +717,20 @@ function UniReader:getTocTitleByPage(pageno) end pre_entry = _v end - return self:cleanUpTOCTitle(pre_entry.title) + return self:cleanUpTocTitle(pre_entry.title) end -function UniReader:showTOC() +function UniReader:showToc() if not self.toc then -- build toc when needed. - self:fillTOC() + self:fillToc() end local menu_items = {} local filtered_toc = {} -- build menu items for k,v in ipairs(self.toc) do table.insert(menu_items, - (" "):rep(v.depth-1)..self:cleanUpTOCTitle(v.title)) + (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title)) table.insert(filtered_toc,v.page) end toc_menu = SelectMenu:new{ @@ -789,7 +789,8 @@ function UniReader:showHighLight() end end -function UniReader:showMenu() +-- used in UniReader:showMenu() +function UniReader:_drawReadingInfo() local ypos = height - 50 local load_percent = (self.pageno / self.doc:getPages()) @@ -808,6 +809,11 @@ function UniReader:showMenu() ypos = ypos + 15 blitbuffer.progressBar(fb.bb, 10, ypos, width-20, 15, 5, 4, load_percent, 8) +end + +function UniReader:showMenu() + self:_drawReadingInfo() + fb:refresh(1) while 1 do local ev = input.waitForEvent() @@ -1004,7 +1010,7 @@ function UniReader:addAllCommands() self.commands:add(KEY_T,nil,"T", "show table of content", function(unireader) - unireader:showTOC() + unireader:showToc() end) self.commands:add(KEY_B,nil,"B", "show jump stack", From 28e53ce7718e3efa7880af4dc5e8f5100f205a68 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 29 Mar 2012 19:35:56 +0800 Subject: [PATCH 09/40] mod: adapt jumpstack in CREReader --- crereader.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crereader.lua b/crereader.lua index 04548345e..832bdf5b3 100644 --- a/crereader.lua +++ b/crereader.lua @@ -27,6 +27,12 @@ end function CREReader:goto(pos) local pos = math.min(pos, self.doc:GetFullHeight()) pos = math.max(pos, 0) + + -- add to jump_stack, distinguish jump from normal page turn + if self.pos and math.abs(self.pos - pos) > height then + self:addJump(self.pos) + end + self.doc:gotoPos(pos) self.doc:drawCurrentPage(self.nulldc, fb.bb) From 7e07ea5a1f85c072e0283783db200231168667dd Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 29 Mar 2012 20:52:57 +0800 Subject: [PATCH 10/40] fix: bug in Commands:new() assign a new map to every created object --- commands.lua | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/commands.lua b/commands.lua index a6622ac43..731f3deaa 100644 --- a/commands.lua +++ b/commands.lua @@ -5,6 +5,7 @@ Keydef = { modifier = nil, descr = nil } + function Keydef:_new(obj) -- obj definition obj = obj or {} @@ -13,6 +14,7 @@ function Keydef:_new(obj) self.__tostring=Keydef.tostring return obj end + function Keydef:new(keycode,modifier,descr) obj = Keydef:_new() obj.keycode = keycode @@ -20,13 +22,16 @@ function Keydef:new(keycode,modifier,descr) obj.descr = descr return obj end + function Keydef:display() return ((self.modifier and self.modifier.."+") or "")..(self.descr or "") end + function Keydef:tostring() return ((self.modifier and self.modifier.."+") or "").."["..(self.keycode or "").."]"..(self.descr or "") end + Command = { keydef = nil, keygroup = nil, @@ -34,6 +39,7 @@ Command = { help = nil, order = nil } + function Command:_new(obj) -- obj definition obj = obj or {} @@ -42,6 +48,7 @@ function Command:_new(obj) self.__tostring=Command.tostring return obj end + function Command:new(keydef, func, help, keygroup, order) obj = Command:_new() obj.keydef = keydef @@ -52,6 +59,7 @@ function Command:new(keydef, func, help, keygroup, order) --print("creating command: ["..tostring(keydef).."] keygroup:["..(keygroup or "").."] help:"..help) return obj end + function Command:tostring() return tostring(self.keydef)..": "..(self.help or "") end @@ -61,6 +69,7 @@ Commands = { map = {}, size = 0 } + function Commands:add(keycode,modifier,keydescr,help,func) if type(keycode) == "table" then for i=1,#keycode,1 do @@ -72,11 +81,13 @@ function Commands:add(keycode,modifier,keydescr,help,func) self:_addImpl(keydef,help,func) end end + function Commands:addGroup(keygroup,keys,help,func) for _k,keydef in pairs(keys) do self:_addImpl(keydef,help,func,keygroup) end end + function Commands:_addImpl(keydef,help,func,keygroup) if keydef.modifier==MOD_ANY then self:addGroup(keygroup or keydef.descr,{Keydef:new(keydef.keycode,nil), Keydef:new(keydef.keycode,MOD_SHIFT), Keydef:new(keydef.keycode,MOD_ALT)},help,func) @@ -95,25 +106,32 @@ function Commands:_addImpl(keydef,help,func,keygroup) end end end + function Commands:get(keycode,modifier) return self.map[Keydef:new(keycode, modifier)] end + function Commands:getByKeydef(keydef) return self.map[keydef] end + function Commands:new(obj) + -- obj definition + obj = obj or {} + obj.map = {} + obj.size = 0 + setmetatable(obj, self) + self.__index = self + -- payload local mt = {} - setmetatable(self.map,mt) - mt.__index=function (table, key) + mt.__index = function(table, key) return rawget(table,(key.modifier or "").."@#@"..(key.keycode or "")) end - mt.__newindex=function (table, key, value) + mt.__newindex = function(table, key, value) return rawset(table,(key.modifier or "").."@#@"..(key.keycode or ""),value) end - -- obj definition - obj = obj or {} - setmetatable(obj, self) - self.__index = self + setmetatable(obj.map, mt) + return obj end From e94fe052d361b908038069100c7c4b83058f0ed1 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 29 Mar 2012 21:10:25 +0800 Subject: [PATCH 11/40] mod: rewrite selectmenu with commands also fixed bug in page counting --- selectmenu.lua | 285 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 187 insertions(+), 98 deletions(-) diff --git a/selectmenu.lua b/selectmenu.lua index 3572a5c99..b157bb301 100644 --- a/selectmenu.lua +++ b/selectmenu.lua @@ -2,6 +2,7 @@ require "rendertext" require "keys" require "graphics" require "font" +require "commands" SelectMenu = { -- font for displaying item names @@ -32,10 +33,14 @@ SelectMenu = { "Z", "X", "C", "V", "B", "N", "M", ".", "Sym", "Ent", }, last_shortcut = 0, + -- state buffer page = 1, current = 1, oldcurrent = 0, + selected_item = nil, + + commands = nil, } function SelectMenu:new(o) @@ -46,10 +51,12 @@ function SelectMenu:new(o) o.page = 1 o.current = 1 o.oldcurrent = 0 + o.selected_item = nil -- increase spacing for DXG so we don't have more than 30 shortcuts if fb.bb:getHeight() == 1200 then o.spacing = 37 end + o:addAllCommands() return o end @@ -62,43 +69,154 @@ function SelectMenu:getItemIndexByShortCut(c, perpage) end end ---[ --- return the index of selected item ---] -function SelectMenu:choose(ypos, height) - local perpage = math.floor(height / self.spacing) - 2 - local pagedirty = true - local markerdirty = false - - local prevItem = function () - if self.current == 1 then - if self.page > 1 then - self.current = perpage - self.page = self.page - 1 - pagedirty = true +function SelectMenu:addAllCommands() + self.commands = Commands:new{} + + self.commands:add(KEY_FW_UP, nil, "", + "previous item", + function(sm) + if sm.current == 1 then + if sm.page > 1 then + sm.current = sm.perpage + sm.page = sm.page - 1 + sm.pagedirty = true + end + else + sm.current = sm.current - 1 + sm.markerdirty = true end - else - self.current = self.current - 1 - markerdirty = true - end - end + end) - local nextItem = function () - if self.current == perpage then - if self.page < (self.items / perpage) then - self.current = 1 - self.page = self.page + 1 - pagedirty = true + self.commands:add(KEY_FW_DOWN, nil, "", + "next item", + function(sm) + if sm.current == sm.perpage then + if sm.page < (sm.items / sm.perpage) then + sm.current = 1 + sm.page = sm.page + 1 + sm.pagedirty = true + end + else + if sm.page ~= math.floor(sm.items / sm.perpage) + 1 + or sm.current + (sm.page - 1) * sm.perpage < sm.items then + sm.current = sm.current + 1 + sm.markerdirty = true + end end - else - if self.page ~= math.floor(self.items / perpage) + 1 - or self.current + (self.page-1)*perpage < self.items then - self.current = self.current + 1 - markerdirty = true + end) + + self.commands:add({KEY_PGFWD, KEY_LPGFWD}, nil, "", + "next page", + function(sm) + if sm.page < (sm.items / sm.perpage) then + if sm.current + sm.page * sm.perpage > sm.items then + sm.current = sm.items - sm.page * sm.perpage + end + sm.page = sm.page + 1 + sm.pagedirty = true + else + sm.current = sm.items - (sm.page - 1) * sm.perpage + sm.markerdirty = true end - end + end) + + self.commands:add({KEY_PGBCK, KEY_LPGBCK}, nil, "", + "previous page", + function(sm) + if sm.page > 1 then + sm.page = sm.page - 1 + sm.pagedirty = true + else + sm.current = 1 + sm.markerdirty = true + end + end) + + self.commands:add(KEY_FW_PRESS, nil, "", + "select menu item", + function(sm) + if sm.last_shortcut < 30 then + if sm.items == 0 then + return "break" + else + self.selected_item = (sm.perpage * (sm.page - 1) + + sm.current) + end + end + end) + + local KEY_Q_to_E = {} + for i = KEY_Q, KEY_P do + table.insert(KEY_Q_to_E, Keydef:new(i, nil, "")) + end + self.commands:addGroup("Q to E", KEY_Q_to_E, + "Select menu item with Q to E key as shortcut", + function(sm, keydef) + sm.selected_item = sm:getItemIndexByShortCut( + sm.item_shortcuts[ keydef.keycode - KEY_Q + 1 ], sm.perpage) + end) + + local KEY_A_to_L = {} + for i = KEY_A, KEY_L do + table.insert(KEY_A_to_L, Keydef:new(i, nil, "")) end + self.commands:addGroup("A to L", KEY_A_to_L, + "Select menu item with A to L key as shortcut", + function(sm, keydef) + sm.selected_item = sm:getItemIndexByShortCut( + sm.item_shortcuts[ keydef.keycode - KEY_A + 11 ], sm.perpage) + end) + local KEY_Z_to_M = {} + for i = KEY_Z, KEY_M do + table.insert(KEY_Z_to_M, Keydef:new(i, nil, "")) + end + self.commands:addGroup("Z to M", KEY_Z_to_M, + "Select menu item with Z to M key as shortcut", + function(sm, keydef) + sm.selected_item = sm:getItemIndexByShortCut( + sm.item_shortcuts[ keydef.keycode - KEY_Z + 21 ], sm.perpage) + end) + + self.commands:add(KEY_DEL, nil, "", + "Select menu item with del key as shortcut", + function(sm) + sm.selected_item = sm:getItemIndexByShortCut("Del", sm.perpage) + end) + + self.commands:add(KEY_DOT, nil, "", + "Select menu item with dot key as shortcut", + function(sm) + sm.selected_item = sm:getItemIndexByShortCut(".", sm.perpage) + end) + + self.commands:add({KEY_SYM, KEY_SLASH}, nil, "", + "Select menu item with sym/slash key as shortcut", + function(sm) + -- DXG has slash after dot + sm.selected_item = sm:getItemIndexByShortCut("Sym", sm.perpage) + end) + + self.commands:add(KEY_ENTER, nil, "", + "Select menu item with enter key as shortcut", + function(sm) + sm.selected_item = sm:getItemIndexByShortCut("Ent", sm.perpage) + end) + + self.commands:add(KEY_BACK, nil, "", + "Exit menu", + function(sm) + return "break" + end) +end + +------------------------------------------------ +-- return the index of selected item +------------------------------------------------ +function SelectMenu:choose(ypos, height) + self.perpage = math.floor(height / self.spacing) - 2 + self.pagedirty = true + self.markerdirty = false self.last_shortcut = 0 while true do @@ -106,8 +224,8 @@ function SelectMenu:choose(ypos, height) local tface, tfhash = Font:getFaceAndHash(25, Font.tfont) local fface, ffhash = Font:getFaceAndHash(16, Font.ffont) - if pagedirty then - markerdirty = true + if self.pagedirty then + self.markerdirty = true -- draw menu title fb.bb:paintRect(0, ypos, fb.bb:getWidth(), self.title_H + 10, 0) fb.bb:paintRect(10, ypos + 10, fb.bb:getWidth() - 20, self.title_H, 5) @@ -125,11 +243,11 @@ function SelectMenu:choose(ypos, height) y = y + self.spacing renderUtf8Text(fb.bb, 30, y, cface, cfhash, self.no_item_msg, true) - markerdirty = false + self.markerdirty = false else local c - for c = 1, perpage do - local i = (self.page - 1) * perpage + c + for c = 1, self.perpage do + local i = (self.page - 1) * self.perpage + c if i <= self.items then y = ypos + self.title_H + (self.spacing * c) @@ -153,19 +271,21 @@ function SelectMenu:choose(ypos, height) renderUtf8Text(fb.bb, 50, y, cface, cfhash, self.item_array[i], true) - end - end - end + end -- EOF if i <= self.items + end -- EOF for + end -- EOF if -- draw footer - y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H + 5 + y = ypos + self.title_H + (self.spacing * self.perpage) + + self.foot_H + 5 x = (fb.bb:getWidth() / 2) - 50 renderUtf8Text(fb.bb, x, y, fface, ffhash, - "Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true) + "Page "..self.page.." of ".. + (math.ceil(self.items / self.perpage)), true) end - if markerdirty then - if not pagedirty then + if self.markerdirty then + if not self.pagedirty then if self.oldcurrent > 0 then y = ypos + self.title_H + (self.spacing * self.oldcurrent) + 8 fb.bb:paintRect(45, y, fb.bb:getWidth() - 60, 3, 0) @@ -175,72 +295,41 @@ function SelectMenu:choose(ypos, height) -- draw new marker line y = ypos + self.title_H + (self.spacing * self.current) + 8 fb.bb:paintRect(45, y, fb.bb:getWidth() - 60, 3, 15) - if not pagedirty then + if not self.pagedirty then fb:refresh(1, 45, y, fb.bb:getWidth() - 60, 3) end self.oldcurrent = self.current - markerdirty = false + self.markerdirty = false end - if pagedirty then + if self.pagedirty then fb:refresh(0, 0, ypos, fb.bb:getWidth(), height) - pagedirty = false + self.pagedirty = false end local ev = input.waitForEvent() ev.code = adjustKeyEvents(ev) if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then - local selected = nil - if ev.code == KEY_FW_UP then - prevItem() - elseif ev.code == KEY_FW_DOWN then - nextItem() - elseif ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then - if self.page < (self.items / perpage) then - if self.current + self.page*perpage > self.items then - self.current = self.items - self.page*perpage - end - self.page = self.page + 1 - pagedirty = true - else - self.current = self.items - (self.page-1)*perpage - markerdirty = true - end - elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then - if self.page > 1 then - self.page = self.page - 1 - pagedirty = true - else - self.current = 1 - markerdirty = true - end - elseif ev.code == KEY_FW_PRESS or ev.code == KEY_ENTER and self.last_shortcut < 30 then - if self.items == 0 then - return nil - else - return (perpage*(self.page-1) + self.current) - end - elseif ev.code >= KEY_Q and ev.code <= KEY_P then - selected = self:getItemIndexByShortCut(self.item_shortcuts[ ev.code - KEY_Q + 1 ], perpage) - elseif ev.code >= KEY_A and ev.code <= KEY_L then - selected = self:getItemIndexByShortCut(self.item_shortcuts[ ev.code - KEY_A + 11], perpage) - elseif ev.code >= KEY_Z and ev.code <= KEY_M then - selected = self:getItemIndexByShortCut(self.item_shortcuts[ ev.code - KEY_Z + 21], perpage) - elseif ev.code == KEY_DEL then - selected = self:getItemIndexByShortCut("Del", perpage) - elseif ev.code == KEY_DOT then - selected = self:getItemIndexByShortCut(".", perpage) - elseif ev.code == KEY_SYM or ev.code == KEY_SLASH then -- DXG has slash after dot - selected = self:getItemIndexByShortCut("Sym", perpage) - elseif ev.code == KEY_ENTER then - selected = self:getItemIndexByShortCut("Ent", perpage) - elseif ev.code == KEY_BACK then - return nil + keydef = Keydef:new(ev.code, getKeyModifier()) + print("key pressed: "..tostring(keydef)) + + command = self.commands:getByKeydef(keydef) + if command ~= nil then + print("command to execute: "..tostring(command)) + ret_code = command.func(self, keydef) + else + print("command not found: "..tostring(command)) end - if selected ~= nil then - print("# selected "..selected) - return selected + + if ret_code == "break" then + break end - end - end + + if self.selected_item ~= nil then + print("# selected "..self.selected_item) + return self.selected_item + end + end -- EOF if + end -- EOF while + return nil end From c89e3efc19e85c7ae4680bc8e7330ee71b5e4958 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 29 Mar 2012 21:16:09 +0800 Subject: [PATCH 12/40] fix: clear commands when no item in menu --- selectmenu.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/selectmenu.lua b/selectmenu.lua index b157bb301..c4ce67f45 100644 --- a/selectmenu.lua +++ b/selectmenu.lua @@ -210,6 +210,16 @@ function SelectMenu:addAllCommands() end) end +function SelectMenu:clearCommands() + self.commands = Commands:new{} + + self.commands:add(KEY_BACK, nil, "", + "Exit menu", + function(sm) + return "break" + end) +end + ------------------------------------------------ -- return the index of selected item ------------------------------------------------ @@ -244,6 +254,7 @@ function SelectMenu:choose(ypos, height) renderUtf8Text(fb.bb, 30, y, cface, cfhash, self.no_item_msg, true) self.markerdirty = false + self:clearCommands() else local c for c = 1, self.perpage do From 5c4b0868bae42ccef7bd35be4fc445ee61f6ad1c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 30 Mar 2012 12:01:59 +0800 Subject: [PATCH 13/40] add: del method in commands --- commands.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/commands.lua b/commands.lua index 731f3deaa..2b5b58aef 100644 --- a/commands.lua +++ b/commands.lua @@ -88,6 +88,24 @@ function Commands:addGroup(keygroup,keys,help,func) end end +function Commands:del(keycode, modifier, keydescr) + local keydef = nil + + if not keydescr then + for k,v in pairs(self.map) do + if v.keydef.keycode == keycode + and v.keydef.modifier == modifier then + keydef = k + break + end + end -- EOF for + else + keydef = Keydef:new(keycode, modifier, keydescr) + end -- EOF if + + self.map[keydef] = nil +end + function Commands:_addImpl(keydef,help,func,keygroup) if keydef.modifier==MOD_ANY then self:addGroup(keygroup or keydef.descr,{Keydef:new(keydef.keycode,nil), Keydef:new(keydef.keycode,MOD_SHIFT), Keydef:new(keydef.keycode,MOD_ALT)},help,func) From c0edbfae27934cdbd108cf6319d106270b9b5a8f Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 30 Mar 2012 12:06:33 +0800 Subject: [PATCH 14/40] mod: remove not used shorcuts in CREReader --- crereader.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crereader.lua b/crereader.lua index 832bdf5b3..4862000f2 100644 --- a/crereader.lua +++ b/crereader.lua @@ -6,6 +6,10 @@ CREReader = UniReader:new{ pan_overlap_vertical = 0, } +function CREReader:init() + self:adjustCreReaderCommands() +end + -- open a CREngine supported file and its settings store function CREReader:open(filename) local ok @@ -83,3 +87,24 @@ end function CREReader:prevView() return self.pos - height + self.pan_overlap_vertical end + +function CREReader:adjustCreReaderCommands() + self.commands:del(KEY_G, nil, "G") + self.commands:del(KEY_J, nil, "J") + self.commands:del(KEY_K, nil, "K") + self.commands:del(KEY_Z, nil, "Z") + self.commands:del(KEY_Z, MOD_SHIFT, "Z") + self.commands:del(KEY_Z, MOD_ALT, "Z") + self.commands:del(KEY_A, nil, "A") + self.commands:del(KEY_A, MOD_SHIFT, "A") + self.commands:del(KEY_A, MOD_ALT, "A") + self.commands:del(KEY_S, nil, "S") + self.commands:del(KEY_S, MOD_SHIFT, "S") + self.commands:del(KEY_S, MOD_ALT, "S") + self.commands:del(KEY_D, nil, "D") + self.commands:del(KEY_D, MOD_SHIFT, "D") + self.commands:del(KEY_D, MOD_ALT, "D") + self.commands:del(KEY_F, nil, "F") + self.commands:del(KEY_F, MOD_SHIFT, "F") + self.commands:del(KEY_F, MOD_ALT, "F") +end From ad750a89f8f9d9e9317da08f0e4e5cba664864fa Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 30 Mar 2012 12:31:09 +0800 Subject: [PATCH 15/40] add: font zooming in CREReader --- cre.cpp | 50 +++++++++++++++++++++++++++++++------------------- crereader.lua | 17 +++++++++++++++++ 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/cre.cpp b/cre.cpp index 98cbe286a..96c2aad0a 100644 --- a/cre.cpp +++ b/cre.cpp @@ -60,24 +60,6 @@ static int closeDocument(lua_State *L) { return 0; } -static int gotoPage(lua_State *L) { - CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); - int pageno = luaL_checkint(L, 2); - - doc->text_view->goToPage(pageno); - - return 0; -} - -static int gotoPos(lua_State *L) { - CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); - int pos = luaL_checkint(L, 2); - - doc->text_view->SetPos(pos); - - return 0; -} - static int getNumberOfPages(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); @@ -170,6 +152,35 @@ static int getTableOfContent(lua_State *L) { return 1; } +static int gotoPage(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + int pageno = luaL_checkint(L, 2); + + doc->text_view->goToPage(pageno); + + return 0; +} + +static int gotoPos(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + int pos = luaL_checkint(L, 2); + + doc->text_view->SetPos(pos); + + return 0; +} + +/* zoom font by given delta and return zoomed font size */ +static int zoomFont(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + int delta = luaL_checkint(L, 2); + + doc->text_view->ZoomFont(delta); + + lua_pushnumber(L, doc->text_view->getFontSize()); + return 1; +} + static int drawCurrentPage(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); @@ -214,8 +225,9 @@ static const struct luaL_Reg credocument_meth[] = { {"getPos", getPos}, {"GetFullHeight", getFullHeight}, {"getToc", getTableOfContent}, - {"gotoPos", gotoPos}, {"gotoPage", gotoPage}, + {"gotoPos", gotoPos}, + {"zoomFont", zoomFont}, {"drawCurrentPage", drawCurrentPage}, {"close", closeDocument}, {"__gc", closeDocument}, diff --git a/crereader.lua b/crereader.lua index 4862000f2..f9e60bd86 100644 --- a/crereader.lua +++ b/crereader.lua @@ -89,6 +89,7 @@ function CREReader:prevView() end function CREReader:adjustCreReaderCommands() + -- delete commands self.commands:del(KEY_G, nil, "G") self.commands:del(KEY_J, nil, "J") self.commands:del(KEY_K, nil, "K") @@ -107,4 +108,20 @@ function CREReader:adjustCreReaderCommands() self.commands:del(KEY_F, nil, "F") self.commands:del(KEY_F, MOD_SHIFT, "F") self.commands:del(KEY_F, MOD_ALT, "F") + + -- overwrite commands + self.commands:add(KEY_PGFWD, MOD_SHIFT_OR_ALT, ">", + "increase font size", + function(cr) + cr.doc:zoomFont(1) + cr:redrawCurrentPage() + end + ) + self.commands:add(KEY_PGBCK, MOD_SHIFT_OR_ALT, "<", + "decrease font size", + function(cr) + cr.doc:zoomFont(-1) + cr:redrawCurrentPage() + end + ) end From 612890850cab20264ea9002e12b1669f74b317dd Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 30 Mar 2012 12:38:41 +0800 Subject: [PATCH 16/40] add: percent jump in CREReader --- crereader.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crereader.lua b/crereader.lua index f9e60bd86..3fd4b091d 100644 --- a/crereader.lua +++ b/crereader.lua @@ -124,4 +124,17 @@ function CREReader:adjustCreReaderCommands() cr:redrawCurrentPage() end ) + local numeric_keydefs = {} + for i=1,10 do + numeric_keydefs[i]=Keydef:new(KEY_1+i-1, nil, tostring(i%10)) + end + self.commands:addGroup("[1..0]", numeric_keydefs, + "jump to *10% of document", + function(cr, keydef) + print('jump to position: '.. + math.floor(cr.doc:GetFullHeight()*(keydef.keycode-KEY_1)/9).. + '/'..cr.doc:GetFullHeight()) + cr:goto(math.floor(cr.doc:GetFullHeight()*(keydef.keycode-KEY_1)/9)) + end + ) end From 8a2b86e2032b70780bbdd8d436b318f5cca634e8 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 30 Mar 2012 13:07:48 +0800 Subject: [PATCH 17/40] mod: factor last reading page saving and resotring --- reader.lua | 1 + unireader.lua | 41 ++++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/reader.lua b/reader.lua index 8e6b33af6..087dc72a2 100755 --- a/reader.lua +++ b/reader.lua @@ -51,6 +51,7 @@ function openFile(filename) if ok then reader:loadSettings(filename) page_num = reader.settings:readSetting("last_page") or 1 + page_num = reader:getLastPageOrPos() reader:goto(tonumber(page_num)) reader_settings:savesetting("lastfile", filename) return reader:inputLoop() diff --git a/unireader.lua b/unireader.lua index 81b37e1fc..51c02c5cf 100644 --- a/unireader.lua +++ b/unireader.lua @@ -128,6 +128,24 @@ end --[ following are default methods ]-- +function UniReader:initGlobalSettings(settings) + local pan_overlap_vertical = settings:readSetting("pan_overlap_vertical") + if pan_overlap_vertical then + self.pan_overlap_vertical = pan_overlap_vertical + end + -- initialize commands + self:addAllCommands() + + local cache_max_memsize = settings:readSetting("cache_max_memsize") + if cache_max_memsize then + self.cache_max_memsize = cache_max_memsize + end + + local cache_max_ttl = settings:readSetting("cache_max_ttl") + if cache_max_ttl then + self.cache_max_ttl = cache_max_ttl + end +end function UniReader:loadSettings(filename) if self.doc ~= nil then @@ -156,23 +174,12 @@ function UniReader:loadSettings(filename) return false end -function UniReader:initGlobalSettings(settings) - local pan_overlap_vertical = settings:readSetting("pan_overlap_vertical") - if pan_overlap_vertical then - self.pan_overlap_vertical = pan_overlap_vertical - end - -- initialize commands - self:addAllCommands() - - local cache_max_memsize = settings:readSetting("cache_max_memsize") - if cache_max_memsize then - self.cache_max_memsize = cache_max_memsize - end +function UniReader:getLastPageOrPos() + return self.settings:readSetting("last_page") or 1 +end - local cache_max_ttl = settings:readSetting("cache_max_ttl") - if cache_max_ttl then - self.cache_max_ttl = cache_max_ttl - end +function UniReader:saveLastPageOrPos() + self.settings:savesetting("last_page", self.pageno) end -- guarantee that we have enough memory in cache @@ -869,7 +876,7 @@ function UniReader:inputLoop() self.doc:close() end if self.settings ~= nil then - self.settings:savesetting("last_page", self.pageno) + self:saveLastPageOrPos() self.settings:savesetting("gamma", self.globalgamma) self.settings:savesetting("jumpstack", self.jump_stack) self.settings:savesetting("bbox", self.bbox) From 937f445b920efdc812d17098c1bdead4ec1eeb46 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 30 Mar 2012 14:00:41 +0800 Subject: [PATCH 18/40] fix: mistakenly over written unireader's method --- crereader.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crereader.lua b/crereader.lua index 3fd4b091d..21826b202 100644 --- a/crereader.lua +++ b/crereader.lua @@ -58,8 +58,8 @@ function CREReader:redrawCurrentPage() self:goto(self.pos) end --- used in UniReader:showMenu() -function UniReader:_drawReadingInfo() +-- used in CREReader:showMenu() +function CREReader:_drawReadingInfo() local ypos = height - 50 local load_percent = (self.pos / self.doc:GetFullHeight()) From 37dfc84d5ae69f77a120160e49d5de99553314b2 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 30 Mar 2012 14:10:04 +0800 Subject: [PATCH 19/40] fix: move commands initilization from global init to local If we call addAllCommands in initGlobalSettings, all the readers will share the same commands and we cannot adjust commands for a specific reader. I thus moved this method call to Unireader:init() method. --- crereader.lua | 1 + reader.lua | 1 - unireader.lua | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crereader.lua b/crereader.lua index 21826b202..f6081ecb0 100644 --- a/crereader.lua +++ b/crereader.lua @@ -7,6 +7,7 @@ CREReader = UniReader:new{ } function CREReader:init() + self:addAllCommands() self:adjustCreReaderCommands() end diff --git a/reader.lua b/reader.lua index 087dc72a2..adbd99447 100755 --- a/reader.lua +++ b/reader.lua @@ -50,7 +50,6 @@ function openFile(filename) local ok, err = reader:open(filename) if ok then reader:loadSettings(filename) - page_num = reader.settings:readSetting("last_page") or 1 page_num = reader:getLastPageOrPos() reader:goto(tonumber(page_num)) reader_settings:savesetting("lastfile", filename) diff --git a/unireader.lua b/unireader.lua index 51c02c5cf..a45776042 100644 --- a/unireader.lua +++ b/unireader.lua @@ -101,6 +101,8 @@ end -- overwrite other methods if needed. ---------------------------------------------------- function UniReader:init() + -- initialize commands + self:addAllCommands() end -- open a file and its settings store @@ -133,8 +135,6 @@ function UniReader:initGlobalSettings(settings) if pan_overlap_vertical then self.pan_overlap_vertical = pan_overlap_vertical end - -- initialize commands - self:addAllCommands() local cache_max_memsize = settings:readSetting("cache_max_memsize") if cache_max_memsize then From 9df574de01d065d26dc7897888df27856d8f093d Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 30 Mar 2012 14:25:36 +0800 Subject: [PATCH 20/40] add: last reading position saving and restoring --- crereader.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crereader.lua b/crereader.lua index f6081ecb0..679df6d4a 100644 --- a/crereader.lua +++ b/crereader.lua @@ -25,10 +25,21 @@ function CREReader:open(filename) return true end +function CREReader:getLastPageOrPos() + return self.settings:readSetting("last_pos") or 0 +end + +function CREReader:saveLastPageOrPos() + self.settings:savesetting("last_pos", self.pos) +end + function CREReader:setzoom(page, preCache) return end +function CREReader:addJump(pos, notes) +end + function CREReader:goto(pos) local pos = math.min(pos, self.doc:GetFullHeight()) pos = math.max(pos, 0) From 4633ca08328f9dc21661e86bebfb067a45982099 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 31 Mar 2012 20:22:22 +0800 Subject: [PATCH 21/40] mod: use percent as absolute location in DOCs in CREReader The height of documents will be changed after zoom in or zoom out, so we cannot use pos to mark positions inside documents. --- cre.cpp | 21 ++++++++++++++++++++- crereader.lua | 26 ++++++++++++++++---------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/cre.cpp b/cre.cpp index 96c2aad0a..efd989863 100644 --- a/cre.cpp +++ b/cre.cpp @@ -84,6 +84,14 @@ static int getPos(lua_State *L) { return 1; } +static int getPosPercent(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + lua_pushinteger(L, doc->text_view->getPosPercent()); + + return 1; +} + static int getFullHeight(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); @@ -161,6 +169,15 @@ static int gotoPage(lua_State *L) { return 0; } +static int gotoPercent(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + int percent = luaL_checkint(L, 2); + + doc->text_view->SetPos(percent * doc->text_view->GetFullHeight() / 10000); + + return 0; +} + static int gotoPos(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); int pos = luaL_checkint(L, 2); @@ -223,9 +240,11 @@ static const struct luaL_Reg credocument_meth[] = { {"getPages", getNumberOfPages}, {"getCurrentPage", getCurrentPage}, {"getPos", getPos}, - {"GetFullHeight", getFullHeight}, + {"getPosPercent", getPosPercent}, + {"getFullHeight", getFullHeight}, {"getToc", getTableOfContent}, {"gotoPage", gotoPage}, + {"gotoPercent", gotoPercent}, {"gotoPos", gotoPos}, {"zoomFont", zoomFont}, {"drawCurrentPage", drawCurrentPage}, diff --git a/crereader.lua b/crereader.lua index 679df6d4a..c730eb846 100644 --- a/crereader.lua +++ b/crereader.lua @@ -3,6 +3,7 @@ require "inputbox" CREReader = UniReader:new{ pos = 0, + percent = 0, pan_overlap_vertical = 0, } @@ -26,11 +27,16 @@ function CREReader:open(filename) end function CREReader:getLastPageOrPos() - return self.settings:readSetting("last_pos") or 0 + local last_percent = self.settings:readSetting("last_percent") + if last_percent then + return (last_percent * self.doc:getFullHeight()) / 10000 + else + return 0 + end end function CREReader:saveLastPageOrPos() - self.settings:savesetting("last_pos", self.pos) + self.settings:savesetting("last_percent", self.percent) end function CREReader:setzoom(page, preCache) @@ -41,12 +47,12 @@ function CREReader:addJump(pos, notes) end function CREReader:goto(pos) - local pos = math.min(pos, self.doc:GetFullHeight()) + local pos = math.min(pos, self.doc:getFullHeight()) pos = math.max(pos, 0) -- add to jump_stack, distinguish jump from normal page turn if self.pos and math.abs(self.pos - pos) > height then - self:addJump(self.pos) + self:addJump(self.percent) end self.doc:gotoPos(pos) @@ -64,6 +70,7 @@ function CREReader:goto(pos) self.pos = pos self.pageno = self.doc:getCurrentPage() + self.percent = self.doc:getPosPercent() end function CREReader:redrawCurrentPage() @@ -73,7 +80,7 @@ end -- used in CREReader:showMenu() function CREReader:_drawReadingInfo() local ypos = height - 50 - local load_percent = (self.pos / self.doc:GetFullHeight()) + local load_percent = self.percent/100 fb.bb:paintRect(0, ypos, width, 50, 0) @@ -84,8 +91,7 @@ function CREReader:_drawReadingInfo() cur_section = "Section: "..cur_section end renderUtf8Text(fb.bb, 10, ypos+6, face, fhash, - "Position: "..math.floor((load_percent*100)).."%".. - " "..cur_section, true) + "Position: "..load_percent.."%".." "..cur_section, true) ypos = ypos + 15 blitbuffer.progressBar(fb.bb, 10, ypos, width-20, 15, @@ -144,9 +150,9 @@ function CREReader:adjustCreReaderCommands() "jump to *10% of document", function(cr, keydef) print('jump to position: '.. - math.floor(cr.doc:GetFullHeight()*(keydef.keycode-KEY_1)/9).. - '/'..cr.doc:GetFullHeight()) - cr:goto(math.floor(cr.doc:GetFullHeight()*(keydef.keycode-KEY_1)/9)) + math.floor(cr.doc:getFullHeight()*(keydef.keycode-KEY_1)/9).. + '/'..cr.doc:getFullHeight()) + cr:goto(math.floor(cr.doc:getFullHeight()*(keydef.keycode-KEY_1)/9)) end ) end From 2814102d28c0acb80529f2cd5a55662ffa38523b Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 2 Apr 2012 11:52:34 +0800 Subject: [PATCH 22/40] mod: use customed cmake rules to build CREngine libraries --- .gitmodules | 4 ++-- Makefile | 26 ++++++++------------------ crengine | 1 - kpvcrlib/CMakeLists.txt | 39 +++++++++++++++++++++++++++++++++++++++ kpvcrlib/crengine | 1 + 5 files changed, 50 insertions(+), 21 deletions(-) delete mode 160000 crengine create mode 100644 kpvcrlib/CMakeLists.txt create mode 160000 kpvcrlib/crengine diff --git a/.gitmodules b/.gitmodules index 6c5c235cf..ead63e79f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,6 @@ [submodule "djvulibre"] path = djvulibre url = git://djvu.git.sourceforge.net/gitroot/djvu/djvulibre.git -[submodule "crengine"] - path = crengine +[submodule "kpvcrlib/crengine"] + path = kpvcrlib/crengine url = git://crengine.git.sourceforge.net/gitroot/crengine/crengine diff --git a/Makefile b/Makefile index e75b7ea76..05bd9bc60 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ MUPDFDIR=mupdf MUPDFTARGET=build/debug MUPDFLIBDIR=$(MUPDFDIR)/$(MUPDFTARGET) DJVUDIR=djvulibre -CRENGINEDIR=crengine +KPVCRLIGDIR=kpvcrlib +CRENGINEDIR=$(KPVCRLIGDIR)/crengine FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.8 LFSDIR=luafilesystem @@ -59,19 +60,13 @@ DJVULIBS := $(DJVUDIR)/build/libdjvu/.libs/libdjvulibre.a CRENGINELIBS := $(CRENGINEDIR)/crengine/libcrengine.a \ $(CRENGINEDIR)/thirdparty/chmlib/libchmlib.a \ $(CRENGINEDIR)/thirdparty/libpng/libpng.a \ - $(CRENGINEDIR)/thirdparty/libjpeg/libjpeg.a \ - $(CRENGINEDIR)/thirdparty/zlib/libz.a \ $(CRENGINEDIR)/thirdparty/antiword/libantiword.a THIRDPARTYLIBS := $(MUPDFLIBDIR)/libfreetype.a \ $(MUPDFLIBDIR)/libopenjpeg.a \ $(MUPDFLIBDIR)/libjbig2dec.a \ + $(MUPDFLIBDIR)/libjpeg.a \ $(MUPDFLIBDIR)/libz.a -# @TODO the libjpeg used by mupdf is too new for crengine and will cause -# a segment fault when decoding jpeg images in crengine, we need to fix -# this. 28.03 2012 (houqp) - #$(MUPDFLIBDIR)/libjpeg.a - LUALIB := $(LUADIR)/src/liblua.a kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft.o lfs.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS) @@ -117,8 +112,6 @@ fetchthirdparty: -rm -Rf mupdf/thirdparty git submodule init git submodule update - 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 - test -f $(CRENGINEDIR)/thirdparty/zlib/qconfig.h || touch $(CRENGINEDIR)/thirdparty/zlib/qconfig.h test -f mupdf-thirdparty.zip || wget http://www.mupdf.com/download/mupdf-thirdparty.zip unzip mupdf-thirdparty.zip -d mupdf test -f lua-5.1.4.tar.gz || wget http://www.lua.org/ftp/lua-5.1.4.tar.gz @@ -130,7 +123,10 @@ clean: cleanthirdparty: make -C $(LUADIR) clean make -C $(MUPDFDIR) clean - make -C $(CRENGINEDIR) clean + make -C $(CRENGINEDIR)/thirdparty/antiword clean + make -C $(CRENGINEDIR)/thirdparty/chmlib clean + make -C $(CRENGINEDIR)/thirdparty/libpng clean + make -C $(CRENGINEDIR)/crengine clean -rm -rf $(DJVUDIR)/build -rm -f $(MUPDFDIR)/fontdump.host -rm -f $(MUPDFDIR)/cmapdump.host @@ -159,13 +155,7 @@ endif make -C $(DJVUDIR)/build $(CRENGINELIBS): - cd $(CRENGINEDIR) && cmake -D CR3_PNG=1 -D CR3_JPEG=1 . - cd $(CRENGINEDIR)/thirdparty/libjpeg && make - cd $(CRENGINEDIR)/thirdparty/chmlib && make - cd $(CRENGINEDIR)/thirdparty/antiword && make - cd $(CRENGINEDIR)/thirdparty/libpng && make - cd $(CRENGINEDIR)/thirdparty/zlib && make - cd $(CRENGINEDIR)/crengine && make + cd $(KPVCRLIGDIR) && CC="$(CC)" CXX="$(CXX)" cmake . && make $(LUALIB): make -C lua/src CC="$(CC)" CFLAGS="$(CFLAGS)" MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E" liblua.a diff --git a/crengine b/crengine deleted file mode 160000 index e0a86d85a..000000000 --- a/crengine +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e0a86d85a3da3bed48a84fd3096ee6040ba1ba34 diff --git a/kpvcrlib/CMakeLists.txt b/kpvcrlib/CMakeLists.txt new file mode 100644 index 000000000..59ac5c365 --- /dev/null +++ b/kpvcrlib/CMakeLists.txt @@ -0,0 +1,39 @@ +PROJECT(kpvcrlib) +cmake_minimum_required(VERSION 2.6) + +SET(CR_3RDPARTY_DIR crengine/thirdparty) + +SET(CR3_PNG 1) +SET(CR3_JPEG 1) + +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) + +INCLUDE_DIRECTORIES( + ${FREETYPE_INCLUDE_DIRS} + ${ANTIWORD_INCLUDE_DIR} + ${CHM_INCLUDE_DIRS} + ${PNG_INCLUDE_DIR} +) + +ADD_DEFINITIONS(-DUSE_FONTCONFIG=0 -DUSE_FREETYPE=1 -DCR3_PATCH=1 -DNDEBUG=1) + +#ADD_SUBDIRECTORY(crengine) + +message("Will build patched LIBCHM library") +ADD_DEFINITIONS(-DCHM_SUPPORT_ENABLED=1) +ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/chmlib) + +message("Will build patched LIBPNG library") +ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/libpng) + +message("Will build patched ANTIWORD library") +ADD_DEFINITIONS(-DENABLE_ANTIWORD=1) +ADD_DEFINITIONS(-DCR3_ANTIWORD_PATCH=1) +ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/antiword) + +SET(GUI kpv) +ADD_SUBDIRECTORY(crengine/crengine) + diff --git a/kpvcrlib/crengine b/kpvcrlib/crengine new file mode 160000 index 000000000..ba469d334 --- /dev/null +++ b/kpvcrlib/crengine @@ -0,0 +1 @@ +Subproject commit ba469d33473670ca303e2ef7f9762452a86e18b1 From 74ffdf019ec2b2b98e5e2c952a8701893756f6f3 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 4 Apr 2012 02:57:02 +0800 Subject: [PATCH 23/40] add: dirty hack for libjpeg as workaround no segfault now, but no images displayed. --- Makefile | 12 +++++++++++- cre.cpp | 2 +- kpvcrlib/CMakeLists.txt | 12 ++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 05bd9bc60..44dec6efc 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,10 @@ THIRDPARTYLIBS := $(MUPDFLIBDIR)/libfreetype.a \ $(MUPDFLIBDIR)/libjpeg.a \ $(MUPDFLIBDIR)/libz.a +#@TODO patch crengine to use the latest libjpeg 04.04 2012 (houqp) + #$(MUPDFLIBDIR)/libjpeg.a + #$(CRENGINEDIR)/thirdparty/libjpeg/libjpeg.a + LUALIB := $(LUADIR)/src/liblua.a kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft.o lfs.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS) @@ -112,8 +116,12 @@ fetchthirdparty: -rm -Rf mupdf/thirdparty git submodule init git submodule update + ln -s kpvcrlib/crengine/cr3gui/data data test -f mupdf-thirdparty.zip || wget http://www.mupdf.com/download/mupdf-thirdparty.zip unzip mupdf-thirdparty.zip -d mupdf + cd mupdf/thirdparty/jpeg-*/ && \ + patch -N -p0 < ../../../kpvcrlib/jpeg_compress_struct_size.patch &&\ + patch -N -p0 < ../../../kpvcrlib/jpeg_decompress_struct_size.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 @@ -155,7 +163,9 @@ endif make -C $(DJVUDIR)/build $(CRENGINELIBS): - cd $(KPVCRLIGDIR) && CC="$(CC)" CXX="$(CXX)" cmake . && make + cd $(KPVCRLIGDIR) && rm -rf CMakeCache.txt CMakeFiles && \ + CFLAGS="$(CFLAGS)" CC="$(CC)" CXX="$(CXX)" cmake . && \ + make $(LUALIB): make -C lua/src CC="$(CC)" CFLAGS="$(CFLAGS)" MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E" liblua.a diff --git a/cre.cpp b/cre.cpp index efd989863..29337a2db 100644 --- a/cre.cpp +++ b/cre.cpp @@ -45,6 +45,7 @@ static int openDocument(lua_State *L) { doc->text_view = new LVDocView(); doc->text_view->setStyleSheet(lString8(style_sheet)); + doc->text_view->setBackgroundColor(0x000000); doc->text_view->LoadDocument(file_name); doc->text_view->setViewMode(DVM_SCROLL, -1); doc->text_view->Resize(width, height); @@ -209,7 +210,6 @@ static int drawCurrentPage(lua_State *L) { doc->text_view->Resize(w, h); doc->text_view->Render(); - drawBuf.Clear(0xFFFFFF); doc->text_view->Draw(drawBuf); diff --git a/kpvcrlib/CMakeLists.txt b/kpvcrlib/CMakeLists.txt index 59ac5c365..8e325b2e0 100644 --- a/kpvcrlib/CMakeLists.txt +++ b/kpvcrlib/CMakeLists.txt @@ -2,6 +2,7 @@ PROJECT(kpvcrlib) cmake_minimum_required(VERSION 2.6) SET(CR_3RDPARTY_DIR crengine/thirdparty) +SET(MUPDF_3RDPARTY_DIR ../mupdf/thirdparty) SET(CR3_PNG 1) SET(CR3_JPEG 1) @@ -10,18 +11,21 @@ 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(JPEGLIB_INCLUDE_DIR ${MUPDF_3RDPARTY_DIR}/jpeg-8d) +#SET(JPEGLIB_INCLUDE_DIR ${CR_3RDPARTY_DIR}/libjpeg) INCLUDE_DIRECTORIES( ${FREETYPE_INCLUDE_DIRS} ${ANTIWORD_INCLUDE_DIR} ${CHM_INCLUDE_DIRS} ${PNG_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIR} + ${JPEGLIB_INCLUDE_DIR} ) ADD_DEFINITIONS(-DUSE_FONTCONFIG=0 -DUSE_FREETYPE=1 -DCR3_PATCH=1 -DNDEBUG=1) -#ADD_SUBDIRECTORY(crengine) - message("Will build patched LIBCHM library") ADD_DEFINITIONS(-DCHM_SUPPORT_ENABLED=1) ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/chmlib) @@ -29,11 +33,15 @@ ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/chmlib) message("Will build patched LIBPNG library") ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/libpng) +#message("Will build patched JPEGLIB library") +#ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/libjpeg) + message("Will build patched ANTIWORD library") ADD_DEFINITIONS(-DENABLE_ANTIWORD=1) ADD_DEFINITIONS(-DCR3_ANTIWORD_PATCH=1) ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/antiword) SET(GUI kpv) +ADD_DEFINITIONS(-DJCONFIG_INCLUDE=1) ADD_SUBDIRECTORY(crengine/crengine) From bb5e28883c807db32d67c2221974e5ea3a885260 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 4 Apr 2012 03:00:20 +0800 Subject: [PATCH 24/40] add: patch files for previous commit --- .gitignore | 4 ++++ kpvcrlib/jpeg_compress_struct_size.patch | 15 +++++++++++++++ kpvcrlib/jpeg_decompress_struct_size.patch | 15 +++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 kpvcrlib/jpeg_compress_struct_size.patch create mode 100644 kpvcrlib/jpeg_decompress_struct_size.patch diff --git a/.gitignore b/.gitignore index 21f649e41..81a4bd850 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ kindlepdfviewer-*.zip /.project /.reader.kpdfview +kpvcrlib/CMakeCache.txt +kpvcrlib/CMakeFiles/ +kpvcrlib/cmake_install.cmake +kpvcrlib/Makefile diff --git a/kpvcrlib/jpeg_compress_struct_size.patch b/kpvcrlib/jpeg_compress_struct_size.patch new file mode 100644 index 000000000..e2da6de22 --- /dev/null +++ b/kpvcrlib/jpeg_compress_struct_size.patch @@ -0,0 +1,15 @@ +--- jcapimin.c 2012-04-04 00:02:30.000000000 +0800 ++++ jcapimin-patched.c 2012-04-04 00:02:26.000000000 +0800 +@@ -36,9 +36,9 @@ + cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ + if (version != JPEG_LIB_VERSION) + ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); +- if (structsize != SIZEOF(struct jpeg_compress_struct)) +- ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, +- (int) SIZEOF(struct jpeg_compress_struct), (int) structsize); ++ /*if (structsize != SIZEOF(struct jpeg_compress_struct))*/ ++ /*ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, */ ++ /*(int) SIZEOF(struct jpeg_compress_struct), (int) structsize);*/ + + /* For debugging purposes, we zero the whole master structure. + * But the application has already set the err pointer, and may have set diff --git a/kpvcrlib/jpeg_decompress_struct_size.patch b/kpvcrlib/jpeg_decompress_struct_size.patch new file mode 100644 index 000000000..deaf375a1 --- /dev/null +++ b/kpvcrlib/jpeg_decompress_struct_size.patch @@ -0,0 +1,15 @@ +--- jdapimin.c 2012-04-04 01:09:00.000000000 +0800 ++++ jdapimin-patched.c 2012-04-04 01:42:44.000000000 +0800 +@@ -36,9 +36,9 @@ + cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ + if (version != JPEG_LIB_VERSION) + ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); +- if (structsize != SIZEOF(struct jpeg_decompress_struct)) +- ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, +- (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize); ++ /*if (structsize != SIZEOF(struct jpeg_decompress_struct))*/ ++ /*ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, */ ++ /*(int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);*/ + + /* For debugging purposes, we zero the whole master structure. + * But the application has already set the err pointer, and may have set From 8b6398b58e38a873b9e95c1ab34e0f38d3f6f222 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 4 Apr 2012 15:27:01 +0800 Subject: [PATCH 25/40] mod: small changes for kindle build --- Makefile | 5 ++++- kpvcrlib/CMakeLists.txt | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 44dec6efc..557293ea8 100644 --- a/Makefile +++ b/Makefile @@ -135,6 +135,7 @@ cleanthirdparty: make -C $(CRENGINEDIR)/thirdparty/chmlib clean make -C $(CRENGINEDIR)/thirdparty/libpng clean make -C $(CRENGINEDIR)/crengine clean + make -C $(KPVCRLIGDIR) clean -rm -rf $(DJVUDIR)/build -rm -f $(MUPDFDIR)/fontdump.host -rm -f $(MUPDFDIR)/cmapdump.host @@ -164,7 +165,7 @@ endif $(CRENGINELIBS): cd $(KPVCRLIGDIR) && rm -rf CMakeCache.txt CMakeFiles && \ - CFLAGS="$(CFLAGS)" CC="$(CC)" CXX="$(CXX)" cmake . && \ + CC="$(CC)" CXX="$(CXX)" cmake . && \ make $(LUALIB): @@ -185,6 +186,8 @@ customupdate: kpdfview file kpdfview | grep ARM || exit 1 mkdir $(INSTALL_DIR) cp -p README.TXT COPYING kpdfview *.lua $(INSTALL_DIR) + cp -rpL data $(INSTALL_DIR) + cp -rp fonts $(INSTALL_DIR) zip -r kindlepdfviewer-$(VERSION).zip $(INSTALL_DIR) launchpad/ rm -Rf $(INSTALL_DIR) @echo "copy kindlepdfviewer-$(VERSION).zip to /mnt/us/customupdates and install with shift+shift+I" diff --git a/kpvcrlib/CMakeLists.txt b/kpvcrlib/CMakeLists.txt index 8e325b2e0..19bafa56b 100644 --- a/kpvcrlib/CMakeLists.txt +++ b/kpvcrlib/CMakeLists.txt @@ -1,19 +1,22 @@ PROJECT(kpvcrlib) cmake_minimum_required(VERSION 2.6) +SET(MUPDF_DIR ../mupdf) +SET(MUPDF_3RDPARTY_DIR ${MUPDF_DIR}/thirdparty) SET(CR_3RDPARTY_DIR crengine/thirdparty) -SET(MUPDF_3RDPARTY_DIR ../mupdf/thirdparty) SET(CR3_PNG 1) -SET(CR3_JPEG 1) +#SET(CR3_JPEG 1) 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 ${CR_3RDPARTY_DIR}/zlib) SET(JPEGLIB_INCLUDE_DIR ${MUPDF_3RDPARTY_DIR}/jpeg-8d) #SET(JPEGLIB_INCLUDE_DIR ${CR_3RDPARTY_DIR}/libjpeg) +SET(JCONFIG_INCLUDE_DIR ${MUPDF_DIR}/scripts) INCLUDE_DIRECTORIES( ${FREETYPE_INCLUDE_DIRS} @@ -22,6 +25,7 @@ INCLUDE_DIRECTORIES( ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${JPEGLIB_INCLUDE_DIR} + ${JCONFIG_INCLUDE_DIR} ) ADD_DEFINITIONS(-DUSE_FONTCONFIG=0 -DUSE_FREETYPE=1 -DCR3_PATCH=1 -DNDEBUG=1) @@ -42,6 +46,6 @@ ADD_DEFINITIONS(-DCR3_ANTIWORD_PATCH=1) ADD_SUBDIRECTORY(${CR_3RDPARTY_DIR}/antiword) SET(GUI kpv) -ADD_DEFINITIONS(-DJCONFIG_INCLUDE=1) +#ADD_DEFINITIONS(-DJCONFIG_INCLUDED=1) ADD_SUBDIRECTORY(crengine/crengine) From b9b9455fe0d99f3c5b7ecf42d10b01e2d9c83eae Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 4 Apr 2012 17:03:01 +0800 Subject: [PATCH 26/40] fix: progressbar display in crereader --- crereader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crereader.lua b/crereader.lua index c730eb846..7575e3d9b 100644 --- a/crereader.lua +++ b/crereader.lua @@ -95,7 +95,7 @@ function CREReader:_drawReadingInfo() ypos = ypos + 15 blitbuffer.progressBar(fb.bb, 10, ypos, width-20, 15, - 5, 4, load_percent, 8) + 5, 4, load_percent/100, 8) end function CREReader:nextView() From f90ae38cb5dbf0e1374a41480c4b2afdc1799767 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 4 Apr 2012 17:25:18 +0800 Subject: [PATCH 27/40] mod: load css in crereader --- cre.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cre.cpp b/cre.cpp index 29337a2db..54df5b830 100644 --- a/cre.cpp +++ b/cre.cpp @@ -36,19 +36,26 @@ typedef struct CreDocument { static int openDocument(lua_State *L) { const char *file_name = luaL_checkstring(L, 1); const char *style_sheet = luaL_checkstring(L, 2); + int width = luaL_checkint(L, 3); int height = luaL_checkint(L, 4); + lString8 css; CreDocument *doc = (CreDocument*) lua_newuserdata(L, sizeof(CreDocument)); luaL_getmetatable(L, "credocument"); lua_setmetatable(L, -2); doc->text_view = new LVDocView(); - doc->text_view->setStyleSheet(lString8(style_sheet)); doc->text_view->setBackgroundColor(0x000000); - doc->text_view->LoadDocument(file_name); + if (LVLoadStylesheetFile(lString16(style_sheet), css)){ + if (!css.empty()){ + doc->text_view->setStyleSheet(css); + } + } doc->text_view->setViewMode(DVM_SCROLL, -1); doc->text_view->Resize(width, height); + + doc->text_view->LoadDocument(file_name); doc->text_view->Render(); return 1; From 17823a0b589aadb1f78aee850434764d8bce6ec7 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 4 Apr 2012 20:24:17 +0800 Subject: [PATCH 28/40] mod: add cflags in crereader compiling --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 557293ea8..709fab96c 100644 --- a/Makefile +++ b/Makefile @@ -165,7 +165,7 @@ endif $(CRENGINELIBS): cd $(KPVCRLIGDIR) && rm -rf CMakeCache.txt CMakeFiles && \ - CC="$(CC)" CXX="$(CXX)" cmake . && \ + CFLAGS="$(CFLAGS)" CC="$(CC)" CXX="$(CXX)" cmake . && \ make $(LUALIB): From 1593c568033be0e2df2b80e7253debec552c6a54 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 5 Apr 2012 10:31:31 +0800 Subject: [PATCH 29/40] mod: add html support in crereader --- crereader.lua | 3 +++ filechooser.lua | 6 +++++- filesearcher.lua | 1 + reader.lua | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crereader.lua b/crereader.lua index 7575e3d9b..79733ae91 100644 --- a/crereader.lua +++ b/crereader.lua @@ -16,6 +16,9 @@ end function CREReader:open(filename) local ok local file_type = string.lower(string.match(filename, ".+%.([^.]+)")) + if file_type == "html" then + file_type = "htm" + end local style_sheet = "./data/"..file_type..".css" ok, self.doc = pcall(cre.openDocument, filename, style_sheet, width, height) diff --git a/filechooser.lua b/filechooser.lua index 58c294f65..cb5a5aaf5 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -54,7 +54,11 @@ function FileChooser:readDir() table.insert(self.dirs, f) else local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "") - if file_type == "djvu" or file_type == "pdf" or file_type == "xps" or file_type == "cbz" or file_type == "epub" or file_type == "txt" or file_type == "rtf" or file_type == "htm" or file_type == "fb2" or file_type == "chm" then + if file_type == "djvu" + or file_type == "pdf" or file_type == "xps" or file_type == "cbz" + or file_type == "epub" or file_type == "txt" or file_type == "rtf" + or file_type == "htm" or file_type == "html" + or file_type == "fb2" or file_type == "chm" then table.insert(self.files, f) end end diff --git a/filesearcher.lua b/filesearcher.lua index 097fb5c57..31ec6e371 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -38,6 +38,7 @@ function FileSearcher:readDir() or file_type == "xps" or file_type == "cbz" or file_type == "epub" or file_type == "txt" or file_type == "rtf" or file_type == "htm" + or file_type == "html" or file_type == "fb2" or file_type == "chm" then file_entry = {dir=d, name=f,} table.insert(self.files, file_entry) diff --git a/reader.lua b/reader.lua index adbd99447..f74f5d1f5 100755 --- a/reader.lua +++ b/reader.lua @@ -43,7 +43,7 @@ function openFile(filename) reader = DJVUReader elseif file_type == "pdf" or file_type == "xps" or file_type == "cbz" then reader = PDFReader - elseif file_type == "epub" or file_type == "txt" or file_type == "rtf" or file_type == "htm" or file_type == "fb2" or file_type == "chm" then + elseif file_type == "epub" or file_type == "txt" or file_type == "rtf" or file_type == "htm" or file_type == "html" or file_type == "fb2" or file_type == "chm" then reader = CREReader end if reader then From d3e8c57bc8401f69066d134e29e6b3096cf043fa Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 6 Apr 2012 16:34:53 +0800 Subject: [PATCH 30/40] mod: reenable global pan_overlap_vertical in crereader --- crereader.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/crereader.lua b/crereader.lua index 79733ae91..e1004b299 100644 --- a/crereader.lua +++ b/crereader.lua @@ -4,7 +4,6 @@ require "inputbox" CREReader = UniReader:new{ pos = 0, percent = 0, - pan_overlap_vertical = 0, } function CREReader:init() From 085d79d033f7d8fcacaf2715c7a2dc18c1358065 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 6 Apr 2012 18:05:54 +0800 Subject: [PATCH 31/40] add: font menu and bold attribute toggle shortcut in crereader --- cre.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++-- crereader.lua | 28 ++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/cre.cpp b/cre.cpp index 54df5b830..7ec155d21 100644 --- a/cre.cpp +++ b/cre.cpp @@ -54,7 +54,6 @@ static int openDocument(lua_State *L) { } doc->text_view->setViewMode(DVM_SCROLL, -1); doc->text_view->Resize(width, height); - doc->text_view->LoadDocument(file_name); doc->text_view->Render(); @@ -153,7 +152,8 @@ static int walkTableOfContent(lua_State *L, LVTocItem *toc, int *count) { * } * * Warnning: not like pdf or djvu support, page here refers to the - * position(height) within the document, not the real page number. + * percent of height within the document, not the real page number. + * We use page here just to keep consistent with other readers. * */ static int getTableOfContent(lua_State *L) { @@ -168,6 +168,41 @@ static int getTableOfContent(lua_State *L) { return 1; } +/* + * Return a table like this: + * { + * "FreeMono", + * "FreeSans", + * "FreeSerif", + * } + * + */ +static int getFontFaces(lua_State *L) { + int i = 0; + lString16Collection face_list; + + fontMan->getFaceList(face_list); + + lua_newtable(L); + for (i = 0; i < face_list.length(); i++) + { + lua_pushnumber(L, i+1); + lua_pushstring(L, UnicodeToLocal(face_list[i]).c_str()); + lua_settable(L, -3); + } + + return 1; +} + +static int setFontFace(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + const char *face = luaL_checkstring(L, 2); + + doc->text_view->setDefaultFontFace(lString8(face)); + + return 0; +} + static int gotoPage(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); int pageno = luaL_checkint(L, 2); @@ -206,6 +241,14 @@ static int zoomFont(lua_State *L) { return 1; } +static int toggleFontBolder(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + doc->text_view->doCommand(DCMD_TOGGLE_BOLD); + + return 0; +} + static int drawCurrentPage(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); @@ -240,20 +283,26 @@ static int drawCurrentPage(lua_State *L) { static const struct luaL_Reg cre_func[] = { {"openDocument", openDocument}, + {"getFontFaces", getFontFaces}, {NULL, NULL} }; static const struct luaL_Reg credocument_meth[] = { + /* get methods */ {"getPages", getNumberOfPages}, {"getCurrentPage", getCurrentPage}, {"getPos", getPos}, {"getPosPercent", getPosPercent}, {"getFullHeight", getFullHeight}, {"getToc", getTableOfContent}, + /* set methods */ + {"setFontFace", setFontFace}, + /* control methods */ {"gotoPage", gotoPage}, {"gotoPercent", gotoPercent}, {"gotoPos", gotoPos}, {"zoomFont", zoomFont}, + {"toggleFontBolder", toggleFontBolder}, {"drawCurrentPage", drawCurrentPage}, {"close", closeDocument}, {"__gc", closeDocument}, diff --git a/crereader.lua b/crereader.lua index e1004b299..9ab7b5d81 100644 --- a/crereader.lua +++ b/crereader.lua @@ -1,5 +1,6 @@ require "unireader" require "inputbox" +require "selectmenu" CREReader = UniReader:new{ pos = 0, @@ -15,6 +16,7 @@ end function CREReader:open(filename) local ok local file_type = string.lower(string.match(filename, ".+%.([^.]+)")) + -- these two format use the same css file if file_type == "html" then file_type = "htm" end @@ -125,7 +127,6 @@ function CREReader:adjustCreReaderCommands() self.commands:del(KEY_D, nil, "D") self.commands:del(KEY_D, MOD_SHIFT, "D") self.commands:del(KEY_D, MOD_ALT, "D") - self.commands:del(KEY_F, nil, "F") self.commands:del(KEY_F, MOD_SHIFT, "F") self.commands:del(KEY_F, MOD_ALT, "F") @@ -157,4 +158,29 @@ function CREReader:adjustCreReaderCommands() cr:goto(math.floor(cr.doc:getFullHeight()*(keydef.keycode-KEY_1)/9)) end ) + self.commands:add(KEY_F, nil, "F", + "invoke font menu", + function(cr) + local face_list = cre.getFontFaces() + + local fonts_menu = SelectMenu:new{ + menu_title = "Fonts Menu", + item_array = face_list, + } + + local item_no = fonts_menu:choose(0, height) + print(face_list[item_no]) + if item_no then + cr.doc:setFontFace(face_list[item_no]) + end + cr:redrawCurrentPage() + end + ) + self.commands:add(KEY_F, MOD_ALT, "F", + "Toggle font bolder attribute", + function(cr) + cr.doc:toggleFontBolder() + cr:redrawCurrentPage() + end + ) end From a5a5c477acc9189af5bd5876f818fb12f6857365 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 6 Apr 2012 19:11:18 +0800 Subject: [PATCH 32/40] mod: save and restore font face for each book in crereader --- crereader.lua | 13 +++++++++++++ unireader.lua | 37 +++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/crereader.lua b/crereader.lua index 9ab7b5d81..55196c265 100644 --- a/crereader.lua +++ b/crereader.lua @@ -5,6 +5,8 @@ require "selectmenu" CREReader = UniReader:new{ pos = 0, percent = 0, + + font_face = nil, } function CREReader:init() @@ -30,6 +32,16 @@ function CREReader:open(filename) return true end +function CREReader:loadSpecialSettings() + local font_face = self.settings:readSetting("font_face") + self.font_face = font_face or "FreeSerif" + self.doc:setFontFace(self.font_face) +end + +function CREReader:saveSpecialSettings() + self.settings:savesetting("font_face", self.font_face) +end + function CREReader:getLastPageOrPos() local last_percent = self.settings:readSetting("last_percent") if last_percent then @@ -172,6 +184,7 @@ function CREReader:adjustCreReaderCommands() print(face_list[item_no]) if item_no then cr.doc:setFontFace(face_list[item_no]) + self.font_face = face_list[item_no] end cr:redrawCurrentPage() end diff --git a/unireader.lua b/unireader.lua index 706a43730..d37fc1f87 100644 --- a/unireader.lua +++ b/unireader.lua @@ -94,24 +94,23 @@ end -- !!!!!!!!!!!!!!!!!!!!!!!!! -- -- For a new specific reader, --- you must always overwrite following two methods: +-- you must always overwrite following method: -- -- * self:open() --- * self:init() -- -- overwrite other methods if needed. ---------------------------------------------------- -function UniReader:init() - -- initialize commands - self:addAllCommands() -end --- open a file and its settings store --- tips: you can use self:loadSettings in open() method. +-- open a file function UniReader:open(filename, cache_size) return false end +function UniReader:init() + -- initialize commands + self:addAllCommands() +end + ---------------------------------------------------- -- You need to overwrite following two methods if your -- reader supports highlight feature. @@ -130,7 +129,7 @@ function UniReader:toggleTextHighLight(word_list) end ---------------------------------------------------- --- renderer memory +-- Renderer memory ---------------------------------------------------- function UniReader:getCacheSize() @@ -141,8 +140,23 @@ function UniReader:cleanCache() return end +---------------------------------------------------- +-- Setting related methods +---------------------------------------------------- + +-- load special settings for specific reader +function UniReader:loadSpecialSettings() + return +end + +-- save special settings for specific reader +function UniReader:saveSpecialSettings() +end + + --[ following are default methods ]-- + function UniReader:initGlobalSettings(settings) local pan_overlap_vertical = settings:readSetting("pan_overlap_vertical") if pan_overlap_vertical then @@ -165,6 +179,7 @@ function UniReader:initGlobalSettings(settings) end end +-- This is a low-level method that can be shared with all readers. function UniReader:loadSettings(filename) if self.doc ~= nil then self.settings = DocSettings:open(filename,self.cache_document_size) @@ -187,6 +202,7 @@ function UniReader:loadSettings(filename) self.globalzoom = self.settings:readSetting("globalzoom") or 1.0 self.globalzoommode = self.settings:readSetting("globalzoommode") or -1 + self:loadSpecialSettings() return true end return false @@ -913,6 +929,7 @@ function UniReader:inputLoop() self.settings:savesetting("globalzoom", self.globalzoom) self.settings:savesetting("globalzoommode", self.globalzoommode) self.settings:savesetting("highlight", self.highlight) + self:saveSpecialSettings() self.settings:close() end @@ -1228,5 +1245,5 @@ function UniReader:addAllCommands() end end) -- end panning - print("## defined commands "..dump(self.commands.map)) + --print("## defined commands "..dump(self.commands.map)) end From 9650a4a0573a91d5d7ad85a39f590c3c8dbf4ff7 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 6 Apr 2012 19:30:10 +0800 Subject: [PATCH 33/40] add: gamma settings in crereader --- cre.cpp | 18 ++++++++++++++++++ crereader.lua | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/cre.cpp b/cre.cpp index 7ec155d21..bde307520 100644 --- a/cre.cpp +++ b/cre.cpp @@ -57,9 +57,25 @@ static int openDocument(lua_State *L) { doc->text_view->LoadDocument(file_name); doc->text_view->Render(); + printf("gamma: %d\n", fontMan->GetGammaIndex()); + + return 1; +} + +static int getGammaIndex(lua_State *L) { + lua_pushinteger(L, fontMan->GetGammaIndex()); + return 1; } +static int setGammaIndex(lua_State *L) { + int index = luaL_checkint(L, 1); + + fontMan->SetGammaIndex(index); + + return 0; +} + static int closeDocument(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); delete doc->text_view; @@ -284,6 +300,8 @@ static int drawCurrentPage(lua_State *L) { static const struct luaL_Reg cre_func[] = { {"openDocument", openDocument}, {"getFontFaces", getFontFaces}, + {"getGammaIndex", getGammaIndex}, + {"setGammaIndex", setGammaIndex}, {NULL, NULL} }; diff --git a/crereader.lua b/crereader.lua index 55196c265..ba1d77e86 100644 --- a/crereader.lua +++ b/crereader.lua @@ -6,6 +6,7 @@ CREReader = UniReader:new{ pos = 0, percent = 0, + gamma_index = 15, font_face = nil, } @@ -36,10 +37,15 @@ function CREReader:loadSpecialSettings() local font_face = self.settings:readSetting("font_face") self.font_face = font_face or "FreeSerif" self.doc:setFontFace(self.font_face) + + local gamma_index = self.settings:readSetting("gamma_index") + self.gamma_index = gamma_index or self.gamma_index + cre.setGammaIndex(self.gamma_index) end function CREReader:saveSpecialSettings() self.settings:savesetting("font_face", self.font_face) + self.settings:savesetting("gamma_index", self.gamma_index) end function CREReader:getLastPageOrPos() @@ -60,6 +66,7 @@ function CREReader:setzoom(page, preCache) end function CREReader:addJump(pos, notes) + return end function CREReader:goto(pos) @@ -196,4 +203,20 @@ function CREReader:adjustCreReaderCommands() cr:redrawCurrentPage() end ) + self.commands:add(KEY_VPLUS, nil, "vol+", + "increase gamma", + function(cr) + cre.setGammaIndex(self.gamma_index + 1) + self.gamma_index = cre.getGammaIndex() + cr:redrawCurrentPage() + end + ) + self.commands:add(KEY_VMINUS, nil, "vol-", + "decrease gamma", + function(cr) + cre.setGammaIndex(self.gamma_index - 1) + self.gamma_index = cre.getGammaIndex() + cr:redrawCurrentPage() + end + ) end From 5e58a94632d37eca70b891cff587ea412ca16a35 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 6 Apr 2012 20:13:46 +0800 Subject: [PATCH 34/40] mod: rm unused shortcuts in crereader --- commands.lua | 11 +++++++++++ crereader.lua | 1 + djvureader.lua | 21 +++++++++++++++++++++ unireader.lua | 12 ------------ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/commands.lua b/commands.lua index 2b5b58aef..1d7064b03 100644 --- a/commands.lua +++ b/commands.lua @@ -88,6 +88,7 @@ function Commands:addGroup(keygroup,keys,help,func) end end +--@TODO handle MOD_ANY 06.04 2012 (houqp) function Commands:del(keycode, modifier, keydescr) local keydef = nil @@ -106,6 +107,16 @@ function Commands:del(keycode, modifier, keydescr) self.map[keydef] = nil end +function Commands:delGroup(keygroup) + if keygroup then + for k,v in pairs(self.map) do + if v.keygroup == keygroup then + self.map[k] = nil + end + end -- EOF for + end +end + function Commands:_addImpl(keydef,help,func,keygroup) if keydef.modifier==MOD_ANY then self:addGroup(keygroup or keydef.descr,{Keydef:new(keydef.keycode,nil), Keydef:new(keydef.keycode,MOD_SHIFT), Keydef:new(keydef.keycode,MOD_ALT)},help,func) diff --git a/crereader.lua b/crereader.lua index ba1d77e86..41fc5e20c 100644 --- a/crereader.lua +++ b/crereader.lua @@ -131,6 +131,7 @@ end function CREReader:adjustCreReaderCommands() -- delete commands + self.commands:delGroup("[joypad]") self.commands:del(KEY_G, nil, "G") self.commands:del(KEY_J, nil, "J") self.commands:del(KEY_K, nil, "K") diff --git a/djvureader.lua b/djvureader.lua index be72ec4c0..c9ec0cdf4 100644 --- a/djvureader.lua +++ b/djvureader.lua @@ -13,6 +13,27 @@ function DJVUReader:open(filename) return ok end +function DJVUReader:init() + self:addAllCommands() + self:adjustDjvuReaderCommand() +end + +function DJVUReader:adjustDjvuReaderCommand() + self.commands:add(KEY_N, nil, "N", + "start highlight mode", + function(unireader) + unireader:startHighLightMode() + unireader:goto(unireader.pageno) + end + ) + self.commands:add(KEY_N, MOD_SHIFT, "N", + "display all highlights", + function(unireader) + unireader:showHighLight() + unireader:goto(unireader.pageno) + end + ) +end -----------[ highlight support ]---------- diff --git a/unireader.lua b/unireader.lua index d37fc1f87..4d010de80 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1096,18 +1096,6 @@ function UniReader:addAllCommands() function(unireader) unireader:screenRotate("anticlockwise") end) - self.commands:add(KEY_N, nil, "N", - "start highlight mode", - function(unireader) - unireader:startHighLightMode() - unireader:goto(unireader.pageno) - end) - self.commands:add(KEY_N, MOD_SHIFT, "N", - "display all highlights", - function(unireader) - unireader:showHighLight() - unireader:goto(unireader.pageno) - end) self.commands:add(KEY_R, MOD_SHIFT, "R", "manual full screen refresh", function(unireader) From 3992fdca0f9a2a23da89525556e4ab9cc4e50fd2 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 6 Apr 2012 20:26:53 +0800 Subject: [PATCH 35/40] add: vertical pan in crereader --- crereader.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crereader.lua b/crereader.lua index 41fc5e20c..9b5358765 100644 --- a/crereader.lua +++ b/crereader.lua @@ -43,11 +43,6 @@ function CREReader:loadSpecialSettings() cre.setGammaIndex(self.gamma_index) end -function CREReader:saveSpecialSettings() - self.settings:savesetting("font_face", self.font_face) - self.settings:savesetting("gamma_index", self.gamma_index) -end - function CREReader:getLastPageOrPos() local last_percent = self.settings:readSetting("last_percent") if last_percent then @@ -57,6 +52,11 @@ function CREReader:getLastPageOrPos() end end +function CREReader:saveSpecialSettings() + self.settings:savesetting("font_face", self.font_face) + self.settings:savesetting("gamma_index", self.gamma_index) +end + function CREReader:saveLastPageOrPos() self.settings:savesetting("last_percent", self.percent) end @@ -220,4 +220,16 @@ function CREReader:adjustCreReaderCommands() cr:redrawCurrentPage() end ) + self.commands:add(KEY_FW_UP, nil, "joypad up", + "pan "..self.shift_y.." pixels upwards", + function(cr) + cr:goto(cr.pos - cr.shift_y) + end + ) + self.commands:add(KEY_FW_DOWN, nil, "joypad down", + "pan "..self.shift_y.." pixels downwards", + function(cr) + cr:goto(cr.pos + cr.shift_y) + end + ) end From 3160ae15f4eaf2b3fcf9e1230092781d6c86bee4 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 7 Apr 2012 13:37:13 +0200 Subject: [PATCH 36/40] make fetchthirdparty fails on existing data dir #77 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 709fab96c..f9b2c1e32 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ fetchthirdparty: -rm -Rf mupdf/thirdparty git submodule init git submodule update - ln -s kpvcrlib/crengine/cr3gui/data data + ln -sf kpvcrlib/crengine/cr3gui/data data test -f mupdf-thirdparty.zip || wget http://www.mupdf.com/download/mupdf-thirdparty.zip unzip mupdf-thirdparty.zip -d mupdf cd mupdf/thirdparty/jpeg-*/ && \ From f1ba76bfdc779f78ee7471746fee3f230052a411 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 7 Apr 2012 13:48:21 +0200 Subject: [PATCH 37/40] create fonts symlink to TTF_FONTS_DIR #77 It took me few tries to figure out that fonts should point to directory with *.ttf files as opposed to directory with subdirectories so I decided to add comment about it --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index f9b2c1e32..8ff43ed3a 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ CRENGINEDIR=$(KPVCRLIGDIR)/crengine FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.8 LFSDIR=luafilesystem +# must point to directory with *.ttf fonts for crengine +TTF_FONTS_DIR=/usr/share/fonts/truetype/freefont/ + # set this to your ARM cross compiler: CC:=arm-unknown-linux-gnueabi-gcc @@ -117,6 +120,7 @@ fetchthirdparty: git submodule init git submodule update ln -sf kpvcrlib/crengine/cr3gui/data data + test -d fonts || ln -sf $(TTF_FONTS_DIR) fonts test -f mupdf-thirdparty.zip || wget http://www.mupdf.com/download/mupdf-thirdparty.zip unzip mupdf-thirdparty.zip -d mupdf cd mupdf/thirdparty/jpeg-*/ && \ From cb83e478758062e2f3f95aa31e52b943e97dada2 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 7 Apr 2012 22:55:56 +0800 Subject: [PATCH 38/40] mod: use XPointer as absolute postion indicator inside document --- cre.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++++----- crereader.lua | 111 +++++++++++++++++++++++++++++++++++++-------- unireader.lua | 32 +++++++++---- 3 files changed, 226 insertions(+), 39 deletions(-) diff --git a/cre.cpp b/cre.cpp index bde307520..27260bd63 100644 --- a/cre.cpp +++ b/cre.cpp @@ -30,6 +30,7 @@ extern "C" { typedef struct CreDocument { LVDocView *text_view; + ldomDocument *dom_doc; } CreDocument; @@ -55,9 +56,9 @@ static int openDocument(lua_State *L) { doc->text_view->setViewMode(DVM_SCROLL, -1); doc->text_view->Resize(width, height); doc->text_view->LoadDocument(file_name); + doc->dom_doc = doc->text_view->getDocument(); doc->text_view->Render(); - printf("gamma: %d\n", fontMan->GetGammaIndex()); return 1; } @@ -99,7 +100,20 @@ static int getCurrentPage(lua_State *L) { return 1; } -static int getPos(lua_State *L) { +static int getPageFromXPointer(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + const char *xpointer_str = luaL_checkstring(L, 2); + + int page = 0; + ldomXPointer xp = doc->dom_doc->createXPointer(lString16(xpointer_str)); + + page = doc->text_view->getBookmarkPage(xp); + lua_pushinteger(L, page); + + return 1; +} + +static int getCurrentPos(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); lua_pushinteger(L, doc->text_view->GetPos()); @@ -107,7 +121,22 @@ static int getPos(lua_State *L) { return 1; } -static int getPosPercent(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); + + //lvRect rc; + //int pos; + + //ldomXPointer *xp = NULL; + //xp = doc->dom_doc->createXPointer(lString16(xpointer_str)); + //getCursorDocRect(*xp, rc); + //pos = + + //return 1; +//} + +static int getCurrentPercent(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); lua_pushinteger(L, doc->text_view->getPosPercent()); @@ -115,6 +144,15 @@ static int getPosPercent(lua_State *L) { return 1; } +static int getXPointer(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + ldomXPointer xp = doc->text_view->getBookmark(); + lua_pushstring(L, UnicodeToLocal(xp.toString()).c_str()); + + return 1; +} + static int getFullHeight(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); @@ -138,7 +176,13 @@ static int walkTableOfContent(lua_State *L, LVTocItem *toc, int *count) { /* set subtable, Toc entry */ lua_newtable(L); lua_pushstring(L, "page"); - lua_pushnumber(L, toc_tmp->getY()); + lua_pushnumber(L, toc_tmp->getPercent()); + lua_settable(L, -3); + + lua_pushstring(L, "xpointer"); + lua_pushstring(L, UnicodeToLocal( + toc_tmp->getXPointer().toString()).c_str() + ); lua_settable(L, -3); lua_pushstring(L, "depth"); @@ -163,8 +207,18 @@ static int walkTableOfContent(lua_State *L, LVTocItem *toc, int *count) { /* * Return a table like this: * { - * {page=12, depth=1, title="chapter1"}, - * {page=54, depth=1, title="chapter2"}, + * { + * page=12, + * xpointer = "/body/DocFragment[11].0", + * depth=1, + * title="chapter1" + * }, + * { + * page=54, + * xpointer = "/body/DocFragment[13].0", + * depth=1, + * title="chapter2" + * }, * } * * Warnning: not like pdf or djvu support, page here refers to the @@ -246,6 +300,21 @@ static int gotoPos(lua_State *L) { return 0; } +static int gotoXPointer(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + const char *xpointer_str = luaL_checkstring(L, 2); + + ldomXPointer xp = doc->dom_doc->createXPointer(lString16(xpointer_str)); + + doc->text_view->goToBookmark(xp); + /* CREngine does not call checkPos() immediately after goToBookmark, + * so I have to manually update the pos in order to get a correctionColor + * return from GetPos() call. */ + doc->text_view->SetPos(xp.toPoint().y); + + return 0; +} + /* zoom font by given delta and return zoomed font size */ static int zoomFont(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); @@ -265,6 +334,32 @@ static int toggleFontBolder(lua_State *L) { return 0; } +static int cursorRight(lua_State *L) { + //CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + //LVDocView *tv = doc->text_view; + + //ldomXPointer p = tv->getCurrentPageMiddleParagraph(); + //lString16 s = p.toString(); + //printf("~~~~~~~~~~%s\n", UnicodeToLocal(s).c_str()); + + //tv->selectRange(*(tv->selectFirstPageLink())); + //ldomXRange *r = tv->selectNextPageLink(true); + //lString16 s = r->getRangeText(); + //printf("------%s\n", UnicodeToLocal(s).c_str()); + + //tv->selectRange(*r); + //tv->updateSelections(); + + //LVPageWordSelector sel(doc->text_view); + //doc->text_view->doCommand(DCMD_SELECT_FIRST_SENTENCE); + //sel.moveBy(DIR_RIGHT, 2); + //sel.updateSelection(); + //printf("---------------- %s\n", UnicodeToLocal(sel.getSelectedWord()->getText()).c_str()); + + return 0; +} + static int drawCurrentPage(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); @@ -306,21 +401,26 @@ static const struct luaL_Reg cre_func[] = { }; static const struct luaL_Reg credocument_meth[] = { - /* get methods */ + /*--- get methods ---*/ {"getPages", getNumberOfPages}, {"getCurrentPage", getCurrentPage}, - {"getPos", getPos}, - {"getPosPercent", getPosPercent}, + {"getPageFromXPointer", getPageFromXPointer}, + {"getCurrentPos", getCurrentPos}, + {"getCurrentPercent", getCurrentPercent}, + {"getXPointer", getXPointer}, {"getFullHeight", getFullHeight}, {"getToc", getTableOfContent}, - /* set methods */ + /*--- set methods ---*/ {"setFontFace", setFontFace}, - /* control methods */ + /* --- control methods ---*/ {"gotoPage", gotoPage}, {"gotoPercent", gotoPercent}, {"gotoPos", gotoPos}, + {"gotoXPointer", gotoXPointer}, {"zoomFont", zoomFont}, {"toggleFontBolder", toggleFontBolder}, + //{"cursorLeft", cursorLeft}, + //{"cursorRight", cursorRight}, {"drawCurrentPage", drawCurrentPage}, {"close", closeDocument}, {"__gc", closeDocument}, diff --git a/crereader.lua b/crereader.lua index 9b5358765..f51adbea7 100644 --- a/crereader.lua +++ b/crereader.lua @@ -3,7 +3,7 @@ require "inputbox" require "selectmenu" CREReader = UniReader:new{ - pos = 0, + pos = nil, percent = 0, gamma_index = 15, @@ -33,6 +33,9 @@ function CREReader:open(filename) return true end +---------------------------------------------------- +-- setting related methods +---------------------------------------------------- function CREReader:loadSpecialSettings() local font_face = self.settings:readSetting("font_face") self.font_face = font_face or "FreeSerif" @@ -46,7 +49,7 @@ end function CREReader:getLastPageOrPos() local last_percent = self.settings:readSetting("last_percent") if last_percent then - return (last_percent * self.doc:getFullHeight()) / 10000 + return math.floor((last_percent * self.doc:getFullHeight()) / 10000) else return 0 end @@ -61,24 +64,40 @@ function CREReader:saveLastPageOrPos() self.settings:savesetting("last_percent", self.percent) end +---------------------------------------------------- +-- render related methods +---------------------------------------------------- +-- we don't need setzoom in CREReader function CREReader:setzoom(page, preCache) return end -function CREReader:addJump(pos, notes) - return +function CREReader:redrawCurrentPage() + self:goto(self.pos) end -function CREReader:goto(pos) - local pos = math.min(pos, self.doc:getFullHeight()) - pos = math.max(pos, 0) +---------------------------------------------------- +-- goto related methods +---------------------------------------------------- +function CREReader:goto(pos, pos_type) + local prev_xpointer = self.doc:getXPointer() + if pos_type == "xpointer" then + self.doc:gotoXPointer(pos) + pos = self.doc:getCurrentPos() + else -- pos_type is PERCENT * 100 + pos = math.min(pos, self.doc:getFullHeight()) + pos = math.max(pos, 0) + self.doc:gotoPos(pos) + end -- add to jump_stack, distinguish jump from normal page turn + -- NOTE: + -- even though we have called gotoPos() or gotoXPointer() previously, + -- self.pos hasn't been updated yet here, so we can still make use of it. if self.pos and math.abs(self.pos - pos) > height then - self:addJump(self.percent) + self:addJump(prev_xpointer) end - self.doc:gotoPos(pos) self.doc:drawCurrentPage(self.nulldc, fb.bb) if self.rcount == self.rcountmax then @@ -93,13 +112,65 @@ function CREReader:goto(pos) self.pos = pos self.pageno = self.doc:getCurrentPage() - self.percent = self.doc:getPosPercent() + self.percent = self.doc:getCurrentPercent() end -function CREReader:redrawCurrentPage() - self:goto(self.pos) +function CREReader:gotoPercent(percent) + self:goto(percent * self.doc:getFullHeight() / 10000) +end + +function CREReader:gotoTocEntry(entry) + self:goto(entry.xpointer, "xpointer") +end + +function CREReader:nextView() + return self.pos + height - self.pan_overlap_vertical +end + +function CREReader:prevView() + return self.pos - height + self.pan_overlap_vertical +end + +---------------------------------------------------- +-- jump stack related methods +---------------------------------------------------- +function CREReader:isSamePage(p1, p2) + return self.doc:getPageFromXPointer(p1) == self.doc:getPageFromXPointer(p2) end +function CREReader:showJumpStack() + local menu_items = {} + print(dump(self.jump_stack)) + for k,v in ipairs(self.jump_stack) do + table.insert(menu_items, + v.datetime.." -> page ".. + (self.doc:getPageFromXPointer(v.page)).." "..v.notes) + end + jump_menu = SelectMenu:new{ + menu_title = "Jump Keeper (current page: "..self.pageno..")", + item_array = menu_items, + no_item_msg = "No jump history.", + } + item_no = jump_menu:choose(0, fb.bb:getHeight()) + if item_no then + local jump_item = self.jump_stack[item_no] + self:goto(jump_item.page, "xpointer") + else + self:redrawCurrentPage() + end +end + +---------------------------------------------------- +-- TOC related methods +---------------------------------------------------- +function CREReader:getTocTitleOfCurrentPage() + return self:getTocTitleByPage(self.percent) +end + + +---------------------------------------------------- +-- menu related methods +---------------------------------------------------- -- used in CREReader:showMenu() function CREReader:_drawReadingInfo() local ypos = height - 50 @@ -109,7 +180,7 @@ function CREReader:_drawReadingInfo() ypos = ypos + 15 local face, fhash = Font:getFaceAndHash(22) - local cur_section = self:getTocTitleByPage(self.pos) + local cur_section = self:getTocTitleOfCurrentPage() if cur_section ~= "" then cur_section = "Section: "..cur_section end @@ -121,13 +192,7 @@ function CREReader:_drawReadingInfo() 5, 4, load_percent/100, 8) end -function CREReader:nextView() - return self.pos + height - self.pan_overlap_vertical -end -function CREReader:prevView() - return self.pos - height + self.pan_overlap_vertical -end function CREReader:adjustCreReaderCommands() -- delete commands @@ -204,6 +269,14 @@ function CREReader:adjustCreReaderCommands() cr:redrawCurrentPage() end ) + self.commands:add(KEY_BACK,nil,"back", + "back to last jump", + function(cr) + if #cr.jump_stack ~= 0 then + cr:goto(cr.jump_stack[1].page, "xpointer") + end + end + ) self.commands:add(KEY_VPLUS, nil, "vol+", "increase gamma", function(cr) diff --git a/unireader.lua b/unireader.lua index 4d010de80..f46f85d57 100644 --- a/unireader.lua +++ b/unireader.lua @@ -563,22 +563,27 @@ function UniReader:show(no) self.slot_visible = slot; end +function UniReader:isSamePage(p1, p2) + return p1 == p2 +end + --[[ @ pageno is the page you want to add to jump_stack + NOTE: for CREReader, pageno refers to xpointer --]] function UniReader:addJump(pageno, notes) local jump_item = nil local notes_to_add = notes if not notes_to_add then -- no notes given, auto generate from Toc entry - notes_to_add = self:getTocTitleByPage(self.pageno) + notes_to_add = self:getTocTitleOfCurrentPage() if notes_to_add ~= "" then notes_to_add = "in "..notes_to_add end end -- move pageno page to jump_stack top if already in for _t,_v in ipairs(self.jump_stack) do - if _v.page == pageno then + if self:isSamePage(_v.page, pageno) then jump_item = _v table.remove(self.jump_stack, _t) -- if original notes is not empty, probably defined by users, @@ -762,29 +767,38 @@ function UniReader:getTocTitleByPage(pageno) return self:cleanUpTocTitle(pre_entry.title) end +function UniReader:getTocTitleOfCurrentPage() + return self:getTocTitleByPage(self.pageno) +end + +function UniReader:gotoTocEntry(entry) + self:goto(entry.page) +end + function UniReader:showToc() if not self.toc then - -- build toc when needed. + -- build toc if needed. self:fillToc() end - local menu_items = {} - local filtered_toc = {} + -- build menu items + local menu_items = {} for k,v in ipairs(self.toc) do table.insert(menu_items, (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title)) - table.insert(filtered_toc,v.page) end + toc_menu = SelectMenu:new{ menu_title = "Table of Contents", item_array = menu_items, no_item_msg = "This document does not have a Table of Contents.", } item_no = toc_menu:choose(0, fb.bb:getHeight()) + if item_no then - self:goto(filtered_toc[item_no]) + self:gotoTocEntry(self.toc[item_no]) else - self:goto(self.pageno) + self:redrawCurrentPage() end end @@ -849,7 +863,7 @@ function UniReader:_drawReadingInfo() local ypos = height - 50 fb.bb:paintRect(0, ypos, width, 50, 0) ypos = ypos + 15 - local cur_section = self:getTocTitleByPage(self.pageno) + local cur_section = self:getTocTitleOfCurrentPage() if cur_section ~= "" then cur_section = "Section: "..cur_section end From 4631fe492aab2456e3397f2766cd76b0a36eb8ec Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 7 Apr 2012 23:03:29 +0800 Subject: [PATCH 39/40] fix: add jump feature --- crereader.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crereader.lua b/crereader.lua index f51adbea7..698a0d2b5 100644 --- a/crereader.lua +++ b/crereader.lua @@ -269,6 +269,12 @@ function CREReader:adjustCreReaderCommands() cr:redrawCurrentPage() end ) + self.commands:add(KEY_B, MOD_SHIFT, "B", + "add jump", + function(cr) + cr:addJump(self.doc:getXPointer()) + end + ) self.commands:add(KEY_BACK,nil,"back", "back to last jump", function(cr) From 245247b2d17549a8acb4737160061ef560345c1d Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 7 Apr 2012 23:28:56 +0800 Subject: [PATCH 40/40] mod: use redrawCurrentPage() for all page redraw different readers might have different way to redraw pages, so I added this abstract method --- unireader.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/unireader.lua b/unireader.lua index d9fa01a5e..c0a3d42d5 100644 --- a/unireader.lua +++ b/unireader.lua @@ -707,14 +707,14 @@ end function UniReader:modifyGamma(factor) print("modifyGamma, gamma="..self.globalgamma.." factor="..factor) self.globalgamma = self.globalgamma * factor; - self:goto(self.pageno) + self:redrawCurrentPage() end -- adjust zoom state and trigger re-rendering function UniReader:setGlobalZoomMode(newzoommode) if self.globalzoommode ~= newzoommode then self.globalzoommode = newzoommode - self:goto(self.pageno) + self:redrawCurrentPage() end end @@ -723,13 +723,13 @@ function UniReader:setGlobalZoom(zoom) if self.globalzoom ~= zoom then self.globalzoommode = self.ZOOM_BY_VALUE self.globalzoom = zoom - self:goto(self.pageno) + self:redrawCurrentPage() end end function UniReader:setRotate(rotate) self.globalrotate = rotate - self:goto(self.pageno) + self:redrawCurrentPage() end -- @ orien: 1 for clockwise rotate, -1 for anti-clockwise @@ -737,7 +737,7 @@ function UniReader:screenRotate(orien) Screen:screenRotate(orien) width, height = fb:getSize() self:clearCache() - self:goto(self.pageno) + self:redrawCurrentPage() end function UniReader:cleanUpTocTitle(title) @@ -820,7 +820,7 @@ function UniReader:showJumpStack() local jump_item = self.jump_stack[item_no] self:goto(jump_item.page) else - self:goto(self.pageno) + self:redrawCurrentPage() end end @@ -1075,7 +1075,7 @@ function UniReader:addAllCommands() "show help page", function(unireader) HelpPage:show(0,height,unireader.commands) - unireader:goto(unireader.pageno) + unireader:redrawCurrentPage() end) self.commands:add(KEY_T,nil,"T", "show table of content", @@ -1244,7 +1244,7 @@ function UniReader:addAllCommands() end if old_offset_x ~= unireader.offset_x or old_offset_y ~= unireader.offset_y then - unireader:goto(unireader.pageno) + unireader:redrawCurrentPage() end end end) @@ -1262,7 +1262,7 @@ function UniReader:addAllCommands() os.execute("sleep 1") os.execute("killall -stop cvm") fb:setOrientation(Screen.kpv_rotation_mode) - unireader:goto(unireader.pageno) + unireader:redrawCurrentPage() end) print("## defined commands "..dump(self.commands.map)) end