Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/gzreader.koplugin/gzreader_changelog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ return {
{
version = "next",
changes = {
{ short = "Drawing: Kid Pix stickers", text = "The drawing screen has a Stickers tool, under Text: the 935 Kid Pix stickers of the Memos fork's drawing sheet (animals, food, flags, vehicles, praise and more, in 42 categories). The first tap opens them, a tap on one takes it, and then each tap on the page puts it down there; tap Stickers again for another sticker or its size (Small, Medium, Large). A sticker is a picture in the drawing, as in Memos' Kid Pix mode: Undo takes it off, the lasso moves and sizes it, and Memos shows it. They come from your Memos server (the fork, with its sticker pictures): a category is fetched over Wi-Fi the first time it's opened and then kept on the Kindle. On a colour Kindle they're in colour. Pictures with a clear ground (stickers, PNGs) now show the paper and the ink under them instead of a box." },
{ short = "GZreader has a folder of its own, beside KOReader: GZreader/app, books, music, audiobooks, notes", text = "GZreader used to take KOReader's place on the drive (the koreader folder, or .adds/koreader on a Kobo), so you couldn't have both. Everything GZreader keeps is now in one GZreader folder: app (GZreader itself, its settings and logs), books (your books and their reading positions), music and audiobooks (what you downloaded, no longer in hidden folders) and notes (the notes kept on the device, drawings waiting to be sent, attachments). The koreader folder is left free, so KOReader can be installed beside GZreader. When you update, GZreader moves everything there itself at its first start: your books with their reading positions, highlights and history, your music, audiobooks and notes, and the program, then starts again (a few seconds longer than usual, once) and says what it did. The Kindle's KUAL menu and the Kobo's NickelMenu and KFMon entries are changed to start it from its new place. Sign-ins stay on the Kindle's own disk, as before. On the Nook, GZreader's programs and settings stay on its own disk (the card can't run programs), and everything else goes into GZreader on the card the same way: the hidden .gzreader-app becomes GZreader/app (still checked against its fingerprints at every start), and your books, music, audiobooks and notes are moved into their folders (the notes off the Nook's small internal disk), without a restart." },
{ short = "Drawing: the Kindle no longer falls asleep, or stops answering, while you draw", text = "While you drew, the drawing screen took the pen's input before KOReader's sleep timer saw it, so KOReader thought the Kindle hadn't been touched since the drawing opened. It put the Kindle to sleep in the middle of a drawing, and after a long while drawing, its sleep timer's rounds took longer and longer until the screen stopped answering the pen and the power button, and GZreader restarted, losing the drawing. Now the drawing screen tells the sleep timer you're active as you draw (at most every 5 seconds), as any other tap does. The Kindle still sleeps when you put it down for as long as your sleep setting says." },
{ short = "Drawing: what you draw is kept as you go, and comes back if GZreader stops before you save", text = "A drawing was only written to the Kindle when you saved it, so if GZreader stopped first (it hung, crashed or the battery ran out), everything drawn since was lost. Now every drawing is kept as you draw: a few seconds after you pause (at most every 30 seconds, and at least every minute and a half however long you write, between strokes), and right before the Kindle goes to sleep. It is never written while the pen is on the page or has just moved (hovering counts), and it is written by a separate background process, so writing is never held up by it. (In the first test build it was written on the screen's own thread: on a full page that froze the pen for a second or more, and a stroke begun then could break.) When you save or discard it, that copy is deleted. If GZreader stops before then, the next time it starts it asks about the drawing: Open it (a journal entry comes back with its mood, tags, words and drawing; a note's drawing opens as a new drawing note), Later (it asks again at the next start), or Delete it." },
Expand Down
101 changes: 94 additions & 7 deletions plugins/gzreader.koplugin/gzreader_drawscreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ DrawScreen.SIDE_TOOLS = {
{ id = "highlighter", icon = "highlighter", label = _("Highlighter") },
{ id = "shape", icon = "shapes", label = _("Shapes") },
{ id = "text", icon = "text", label = _("Text") },
-- (Kid Pix's stickers, from the Memos server: gzreader_stickers.lua)
{ id = "sticker", icon = "sticker", label = _("Stickers") },
{ id = "eraser", icon = "eraser", label = _("Eraser") },
{ id = "lasso", icon = "lasso", label = _("Lasso") },
{ id = "hand", icon = "hand", label = _("Move the page") },
Expand Down Expand Up @@ -248,6 +250,16 @@ function DrawScreen:init()
if self.writing == "highlighter" then self.tool, self.writing = "highlighter", "pen" end
self.hl_width = oneOf("gzreader_drawing_hl_width", Sketch.WIDTHS, 2)
self.eraser_width = oneOf("gzreader_drawing_eraser_width", Sketch.ERASER_WIDTHS, 4)
-- the sticker last put down, and its size (the Stickers tool stamps it)
do
local Stickers = require("gzreader_stickers")
local last, size = Stickers.last()
self.sticker_size = size
if last then
local item = Stickers.find(Stickers.index(), last.slug, last.n)
if item and Stickers.path(item) then self.sticker = item end
end
end
local shape = G_reader_settings and G_reader_settings:readSetting("gzreader_drawing_shape")
self.shape = Sketch.SHAPE_SET[shape or ""] and shape or "square"
self.has_color = DrawScreen.hasColor()
Expand Down Expand Up @@ -525,6 +537,11 @@ function DrawScreen:flyoutRows(which)
rows[#rows + 1] = { id = "e" .. tostring(w), row = true, eraser_width = w, bar = k, hollow = true, label = DrawScreen.WIDTH_NAMES[k] }
end
rows[#rows + 1] = { id = "clear", row = true, label = _("Erase page") }
elseif which == "sticker" then
rows[#rows + 1] = { id = "sticker-pick", row = true, label = _("Choose a sticker…") }
for k, _f in ipairs(require("gzreader_stickers").SIZES) do
rows[#rows + 1] = { id = "ss" .. k, row = true, sticker_size = k, label = DrawScreen.STICKER_SIZE_NAMES[k] }
end
elseif which == "more" then
rows[#rows + 1] = { id = "side", row = true, label = self.toolbar_side == "left" and _("Move to right side") or _("Move to left side") }
if self.has_pen then
Expand Down Expand Up @@ -765,6 +782,7 @@ DrawScreen.EDGE = function() return S(24) end
DrawScreen.FLYOUT_ANCHOR = { tags = "tag" }

function DrawScreen:selected(t)
if t.sticker_size then return self.sticker_size == t.sticker_size end
if t.writing then return self.tool == "pen" and self.writing == t.writing end
if t.width then return self.tool ~= "highlighter" and self.width == t.width end
if t.hl_width then return self.hl_width == t.hl_width end
Expand All @@ -775,7 +793,7 @@ function DrawScreen:selected(t)
for _i, name in ipairs(self.meta and self.meta.tags or {}) do if name == t.tagname then return true end end
return false
end
if t.id == "pen" or t.id == "highlighter" or t.id == "shape" or t.id == "eraser" or t.id == "text" or t.id == "hand" or t.id == "lasso" then return self.tool == t.id end
if t.id == "pen" or t.id == "highlighter" or t.id == "shape" or t.id == "eraser" or t.id == "text" or t.id == "hand" or t.id == "lasso" or t.id == "sticker" then return self.tool == t.id end
if t.id == "fingers" then return not self.pen_only end
if t.id == "more" or t.id == "options" then return self.flyout == t.id end
if t.id == "tag" then return self.flyout == "tags" end
Expand Down Expand Up @@ -1144,6 +1162,26 @@ local function strokeSegments(sk, st)
return out
end

--- A picture onto the page: through its transparency when it has one (a
--- sticker, a PNG with a clear ground: the paper and the ink under it show),
--- else copied as it is (quicker).
function DrawScreen.blitPicture(dst, src, dx, dy, sx, sy, w, h)
local t = src.getType and src:getType()
if t ~= nil and (t == Blitbuffer.TYPE_BB8A or t == Blitbuffer.TYPE_BBRGB32) then
if dst.getType and dst:getType() == Blitbuffer.TYPE_BBRGB24 then
-- (KOReader's blitter can't blend into 24-bit colour, the PNG's page: through a 32-bit copy of that part)
local tmp = Blitbuffer.new(w, h, Blitbuffer.TYPE_BBRGB32)
tmp:blitFrom(dst, 0, 0, dx, dy, w, h)
tmp:alphablitFrom(src, 0, 0, sx, sy, w, h)
dst:blitFrom(tmp, dx, dy, 0, 0, w, h)
tmp:free()
return
end
return dst:alphablitFrom(src, dx, dy, sx, sy, w, h)
end
return dst:blitFrom(src, dx, dy, sx, sy, w, h)
end

--- Picture `el` of the page's scene, at w x h (cached for the page): a
--- BlitBuffer, or nil when it can't be read.
function DrawScreen:picture(el, w, h)
Expand Down Expand Up @@ -1195,12 +1233,12 @@ function DrawScreen:paintPicture(el)
local dx, dy = math.max(0, x1), math.max(0, y1)
local bw, bh = math.min(w - sx, c.w - dx), math.min(h - sy, c.h - dy)
if bw <= 0 or bh <= 0 then return true end
self.canvas_bb:blitFrom(bb, dx, dy, sx, sy, bw, bh)
DrawScreen.blitPicture(self.canvas_bb, bb, dx, dy, sx, sy, bw, bh)
if not self.color_bb then
self.color_bb = Blitbuffer.new(c.w, c.h, Blitbuffer.TYPE_BBRGB24)
self.color_bb:fill(Blitbuffer.ColorRGB24(DrawScreen.hexRGB(Drawing.PAPER)))
end
self.color_bb:blitFrom(bb, dx, dy, sx, sy, bw, bh)
DrawScreen.blitPicture(self.color_bb, bb, dx, dy, sx, sy, bw, bh)
return true
end

Expand All @@ -1223,12 +1261,12 @@ function DrawScreen:paintPicturePart(el, x1, y1, w, h)
return require("ui/renderimage"):scaleBlitBuffer(view, dx1 - dx0, dy1 - dy0, false)
end)
if not ok or not part then return false end
self.canvas_bb:blitFrom(part, dx0, dy0, 0, 0, dx1 - dx0, dy1 - dy0)
DrawScreen.blitPicture(self.canvas_bb, part, dx0, dy0, 0, 0, dx1 - dx0, dy1 - dy0)
if not self.color_bb then
self.color_bb = Blitbuffer.new(c.w, c.h, Blitbuffer.TYPE_BBRGB24)
self.color_bb:fill(Blitbuffer.ColorRGB24(DrawScreen.hexRGB(Drawing.PAPER)))
end
self.color_bb:blitFrom(part, dx0, dy0, 0, 0, dx1 - dx0, dy1 - dy0)
DrawScreen.blitPicture(self.color_bb, part, dx0, dy0, 0, 0, dx1 - dx0, dy1 - dy0)
part:free()
return true
end
Expand Down Expand Up @@ -1374,8 +1412,8 @@ function DrawScreen:repaintArea(area)
local dx0, dy0 = math.max(x0, p.x), math.max(y0, p.y)
local dx1, dy1 = math.min(x1, p.x + p.w), math.min(y1, p.y + p.h)
if dx1 > dx0 and dy1 > dy0 then
self.canvas_bb:blitFrom(part.bb, dx0, dy0, dx0 - p.x, dy0 - p.y, dx1 - dx0, dy1 - dy0)
if self.color_bb then self.color_bb:blitFrom(part.bb, dx0, dy0, dx0 - p.x, dy0 - p.y, dx1 - dx0, dy1 - dy0) end
DrawScreen.blitPicture(self.canvas_bb, part.bb, dx0, dy0, dx0 - p.x, dy0 - p.y, dx1 - dx0, dy1 - dy0)
if self.color_bb then DrawScreen.blitPicture(self.color_bb, part.bb, dx0, dy0, dx0 - p.x, dy0 - p.y, dx1 - dx0, dy1 - dy0) end
end
end
-- …and the bits of line that cross it (highlighters under the rest, as on the whole page;
Expand Down Expand Up @@ -1779,6 +1817,7 @@ function DrawScreen:apply(out)
self._stroke_area, self._stroke_grey = nil, nil
end
for _i, tap in ipairs(out.taps) do self:tapAt(tap.x, tap.y) end
if out.sticker_tap then self:stampSticker(out.sticker_tap.x, out.sticker_tap.y) end
if out.text_tap then self:textTap(out.text_tap) end
if out.pull then self:pullPanel() end
end
Expand Down Expand Up @@ -2427,6 +2466,16 @@ function DrawScreen:use(t)
elseif t.color then self:setColor(t.color); self:setFlyout(nil)
elseif t.tagname then self:toggleTag(t.tagname); self:setFlyout("tags")
elseif t.id == "newtag" then self:newTag()
elseif t.sticker_size then
self.sticker_size = t.sticker_size
keep("gzreader_drawing_sticker_size", t.sticker_size)
self:setTool("sticker"); self:setFlyout(nil)
elseif t.id == "sticker" then
-- in hand already: its panel (another sticker, its size); none chosen yet: the stickers to choose from
if self.tool == "sticker" then self:setFlyout(self.flyout ~= "sticker" and "sticker" or nil)
elseif self.sticker then self:setTool("sticker"); self:setFlyout(nil)
else self:setFlyout(nil); self:pickSticker() end
elseif t.id == "sticker-pick" then self:setFlyout(nil); self:pickSticker()
elseif t.id == "tag" then self:setFlyout(self.flyout ~= "tags" and "tags" or nil)
elseif t.id == "title" then self:setFlyout(nil); self:rename()
elseif t.id == "snap" then
Expand Down Expand Up @@ -2657,6 +2706,44 @@ end

-- ------------------------------------------------------------ pictures

DrawScreen.STICKER_SIZE_NAMES = { _("Small"), _("Medium"), _("Large") }

--- The Stickers tool's picker (gzreader_stickergrid.lua): the sticker picked is the one each tap puts down.
function DrawScreen:pickSticker()
return require("gzreader_stickergrid").show(self.plugin, { on_pick = function(item)
if self._closed then return end
self.sticker = item
if G_reader_settings then
G_reader_settings:saveSetting("gzreader_drawing_sticker", { slug = item.slug, n = require("gzreader_stickers").number(item) })
end
self:setTool("sticker"); self:setFlyout(nil)
end })
end

--- A tap with the Stickers tool at canvas point (x, y): the sticker put down
--- there, centred on it (a picture in the drawing, as Memos' Kid Pix mode puts
--- its stickers in; Undo takes it off, the lasso moves and sizes it).
function DrawScreen:stampSticker(x, y)
local Stickers = require("gzreader_stickers")
local item = self.sticker
if not item then return self:pickSticker() end
local w, h = Stickers.size(item, self.sticker_size)
-- (drawn from its SVG at the size it goes down: sharp at any size)
local url = Stickers.dataURL(item, w, h)
if not url then return self:pickSticker() end
local sk = self.sketch
local sx, sy = sk:toScene(x, y)
local el = sk:addPicture(url, "image/png", w, h, sx, sy)
self:touched()
Log.info("drawing: a sticker,", item.file)
-- (only where it went)
local x0, y0 = sk:toCanvas(el.x, el.y)
local x1, y1 = sk:toCanvas(el.x + el.width, el.y + el.height)
local area = { x0 = math.floor(x0) - 1, y0 = math.floor(y0) - 1, x1 = math.ceil(x1) + 1, y1 = math.ceil(y1) + 1 }
if self:repaintArea(area) then self:refreshBar() else self:redrawAll() end
return el
end

--- Photos from Immich (gzreader_immichpick.lua), placed on the page as
--- memos' drawing sheet places them: in the middle of what's shown.
function DrawScreen:pickPictures()
Expand Down
10 changes: 8 additions & 2 deletions plugins/gzreader.koplugin/gzreader_gzip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ end

function Gzip.available() return lib() ~= nil end

--- Decompress gzip data; nil, err on failure.
function Gzip.inflate(data)
--- Decompress gzip data; nil, err on failure. `max`: give up past that many bytes ("too big").
function Gzip.inflate(data, max)
local z = lib()
if not z then return nil, "no zlib" end
local strm = ffi.new("gz_z_stream")
Expand All @@ -59,6 +59,7 @@ function Gzip.inflate(data)
local chunk = math.max(65536, #data * 4)
local buf = ffi.new("unsigned char[?]", chunk)
local parts = {}
local total = 0
local ret
repeat
strm.next_out = buf
Expand All @@ -69,6 +70,11 @@ function Gzip.inflate(data)
return nil, "inflate error " .. tostring(ret)
end
parts[#parts + 1] = ffi.string(buf, chunk - strm.avail_out)
total = total + chunk - strm.avail_out
if max and total > max then
z.inflateEnd(strm)
return nil, "too big"
end
until ret == 1 or (strm.avail_in == 0 and strm.avail_out ~= 0)
z.inflateEnd(strm)
return table.concat(parts)
Expand Down
7 changes: 7 additions & 0 deletions plugins/gzreader.koplugin/gzreader_sketch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,9 @@ local function startContact(self, s, now, out)
local el, part = self:textAt(s.x - self.canvas.x, s.y - self.canvas.y)
c.kind, c.el, c.part, c.at = "text", el, part, now
if el then c.orig = { x = el.x, y = el.y, width = el.width, height = el.height } end
elseif self.tool == "sticker" then
-- the Stickers tool: a tap puts the sticker down there (the pen or a finger); a drag does nothing
c.kind = "sticker"
elseif self.pen_only and not pen and self.zoomed then
-- A pen Kindle, zoomed in: a finger moves the page (a second, at once: a pinch).
-- Whatever else rests on the screen: only "the first finger down, nothing else
Expand Down Expand Up @@ -1188,6 +1191,10 @@ local function endContact(self, slot, out)
if self.pan_slot == slot then self.pan_slot = nil end
return
end
if c.kind == "sticker" then
if c.moved <= self.tap_slop then out.sticker_tap = { x = c.x0 - self.canvas.x, y = c.y0 - self.canvas.y } end
return
end
if c.kind == "text" then
if c.moved <= self.tap_slop then
out.text_tap = { el = c.el, x = c.x0 - self.canvas.x, y = c.y0 - self.canvas.y }
Expand Down
Loading