diff --git a/blitbuffer.c b/blitbuffer.c index 2294b8d19..123b9cb55 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -423,6 +423,67 @@ static int invertRect(lua_State *L) { return 0; } +static int dimRect(lua_State *L) { + BlitBuffer *dst = (BlitBuffer*) luaL_checkudata(L, 1, "blitbuffer"); + int x = luaL_checkint(L, 2); + int y = luaL_checkint(L, 3); + int w = luaL_checkint(L, 4); + int h = luaL_checkint(L, 5); + uint8_t *dstptr; + + int cy, cx; + if(w <= 0 || h <= 0 || x >= dst->w || y >= dst->h) { + return 0; + } + if(x + w > dst->w) { + w = dst->w - x; + } + if(y + h > dst->h) { + h = dst->h - y; + } + + if(x & 1) { + /* This will dimm the leftmost column + * in the case when x is odd. After this, + * x will become even. */ + dstptr = (uint8_t*)(dst->data + + y * dst->pitch + + x / 2); + for(cy = 0; cy < h; cy++) { + int px = *dstptr & 0x0F; + *dstptr &= 0xF0 | px >> 1; + dstptr += dst->pitch; + } + x++; + w--; + } + dstptr = (uint8_t*)(dst->data + + y * dst->pitch + + x / 2); + for(cy = 0; cy < h; cy++) { + for(cx = 0; cx < w/2; cx++) { + *(dstptr+cx) = + *(dstptr+cx) >> 1 & 0xF0 | + *(dstptr+cx) & 0x0F >> 1; + } + dstptr += dst->pitch; + } + if(w & 1) { + /* This will dimm the rightmost column + * in the case when (w & 1) && !(x & 1) or + * !(w & 1) && (x & 1). */ + dstptr = (uint8_t*)(dst->data + + y * dst->pitch + + (x + w) / 2); + for(cy = 0; cy < h; cy++) { + int px = *dstptr & 0xF0; + *dstptr &= 0x0F | ( px >> 1 & 0xF0 ); + dstptr += dst->pitch; + } + } + return 0; +} + static const struct luaL_Reg blitbuffer_func[] = { {"new", newBlitBuffer}, {NULL, NULL} @@ -436,6 +497,7 @@ static const struct luaL_Reg blitbuffer_meth[] = { {"blitFullFrom", blitFullToBuffer}, {"paintRect", paintRect}, {"invertRect", invertRect}, + {"dimRect", dimRect}, {"free", freeBlitBuffer}, {"__gc", freeBlitBuffer}, {NULL, NULL} diff --git a/crereader.lua b/crereader.lua index 4578edc19..a1f77deec 100644 --- a/crereader.lua +++ b/crereader.lua @@ -111,6 +111,14 @@ function CREReader:goto(pos, pos_type) self.doc:drawCurrentPage(self.nulldc, fb.bb) + print("## self.show_overlap "..self.show_overlap) + if self.show_overlap < 0 then + fb.bb:dimRect(0,0, width, -self.show_overlap) + elseif self.show_overlap > 0 then + fb.bb:dimRect(0,height - self.show_overlap, width, self.show_overlap) + end + self.show_overlap = 0 + if self.rcount == self.rcountmax then print("full refresh") self.rcount = 1 @@ -136,10 +144,12 @@ function CREReader:gotoTocEntry(entry) end function CREReader:nextView() + self.show_overlap = -self.pan_overlap_vertical return self.pos + G_height - self.pan_overlap_vertical end function CREReader:prevView() + self.show_overlap = self.pan_overlap_vertical return self.pos - G_height + self.pan_overlap_vertical end diff --git a/test/tall.pdf b/test/tall.pdf new file mode 100644 index 000000000..c58ebc3d8 Binary files /dev/null and b/test/tall.pdf differ diff --git a/unireader.lua b/unireader.lua index cf3868a41..b856f606d 100644 --- a/unireader.lua +++ b/unireader.lua @@ -54,6 +54,7 @@ UniReader = { pan_y = 0, pan_margin = 20, -- horizontal margin for two-column zoom pan_overlap_vertical = 30, + show_overlap = 0, -- the document: doc = nil, @@ -555,6 +556,14 @@ function UniReader:show(no) "width:"..width..", height:"..height) fb.bb:blitFrom(bb, dest_x, dest_y, offset_x, offset_y, width, height) + print("## self.show_overlap "..self.show_overlap) + if self.show_overlap < 0 then + fb.bb:dimRect(0,0, width, dest_y - self.show_overlap) + elseif self.show_overlap > 0 then + fb.bb:dimRect(0,dest_y + height - self.show_overlap, width, self.show_overlap) + end + self.show_overlap = 0 + -- render highlights to page if self.highlight[no] then self:toggleTextHighLight(self.highlight[no]) @@ -671,6 +680,7 @@ function UniReader:nextView() -- goto next view of current page self.offset_y = self.offset_y - G_height + self.pan_overlap_vertical + self.show_overlap = -self.pan_overlap_vertical -- top < 0 end else -- not in fit to content width pan mode, just do a page turn @@ -698,6 +708,7 @@ function UniReader:prevView() -- goto previous view of current page self.offset_y = self.offset_y + G_height - self.pan_overlap_vertical + self.show_overlap = self.pan_overlap_vertical -- bottom > 0 end else -- not in fit to content width pan mode, just do a page turn @@ -1186,8 +1197,8 @@ function UniReader:addAllCommands() x = unireader.shift_x / 5 y = unireader.shift_y / 5 elseif unireader.pan_by_page then - x = G_width; - y = G_height - unireader.pan_overlap_vertical; -- overlap for lines which didn't fit + x = G_width + y = G_height - unireader.pan_overlap_vertical -- overlap for lines which didn't fit else x = unireader.shift_x y = unireader.shift_y @@ -1229,11 +1240,15 @@ function UniReader:addAllCommands() unireader.offset_y = unireader.offset_y + y if unireader.offset_y > 0 then unireader.offset_y = 0 + elseif unireader.pan_by_page then + unireader.show_overlap = unireader.pan_overlap_vertical -- bottom end elseif keydef.keycode == KEY_FW_DOWN then unireader.offset_y = unireader.offset_y - y if unireader.offset_y < unireader.min_offset_y then unireader.offset_y = unireader.min_offset_y + elseif unireader.pan_by_page then + unireader.show_overlap = -unireader.pan_overlap_vertical -- top end elseif keydef.keycode == KEY_FW_PRESS then if keydef.modifier==MOD_SHIFT then