From c11ecce55a5e8763e4bc450fd528a3fe5421756b Mon Sep 17 00:00:00 2001 From: traycold Date: Mon, 19 Mar 2012 19:41:09 +0100 Subject: [PATCH 01/11] draft commit, test implementation --- ft.c | 22 ++++++++++++++++++++++ rendertext.lua | 32 +++++++++++++++++++++++++++++++- rendertext_example.lua | 21 +++++++++++++++------ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/ft.c b/ft.c index 5cfc9b69b..1b3682545 100644 --- a/ft.c +++ b/ft.c @@ -142,6 +142,8 @@ static int renderGlyph(lua_State *L) { lua_setfield(L, -2, "t"); lua_pushinteger(L, (*face)->glyph->advance.x >> 6); lua_setfield(L, -2, "ax"); + lua_pushinteger(L, (*face)->glyph->advance.y >> 6); + lua_setfield(L, -2, "ay"); return 1; } @@ -169,6 +171,25 @@ static int getKerning(lua_State *L) { return 1; } +static int getHeight(lua_State *L) { + FT_Face *face = (FT_Face*) luaL_checkudata(L, 1, "ft_face"); + + double pixels_height,pixels_ascender; + double em_size, y_scale; + + /* compute floating point scale factors */ + em_size = 1.0 * (*face)->units_per_EM; + y_scale = (*face)->size->metrics.y_ppem / em_size; + + /* convert design distances to floating point pixels */ + pixels_height = (*face)->height * y_scale; + pixels_ascender = (*face)->ascender * y_scale; + + lua_pushnumber(L, pixels_height); + lua_pushnumber(L, pixels_ascender); + return 2; +} + static int doneFace(lua_State *L) { FT_Face *face = (FT_Face*) luaL_checkudata(L, 1, "ft_face"); if(*face != NULL) { @@ -185,6 +206,7 @@ static const struct luaL_reg ft_face_meth[] = { {"renderGlyph", renderGlyph}, {"hasKerning", hasKerning}, {"getKerning", getKerning}, + {"getHeight", getHeight}, {"done", doneFace}, {"__gc", doneFace}, {NULL, NULL} diff --git a/rendertext.lua b/rendertext.lua index 0096b84b7..e194ea14b 100644 --- a/rendertext.lua +++ b/rendertext.lua @@ -43,6 +43,35 @@ function clearglyphcache() glyphcache = {} end +function sizeUtf8Text(face, facehash, text, kerning) + if text == nil then + print("# sizeUtf8Text called without text"); + return + end + -- may still need more adaptive pen placement when kerning, + -- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html + local pen_x = 0 + local prevcharcode = 0 + 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) + if kerning and prevcharcode then + local kern = face:getKerning(prevcharcode, charcode) + pen_x = pen_x + kern + print("prev:"..string.char(prevcharcode+10).." curr:"..string.char(charcode).." kern:"..kern) + buffer:addblitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) + else + print("curr:"..string.char(charcode)) + buffer:blitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) + end + pen_x = pen_x + glyph.ax + prevcharcode = charcode + end + end + return pen_x +end + function renderUtf8Text(buffer, x, y, face, facehash, text, kerning) if text == nil then print("# renderUtf8Text called without text"); @@ -59,8 +88,10 @@ function renderUtf8Text(buffer, x, y, face, facehash, text, kerning) if kerning and prevcharcode then local kern = face:getKerning(prevcharcode, charcode) pen_x = pen_x + kern + --print("prev:"..prevcharcode.." curr:"..charcode.." kern:"..kern) buffer:addblitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) else + --print(" curr:"..charcode) buffer:blitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) end pen_x = pen_x + glyph.ax @@ -69,4 +100,3 @@ function renderUtf8Text(buffer, x, y, face, facehash, text, kerning) end return pen_x end - diff --git a/rendertext_example.lua b/rendertext_example.lua index 12dbf524d..8b8a24bdf 100755 --- a/rendertext_example.lua +++ b/rendertext_example.lua @@ -6,19 +6,28 @@ fb = einkfb.open("/dev/fb0") width, height = fb:getSize() print("open") - -face = freetype.newBuiltinFace("sans", 64) ---face = freetype.newFace("test.ttf", 64) +size = 50 +--face = freetype.newBuiltinFace("sans", 64) +face = freetype.newFace("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", size) print("got face") if face:hasKerning() then print("has kerning") end -fb.bb:paintRect(1,1,599,300,7); +width, height = fb:getSize() +fb.bb:paintRect(5,5,width-5,height-5,4); -renderUtf8Text(fb.bb, 100, 100, face, "h", "AV T.T: gxyt!", true) -renderUtf8Text(fb.bb, 100, 200, face, "h", "AV T.T: gxyt!", false) +faceHeight, faceAscender = face:getHeight(); +print("face height:"..tostring(faceHeight).." - ascender:"..faceAscender) +faceHeight = math.ceil(faceHeight) +faceAscender = math.ceil(faceAscender) +print("face height:"..tostring(faceHeight).." - ascender:"..faceAscender) + +posY = 5 + faceAscender +renderUtf8Text(fb.bb, 5, posY, face, "h", "AV T.T: gxyt!", true) +posY = posY + faceHeight +renderUtf8Text(fb.bb, 5, posY, face, "h2", "AV T.T: gxyt!", false) fb:refresh() From ce30d9c65212f81fd48c26f98bbeaed2dc9b4a83 Mon Sep 17 00:00:00 2001 From: traycold Date: Tue, 20 Mar 2012 23:28:49 +0100 Subject: [PATCH 02/11] use font metric to better display help page (to exted to other pages in future) --- ft.c | 4 ++-- helppage.lua | 37 ++++++++++++++++++++----------------- rendertext.lua | 4 ++-- rendertext_example.lua | 2 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/ft.c b/ft.c index df27e96fd..e399b673c 100644 --- a/ft.c +++ b/ft.c @@ -171,7 +171,7 @@ static int getKerning(lua_State *L) { return 1; } -static int getHeight(lua_State *L) { +static int getHeightAndAscender(lua_State *L) { FT_Face *face = (FT_Face*) luaL_checkudata(L, 1, "ft_face"); double pixels_height,pixels_ascender; @@ -206,7 +206,7 @@ static const struct luaL_Reg ft_face_meth[] = { {"renderGlyph", renderGlyph}, {"hasKerning", hasKerning}, {"getKerning", getKerning}, - {"getHeight", getHeight}, + {"getHeightAndAscender", getHeightAndAscender}, {"done", doneFace}, {"__gc", doneFace}, {NULL, NULL} diff --git a/helppage.lua b/helppage.lua index 33ba5e9a9..8e28034f4 100644 --- a/helppage.lua +++ b/helppage.lua @@ -7,11 +7,6 @@ require "selectmenu" require "commands" HelpPage = { - -- Other Class vars: - - -- spacing between lines - spacing = 25, - -- state buffer commands = nil, items = 0, @@ -21,16 +16,13 @@ HelpPage = { -- Other Class vars: -- font for displaying keys -HelpPage.fsize = 20 -HelpPage.face, HelpPage.fhash = Font:getFaceAndHash(HelpPage.fsize, "mono") +HelpPage.mFace, HelpPage.mHash = Font:getFaceAndHash(20, "mono") -- font for displaying help messages -HelpPage.hfsize = 20 -HelpPage.hface, HelpPage.hfhash = Font:getFaceAndHash(HelpPage.hfsize, "sans") +HelpPage.sFace, HelpPage.sHash = Font:getFaceAndHash(20, "sans") -- font for paging display -HelpPage.ffsize = 15 -HelpPage.fface, HelpPage.ffhash = Font:getFaceAndHash(HelpPage.ffsize, "sans") +HelpPage.fFace, HelpPage.fHash = Font:getFaceAndHash(15, "sans") -function HelpPage:show(ypos, height,commands) +function HelpPage:show(ypos,height,commands) self.commands = {} self.items = 0 local keys = {} @@ -44,28 +36,39 @@ function HelpPage:show(ypos, height,commands) end end table.sort(self.commands,function(w1,w2) return w1.order Date: Sat, 24 Mar 2012 17:47:52 +0100 Subject: [PATCH 03/11] update mupdf submodule to commit bdb6b688a238df56b2cf47fa17a08a4dd4b7a122 and small modification to source code to adapt to mupdf modifications --- Makefile | 2 +- ft.c | 11 +++++------ mupdf | 2 +- pdf.c | 13 ++++++------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 8d9fb99b0..b09fd5120 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ einkfb.o input.o: %.o: %.c $(CC) -c $(KPDFREADER_CFLAGS) $(EMU_CFLAGS) $< -o $@ ft.o: %.o: %.c - $(CC) -c $(KPDFREADER_CFLAGS) -I$(FREETYPEDIR)/include $< -o $@ + $(CC) -c $(KPDFREADER_CFLAGS) -I$(FREETYPEDIR)/include -I$(MUPDFDIR)/fitz $< -o $@ kpdfview.o pdf.o blitbuffer.o util.o drawcontext.o: %.o: %.c $(CC) -c $(KPDFREADER_CFLAGS) -I$(LFSDIR)/src $< -o $@ diff --git a/ft.c b/ft.c index 151ba4c48..e356c1a4e 100644 --- a/ft.c +++ b/ft.c @@ -23,8 +23,7 @@ #include "blitbuffer.h" /* for font access: */ -#include -#include +#include #include "ft.h" @@ -64,13 +63,13 @@ static int newBuiltinFace(lua_State *L) { 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); + fontdata = pdf_lookup_substitute_font(1, 0, 0, 0, &size); } else if(!strcmp("sans", fontname)) { - fontdata = pdf_find_substitute_font(0, 0, 0, 0, &size); + fontdata = pdf_lookup_substitute_font(0, 0, 0, 0, &size); } else if(!strcmp("cjk", fontname)) { - fontdata = pdf_find_substitute_cjk_font(0, 0, &size); + fontdata = pdf_lookup_substitute_cjk_font(0, 0, &size); } else { - fontdata = pdf_find_builtin_font(fontname, &size); + fontdata = pdf_lookup_builtin_font(fontname, &size); } if(fontdata == NULL) { return luaL_error(L, "no such built-in font"); diff --git a/mupdf b/mupdf index e7bb1c493..bdb6b688a 160000 --- a/mupdf +++ b/mupdf @@ -1 +1 @@ -Subproject commit e7bb1c4937593c95065dbbbdd7eb15a73996c470 +Subproject commit bdb6b688a238df56b2cf47fa17a08a4dd4b7a122 diff --git a/pdf.c b/pdf.c index 5583e09a0..6c904030f 100644 --- a/pdf.c +++ b/pdf.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include +#include #include "blitbuffer.h" #include "drawcontext.h" @@ -371,16 +371,15 @@ static int drawPage(lua_State *L) { fz_device *dev; fz_matrix ctm; fz_bbox bbox; - fz_bbox rect; PdfPage *page = (PdfPage*) luaL_checkudata(L, 1, "pdfpage"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); BlitBuffer *bb = (BlitBuffer*) luaL_checkudata(L, 3, "blitbuffer"); - rect.x0 = luaL_checkint(L, 4); - rect.y0 = luaL_checkint(L, 5); - rect.x1 = rect.x0 + bb->w; - rect.y1 = rect.y0 + bb->h; - pix = fz_new_pixmap_with_rect(page->doc->context, fz_device_gray, rect); + bbox.x0 = luaL_checkint(L, 4); + bbox.y0 = luaL_checkint(L, 5); + bbox.x1 = bbox.x0 + bb->w; + bbox.y1 = bbox.y0 + bb->h; + pix = fz_new_pixmap_with_bbox(page->doc->context, fz_device_gray, bbox); fz_clear_pixmap_with_value(page->doc->context, pix, 0xff); ctm = fz_scale(dc->zoom, dc->zoom); From 0350822ade29b6bec735091ee25d74436af71a4e Mon Sep 17 00:00:00 2001 From: traycold Date: Sun, 15 Apr 2012 16:05:44 +0200 Subject: [PATCH 04/11] remove some trailing white spaces --- blitbuffer.c | 32 ++++++++++++++++---------------- inputbox.lua | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/blitbuffer.c b/blitbuffer.c index 93642fd61..248db52ed 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -75,7 +75,7 @@ static int blitFullToBuffer(lua_State *L) { if(src->w != dst->w || src->h != dst->h) { return luaL_error(L, "blitbuffer size must be framebuffer size!"); } - + memcpy(dst->data, src->data, src->pitch * src->h); return 0; @@ -146,8 +146,8 @@ static int blitToBuffer(lua_State *L) { if(xdest & 1) { /* this will render the leftmost column */ - dstptr = (uint8_t*)(dst->data + - ydest * dst->pitch + + dstptr = (uint8_t*)(dst->data + + ydest * dst->pitch + xdest / 2); srcptr = (uint8_t*)(src->data + yoffs * src->pitch + @@ -172,8 +172,8 @@ static int blitToBuffer(lua_State *L) { w--; } - dstptr = (uint8_t*)(dst->data + - ydest * dst->pitch + + dstptr = (uint8_t*)(dst->data + + ydest * dst->pitch + xdest / 2); srcptr = (uint8_t*)(src->data + yoffs * src->pitch + @@ -243,8 +243,8 @@ static int addblitToBuffer(lua_State *L) { if(xdest & 1) { /* this will render the leftmost column */ - dstptr = (uint8_t*)(dst->data + - ydest * dst->pitch + + dstptr = (uint8_t*)(dst->data + + ydest * dst->pitch + xdest / 2); srcptr = (uint8_t*)(src->data + yoffs * src->pitch + @@ -269,8 +269,8 @@ static int addblitToBuffer(lua_State *L) { w--; } - dstptr = (uint8_t*)(dst->data + - ydest * dst->pitch + + dstptr = (uint8_t*)(dst->data + + ydest * dst->pitch + xdest / 2); srcptr = (uint8_t*)(src->data + yoffs * src->pitch + @@ -332,8 +332,8 @@ static int paintRect(lua_State *L) { /* This will render the leftmost column * in the case when x is odd. After this, * x will become even. */ - dstptr = (uint8_t*)(dst->data + - y * dst->pitch + + dstptr = (uint8_t*)(dst->data + + y * dst->pitch + x / 2); for(cy = 0; cy < h; cy++) { *dstptr &= 0xF0; @@ -343,19 +343,19 @@ static int paintRect(lua_State *L) { x++; w--; } - dstptr = (uint8_t*)(dst->data + - y * dst->pitch + + dstptr = (uint8_t*)(dst->data + + y * dst->pitch + x / 2); for(cy = 0; cy < h; cy++) { memset(dstptr, c | (c << 4), w / 2); dstptr += dst->pitch; } if(w & 1) { - /* This will render the rightmost column + /* This will render the rightmost column * in the case when (w & 1) && !(x & 1) or * !(w & 1) && (x & 1). */ - dstptr = (uint8_t*)(dst->data + - y * dst->pitch + + dstptr = (uint8_t*)(dst->data + + y * dst->pitch + (x + w) / 2); for(cy = 0; cy < h; cy++) { *dstptr &= 0x0F; diff --git a/inputbox.lua b/inputbox.lua index 6e3fc6667..2f354610e 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -49,7 +49,7 @@ function InputBox:delChar() end self.input_cur_x = self.input_cur_x - self.fwidth --fill last character with blank rectangle - fb.bb:paintRect(self.input_cur_x, self.input_start_y-19, + fb.bb:paintRect(self.input_cur_x, self.input_start_y-19, self.fwidth, self.fheight, self.input_bg) fb:refresh(1, self.input_cur_x, self.input_start_y-19, self.fwidth, self.fheight) self.input_string = self.input_string:sub(0,-2) From 6c9ec8c896acd8048dc1e07bbcfbb4cb99fdcec3 Mon Sep 17 00:00:00 2001 From: traycold Date: Sun, 15 Apr 2012 16:07:39 +0200 Subject: [PATCH 05/11] refactoring for display help page --- commands.lua | 4 +-- ft.c | 2 ++ helppage.lua | 31 ++++++++++++++++----- keys.lua | 11 +++++--- rendertext.lua | 20 ++++++++------ unireader.lua | 73 +++++++++++++++++++------------------------------- 6 files changed, 74 insertions(+), 67 deletions(-) diff --git a/commands.lua b/commands.lua index 43dfca87d..09611a77c 100644 --- a/commands.lua +++ b/commands.lua @@ -21,7 +21,7 @@ function Keydef:new(keycode,modifier,descr) return obj end function Keydef:display() - return ((self.modifier and self.modifier.."+") or "")..(self.descr or "") + return (self.modifier or "")..(self.descr or "") end function Keydef:tostring() return ((self.modifier and self.modifier.."+") or "").."["..(self.keycode or "").."]"..(self.descr or "") @@ -74,7 +74,7 @@ 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) elseif keydef.modifier==MOD_SHIFT_OR_ALT then - self:addGroup(keygroup or (MOD_SHIFT.."|"..MOD_ALT.."+"..(keydef.descr or "")),{Keydef:new(keydef.keycode,MOD_SHIFT), Keydef:new(keydef.keycode,MOD_ALT)},help,func) + self:addGroup(keygroup or (MOD_SHIFT..MOD_ALT..(keydef.descr or "")),{Keydef:new(keydef.keycode,MOD_SHIFT), Keydef:new(keydef.keycode,MOD_ALT)},help,func) else local command = self.map[keydef] if command == nil then diff --git a/ft.c b/ft.c index 38b16542e..a073fd415 100644 --- a/ft.c +++ b/ft.c @@ -139,6 +139,8 @@ static int renderGlyph(lua_State *L) { lua_setfield(L, -2, "l"); lua_pushinteger(L, (*face)->glyph->bitmap_top); lua_setfield(L, -2, "t"); + lua_pushinteger(L, (*face)->glyph->metrics.horiAdvance >> 6); + lua_setfield(L, -2, "r"); lua_pushinteger(L, (*face)->glyph->advance.x >> 6); lua_setfield(L, -2, "ax"); lua_pushinteger(L, (*face)->glyph->advance.y >> 6); diff --git a/helppage.lua b/helppage.lua index 8e28034f4..12fba6ff5 100644 --- a/helppage.lua +++ b/helppage.lua @@ -15,10 +15,10 @@ HelpPage = { -- Other Class vars: --- font for displaying keys -HelpPage.mFace, HelpPage.mHash = Font:getFaceAndHash(20, "mono") -- font for displaying help messages HelpPage.sFace, HelpPage.sHash = Font:getFaceAndHash(20, "sans") +-- font for displaying keys +HelpPage.mFace, HelpPage.mHash = Font:getFaceAndHash(20, "sans") -- font for paging display HelpPage.fFace, HelpPage.fHash = Font:getFaceAndHash(15, "sans") @@ -39,8 +39,8 @@ function HelpPage:show(ypos,height,commands) local mFaceHeight, mFaceAscender = self.mFace:getHeightAndAscender(); local fFaceHeight, fFaceAscender = self.fFace:getHeightAndAscender(); - print(mFaceHeight.."-"..mFaceAscender) - print(fFaceHeight.."-"..fFaceAscender) + --print(mFaceHeight.."-"..mFaceAscender) + --print(fFaceHeight.."-"..fFaceAscender) mFaceHeight = math.ceil(mFaceHeight) mFaceAscender = math.ceil(mFaceAscender) fFaceHeight = math.ceil(fFaceHeight) @@ -52,14 +52,31 @@ function HelpPage:show(ypos,height,commands) while true do if pagedirty then - fb.bb:paintRect(0, 0, fb.bb:getWidth(), height, 0) + fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) local c local max_x = 0 for c = 1, perpage do + local x = 5 local i = (self.page - 1) * perpage + c if i <= self.items then - local pen_x = renderUtf8Text(fb.bb, 5, ypos + spacing*c, self.mFace, self.mHash, self.commands[i].shortcut, true) - max_x = math.max(max_x, pen_x) + local key = self.commands[i].shortcut + for _k,aMod in pairs(MOD_TABLE) do + local modStart, modEnd = key:find(aMod.v) + print("key:"..key.." v:"..aMod.v.." d:"..aMod.d.." modstart:"..(modStart or "nil")) + if(modStart ~= nil) then + key = key:sub(1,modStart-1)..key:sub(modEnd+1) + local box = sizeUtf8Text( x, fb.bb:getWidth(), self.mFace, self.mHash, aMod.d, true) + fb.bb:paintRect(x, ypos + spacing*c - box.y_top, box.x, box.y_top + box.y_bottom, 4); + local pen_x = renderUtf8Text(fb.bb, x, ypos + spacing*c, self.mFace, self.mHash, aMod.d.." + ", true) + x = x + pen_x + max_x = math.max(max_x, pen_x) + end + end + local box = sizeUtf8Text( x, fb.bb:getWidth(), self.mFace, self.mHash, key , true) + fb.bb:paintRect(x, ypos + spacing*c - box.y_top, box.x, box.y_top + box.y_bottom, 4); + local pen_x = renderUtf8Text(fb.bb, x, ypos + spacing*c, self.mFace, self.mHash, key, true) + x = x + pen_x + max_x = math.max(max_x, x) end end for c = 1, perpage do diff --git a/keys.lua b/keys.lua index 43e683120..e07af2ada 100644 --- a/keys.lua +++ b/keys.lua @@ -96,10 +96,13 @@ EVENT_VALUE_KEY_REPEAT = 2 EVENT_VALUE_KEY_RELEASE = 0 -- modifiers -MOD_SHIFT = "Shift" -MOD_ALT = "Alt" -MOD_SHIFT_OR_ALT = "ShiftAlt" -MOD_ANY = "Any" +MOD_SHIFT = "_Shift_" +MOD_ALT = "_Alt_" +MOD_SHIFT_OR_ALT = "_ShiftAlt_" +MOD_ANY = "_Any_" +MOD_SHIFT_DISPLAY = "Shift" +MOD_ALT_DISPLAY = "Alt" +MOD_TABLE = {MOD_SHIFT={v=MOD_SHIFT,d=MOD_SHIFT_DISPLAY},MOD_ALT={v=MOD_ALT,d=MOD_ALT_DISPLAY}} function getKeyModifier() return Keys.altmode and MOD_ALT or Keys.shiftmode and MOD_SHIFT diff --git a/rendertext.lua b/rendertext.lua index 4d4f46a71..337d86285 100644 --- a/rendertext.lua +++ b/rendertext.lua @@ -43,7 +43,7 @@ function clearGlyphCache() glyphcache = {} end -function sizeUtf8Text(face, facehash, text, kerning) +function sizeUtf8Text(x, width, face, facehash, text, kerning) if text == nil then print("# sizeUtf8Text called without text"); return @@ -51,28 +51,32 @@ function sizeUtf8Text(face, facehash, text, kerning) -- may still need more adaptive pen placement when kerning, -- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html local pen_x = 0 + local pen_y_top = 0 + local pen_y_bottom = 0 local prevcharcode = 0 + --print("----------------- text:"..text) for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do - if pen_x < buffer:getWidth() then + if pen_x < (width - x) then local charcode = util.utf8charcode(uchar) - local glyph = getglyph(face, facehash, charcode) + local glyph = getGlyph(face, facehash, charcode) if kerning and prevcharcode then local kern = face:getKerning(prevcharcode, charcode) pen_x = pen_x + kern - print("prev:"..string.char(prevcharcode+10).." curr:"..string.char(charcode).." kern:"..kern) - buffer:addblitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) + print("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." kern:"..kern) else print("curr:"..string.char(charcode)) - buffer:blitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) end pen_x = pen_x + glyph.ax + pen_y_top = math.max(pen_y_top, glyph.t) + pen_y_bottom = math.max(pen_y_bottom, glyph.bb:getHeight() - glyph.t) + --print("ax:"..glyph.ax.." t:"..glyph.t.." r:"..glyph.r.." h:"..glyph.bb:getHeight().." w:"..glyph.bb:getWidth().." yt:"..pen_y_top.." yb:"..pen_y_bottom) prevcharcode = charcode end end - return pen_x + return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom} end -function renderUtf8Text(buffer, x, y, face, facehash, text, kerning) +function renderUtf8Text(buffer, x, y, face, facehash, text, kerning, backgroundColor) if text == nil then print("# renderUtf8Text called without text"); return diff --git a/unireader.lua b/unireader.lua index bf956be15..bb067a723 100644 --- a/unireader.lua +++ b/unireader.lua @@ -815,63 +815,50 @@ end -- command definitions function UniReader:addAllCommands() self.commands = Commands:new() - self.commands:add(KEY_PGFWD,nil,">", - "next page", - function(unireader) - unireader:goto(unireader:nextView()) + + self.commands:addGroup("< >",{Keydef:new(KEY_PGBCK,nil),Keydef:new(KEY_PGFWD,nil)}, + "previous/next page", + function(unireader,keydef) + unireader:goto(keydef.keycode==KEY_PGBCK and unireader:prevView() or unireader:nextView()) end) - self.commands:add(KEY_PGBCK,nil,"<", - "previous page", - function(unireader) - unireader:goto(unireader:prevView()) + self.commands:addGroup(MOD_ALT.."< >",{Keydef:new(KEY_PGBCK,MOD_ALT),Keydef:new(KEY_PGFWD,MOD_ALT)}, + "zoom out/in 10%", + function(unireader,keydef) + unireader:setGlobalZoom(unireader.globalzoom + (keydef.keycode==KEY_PGBCK and -1 or 1)*unireader.globalzoom_orig*0.1) end) - self.commands:add(KEY_PGFWD,MOD_ALT,">", - "zoom in 10%", - function(unireader) - unireader:setGlobalZoom(unireader.globalzoom+unireader.globalzoom_orig*0.1) + self.commands:addGroup(MOD_SHIFT.."< >",{Keydef:new(KEY_PGBCK,MOD_SHIFT),Keydef:new(KEY_PGFWD,MOD_ALTSHIFT)}, + "zoom out/in 20%", + function(unireader,keydef) + unireader:setGlobalZoom(unireader.globalzoom + (keydef.keycode==KEY_PGBCK and -1 or 1)*unireader.globalzoom_orig*0.2) end) - self.commands:add(KEY_PGBCK,MOD_ALT,"<", - "zoom out 10%", - function(unireader) - unireader:setGlobalZoom(unireader.globalzoom-unireader.globalzoom_orig*0.1) - end) - self.commands:add(KEY_PGFWD,MOD_SHIFT,">", - "zoom in 20%", - function(unireader) - unireader:setGlobalZoom(unireader.globalzoom+unireader.globalzoom_orig*0.2) - end) - self.commands:add(KEY_PGBCK,MOD_SHIFT,"<", - "zoom out 20%", - function(unireader) - unireader:setGlobalZoom(unireader.globalzoom-unireader.globalzoom_orig*0.2) - end) - self.commands:add(KEY_BACK,nil,"back", + self.commands:add(KEY_BACK,nil,"Back", "back to last jump", function(unireader) if #unireader.jump_stack ~= 0 then unireader:goto(unireader.jump_stack[1].page) end end) - self.commands:add(KEY_BACK,MOD_ALT,"back", + self.commands:add(KEY_BACK,MOD_ALT,"Back", "close document", function(unireader) return "break" end) - self.commands:add(KEY_VPLUS,nil,"vol+", - "increase gamma 25%", + self.commands:add(KEY_HOME,MOD_ALT,"Home", + "exit application", function(unireader) - unireader:modifyGamma( 1.25 ) + keep_running = false + return "break" end) - self.commands:add(KEY_VMINUS,nil,"vol-", - "decrease gamma 25%", - function(unireader) - unireader:modifyGamma( 0.80 ) + self.commands:addGroup("vol-/+",{Keydef:new(KEY_VPLUS,nil),Keydef:new(KEY_VMINUS,nil)}, + "decrease/increase gamma 25%", + function(unireader,keydef) + unireader:modifyGamma(keydef.keycode==KEY_VPLUS and 1.25 or 0.8) end) --numeric key group 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", + self.commands:addGroup("[1, 2 .. 9, 0]",numeric_keydefs, + "jump to 10%, 20% .. 90%, 100% of document", function(unireader,keydef) print('jump to page: '..math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1)..'/'..unireader.doc:getPages()) unireader:goto(math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1)) @@ -918,7 +905,7 @@ function UniReader:addAllCommands() unireader:setGlobalZoomMode(unireader.ZOOM_FIT_TO_CONTENT_HALF_WIDTH) end) self.commands:add(KEY_G,nil,"G", - "goto page", + "open 'go to page' input box", function(unireader) local page = InputBox:input(height-100, 100, "Page:") -- convert string to number @@ -972,12 +959,6 @@ function UniReader:addAllCommands() function(unireader) unireader:screenRotate("anticlockwise") end) - self.commands:add(KEY_HOME,MOD_SHIFT_OR_ALT,"Home", - "exit application", - function(unireader) - keep_running = false - return "break" - end) self.commands:add(KEY_Z,nil,"Z", "set crop mode", function(unireader) @@ -1007,7 +988,7 @@ function UniReader:addAllCommands() print("# bbox override: ", unireader.bbox.enabled); end) self.commands:add(KEY_MENU,nil,"Menu", - "open menu", + "toggle info box", function(unireader) unireader:showMenu() unireader:goto(unireader.pageno) From 429f572827cbe70c563c7420005ba67fe1c0c77d Mon Sep 17 00:00:00 2001 From: traycold Date: Mon, 16 Apr 2012 00:10:41 +0200 Subject: [PATCH 06/11] modification to take into account new version of mupdf --- Makefile | 12 +-- font.lua | 2 + helppage.lua | 11 +-- mupdf.patch | 44 +++++------ mupdfimg.c | 2 +- pdf.c | 196 ++++++++++++++++++++++++++----------------------- rendertext.lua | 14 ++-- 7 files changed, 148 insertions(+), 133 deletions(-) diff --git a/Makefile b/Makefile index 41ee1f11d..ca25b57c7 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,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 .) + test -d mupdf && (cd mupdf; git checkout .) || echo warn: mupdf folder not found git submodule init git submodule update ln -sf kpvcrlib/crengine/cr3gui/data data @@ -155,10 +155,10 @@ cleanthirdparty: make -C $(LUADIR) clean make -C $(MUPDFDIR) clean #make -C $(CRENGINEDIR)/thirdparty/antiword clean - make -C $(CRENGINEDIR)/thirdparty/chmlib clean - make -C $(CRENGINEDIR)/thirdparty/libpng clean - make -C $(CRENGINEDIR)/crengine clean - make -C $(KPVCRLIGDIR) clean + test -d $(CRENGINEDIR)/thirdparty/chmlib && make -C $(CRENGINEDIR)/thirdparty/chmlib clean || echo warn: chmlib folder not found + test -d $(CRENGINEDIR)/thirdparty/libpng && (make -C $(CRENGINEDIR)/thirdparty/libpng clean) || echo warn: chmlib folder not found + test -d $(CRENGINEDIR)/crengine && (make -C $(CRENGINEDIR)/crengine clean) || echo warn: chmlib folder not found + test -d $(KPVCRLIGDIR) && (make -C $(KPVCRLIGDIR) clean) || echo warn: chmlib folder not found -rm -rf $(DJVUDIR)/build -rm -f $(MUPDFDIR)/fontdump.host -rm -f $(MUPDFDIR)/cmapdump.host @@ -175,7 +175,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) -DNOBUILTINFONT" make -C mupdf CC="$(CC)" CMAPDUMP=cmapdump.host FONTDUMP=fontdump.host MUPDF= XPS_APPS= verbose=1 + CFLAGS="$(CFLAGS) -DNOBUILTINFONT" make -C mupdf CC="$(CC)" CMAPDUMP=cmapdump.host FONTDUMP=fontdump.host MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1 $(DJVULIBS): -mkdir $(DJVUDIR)/build diff --git a/font.lua b/font.lua index cdf658956..d7e0be87f 100644 --- a/font.lua +++ b/font.lua @@ -38,6 +38,7 @@ Font = { function Font:getFace(font, size) +print("getFace: "..font.." size:"..size) if not font then -- default to content font font = self.cfont @@ -57,6 +58,7 @@ function Font:getFace(font, size) return nil end self.faces[font..size] = face +print("getFace, found: "..realname.." size:"..size) end return { size = size, ftface = face, hash = font..size } end diff --git a/helppage.lua b/helppage.lua index 5c7041bd3..c69eedc5b 100644 --- a/helppage.lua +++ b/helppage.lua @@ -48,8 +48,8 @@ function HelpPage:show(ypos, height, commands) end table.sort(self.commands,function(w1,w2) return w1.orderfont = fz_new_font_from_memory(ctx, data, len, 0, 1); /* RJW: "cannot load freetype font from memory" */ @@ -13,13 +13,13 @@ index 5e54e0b..38bd1d8 100644 + fontdesc->font = fz_new_font_from_file(ctx, data, 0, 1); + free(data); +#endif - + if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats")) fontdesc->flags |= PDF_FD_SYMBOLIC; @@ -199,8 +204,13 @@ pdf_load_substitute_font(fz_context *ctx, pdf_font_desc *fontdesc, int mono, int if (!data) fz_throw(ctx, "cannot find substitute font"); - + +#ifndef NOBUILTINFONT fontdesc->font = fz_new_font_from_memory(ctx, data, len, 0, 1); /* RJW: "cannot load freetype font from memory" */ @@ -27,12 +27,12 @@ index 5e54e0b..38bd1d8 100644 + fontdesc->font = fz_new_font_from_file(ctx, data, 0, 1); + free(data); +#endif - + fontdesc->font->ft_substitute = 1; fontdesc->font->ft_bold = bold && !ft_is_bold(fontdesc->font->ft_face); @@ -218,7 +228,12 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, int ros, fz_throw(ctx, "cannot find builtin CJK font"); - + /* a glyph bbox cache is too big for droid sans fallback (51k glyphs!) */ +#ifndef NOBUILTINFONT fontdesc->font = fz_new_font_from_memory(ctx, data, len, 0, 0); @@ -41,7 +41,7 @@ index 5e54e0b..38bd1d8 100644 + free(data); +#endif /* RJW: "cannot load builtin CJK font" */ - + fontdesc->font->ft_substitute = 1; diff --git a/pdf/pdf_fontfile.c b/pdf/pdf_fontfile.c index 543ce76..a076033 100644 @@ -50,7 +50,7 @@ index 543ce76..a076033 100644 @@ -1,6 +1,8 @@ #include "fitz.h" #include "mupdf.h" - + +#ifndef NOBUILTINFONT + #ifdef NOCJK @@ -83,7 +83,7 @@ index 543ce76..a076033 100644 +} + +unsigned char * -+pdf_find_builtin_font(char *name, unsigned int *len) ++pdf_lookup_builtin_font(char *name, unsigned int *len) +{ + *len = 0; + if (!strcmp("Courier", name)) { @@ -132,37 +132,37 @@ index 543ce76..a076033 100644 +} + +unsigned char * -+pdf_find_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len) ++pdf_lookup_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len) +{ + if (mono) { + if (bold) { -+ if (italic) return pdf_find_builtin_font("Courier-BoldOblique", len); -+ else return pdf_find_builtin_font("Courier-Bold", len); ++ if (italic) return pdf_lookup_builtin_font("Courier-BoldOblique", len); ++ else return pdf_lookup_builtin_font("Courier-Bold", len); + } else { -+ if (italic) return pdf_find_builtin_font("Courier-Oblique", len); -+ else return pdf_find_builtin_font("Courier", len); ++ if (italic) return pdf_lookup_builtin_font("Courier-Oblique", len); ++ else return pdf_lookup_builtin_font("Courier", len); + } + } else if (serif) { + if (bold) { -+ if (italic) return pdf_find_builtin_font("Times-BoldItalic", len); -+ else return pdf_find_builtin_font("Times-Bold", len); ++ if (italic) return pdf_lookup_builtin_font("Times-BoldItalic", len); ++ else return pdf_lookup_builtin_font("Times-Bold", len); + } else { -+ if (italic) return pdf_find_builtin_font("Times-Italic", len); -+ else return pdf_find_builtin_font("Times-Roman", len); ++ if (italic) return pdf_lookup_builtin_font("Times-Italic", len); ++ else return pdf_lookup_builtin_font("Times-Roman", len); + } + } else { + if (bold) { -+ if (italic) return pdf_find_builtin_font("Helvetica-BoldOblique", len); -+ else return pdf_find_builtin_font("Helvetica-Bold", len); ++ if (italic) return pdf_lookup_builtin_font("Helvetica-BoldOblique", len); ++ else return pdf_lookup_builtin_font("Helvetica-Bold", len); + } else { -+ if (italic) return pdf_find_builtin_font("Helvetica-Oblique", len); -+ else return pdf_find_builtin_font("Helvetica", len); ++ if (italic) return pdf_lookup_builtin_font("Helvetica-Oblique", len); ++ else return pdf_lookup_builtin_font("Helvetica", len); + } + } +} + +unsigned char * -+pdf_find_substitute_cjk_font(int ros, int serif, unsigned int *len) ++pdf_lookup_substitute_cjk_font(int ros, int serif, unsigned int *len) +{ + *len = 0; + return get_font_file("droid/DroidSansFallback.ttf"); diff --git a/mupdfimg.c b/mupdfimg.c index cdabaafca..8d745e4a2 100644 --- a/mupdfimg.c +++ b/mupdfimg.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include +#include #include "blitbuffer.h" #include "mupdfimg.h" diff --git a/pdf.c b/pdf.c index b47ea8926..9b89dcc3c 100644 --- a/pdf.c +++ b/pdf.c @@ -311,8 +311,105 @@ static int openPage(lua_State *L) { return 1; } +static void load_lua_text_page(lua_State *L, fz_text_page *page) +{ + fz_text_block *block; + fz_text_line *aline; + fz_text_span *span; + + fz_rect bbox, linebbox; + int i; + int word, line; + int len, c; + int start; + char chars[4]; // max length of UTF-8 encoded rune + luaL_Buffer textbuf; + + /* table that contains all the lines */ + lua_newtable(L); + for (block = page->blocks; block < page->blocks + page->len; block++) + { + for (aline = block->lines; aline < block->lines + block->len; aline++) + { + for (span = aline->spans; span < aline->spans + aline->len; span++) + { + linebbox = span->text[0].bbox; // start with sensible default + for(i = 0; i < span->len; ) { + /* will hold information about a word: */ + lua_newtable(L); + + luaL_buffinit(L, &textbuf); + bbox = span->text[i].bbox; // start with sensible default + for(; i < span->len; i++) { + /* check for space characters */ + if(span->text[i].c == ' ' || + span->text[i].c == '\t' || + span->text[i].c == '\n' || + span->text[i].c == '\v' || + span->text[i].c == '\f' || + span->text[i].c == '\r' || + span->text[i].c == 0xA0 || + span->text[i].c == 0x1680 || + span->text[i].c == 0x180E || + (span->text[i].c >= 0x2000 && span->text[i].c <= 0x200A) || + span->text[i].c == 0x202F || + span->text[i].c == 0x205F || + span->text[i].c == 0x3000) { + // ignore and end word + i++; + break; + } + len = fz_runetochar(chars, &span->text[i].c); + for(c = 0; c < len; c++) { + luaL_addchar(&textbuf, chars[c]); + } + bbox = fz_union_rect(bbox, span->text[i].bbox); + linebbox = fz_union_rect(linebbox, span->text[i].bbox); + } + lua_pushstring(L, "word"); + luaL_pushresult(&textbuf); + lua_settable(L, -3); + + /* bbox for a word: */ + lua_pushstring(L, "x0"); + lua_pushinteger(L, bbox.x0); + lua_settable(L, -3); + lua_pushstring(L, "y0"); + lua_pushinteger(L, bbox.y0); + lua_settable(L, -3); + lua_pushstring(L, "x1"); + lua_pushinteger(L, bbox.x1); + lua_settable(L, -3); + lua_pushstring(L, "y1"); + lua_pushinteger(L, bbox.y1); + lua_settable(L, -3); + + lua_rawseti(L, -2, word++); + } + + /* bbox for a whole line (or in fact, a "span") */ + lua_pushstring(L, "x0"); + lua_pushinteger(L, linebbox.x0); + lua_settable(L, -3); + lua_pushstring(L, "y0"); + lua_pushinteger(L, linebbox.y0); + lua_settable(L, -3); + lua_pushstring(L, "x1"); + lua_pushinteger(L, linebbox.x1); + lua_settable(L, -3); + lua_pushstring(L, "y1"); + lua_pushinteger(L, linebbox.y1); + lua_settable(L, -3); + + lua_rawseti(L, -2, line++); + + } + } + } +} + /* get the text of the given page - * + * * will return text in a Lua table that is modeled after * djvu.c creates this table. * @@ -327,105 +424,20 @@ static int openPage(lua_State *L) { * will return an empty table if we have no text */ static int getPageText(lua_State *L) { - fz_text_span *page_text; - fz_text_span *ptr; + fz_text_page *text_page; fz_device *tdev; - fz_bbox bbox, linebbox; - int i; - int word, line; - int len, c; - int start; - char chars[4]; // max length of UTF-8 encoded rune - luaL_Buffer textbuf; PdfPage *page = (PdfPage*) luaL_checkudata(L, 1, "pdfpage"); - page_text = fz_new_text_span(page->doc->context); - tdev = fz_new_text_device(page->doc->context, page_text); + text_page = fz_new_text_page(page->doc->context, fz_bound_page(page->doc->xref, page->page)); + tdev = fz_new_text_device(page->doc->context, NULL, text_page); fz_run_page(page->doc->xref, page->page, tdev, fz_identity, NULL); fz_free_device(tdev); + tdev = NULL; - /* table that contains all the lines */ - lua_newtable(L); - line = 1; - for(ptr = page_text; ptr != NULL; ptr = ptr->next) { - if(ptr->text == NULL) continue; + load_lua_text_page(L, text_page); - /* table for the words */ - lua_newtable(L); - word = 1; - linebbox = ptr->text[0].bbox; // start with sensible default - for(i = 0; i < ptr->len; ) { - /* will hold information about a word: */ - lua_newtable(L); - - luaL_buffinit(L, &textbuf); - bbox = ptr->text[i].bbox; // start with sensible default - for(; i < ptr->len; i++) { - /* check for space characters */ - if(ptr->text[i].c == ' ' || - ptr->text[i].c == '\t' || - ptr->text[i].c == '\n' || - ptr->text[i].c == '\v' || - ptr->text[i].c == '\f' || - ptr->text[i].c == '\r' || - ptr->text[i].c == 0xA0 || - ptr->text[i].c == 0x1680 || - ptr->text[i].c == 0x180E || - (ptr->text[i].c >= 0x2000 && ptr->text[i].c <= 0x200A) || - ptr->text[i].c == 0x202F || - ptr->text[i].c == 0x205F || - ptr->text[i].c == 0x3000) { - // ignore and end word - i++; - break; - } - len = runetochar(chars, &ptr->text[i].c); - for(c = 0; c < len; c++) { - luaL_addchar(&textbuf, chars[c]); - } - bbox = fz_union_bbox(bbox, ptr->text[i].bbox); - linebbox = fz_union_bbox(linebbox, ptr->text[i].bbox); - } - lua_pushstring(L, "word"); - luaL_pushresult(&textbuf); - lua_settable(L, -3); - - /* bbox for a word: */ - lua_pushstring(L, "x0"); - lua_pushinteger(L, bbox.x0); - lua_settable(L, -3); - lua_pushstring(L, "y0"); - lua_pushinteger(L, bbox.y0); - lua_settable(L, -3); - lua_pushstring(L, "x1"); - lua_pushinteger(L, bbox.x1); - lua_settable(L, -3); - lua_pushstring(L, "y1"); - lua_pushinteger(L, bbox.y1); - lua_settable(L, -3); - - lua_rawseti(L, -2, word++); - } - - /* bbox for a whole line (or in fact, a "span") */ - lua_pushstring(L, "x0"); - lua_pushinteger(L, linebbox.x0); - lua_settable(L, -3); - lua_pushstring(L, "y0"); - lua_pushinteger(L, linebbox.y0); - lua_settable(L, -3); - lua_pushstring(L, "x1"); - lua_pushinteger(L, linebbox.x1); - lua_settable(L, -3); - lua_pushstring(L, "y1"); - lua_pushinteger(L, linebbox.y1); - lua_settable(L, -3); - - lua_rawseti(L, -2, line++); - } - - fz_free_text_span(page->doc->context, page_text); + fz_free_text_page(page->doc->context, text_page); return 1; } diff --git a/rendertext.lua b/rendertext.lua index 32dd2e084..320f7dd41 100644 --- a/rendertext.lua +++ b/rendertext.lua @@ -44,7 +44,7 @@ function clearGlyphCache() glyphcache = {} end -function sizeUtf8Text(x, width, face, facehash, text, kerning) +function sizeUtf8Text(x, width, face, text, kerning) if text == nil then print("# sizeUtf8Text called without text"); return @@ -59,13 +59,13 @@ function sizeUtf8Text(x, width, face, facehash, text, kerning) for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do if pen_x < (width - x) 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 - print("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." kern:"..kern) + --print("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." kern:"..kern) else - print("curr:"..string.char(charcode)) + --print("curr:"..string.char(charcode)) end pen_x = pen_x + glyph.ax pen_y_top = math.max(pen_y_top, glyph.t) @@ -77,10 +77,10 @@ function sizeUtf8Text(x, width, face, facehash, text, kerning) return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom} end -function renderUtf8Text(buffer, x, y, face, facehash, text, kerning, backgroundColor) +function renderUtf8Text(buffer, x, y, face, text, kerning) if text == nil then print("# renderUtf8Text called without text"); - return + return 0 end -- may still need more adaptive pen placement when kerning, -- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html From 819afa3ff3fc1a1b823186a2038593fd4ecd4c3b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 16 Apr 2012 10:53:13 +0200 Subject: [PATCH 07/11] don't patch already patched crengine --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ca25b57c7..c54b68d6d 100644 --- a/Makefile +++ b/Makefile @@ -136,7 +136,7 @@ fetchthirdparty: ln -sf kpvcrlib/crengine/cr3gui/data data test -d fonts || ln -sf $(TTF_FONTS_DIR) fonts # CREngine patch: disable fontconfig - 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 + 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 || echo "USE_FONTCONFIG already disabled" test -f mupdf-thirdparty.zip || wget http://www.mupdf.com/download/mupdf-thirdparty.zip unzip mupdf-thirdparty.zip -d mupdf # dirty patch in MuPDF's thirdparty liby for CREngine From 77f2c3b3863f79fbdb5fe8b2ee3d0d30b3ab375b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 16 Apr 2012 10:53:13 +0200 Subject: [PATCH 08/11] don't patch already patched crengine --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ca25b57c7..c54b68d6d 100644 --- a/Makefile +++ b/Makefile @@ -136,7 +136,7 @@ fetchthirdparty: ln -sf kpvcrlib/crengine/cr3gui/data data test -d fonts || ln -sf $(TTF_FONTS_DIR) fonts # CREngine patch: disable fontconfig - 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 + 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 || echo "USE_FONTCONFIG already disabled" test -f mupdf-thirdparty.zip || wget http://www.mupdf.com/download/mupdf-thirdparty.zip unzip mupdf-thirdparty.zip -d mupdf # dirty patch in MuPDF's thirdparty liby for CREngine From b06927dcfed217798266d0931c7045d8bb0c9eeb Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 16 Apr 2012 14:24:03 +0200 Subject: [PATCH 09/11] fix modifier for zoom in --- unireader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 4cf59ba84..c35e97af0 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1722,7 +1722,7 @@ function UniReader:addAllCommands() function(unireader,keydef) unireader:setGlobalZoom(unireader.globalzoom + (keydef.keycode==KEY_PGBCK and -1 or 1)*unireader.globalzoom_orig*0.1) end) - self.commands:addGroup(MOD_SHIFT.."< >",{Keydef:new(KEY_PGBCK,MOD_SHIFT),Keydef:new(KEY_PGFWD,MOD_ALTSHIFT)}, + self.commands:addGroup(MOD_SHIFT.."< >",{Keydef:new(KEY_PGBCK,MOD_SHIFT),Keydef:new(KEY_PGFWD,MOD_SHIFT)}, "zoom out/in 20%", function(unireader,keydef) unireader:setGlobalZoom(unireader.globalzoom + (keydef.keycode==KEY_PGBCK and -1 or 1)*unireader.globalzoom_orig*0.2) From 53fcb2490bec193554707dff3e9046f011ab9b1b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 16 Apr 2012 14:28:46 +0200 Subject: [PATCH 10/11] exit with just home (no modifier) --- unireader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index c35e97af0..e44fd68dd 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1739,7 +1739,7 @@ function UniReader:addAllCommands() function(unireader) return "break" end) - self.commands:add(KEY_HOME,MOD_ALT,"Home", + self.commands:add(KEY_HOME,nil,"Home", "exit application", function(unireader) keep_running = false From 6031d2066b77f329c5ef65090821f726f047766a Mon Sep 17 00:00:00 2001 From: traycold Date: Mon, 16 Apr 2012 20:16:31 +0200 Subject: [PATCH 11/11] some fixes about coding style (#62) and removed debug code --- font.lua | 3 +-- helppage.lua | 40 ++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/font.lua b/font.lua index d7e0be87f..1518138a8 100644 --- a/font.lua +++ b/font.lua @@ -38,7 +38,6 @@ Font = { function Font:getFace(font, size) -print("getFace: "..font.." size:"..size) if not font then -- default to content font font = self.cfont @@ -58,7 +57,7 @@ print("getFace: "..font.." size:"..size) return nil end self.faces[font..size] = face -print("getFace, found: "..realname.." size:"..size) + --print("getFace, found: "..realname.." size:"..size) end return { size = size, ftface = face, hash = font..size } end diff --git a/helppage.lua b/helppage.lua index c69eedc5b..fb868de9a 100644 --- a/helppage.lua +++ b/helppage.lua @@ -48,21 +48,22 @@ function HelpPage:show(ypos, height, commands) end table.sort(self.commands,function(w1,w2) return w1.order 1 then self.page = self.page - 1 - pagedirty = true + is_pagedirty = true end elseif ev.code == KEY_BACK or ev.code == KEY_HOME then return nil