mirror of https://github.com/koreader/koreader
Merge branch 'master' of github.com:hwhw/kindlepdfviewer
commit
9add90a169
@ -0,0 +1,464 @@
|
||||
/*
|
||||
KindlePDFViewer: CREngine abstraction for Lua
|
||||
Copyright (C) 2012 Hans-Werner Hilse <hilse@web.de>
|
||||
Qingping Hou <qingping.hou@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
extern "C" {
|
||||
#include "blitbuffer.h"
|
||||
#include "drawcontext.h"
|
||||
#include "cre.h"
|
||||
}
|
||||
|
||||
#include "crengine.h"
|
||||
|
||||
//using namespace std;
|
||||
|
||||
typedef struct CreDocument {
|
||||
LVDocView *text_view;
|
||||
ldomDocument *dom_doc;
|
||||
} 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->setBackgroundColor(0x000000);
|
||||
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->dom_doc = doc->text_view->getDocument();
|
||||
doc->text_view->Render();
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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 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());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//static int getPosFromXPointer(lua_State *L) {
|
||||
//CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
|
||||
//const char *xpointer_str = luaL_checkstring(L, 2);
|
||||
|
||||
//lvRect rc;
|
||||
//int pos;
|
||||
|
||||
//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());
|
||||
|
||||
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");
|
||||
|
||||
lua_pushinteger(L, doc->text_view->GetFullHeight());
|
||||
|
||||
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->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");
|
||||
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,
|
||||
* 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
|
||||
* 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
doc->text_view->goToPage(pageno);
|
||||
|
||||
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);
|
||||
|
||||
doc->text_view->SetPos(pos);
|
||||
|
||||
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");
|
||||
int delta = luaL_checkint(L, 2);
|
||||
|
||||
doc->text_view->ZoomFont(delta);
|
||||
|
||||
lua_pushnumber(L, doc->text_view->getFontSize());
|
||||
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 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");
|
||||
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();
|
||||
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},
|
||||
{"getFontFaces", getFontFaces},
|
||||
{"getGammaIndex", getGammaIndex},
|
||||
{"setGammaIndex", setGammaIndex},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static const struct luaL_Reg credocument_meth[] = {
|
||||
/*--- get methods ---*/
|
||||
{"getPages", getNumberOfPages},
|
||||
{"getCurrentPage", getCurrentPage},
|
||||
{"getPageFromXPointer", getPageFromXPointer},
|
||||
{"getCurrentPos", getCurrentPos},
|
||||
{"getCurrentPercent", getCurrentPercent},
|
||||
{"getXPointer", getXPointer},
|
||||
{"getFullHeight", getFullHeight},
|
||||
{"getToc", getTableOfContent},
|
||||
/*--- set methods ---*/
|
||||
{"setFontFace", setFontFace},
|
||||
/* --- control methods ---*/
|
||||
{"gotoPage", gotoPage},
|
||||
{"gotoPercent", gotoPercent},
|
||||
{"gotoPos", gotoPos},
|
||||
{"gotoXPointer", gotoXPointer},
|
||||
{"zoomFont", zoomFont},
|
||||
{"toggleFontBolder", toggleFontBolder},
|
||||
//{"cursorLeft", cursorLeft},
|
||||
//{"cursorRight", cursorRight},
|
||||
{"drawCurrentPage", drawCurrentPage},
|
||||
{"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; i<dir->GetObjectCount(); 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;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
KindlePDFViewer: CREngine abstraction for Lua
|
||||
Copyright (C) 2012 Hans-Werner Hilse <hilse@web.de>
|
||||
Qingping Hou <qingping.hou@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _CRENGING_H
|
||||
#define _CRENGING_H
|
||||
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
int luaopen_cre(lua_State *L);
|
||||
#endif
|
@ -0,0 +1,314 @@
|
||||
require "unireader"
|
||||
require "inputbox"
|
||||
require "selectmenu"
|
||||
|
||||
CREReader = UniReader:new{
|
||||
pos = nil,
|
||||
percent = 0,
|
||||
|
||||
gamma_index = 15,
|
||||
font_face = nil,
|
||||
}
|
||||
|
||||
function CREReader:init()
|
||||
self:addAllCommands()
|
||||
self:adjustCreReaderCommands()
|
||||
end
|
||||
|
||||
-- open a CREngine supported file and its settings store
|
||||
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
|
||||
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
|
||||
|
||||
----------------------------------------------------
|
||||
-- setting related methods
|
||||
----------------------------------------------------
|
||||
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:getLastPageOrPos()
|
||||
local last_percent = self.settings:readSetting("last_percent")
|
||||
if last_percent then
|
||||
return math.floor((last_percent * self.doc:getFullHeight()) / 10000)
|
||||
else
|
||||
return 0
|
||||
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
|
||||
|
||||
----------------------------------------------------
|
||||
-- render related methods
|
||||
----------------------------------------------------
|
||||
-- we don't need setzoom in CREReader
|
||||
function CREReader:setzoom(page, preCache)
|
||||
return
|
||||
end
|
||||
|
||||
function CREReader:redrawCurrentPage()
|
||||
self:goto(self.pos)
|
||||
end
|
||||
|
||||
----------------------------------------------------
|
||||
-- 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(prev_xpointer)
|
||||
end
|
||||
|
||||
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()
|
||||
self.percent = self.doc:getCurrentPercent()
|
||||
end
|
||||
|
||||
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
|
||||
local load_percent = self.percent/100
|
||||
|
||||
fb.bb:paintRect(0, ypos, width, 50, 0)
|
||||
|
||||
ypos = ypos + 15
|
||||
local face, fhash = Font:getFaceAndHash(22)
|
||||
local cur_section = self:getTocTitleOfCurrentPage()
|
||||
if cur_section ~= "" then
|
||||
cur_section = "Section: "..cur_section
|
||||
end
|
||||
renderUtf8Text(fb.bb, 10, ypos+6, face, fhash,
|
||||
"Position: "..load_percent.."%".." "..cur_section, true)
|
||||
|
||||
ypos = ypos + 15
|
||||
blitbuffer.progressBar(fb.bb, 10, ypos, width-20, 15,
|
||||
5, 4, load_percent/100, 8)
|
||||
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")
|
||||
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, 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
|
||||
)
|
||||
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 <key>*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
|
||||
)
|
||||
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])
|
||||
self.font_face = 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
|
||||
)
|
||||
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)
|
||||
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)
|
||||
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
|
||||
)
|
||||
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
|
@ -0,0 +1,51 @@
|
||||
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(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)
|
||||
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}
|
||||
${ANTIWORD_INCLUDE_DIR}
|
||||
${CHM_INCLUDE_DIRS}
|
||||
${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)
|
||||
|
||||
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 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_INCLUDED=1)
|
||||
ADD_SUBDIRECTORY(crengine/crengine)
|
||||
|
@ -0,0 +1 @@
|
||||
Subproject commit ba469d33473670ca303e2ef7f9762452a86e18b1
|
@ -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
|
@ -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
|
@ -1,8 +1,18 @@
|
||||
#!/bin/sh
|
||||
SLIDER_EVENT_PIPE="/tmp/event_slider"
|
||||
export LC_ALL="en_US.UTF-8"
|
||||
|
||||
echo unlock > /proc/keypad
|
||||
echo unlock > /proc/fiveway
|
||||
cd /mnt/us/kindlepdfviewer/
|
||||
./reader.lua $1
|
||||
|
||||
# create the named pipe for power slider event
|
||||
if [ ! -p $SLIDER_EVENT_PIPE ]; then
|
||||
mkfifo $SLIDER_EVENT_PIPE
|
||||
fi
|
||||
killall slider_watcher
|
||||
./slider_watcher $SLIDER_EVENT_PIPE &
|
||||
|
||||
./reader.lua $1 2> /mnt/us/kindlepdfviewer/crash.log
|
||||
killall -cont cvm
|
||||
echo 1 > /proc/eink_fb/update_display
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
KindlePDFViewer: power slider key event watcher
|
||||
Copyright (C) 2012 Qingping Hou <dave2008713@gamil.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/input.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define OUTPUT_SIZE 21
|
||||
#define EVENT_PIPE "/tmp/event_slider"
|
||||
#define CODE_IN_SAVER 10000
|
||||
#define CODE_OUT_SAVER 10001
|
||||
|
||||
int
|
||||
main ( int argc, char *argv[] )
|
||||
{
|
||||
int fd, ret;
|
||||
FILE *fp;
|
||||
char std_out[OUTPUT_SIZE] = "";
|
||||
struct input_event ev;
|
||||
__u16 key_code = 10000;
|
||||
|
||||
/* create the npipe if not exists */
|
||||
/*if(access(argv[1], F_OK)){*/
|
||||
/*printf("npipe %s not found, try to create it...\n", argv[1]);*/
|
||||
/*if(mkfifo(argv[1], 0777)) {*/
|
||||
/*printf("Create npipe %s failed!\n", argv[1]);*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
|
||||
/* open npipe for writing */
|
||||
fd = open(argv[1], O_RDWR | O_NONBLOCK);
|
||||
if(fd < 0) {
|
||||
printf("Open %s falied: %s\n", argv[1], strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* initialize event struct */
|
||||
ev.type = EV_KEY;
|
||||
ev.code = key_code;
|
||||
ev.value = 1;
|
||||
|
||||
while(1) {
|
||||
/* listen power slider events */
|
||||
memset(std_out, 0, OUTPUT_SIZE);
|
||||
fp = popen("lipc-wait-event -s 0 com.lab126.powerd goingToScreenSaver,outOfScreenSaver", "r");
|
||||
ret = fread(std_out, OUTPUT_SIZE, 1, fp);
|
||||
pclose(fp);
|
||||
|
||||
/* fill event struct */
|
||||
gettimeofday(&ev.time, NULL);
|
||||
if(std_out[0] == 'g') {
|
||||
ev.code = CODE_IN_SAVER;
|
||||
} else if(std_out[0] == 'o') {
|
||||
ev.code = CODE_OUT_SAVER;
|
||||
} else {
|
||||
printf("Unrecognized event.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* generate event */
|
||||
ret = write(fd, &ev, sizeof(struct input_event));
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue