From ec2eda0c0525017cb2538c87e2920b54a281caa8 Mon Sep 17 00:00:00 2001 From: HW Date: Mon, 9 Apr 2012 19:04:26 +0200 Subject: [PATCH] switched font handling to only work with external fonts now you can use a environment variable, FONTDIR, to point to a font dir. Otherwise, "./fonts" is used by default. Subdirectories are indexed. --- Makefile | 6 ++-- cre.cpp | 27 ++++++---------- crereader.lua | 13 ++++++-- filechooser.lua | 22 ++++++------- filesearcher.lua | 24 +++++++------- font.lua | 83 ++++++++++++++++++++++++++++++++++++------------ ft.c | 44 ------------------------- helppage.lua | 29 +++++++++-------- inputbox.lua | 8 ++--- reader.lua | 8 ++--- rendertext.lua | 13 ++++---- selectmenu.lua | 27 ++++++++-------- unireader.lua | 6 ++-- 13 files changed, 157 insertions(+), 153 deletions(-) diff --git a/Makefile b/Makefile index 100190348..2eba93c0e 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ 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/ +TTF_FONTS_DIR=$(MUPDFDIR)/fonts # set this to your ARM cross compiler: @@ -119,6 +119,7 @@ lfs.o: $(LFSDIR)/src/lfs.c fetchthirdparty: -rm -Rf lua lua-5.1.4 -rm -Rf mupdf/thirdparty + test -d mupdf && (cd mupdf; git checkout .) git submodule init git submodule update ln -sf kpvcrlib/crengine/cr3gui/data data @@ -128,6 +129,7 @@ fetchthirdparty: cd mupdf/thirdparty/jpeg-*/ && \ patch -N -p0 < ../../../kpvcrlib/jpeg_compress_struct_size.patch &&\ patch -N -p0 < ../../../kpvcrlib/jpeg_decompress_struct_size.patch + cd mupdf && patch -N -p1 < ../mupdf.patch test -f lua-5.1.4.tar.gz || wget http://www.lua.org/ftp/lua-5.1.4.tar.gz tar xvzf lua-5.1.4.tar.gz && ln -s lua-5.1.4 lua @@ -158,7 +160,7 @@ $(MUPDFDIR)/cmapdump.host: $(MUPDFLIBS) $(THIRDPARTYLIBS): $(MUPDFDIR)/cmapdump.host $(MUPDFDIR)/fontdump.host # build only thirdparty libs, libfitz and pdf utils, which will care for libmupdf.a being built - CFLAGS="$(CFLAGS)" make -C mupdf CC="$(CC)" CMAPDUMP=cmapdump.host FONTDUMP=fontdump.host MUPDF= XPS_APPS= + CFLAGS="$(CFLAGS) -DNOBUILTINFONT" make -C mupdf CC="$(CC)" CMAPDUMP=cmapdump.host FONTDUMP=fontdump.host MUPDF= XPS_APPS= verbose=1 $(DJVULIBS): -mkdir $(DJVUDIR)/build diff --git a/cre.cpp b/cre.cpp index 27260bd63..319a7af58 100644 --- a/cre.cpp +++ b/cre.cpp @@ -391,12 +391,20 @@ static int drawCurrentPage(lua_State *L) { } } +static int registerFont(lua_State *L) { + const char *fontfile = luaL_checkstring(L, 1); + if ( !fontMan->RegisterFont(lString8(fontfile)) ) { + return luaL_error(L, "cannot register font <%s>", fontfile); + } + return 0; +} static const struct luaL_Reg cre_func[] = { {"openDocument", openDocument}, {"getFontFaces", getFontFaces}, {"getGammaIndex", getGammaIndex}, {"setGammaIndex", setGammaIndex}, + {"registerFont", registerFont}, {NULL, NULL} }; @@ -437,23 +445,8 @@ int luaopen_cre(lua_State *L) { 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"); - } - } - } + /* initialize font manager for CREngine */ + InitFontManager(lString8()); #ifdef DEBUG_CRENGINE CRLog::setStdoutLogger(); diff --git a/crereader.lua b/crereader.lua index 81e55dc73..4578edc19 100644 --- a/crereader.lua +++ b/crereader.lua @@ -1,3 +1,4 @@ +require "font" require "unireader" require "inputbox" require "selectmenu" @@ -13,6 +14,14 @@ CREReader = UniReader:new{ function CREReader:init() self:addAllCommands() self:adjustCreReaderCommands() + -- we need to initialize the CRE font list + local fonts = Font:getFontList() + for _k, _v in ipairs(fonts) do + local ok, err = pcall(cre.registerFont, Font.fontdir..'/'.._v) + if not ok then + print(err) + end + end end -- open a CREngine supported file and its settings store @@ -182,12 +191,12 @@ function CREReader:_drawReadingInfo() fb.bb:paintRect(0, ypos, G_width, 50, 0) ypos = ypos + 15 - local face, fhash = Font:getFaceAndHash(22) + local face = Font:getFace("rifont", 22) local cur_section = self:getTocTitleOfCurrentPage() if cur_section ~= "" then cur_section = "Section: "..cur_section end - renderUtf8Text(fb.bb, 10, ypos+6, face, fhash, + renderUtf8Text(fb.bb, 10, ypos+6, face, "Position: "..load_percent.."%".." "..cur_section, true) ypos = ypos + 15 diff --git a/filechooser.lua b/filechooser.lua index 301cd052b..e96939035 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -122,8 +122,8 @@ function FileChooser:choose(ypos, height) end while true do - local cface, cfhash= Font:getFaceAndHash(25) - local fface, ffhash = Font:getFaceAndHash(16, Font.ffont) + local cface = Font:getFace("cfont", 25) + local fface = Font:getFace("ffont", 16) if pagedirty then fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) @@ -132,17 +132,17 @@ function FileChooser:choose(ypos, height) local i = (self.page - 1) * perpage + c if i <= #self.dirs then -- resembles display in midnight commander: adds "/" prefix for directories - renderUtf8Text(fb.bb, 39, ypos + self.spacing*c, cface, cfhash, "/", true) - renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, cface, cfhash, self.dirs[i], true) + renderUtf8Text(fb.bb, 39, ypos + self.spacing*c, cface, "/", true) + renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, cface, self.dirs[i], true) elseif i <= self.items then - renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, cface, cfhash, self.files[i-#self.dirs], true) + renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, cface, self.files[i-#self.dirs], true) end end - renderUtf8Text(fb.bb, 5, ypos + self.spacing * perpage + 42, fface, ffhash, + renderUtf8Text(fb.bb, 5, ypos + self.spacing * perpage + 42, fface, "Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true) local msg = self.exception_message and self.exception_message:match("[^%:]+:%d+: (.*)") or "Path: "..self.path self.exception_message = nil - renderUtf8Text(fb.bb, 5, ypos + self.spacing * (perpage+1) + 27, fface, ffhash, msg, true) + renderUtf8Text(fb.bb, 5, ypos + self.spacing * (perpage+1) + 27, fface, msg, true) markerdirty = true end if markerdirty then @@ -173,13 +173,13 @@ function FileChooser:choose(ypos, height) elseif ev.code == KEY_FW_DOWN then nextItem() elseif ev.code == KEY_F then -- invoke fontchooser menu - fonts_menu = SelectMenu:new{ + local fonts_menu = SelectMenu:new{ menu_title = "Fonts Menu", - item_array = Font.fonts, + item_array = Font:getFontList(), } - local re = fonts_menu:choose(0, height) + local re, font = fonts_menu:choose(0, height) if re then - Font.cfont = Font.fonts[re] + Font.fontmap["cfont"] = font Font:update() end pagedirty = true diff --git a/filesearcher.lua b/filesearcher.lua index 415dac45f..6a9e29831 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -177,13 +177,13 @@ function FileSearcher:addAllCommands() self.commands:add(KEY_F, nil, "F", "font menu", function(self) - fonts_menu = SelectMenu:new{ + local fonts_menu = SelectMenu:new{ menu_title = "Fonts Menu", - item_array = Font.fonts, + item_array = Font:getFontList(), } - local re = fonts_menu:choose(0, G_height) + local re, font = fonts_menu:choose(0, G_height) if re then - Font.cfont = Font.fonts[re] + Font.fontmap["cfont"] = font Font:update() end self.pagedirty = true @@ -227,25 +227,25 @@ function FileSearcher:choose(keywords) end while true do - local cface, cfhash = Font:getFaceAndHash(22) - local tface, tfhash = Font:getFaceAndHash(25, Font.tfont) - local fface, ffhash = Font:getFaceAndHash(16, Font.ffont) + local cface = Font:getFace("cfont", 22) + local tface = Font:getFace("tfont", 25) + local fface = Font:getFace("ffont", 16) if self.pagedirty then self.markerdirty = true fb.bb:paintRect(0, 0, width, height, 0) -- draw menu title - renderUtf8Text(fb.bb, 30, 0 + self.title_H, tface, tfhash, + renderUtf8Text(fb.bb, 30, 0 + self.title_H, tface, "Search Result for: "..self.keywords, true) -- draw results local c if self.items == 0 then -- nothing found y = self.title_H + self.spacing * 2 - renderUtf8Text(fb.bb, 20, y, cface, cfhash, + renderUtf8Text(fb.bb, 20, y, cface, "Sorry, no match found.", true) - renderUtf8Text(fb.bb, 20, y + self.spacing, cface, cfhash, + renderUtf8Text(fb.bb, 20, y + self.spacing, cface, "Please try a different keyword.", true) self.markerdirty = false else -- found something, draw it @@ -253,7 +253,7 @@ function FileSearcher:choose(keywords) local i = (self.page - 1) * self.perpage + c if i <= self.items then y = self.title_H + (self.spacing * c) - renderUtf8Text(fb.bb, 50, y, cface, cfhash, + renderUtf8Text(fb.bb, 50, y, cface, self.result[i].name, true) end end @@ -263,7 +263,7 @@ function FileSearcher:choose(keywords) y = self.title_H + (self.spacing * self.perpage) + self.foot_H x = (width / 2) - 50 all_page = (math.floor(self.items / self.perpage)+1) - renderUtf8Text(fb.bb, x, y, fface, ffhash, + renderUtf8Text(fb.bb, x, y, fface, "Page "..self.page.." of "..all_page, true) end diff --git a/font.lua b/font.lua index ef31d6277..5c0f3a584 100644 --- a/font.lua +++ b/font.lua @@ -1,23 +1,40 @@ Font = { - -- default font for menu contents - cfont = "sans", - -- default font for title - tfont = "Helvetica-BoldOblique", - -- default font for footer - ffont = "sans", - - -- built in fonts - fonts = {"sans", "cjk", "mono", - "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", - "Helvetica", "Helvetica-Oblique", "Helvetica-BoldOblique", - "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",}, + fontmap = { + -- default font for menu contents + cfont = "droid/DroidSans.ttf", + -- default font for title + tfont = "NimbusSanL-BoldItal.cff", + -- default font for footer + ffont = "droid/DroidSans.ttf", + + -- default font for reading position info + rifont = "droid/DroidSans.ttf", + + -- default font for pagination display + pgfont = "droid/DroidSans.ttf", + + -- selectmenu: font for item shortcut + scfont = "droid/DroidSansMono.ttf", + + -- help page: font for displaying keys + hpkfont = "droid/DroidSansMono.ttf", + -- font for displaying help messages + hfont = "droid/DroidSans.ttf", + + -- font for displaying input content + -- we have to use mono here for better distance controlling + infont = "droid/DroidSansMono.ttf", + }, + + fontdir = os.getenv("FONTDIR") or "./fonts", -- face table faces = {}, } -function Font:getFaceAndHash(size, font) + +function Font:getFace(font, size) if not font then -- default to content font font = self.cfont @@ -26,21 +43,45 @@ function Font:getFaceAndHash(size, font) local face = self.faces[font..size] -- build face if not found if not face then - for _k,_v in ipairs(self.fonts) do - if font == _v then - face = freetype.newBuiltinFace(font, size) - self.faces[font..size] = face - end + local realname = self.fontmap[font] + if not realname then + realname = font end - if not face then - print("#! Font "..font.." not supported!!") + realname = self.fontdir.."/"..realname + ok, face = pcall(freetype.newFace, realname, size) + if not ok then + print("#! Font "..font.." ("..realname..") not supported: "..face) return nil end + self.faces[font..size] = face end - return face, font..size + return { ftface = face, hash = font..size } +end + +function Font:_readList(target, dir, effective_dir) + for f in lfs.dir(dir) do + if lfs.attributes(dir.."/"..f, "mode") == "directory" and f ~= "." and f ~= ".." then + self:_readList(target, dir.."/"..f, effective_dir..f.."/") + else + local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "") + if file_type == "ttf" or file_type == "cff" or file_type == "otf" then + table.insert(target, effective_dir..f) + end + end + end +end + +function Font:getFontList() + fontlist = {} + self:_readList(fontlist, self.fontdir, "") + table.sort(fontlist) + return fontlist end function Font:update() + for _k, _v in ipairs(self.faces) do + _v:done() + end self.faces = {} clearGlyphCache() end diff --git a/ft.c b/ft.c index 151ba4c48..0dc1f496c 100644 --- a/ft.c +++ b/ft.c @@ -56,49 +56,6 @@ static int newFace(lua_State *L) { return 1; } -static int newBuiltinFace(lua_State *L) { - const char *fontname = luaL_checkstring(L, 1); - int pxsize = luaL_optint(L, 2, 16*64); - char *fontdata = NULL; - - unsigned int size; - /* we use compiled-in font data from mupdf build */ - if(!strcmp("mono", fontname)) { - fontdata = pdf_find_substitute_font(1, 0, 0, 0, &size); - } else if(!strcmp("sans", fontname)) { - fontdata = pdf_find_substitute_font(0, 0, 0, 0, &size); - } else if(!strcmp("cjk", fontname)) { - fontdata = pdf_find_substitute_cjk_font(0, 0, &size); - } else { - fontdata = pdf_find_builtin_font(fontname, &size); - } - if(fontdata == NULL) { - return luaL_error(L, "no such built-in font"); - } - - FT_Face *face = (FT_Face*) lua_newuserdata(L, sizeof(FT_Face)); - luaL_getmetatable(L, "ft_face"); - lua_setmetatable(L, -2); - - FT_Error error = FT_New_Memory_Face(freetypelib, (FT_Byte*)fontdata, size, 0, face); - if(error) { - return luaL_error(L, "freetype error"); - } - - error = FT_Set_Pixel_Sizes(*face, 0, pxsize); - if(error) { - error = FT_Done_Face(*face); - return luaL_error(L, "freetype error"); - } - - if((*face)->charmap == NULL) { - //TODO - //fprintf(stderr, "no unicode charmap found, to be implemented.\n"); - } - return 1; -} - - static int renderGlyph(lua_State *L) { FT_Face *face = (FT_Face*) luaL_checkudata(L, 1, "ft_face"); int ch = luaL_checkint(L, 2); @@ -192,7 +149,6 @@ static const struct luaL_Reg ft_face_meth[] = { static const struct luaL_Reg ft_func[] = { {"newFace", newFace}, - {"newBuiltinFace", newBuiltinFace}, {NULL, NULL} }; diff --git a/helppage.lua b/helppage.lua index cedb17906..25b9b0a9d 100644 --- a/helppage.lua +++ b/helppage.lua @@ -15,20 +15,23 @@ HelpPage = { -- state buffer commands = nil, items = 0, - page = 1 + page = 1, + + -- font for displaying keys + fsize = 20, + face = Font:getFace("hpkfont", 20), + + -- font for displaying help messages + hfsize = 20, + hface = Font:getFace("hfont", 20), + + -- font for paging display + ffsize = 15, + fface = Font:getFace("pgfont", 15) } -- Other Class vars: --- font for displaying keys -HelpPage.fsize = 20 -HelpPage.face, HelpPage.fhash = Font:getFaceAndHash(HelpPage.fsize, "mono") --- font for displaying help messages -HelpPage.hfsize = 20 -HelpPage.hface, HelpPage.hfhash = Font:getFaceAndHash(HelpPage.hfsize, "sans") --- font for paging display -HelpPage.ffsize = 15 -HelpPage.fface, HelpPage.ffhash = Font:getFaceAndHash(HelpPage.ffsize, "sans") function HelpPage:show(ypos, height, commands) self.commands = {} @@ -55,17 +58,17 @@ function HelpPage:show(ypos, height, commands) for c = 1, perpage do local i = (self.page - 1) * perpage + c if i <= self.items then - local pen_x = renderUtf8Text(fb.bb, 5, ypos + self.spacing*c, self.face, self.fhash, self.commands[i].shortcut, true) + local pen_x = renderUtf8Text(fb.bb, 5, ypos + self.spacing*c, self.face, self.commands[i].shortcut, true) max_x = math.max(max_x, pen_x) end end for c = 1, perpage do local i = (self.page - 1) * perpage + c if i <= self.items then - renderUtf8Text(fb.bb, max_x + 20, ypos + self.spacing*c, self.hface, self.hfhash, self.commands[i].help, true) + renderUtf8Text(fb.bb, max_x + 20, ypos + self.spacing*c, self.hface, self.commands[i].help, true) end end - renderUtf8Text(fb.bb, 5, height - math.floor(self.ffsize * 0.4), self.fface, self.ffhash, + renderUtf8Text(fb.bb, 5, height - math.floor(self.ffsize * 0.4), self.fface, "Page "..self.page.." of "..math.ceil(self.items / perpage).." - click Back to close this page", true) markerdirty = true end diff --git a/inputbox.lua b/inputbox.lua index fb942f1bf..afa9603b3 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -1,3 +1,4 @@ +require "font" require "rendertext" require "keys" require "graphics" @@ -21,8 +22,7 @@ InputBox = { -- font for displaying input content -- we have to use mono here for better distance controlling - face = freetype.newBuiltinFace("mono", 25), - fhash = "m25", + face = Font:getFace("infont", 25), fheight = 25, fwidth = 15, commands = nil, @@ -34,7 +34,7 @@ function InputBox:refreshText() self.input_slot_w, self.fheight, self.input_bg) -- paint new text renderUtf8Text(fb.bb, self.input_start_x, self.input_start_y, - self.face, self.fhash, + self.face, self.input_string, 0) end @@ -97,7 +97,7 @@ function InputBox:drawBox(ypos, w, h, title) -- draw input slot fb.bb:paintRect(140, ypos + 10, w - 130, h - 20, self.input_bg) -- draw input title - renderUtf8Text(fb.bb, 35, self.input_start_y, self.face, self.fhash, + renderUtf8Text(fb.bb, 35, self.input_start_y, self.face, title, true) end diff --git a/reader.lua b/reader.lua index 934c09f2f..f28596b27 100755 --- a/reader.lua +++ b/reader.lua @@ -117,9 +117,9 @@ Screen.native_rotation_mode = Screen.cur_rotation_mode -- set up reader's setting: font reader_settings = DocSettings:open(".reader") -r_cfont = reader_settings:readSetting("cfont") -if r_cfont ~=nil then - Font.cfont = r_cfont +fontmap = reader_settings:readSetting("fontmap") +if fontmap ~= nil then + Font.fontmap = fontmap end -- initialize global settings shared among all readers @@ -157,7 +157,7 @@ end -- save reader settings -reader_settings:savesetting("cfont", Font.cfont) +reader_settings:savesetting("fontmap", Font.fontmap) reader_settings:close() -- @TODO dirty workaround, find a way to force native system poll diff --git a/rendertext.lua b/rendertext.lua index 1d95598e3..57f4be75b 100644 --- a/rendertext.lua +++ b/rendertext.lua @@ -13,6 +13,7 @@ function glyphCacheClaim(size) glyphcache[k].age = glyphcache[k].age - 1 else glyphcache_current_memsize = glyphcache_current_memsize - glyphcache[k].size + glyphcache[k].glyph.bb:free() glyphcache[k] = nil end end @@ -20,10 +21,10 @@ function glyphCacheClaim(size) glyphcache_current_memsize = glyphcache_current_memsize + size return true end -function getGlyph(face, facehash, charcode) - local hash = glyphCacheHash(facehash, charcode) +function getGlyph(face, charcode) + local hash = glyphCacheHash(face.hash, charcode) if glyphcache[hash] == nil then - local glyph = face:renderGlyph(charcode) + local glyph = face.ftface:renderGlyph(charcode) local size = glyph.bb:getWidth() * glyph.bb:getHeight() / 2 + 32 glyphCacheClaim(size); glyphcache[hash] = { @@ -43,7 +44,7 @@ function clearGlyphCache() glyphcache = {} end -function renderUtf8Text(buffer, x, y, face, facehash, text, kerning) +function renderUtf8Text(buffer, x, y, face, text, kerning) if text == nil then print("# renderUtf8Text called without text"); return @@ -55,9 +56,9 @@ function renderUtf8Text(buffer, x, y, face, facehash, text, kerning) for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do if pen_x < buffer:getWidth() then local charcode = util.utf8charcode(uchar) - local glyph = getGlyph(face, facehash, charcode) + local glyph = getGlyph(face, charcode) if kerning and prevcharcode then - local kern = face:getKerning(prevcharcode, charcode) + local kern = face.ftface:getKerning(prevcharcode, charcode) pen_x = pen_x + kern buffer:addblitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) else diff --git a/selectmenu.lua b/selectmenu.lua index 9a7b6ec1e..0869644ad 100644 --- a/selectmenu.lua +++ b/selectmenu.lua @@ -12,8 +12,7 @@ SelectMenu = { -- font for paging display ffsize = 16, -- font for item shortcut - sface = freetype.newBuiltinFace("mono", 22), - sfhash = "mono22", + sface = Font:getFace("scfont", 22), -- title height title_H = 40, @@ -22,7 +21,7 @@ SelectMenu = { -- foot height foot_H = 27, - menu_title = "None Titled", + menu_title = "No Title", no_item_msg = "No items found.", item_array = {}, items = 0, @@ -231,9 +230,9 @@ function SelectMenu:choose(ypos, height) self.last_shortcut = 0 while true do - local cface, cfhash = Font:getFaceAndHash(22) - local tface, tfhash = Font:getFaceAndHash(25, Font.tfont) - local fface, ffhash = Font:getFaceAndHash(16, Font.ffont) + local cface = Font:getFace("cfont", 22) + local tface = Font:getFace("tfont", 25) + local fface = Font:getFace("ffont", 16) if self.pagedirty then self.markerdirty = true @@ -243,16 +242,16 @@ function SelectMenu:choose(ypos, height) local x = 20 local y = ypos + self.title_H - renderUtf8Text(fb.bb, x, y, tface, tfhash, self.menu_title, true) + renderUtf8Text(fb.bb, x, y, tface, self.menu_title, true) -- draw items fb.bb:paintRect(0, ypos + self.title_H + 10, fb.bb:getWidth(), height - self.title_H, 0) if self.items == 0 then y = ypos + self.title_H + (self.spacing * 2) - renderUtf8Text(fb.bb, 30, y, cface, cfhash, + renderUtf8Text(fb.bb, 30, y, cface, "Oops... Bad news for you:", true) y = y + self.spacing - renderUtf8Text(fb.bb, 30, y, cface, cfhash, + renderUtf8Text(fb.bb, 30, y, cface, self.no_item_msg, true) self.markerdirty = false self:clearCommands() @@ -272,16 +271,16 @@ function SelectMenu:choose(ypos, height) if self.item_shortcuts[c] ~= nil and string.len(self.item_shortcuts[c]) == 3 then -- print "Del", "Sym and "Ent" - renderUtf8Text(fb.bb, 13, y, fface, ffhash, + renderUtf8Text(fb.bb, 13, y, fface, self.item_shortcuts[c], true) else - renderUtf8Text(fb.bb, 18, y, self.sface, self.sfhash, + renderUtf8Text(fb.bb, 18, y, self.sface, self.item_shortcuts[c], true) end self.last_shortcut = c - renderUtf8Text(fb.bb, 50, y, cface, cfhash, + renderUtf8Text(fb.bb, 50, y, cface, self.item_array[i], true) end -- EOF if i <= self.items end -- EOF for @@ -291,7 +290,7 @@ function SelectMenu:choose(ypos, height) 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, + renderUtf8Text(fb.bb, x, y, fface, "Page "..self.page.." of ".. (math.ceil(self.items / self.perpage)), true) end @@ -339,7 +338,7 @@ function SelectMenu:choose(ypos, height) if self.selected_item ~= nil then print("# selected "..self.selected_item) - return self.selected_item + return self.selected_item, self.item_array[self.selected_item] end end -- EOF if end -- EOF while diff --git a/unireader.lua b/unireader.lua index ad14cd5d2..7796509da 100644 --- a/unireader.lua +++ b/unireader.lua @@ -858,11 +858,11 @@ end function UniReader:_drawReadingInfo() local width, height = G_width, G_height local load_percent = (self.pageno / self.doc:getPages()) - local face, fhash = Font:getFaceAndHash(22) + local face = Font:getFace("cfont", 22) -- display memory on top of page fb.bb:paintRect(0, 0, width, 15+6*2, 0) - renderUtf8Text(fb.bb, 10, 15+6, face, fhash, + renderUtf8Text(fb.bb, 10, 15+6, face, "Memory: ".. math.ceil( self.cache_current_memsize / 1024 ).."/"..math.ceil( self.cache_max_memsize / 1024 ).. " "..math.ceil( self.doc:getCacheSize() / 1024 ).."/"..math.ceil( self.cache_document_size / 1024 ).." k", @@ -876,7 +876,7 @@ function UniReader:_drawReadingInfo() if cur_section ~= "" then cur_section = "Section: "..cur_section end - renderUtf8Text(fb.bb, 10, ypos+6, face, fhash, + renderUtf8Text(fb.bb, 10, ypos+6, face, "Page: "..self.pageno.."/"..self.doc:getPages().. " "..cur_section, true)