add: toc menu

pull/2/merge
Qingping Hou 12 years ago
parent e60242d3f6
commit ea498e7a5a

41
pdf.c

@ -88,28 +88,20 @@ static int getNumberOfPages(lua_State *L) {
}
/*
* Return a table with (title,page) pair as entry:
* {"chapter1"=12, "chapter2"=20}
* helper function for getTableOfContent()
*/
static int getTableOfContent(lua_State *L) {
fz_outline *ol;
int i;
PdfDocument *doc = (PdfDocument*) luaL_checkudata(L, 1, "pdfdocument");
ol = pdf_load_outline(doc->xref);
lua_newtable(L);
i = 1;
static int walkTableOfContent(lua_State *L, fz_outline* ol, int *count, int depth) {
depth++;
while(ol) {
lua_pushnumber(L, i);
lua_pushnumber(L, *count);
/* set subtable */
lua_newtable(L);
lua_pushstring(L, "page");
lua_pushnumber(L, ol->dest.ld.gotor.page + 1);
lua_settable(L, -3);
lua_pushstring(L, "level");
lua_pushnumber(L, 1); // level 1
lua_pushstring(L, "depth");
lua_pushnumber(L, depth);
lua_settable(L, -3);
lua_pushstring(L, "title");
lua_pushstring(L, ol->title);
@ -117,9 +109,28 @@ static int getTableOfContent(lua_State *L) {
lua_settable(L, -3);
i++;
(*count)++;
if (ol->down) {
walkTableOfContent(L, ol->down, count, depth);
}
ol = ol->next;
}
return 0;
}
/*
* Return a table with (title,page) pair as entry:
* {"chapter1"=12, "chapter2"=20}
*/
static int getTableOfContent(lua_State *L) {
fz_outline *ol;
int count = 1;
PdfDocument *doc = (PdfDocument*) luaL_checkudata(L, 1, "pdfdocument");
ol = pdf_load_outline(doc->xref);
lua_newtable(L);
walkTableOfContent(L, ol, &count, 0);
return 1;
}

@ -344,6 +344,8 @@ function PDFReader:inputloop()
no = toc_menu:choose(0, fb.bb:getHeight())
if no then
self:goto(no)
else
self:goto(self.pageno)
end
elseif ev.code == KEY_J then

@ -4,8 +4,8 @@ require "graphics"
TOCMenu = {
-- font for displaying file/dir names
face = freetype.newBuiltinFace("cjk", 25),
fhash = "s25",
face = freetype.newBuiltinFace("cjk", 22),
fhash = "s22",
-- font for page title
tface = freetype.newBuiltinFace("Helvetica-BoldOblique", 25),
tfhash = "hbo25",
@ -15,7 +15,7 @@ TOCMenu = {
-- title height
title_H = 40,
-- spacing between lines
spacing = 40,
spacing = 36,
-- foot height
foot_H = 27,
@ -97,8 +97,8 @@ function TOCMenu:choose(ypos, height)
local i = (self.page - 1) * perpage + c
if i <= self.items then
y = ypos + self.title_H + (self.spacing * c)
renderUtf8Text(fb.bb, 50, y, self.face, self.fhash,
self.toc[i]["title"], true)
renderUtf8Text(fb.bb, 30, y, self.face, self.fhash,
(" "):rep(self.toc[i]["depth"]-1)..self.toc[i]["title"], true)
end
end

Loading…
Cancel
Save