From 5e4a43717ec5d55692b067d3576e902eee6a049e Mon Sep 17 00:00:00 2001 From: Rowan Decker Date: Wed, 25 Oct 2023 21:51:22 -0700 Subject: [PATCH 01/28] Add color highlight menu --- .../apps/reader/modules/readerhighlight.lua | 240 +++++++++++++++--- frontend/apps/reader/modules/readerview.lua | 52 +++- frontend/document/pdfdocument.lua | 3 +- frontend/ui/widget/checkbutton.lua | 5 +- frontend/ui/widget/radiobuttontable.lua | 4 + 5 files changed, 254 insertions(+), 50 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 945f0a4c2..c514c212c 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -21,7 +21,17 @@ local C_ = _.pgettext local T = ffiUtil.template local Screen = Device.screen -local ReaderHighlight = InputContainer:extend{} +local ReaderHighlight = InputContainer:extend{ + highlight_colors = { + {_("Red"), "red"}, + {_("Orange"), "orange"}, + {_("Yellow"), "yellow"}, + {_("Green"), "green"}, + {_("Blue"), "blue"}, + {_("Purple"), "purple"}, + {_("Gray"), "gray"}, + } +} local function inside_box(pos, box) if pos then @@ -403,6 +413,56 @@ function ReaderHighlight:addToMainMenu(menu_items) separator = i == #highlight_style, }) end + if Screen:isColorScreen() then + table.insert(menu_items.highlight_options.sub_item_table, { + text_func = function() + local saved_color = self.view.highlight.saved_color or "yellow" + for __, v in ipairs(self.highlight_colors) do + if v[2] == saved_color then + return T(_("Highlight color: %1"), string.lower(v[1])) + end + end + return T(_("Highlight color: %1"), saved_color) + end, + enabled_func = function() + return Screen:isColorEnabled() and self.view.highlight.saved_drawer ~= "invert" + end, + callback = function(touchmenu_instance) + local default_color = G_reader_settings:readSetting("highlight_color", "yellow") + local saved_color = self.view.highlight.saved_color or "yellow" + local radio_buttons = {} + for _, v in ipairs(self.highlight_colors) do + table.insert(radio_buttons, { + { + text = v[1], + checked = v[2] == saved_color, + provider = v[2], + }, + }) + end + UIManager:show(require("ui/widget/radiobuttonwidget"):new{ + title_text = _("Highlight color"), + width_factor = 0.5, + keep_shown_on_apply = false, + radio_buttons = radio_buttons, + default_provider = default_color, + callback = function(radio) + self.view.highlight.saved_color = radio.provider + self.ui.doc_settings:saveSetting("highlight_color", self.view.highlight.saved_color) + UIManager:setDirty(self.dialog, "ui") + if touchmenu_instance then touchmenu_instance:updateItems() end + end, + }) + end, + hold_callback = function(touchmenu_instance) + G_reader_settings:saveSetting("highlight_color", self.view.highlight.saved_color) + UIManager:show(Notification:new{ + text = T(_("Default highlight color changed to '%1'."), self.view.highlight.saved_color), + }) + if touchmenu_instance then touchmenu_instance:updateItems() end + end, + }) + end table.insert(menu_items.highlight_options.sub_item_table, { text_func = function() return T(_("Highlight opacity: %1"), G_reader_settings:readSetting("highlight_lighten_factor", 0.2)) @@ -475,6 +535,40 @@ function ReaderHighlight:addToMainMenu(menu_items) }) end, }) + if Screen:isColorScreen() then + table.insert(menu_items.highlight_options.sub_item_table, { + text = _("Apply default style to all highlights"), + enabled_func = function() + return Screen:isColorEnabled() + end, + callback = function(touchmenu_instance) + UIManager:show(ConfirmBox:new{ + text = _("Are you sure you want to edit all highlights."), + icon = "texture-box", + ok_callback = function() + local count = 0 + for _, items in pairs(self.view.highlight.saved) do + if items then + count = count + #items + for i = 1, #items do + local item = items[i] + item.drawer = self.view.highlight.saved_drawer + item.color = self.view.highlight.saved_color + end + end + end + if count > 0 then + UIManager:setDirty(self.dialog, "ui") + UIManager:show(Notification:new{ + text = T(N_("Applied default style to 1 highlight", + "Applied default style to %1 highlights", count), count), + }) + end + end + }) + end, + }) + end if self.document.info.has_pages then menu_items.panel_zoom_options = { text = _("Panel zoom (manga/comic)"), @@ -977,42 +1071,57 @@ function ReaderHighlight:showHighlightNoteOrDialog(page, index, bookmark_note) end function ReaderHighlight:onShowHighlightDialog(page, index, is_auto_text) - local buttons = { + local row = { { - { - text = _("Delete"), - callback = function() - self:deleteHighlight(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, - }, - { - text = C_("Highlight", "Style"), - callback = function() - self:editHighlightStyle(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, - }, - { - text = is_auto_text and _("Add note") or _("Edit note"), - callback = function() - self:editHighlight(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, - }, - { - text = "…", - callback = function() - self.selected_text = self.view.highlight.saved[page][index] - self:onShowHighlightMenu(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, - }, - } + text = _("Delete"), + callback = function() + self:deleteHighlight(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }, + { + text = C_("Highlight", "Style"), + callback = function() + self:editHighlightStyle(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }, + } + if Screen:isColorScreen() then + table.insert(row, { + text = C_("Highlight", "Color"), + enabled_func = function() + return Screen:isColorEnabled() + end, + callback = function() + self:editHighlightColor(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }) + end + table.insert(row, { + text = is_auto_text and _("Add note") or _("Edit note"), + callback = function() + self:editHighlight(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }) + table.insert(row, { + text = "…", + callback = function() + self.selected_text = self.view.highlight.saved[page][index] + self:onShowHighlightMenu(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }) + + local buttons = { + row } if self.ui.rolling then @@ -1852,6 +1961,7 @@ function ReaderHighlight:saveHighlight(extend_to_sentence) pboxes = self.selected_text.pboxes, ext = self.selected_text.ext, drawer = self.view.highlight.saved_drawer, + color = self.view.highlight.saved_color, chapter = chapter_name, } table.insert(self.view.highlight.saved[page], hl_item) @@ -2005,6 +2115,28 @@ function ReaderHighlight:editHighlightStyle(page, i) self:showHighlightStyleDialog(apply_drawer, item.drawer) end +function ReaderHighlight:editHighlightColor(page, i) + local item = self.view.highlight.saved[page][i] + local apply_color = function(color) + self:writePdfAnnotation("delete", page, item) + item.color = color + if self.ui.paging then + self:writePdfAnnotation("save", page, item) + local bm_note = self.ui.bookmark:getBookmarkNote(item) + if bm_note then + self:writePdfAnnotation("content", page, item, bm_note) + end + end + UIManager:setDirty(self.dialog, "ui") + self.ui:handleEvent(Event:new("BookmarkUpdated", + self.ui.bookmark:getBookmarkForHighlight({ + page = self.ui.paging and page or item.pos0, + datetime = item.datetime, + }))) + end + self:showHighlightColorDialog(apply_color, item.color) +end + function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer) local default_drawer, keep_shown_on_apply if item_drawer then -- called from editHighlightStyle @@ -2035,6 +2167,36 @@ function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer) }) end +function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) + local default_color, keep_shown_on_apply + if item_color then -- called from editHighlightColor + default_color = self.view.highlight.saved_color or + G_reader_settings:readSetting("highlight_color", "yellow") + keep_shown_on_apply = true + end + local radio_buttons = {} + for _, v in ipairs(self.highlight_colors) do + table.insert(radio_buttons, { + { + text = v[1], + checked = item_color == v[2], + provider = v[2], + }, + }) + end + local RadioButtonWidget = require("ui/widget/radiobuttonwidget") + UIManager:show(RadioButtonWidget:new{ + title_text = _("Highlight color"), + width_factor = 0.5, + keep_shown_on_apply = keep_shown_on_apply, + radio_buttons = radio_buttons, + default_provider = default_color, + callback = function(radio) + caller_callback(radio.provider) + end, + }) +end + function ReaderHighlight:startSelection() self.highlight_page, self.highlight_idx = self:saveHighlight() self.select_mode = true @@ -2160,7 +2322,8 @@ function ReaderHighlight:getSavedExtendedHighlightPage(hl_or_bm, page, index) end local item = {} item.datetime = highlight.datetime - item.drawer = highlight.drawer + item.drawer = highlight.drawer or self.highlight.saved_drawer + item.color = highlight.color or self.highlight.saved_color item.pos0 = highlight.ext[page].pos0 item.pos0.zoom = highlight.pos0.zoom item.pos0.rotation = highlight.pos0.rotation @@ -2175,6 +2338,8 @@ end function ReaderHighlight:onReadSettings(config) self.view.highlight.saved_drawer = config:readSetting("highlight_drawer") or G_reader_settings:readSetting("highlight_drawing_style") or self.view.highlight.saved_drawer + self.view.highlight.saved_color = config:readSetting("highlight_color") + or G_reader_settings:readSetting("highlight_color") or self.view.highlight.saved_color self.view.highlight.disabled = G_reader_settings:has("default_highlight_action") and G_reader_settings:readSetting("default_highlight_action") == "nothing" @@ -2204,6 +2369,7 @@ end function ReaderHighlight:onSaveSettings() self.ui.doc_settings:saveSetting("highlight_drawer", self.view.highlight.saved_drawer) + self.ui.doc_settings:saveSetting("highlight_color", self.view.highlight.saved_color) self.ui.doc_settings:saveSetting("panel_zoom_enabled", self.panel_zoom_enabled) end diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index a8e5bbbe6..b99c3626d 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -41,6 +41,15 @@ local ReaderView = OverlapGroup:extend{ note_mark_sign = nil, note_mark_pos_x1 = nil, -- page 1 note_mark_pos_x2 = nil, -- page 2 in two-page mode + highlight_colors = { + ["red"] = "#fe4400", + ["orange"] = "#ff8800", + ["yellow"] = "#fdff32", + ["green"] = "#00ad65", + ["blue"] = "#00f2ff", + ["purple"] = "#ee00ff", + ["gray"] = "#808080", + }, -- PDF/DjVu continuous paging page_scroll = nil, page_bgcolor = Blitbuffer.gray(G_defaults:readSetting("DBACKGROUND_COLOR") * (1/15)), @@ -93,8 +102,10 @@ function ReaderView:init() lighten_factor = G_reader_settings:readSetting("highlight_lighten_factor", 0.2), note_mark = G_reader_settings:readSetting("highlight_note_marker"), temp_drawer = "invert", + temp_color = "yellow", temp = {}, saved_drawer = "lighten", + saved_color = "yellow", saved = {}, indicator = nil, -- geom: non-touch highlight position indicator: {x = 50, y=50} } @@ -493,6 +504,12 @@ function ReaderView:drawScrollView(bb, x, y) self.state.pos) end +--- Converts a color name into a color struct +function ReaderView:lookupHighlightColor(color_name) + local color = self.highlight_colors[color_name] + return Blitbuffer.colorFromString(color or "#ffff00") +end + function ReaderView:drawHighlightIndicator(bb, x, y) local rect = self.highlight.indicator -- paint big cross line + @@ -515,7 +532,7 @@ function ReaderView:drawTempHighlight(bb, x, y) for i = 1, #boxes do local rect = self:pageToScreenTransform(page, boxes[i]) if rect then - self:drawHighlightRect(bb, x, y, rect, self.highlight.temp_drawer) + self:drawHighlightRect(bb, x, y, rect, self.highlight.temp_drawer, self.highlight.temp_color) end end end @@ -561,13 +578,13 @@ function ReaderView:drawPageSavedHighlight(bb, x, y) for _, item in ipairs(items) do local boxes = self.document:getPageBoxesFromPositions(page, item.pos0, item.pos1) if boxes then - local drawer = item.drawer or self.highlight.saved_drawer + local color = self:lookupHighlightColor(item.color) local draw_note_mark = self.highlight.note_mark and self.ui.bookmark:getBookmarkNote({datetime = item.datetime}) for _, box in ipairs(boxes) do local rect = self:pageToScreenTransform(page, box) if rect then - self:drawHighlightRect(bb, x, y, rect, drawer, draw_note_mark) + self:drawHighlightRect(bb, x, y, rect, item.drawer, color, draw_note_mark) if draw_note_mark and self.highlight.note_mark == "sidemark" then draw_note_mark = false -- side mark in the first line only end @@ -609,12 +626,12 @@ function ReaderView:drawXPointerSavedHighlight(bb, x, y) if start_pos <= cur_view_bottom and end_pos >= cur_view_top then local boxes = self.document:getScreenBoxesFromPositions(pos0, pos1, true) -- get_segments=true if boxes then - local drawer = item.drawer or self.highlight.saved_drawer + local color = self:lookupHighlightColor(item.color) local draw_note_mark = self.highlight.note_mark and self.ui.bookmark:getBookmarkNote({datetime = item.datetime}) for _, box in ipairs(boxes) do if box.h ~= 0 then - self:drawHighlightRect(bb, x, y, box, drawer, draw_note_mark) + self:drawHighlightRect(bb, x, y, box, item.drawer, color, draw_note_mark) if draw_note_mark and self.highlight.note_mark == "sidemark" then draw_note_mark = false -- side mark in the first line only end @@ -627,24 +644,37 @@ function ReaderView:drawXPointerSavedHighlight(bb, x, y) end -- end for all saved highlight end -function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, draw_note_mark) +function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note_mark) local x, y, w, h = rect.x, rect.y, rect.w, rect.h if drawer == "lighten" then - bb:lightenRect(x, y, w, h, self.highlight.lighten_factor) + local alpha = 0xFF*(self.highlight.lighten_factor or 0.5) + if not color or not Screen:isColorEnabled() then + color = Blitbuffer.Color8A(0, alpha) + end + bb:lightenRect(x, y, w, h, color) elseif drawer == "underscore" then - bb:paintRect(x, y + h - 1, w, Size.line.medium, Blitbuffer.COLOR_GRAY) + if not color or not Screen:isColorEnabled() then + color = Blitbuffer.COLOR_GRAY + end + bb:paintRect(x, y + h - 1, w, Size.line.medium, color) elseif drawer == "strikeout" then + if not color or not Screen:isColorEnabled() then + color = Blitbuffer.COLOR_BLACK + end local line_y = y + math.floor(h / 2) + 1 if self.ui.paging then line_y = line_y + 2 end - bb:paintRect(x, line_y, w, Size.line.medium, Blitbuffer.COLOR_BLACK) + bb:paintRect(x, line_y, w, Size.line.medium, color) elseif drawer == "invert" then bb:invertRect(x, y, w, h) end if draw_note_mark then + if not color or not Screen:isColorEnabled() then + color = Blitbuffer.COLOR_BLACK + end if self.highlight.note_mark == "underline" then - bb:paintRect(x, y + h - 1, w, Size.line.medium, Blitbuffer.COLOR_BLACK) + bb:paintRect(x, y + h - 1, w, Size.line.medium, color) else local note_mark_pos_x if self.ui.paging or @@ -655,7 +685,7 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, draw_note_mark) note_mark_pos_x = self.note_mark_pos_x2 end if self.highlight.note_mark == "sideline" then - bb:paintRect(note_mark_pos_x, y, self.note_mark_line_w, h, Blitbuffer.COLOR_BLACK) + bb:paintRect(note_mark_pos_x, y, self.note_mark_line_w, h, color) elseif self.highlight.note_mark == "sidemark" then self.note_mark_sign:paintTo(bb, note_mark_pos_x, y) end diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index aba0ad3a6..deecb6fb3 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -249,6 +249,7 @@ function PdfDocument:saveHighlight(pageno, item) local quadpoints, n = _quadpointsFromPboxes(item.pboxes) local page = self._document:openPage(pageno) local annot_type = C.PDF_ANNOT_HIGHLIGHT + local annot_color = Blitbuffer.colorFromString(item.color) if item.drawer == "lighten" then annot_type = C.PDF_ANNOT_HIGHLIGHT elseif item.drawer == "underscore" then @@ -256,7 +257,7 @@ function PdfDocument:saveHighlight(pageno, item) elseif item.drawer == "strikeout" then annot_type = C.PDF_ANNOT_STRIKE_OUT end - page:addMarkupAnnotation(quadpoints, n, annot_type) -- may update/adjust quadpoints + page:addMarkupAnnotation(quadpoints, n, annot_type, annot_color) -- may update/adjust quadpoints -- Update pboxes with the possibly adjusted coordinates (this will have it updated -- in self.view.highlight.saved[page]) item.pboxes = _quadpointsToPboxes(quadpoints, n) diff --git a/frontend/ui/widget/checkbutton.lua b/frontend/ui/widget/checkbutton.lua index ef7e785aa..71168d36e 100644 --- a/frontend/ui/widget/checkbutton.lua +++ b/frontend/ui/widget/checkbutton.lua @@ -67,11 +67,14 @@ function CheckButton:initCheckButton(checked) show_parent = self.show_parent or self, } end + local fgcolor = self.fgcolor or Blitbuffer.COLOR_BLACK self._textwidget = TextBoxWidget:new{ text = self.text, face = self.face, width = (self.width or self.parent:getAddedWidgetAvailableWidth()) - self._checkmark.dimen.w, - fgcolor = self.enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY, + bold = self.bold, + fgcolor = self.enabled and fgcolor or Blitbuffer.COLOR_DARK_GRAY, + bgcolor = self.bgcolor, } local textbox_shift = math.max(0, self._checkmark.baseline - self._textwidget:getBaseline()) self._verticalgroup = VerticalGroup:new{ diff --git a/frontend/ui/widget/radiobuttontable.lua b/frontend/ui/widget/radiobuttontable.lua index c8ac9c138..635f262da 100644 --- a/frontend/ui/widget/radiobuttontable.lua +++ b/frontend/ui/widget/radiobuttontable.lua @@ -66,6 +66,10 @@ function RadioButtonTable:init() radio = true, provider = btn_entry.provider, + bold = btn_entry.bold, + fgcolor = btn_entry.fgcolor, + bgcolor = btn_entry.bgcolor, + width = (self.width - sizer_space) / column_cnt, bordersize = 0, margin = 0, From a6c6b498f4d2856f534ef12077a89206306806e2 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 21 Jan 2024 06:49:01 +0100 Subject: [PATCH 02/28] LuaCheck'ed --- frontend/apps/reader/modules/readerhighlight.lua | 1 + frontend/document/pdfdocument.lua | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index c514c212c..1719fb95e 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -18,6 +18,7 @@ local ffiUtil = require("ffi/util") local time = require("ui/time") local _ = require("gettext") local C_ = _.pgettext +local N_ = _.ngettext local T = ffiUtil.template local Screen = Device.screen diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index deecb6fb3..162f928fb 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -1,3 +1,4 @@ +local BlitBuffer = require("ffi/blitbuffer") local CacheItem = require("cacheitem") local CanvasContext = require("document/canvascontext") local DocCache = require("document/doccache") @@ -249,7 +250,7 @@ function PdfDocument:saveHighlight(pageno, item) local quadpoints, n = _quadpointsFromPboxes(item.pboxes) local page = self._document:openPage(pageno) local annot_type = C.PDF_ANNOT_HIGHLIGHT - local annot_color = Blitbuffer.colorFromString(item.color) + local annot_color = BlitBuffer.colorFromString(item.color) if item.drawer == "lighten" then annot_type = C.PDF_ANNOT_HIGHLIGHT elseif item.drawer == "underscore" then From 45cc8b654bade15b098ed3457f423b05c91e15bf Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 21 Jan 2024 07:16:04 +0100 Subject: [PATCH 03/28] Honor the ligthen_factor with colors --- frontend/apps/reader/modules/readerview.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index b99c3626d..24711231b 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -650,6 +650,8 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note local alpha = 0xFF*(self.highlight.lighten_factor or 0.5) if not color or not Screen:isColorEnabled() then color = Blitbuffer.Color8A(0, alpha) + else + color = Blitbuffer.ColorRGB32(color.r, color.g, color.b, alpha) end bb:lightenRect(x, y, w, h, color) elseif drawer == "underscore" then From bc3aeab1a5148c9d47acaa2ee9d614ef77958fc4 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 21 Jan 2024 07:26:34 +0100 Subject: [PATCH 04/28] Random 7AM idea is random But feels better than an OVER blend. --- frontend/apps/reader/modules/readerview.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 24711231b..016f86eb6 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -653,6 +653,10 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note else color = Blitbuffer.ColorRGB32(color.r, color.g, color.b, alpha) end + --- @fixme: Use something based on colorblitFrom instead? + -- (except basically, the invert of it, colorizing the non-covered parts of the alpha map). + --- Might be tricky for non-black text, though... + --- Also potentially annoying with software invert, maybe? bb:lightenRect(x, y, w, h, color) elseif drawer == "underscore" then if not color or not Screen:isColorEnabled() then From a022915344e7939c15079e9a90a12ce41328271f Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 21 Jan 2024 08:04:54 +0100 Subject: [PATCH 05/28] More random musings --- frontend/apps/reader/modules/readerview.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 016f86eb6..31ee9bae9 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -651,7 +651,9 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note if not color or not Screen:isColorEnabled() then color = Blitbuffer.Color8A(0, alpha) else - color = Blitbuffer.ColorRGB32(color.r, color.g, color.b, alpha) + -- FIXME: lighten_factor and lightenRect doing the opposite of what they should mean or some such ;p. + -- FIXME: Do we even want a ligthen factor here? + color = Blitbuffer.ColorRGB32(color.r, color.g, color.b, bit.bxor(alpha, 0xFF)) end --- @fixme: Use something based on colorblitFrom instead? -- (except basically, the invert of it, colorizing the non-covered parts of the alpha map). From 9bf0e4e245c97d4a2c8c714b6a0ebf312ddb3e2f Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 21 Jan 2024 18:36:49 +0100 Subject: [PATCH 06/28] I can word good now! --- plugins/terminal.koplugin/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/terminal.koplugin/main.lua b/plugins/terminal.koplugin/main.lua index a94d9bc42..c71be8f31 100644 --- a/plugins/terminal.koplugin/main.lua +++ b/plugins/terminal.koplugin/main.lua @@ -58,7 +58,7 @@ end -- So sorry for the Tolinos with (Android 4.4.x). -- Maybe https://f-droid.org/de/packages/jackpal.androidterm/ could be an alternative then. if (Device:isAndroid() and Device.firmware_rev < 21) or not check_prerequisites() then - logger.warn("Terminal: Device doesn't meet some of the plugin's prerequisites") + logger.warn("Terminal: Device doesn't meet some of the plugin's requirements") return { disabled = true, } end From d971a145243a193a1f6d0b33b6f444b68a37e902 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 21 Jan 2024 20:35:12 +0100 Subject: [PATCH 07/28] This moved to base --- frontend/apps/reader/modules/readerview.lua | 19 ++----------------- frontend/document/pdfdocument.lua | 2 +- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 31ee9bae9..93833f7f4 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -41,15 +41,6 @@ local ReaderView = OverlapGroup:extend{ note_mark_sign = nil, note_mark_pos_x1 = nil, -- page 1 note_mark_pos_x2 = nil, -- page 2 in two-page mode - highlight_colors = { - ["red"] = "#fe4400", - ["orange"] = "#ff8800", - ["yellow"] = "#fdff32", - ["green"] = "#00ad65", - ["blue"] = "#00f2ff", - ["purple"] = "#ee00ff", - ["gray"] = "#808080", - }, -- PDF/DjVu continuous paging page_scroll = nil, page_bgcolor = Blitbuffer.gray(G_defaults:readSetting("DBACKGROUND_COLOR") * (1/15)), @@ -504,12 +495,6 @@ function ReaderView:drawScrollView(bb, x, y) self.state.pos) end ---- Converts a color name into a color struct -function ReaderView:lookupHighlightColor(color_name) - local color = self.highlight_colors[color_name] - return Blitbuffer.colorFromString(color or "#ffff00") -end - function ReaderView:drawHighlightIndicator(bb, x, y) local rect = self.highlight.indicator -- paint big cross line + @@ -578,7 +563,7 @@ function ReaderView:drawPageSavedHighlight(bb, x, y) for _, item in ipairs(items) do local boxes = self.document:getPageBoxesFromPositions(page, item.pos0, item.pos1) if boxes then - local color = self:lookupHighlightColor(item.color) + local color = Blitbuffer.colorFromName(item.color) local draw_note_mark = self.highlight.note_mark and self.ui.bookmark:getBookmarkNote({datetime = item.datetime}) for _, box in ipairs(boxes) do @@ -626,7 +611,7 @@ function ReaderView:drawXPointerSavedHighlight(bb, x, y) if start_pos <= cur_view_bottom and end_pos >= cur_view_top then local boxes = self.document:getScreenBoxesFromPositions(pos0, pos1, true) -- get_segments=true if boxes then - local color = self:lookupHighlightColor(item.color) + local color = Blitbuffer.colorFromName(item.color) local draw_note_mark = self.highlight.note_mark and self.ui.bookmark:getBookmarkNote({datetime = item.datetime}) for _, box in ipairs(boxes) do diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index 162f928fb..b6d89257a 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -250,7 +250,7 @@ function PdfDocument:saveHighlight(pageno, item) local quadpoints, n = _quadpointsFromPboxes(item.pboxes) local page = self._document:openPage(pageno) local annot_type = C.PDF_ANNOT_HIGHLIGHT - local annot_color = BlitBuffer.colorFromString(item.color) + local annot_color = BlitBuffer.colorFromName(item.color) if item.drawer == "lighten" then annot_type = C.PDF_ANNOT_HIGHLIGHT elseif item.drawer == "underscore" then From 2d9e734e66d18f0e852b43c02ad6ca5c1c70b6f4 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 21 Jan 2024 20:58:58 +0100 Subject: [PATCH 08/28] As we effectiuvely only have a single call site for those, move the color type check here, instead of withing BlitBuffer. That thing is already a burden on the JIT, let's avoid gratuitous branches deep in it that 99% of the code will never take... --- frontend/apps/reader/modules/readerview.lua | 35 +++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 93833f7f4..da10bf007 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -634,22 +634,19 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note if drawer == "lighten" then local alpha = 0xFF*(self.highlight.lighten_factor or 0.5) if not color or not Screen:isColorEnabled() then - color = Blitbuffer.Color8A(0, alpha) + bb:darkenRect(x, y, w, h, alpha) else - -- FIXME: lighten_factor and lightenRect doing the opposite of what they should mean or some such ;p. - -- FIXME: Do we even want a ligthen factor here? - color = Blitbuffer.ColorRGB32(color.r, color.g, color.b, bit.bxor(alpha, 0xFF)) + bb:multiplyRectRGB(x, y, w, h, color) end - --- @fixme: Use something based on colorblitFrom instead? - -- (except basically, the invert of it, colorizing the non-covered parts of the alpha map). - --- Might be tricky for non-black text, though... - --- Also potentially annoying with software invert, maybe? - bb:lightenRect(x, y, w, h, color) elseif drawer == "underscore" then if not color or not Screen:isColorEnabled() then color = Blitbuffer.COLOR_GRAY end - bb:paintRect(x, y + h - 1, w, Size.line.medium, color) + if Blitbuffer.isColor8(color) then + bb:paintRect(x, y + h - 1, w, Size.line.medium, color) + else + bb:paintRectRGB32(x, y + h - 1, w, Size.line.medium, color) + end elseif drawer == "strikeout" then if not color or not Screen:isColorEnabled() then color = Blitbuffer.COLOR_BLACK @@ -658,7 +655,11 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note if self.ui.paging then line_y = line_y + 2 end - bb:paintRect(x, line_y, w, Size.line.medium, color) + if Blitbuffer.isColor8(color) then + bb:paintRect(x, line_y, w, Size.line.medium, color) + else + bb:paintRectRGB32(x, line_y, w, Size.line.medium, color) + end elseif drawer == "invert" then bb:invertRect(x, y, w, h) end @@ -667,7 +668,11 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note color = Blitbuffer.COLOR_BLACK end if self.highlight.note_mark == "underline" then - bb:paintRect(x, y + h - 1, w, Size.line.medium, color) + if Blitbuffer.isColor8(color) then + bb:paintRect(x, y + h - 1, w, Size.line.medium, color) + else + bb:paintRectRGB32(x, y + h - 1, w, Size.line.medium, color) + end else local note_mark_pos_x if self.ui.paging or @@ -678,7 +683,11 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note note_mark_pos_x = self.note_mark_pos_x2 end if self.highlight.note_mark == "sideline" then - bb:paintRect(note_mark_pos_x, y, self.note_mark_line_w, h, color) + if Blitbuffer.isColor8(color) then + bb:paintRect(note_mark_pos_x, y, self.note_mark_line_w, h, color) + else + bb:paintRectRGB32(note_mark_pos_x, y, self.note_mark_line_w, h, color) + end elseif self.highlight.note_mark == "sidemark" then self.note_mark_sign:paintTo(bb, note_mark_pos_x, y) end From 6e6e9fc92527cb442ab5698851589b49fb5097d1 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 21 Jan 2024 21:08:50 +0100 Subject: [PATCH 09/28] Finally took the opportunity to fix a 10 year old TODO about the misnamed lighten/dimRect methods... --- frontend/apps/reader/modules/readerview.lua | 3 ++- frontend/ui/widget/container/framecontainer.lua | 2 +- frontend/ui/widget/imagewidget.lua | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index da10bf007..2ec69e612 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -215,7 +215,8 @@ function ReaderView:paintTo(bb, x, y) -- dim last read area if not self.dim_area:isEmpty() and self:isOverlapAllowed() then if self.page_overlap_style == "dim" then - bb:dimRect( + -- NOTE: "dim", as in make black text fainter, e.g., lighten the rect + bb:lightenRect( self.dim_area.x, self.dim_area.y, self.dim_area.w, self.dim_area.h ) diff --git a/frontend/ui/widget/container/framecontainer.lua b/frontend/ui/widget/container/framecontainer.lua index 9e0652d1e..0f780e31c 100644 --- a/frontend/ui/widget/container/framecontainer.lua +++ b/frontend/ui/widget/container/framecontainer.lua @@ -154,7 +154,7 @@ function FrameContainer:paintTo(bb, x, y) container_height - 2*self.bordersize) end if self.dim then - bb:dimRect(x + self.bordersize, y + self.bordersize, + bb:lightenRect(x + self.bordersize, y + self.bordersize, container_width - 2*self.bordersize, container_height - 2*self.bordersize) end diff --git a/frontend/ui/widget/imagewidget.lua b/frontend/ui/widget/imagewidget.lua index de5d4aa24..c0192d2d2 100644 --- a/frontend/ui/widget/imagewidget.lua +++ b/frontend/ui/widget/imagewidget.lua @@ -574,7 +574,7 @@ function ImageWidget:paintTo(bb, x, y) --- This would require the *original* transparent icon, not the flattened one in the cache. --- c.f., https://github.com/koreader/koreader/pull/6937#issuecomment-748372429 for a PoC if self.dim then - bb:dimRect(x, y, size.w, size.h) + bb:lightenRect(x, y, size.w, size.h) end -- In night mode, invert all rendered images, so the original is -- displayed when the whole screen is inverted by night mode. From a15814824604a2312636f71fa9d6167a9b645566 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 00:57:58 +0100 Subject: [PATCH 10/28] Mkay, i'm going to assume the MUL vs. OVER comes from MuPDF... --- frontend/document/pdfdocument.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index b6d89257a..9b246c4a3 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -258,6 +258,8 @@ function PdfDocument:saveHighlight(pageno, item) elseif item.drawer == "strikeout" then annot_type = C.PDF_ANNOT_STRIKE_OUT end + -- NOTE: For highlights, display style may differ compared to ReaderView:drawHighlightRect... + -- (e.g., we do a MUL blend, MuPDF currently appears to do an OVER blend). page:addMarkupAnnotation(quadpoints, n, annot_type, annot_color) -- may update/adjust quadpoints -- Update pboxes with the possibly adjusted coordinates (this will have it updated -- in self.view.highlight.saved[page]) From 0e403a180555c37899597a12583095def1405040 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 01:09:40 +0100 Subject: [PATCH 11/28] Unbreak darkenRect --- frontend/apps/reader/modules/readerview.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 2ec69e612..53d62d0b5 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -633,9 +633,8 @@ end function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note_mark) local x, y, w, h = rect.x, rect.y, rect.w, rect.h if drawer == "lighten" then - local alpha = 0xFF*(self.highlight.lighten_factor or 0.5) if not color or not Screen:isColorEnabled() then - bb:darkenRect(x, y, w, h, alpha) + bb:darkenRect(x, y, w, h, self.highlight.lighten_factor or 0.2) else bb:multiplyRectRGB(x, y, w, h, color) end From bf56868c629ee0097f968685cbf0326207cb30cc Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 01:19:56 +0100 Subject: [PATCH 12/28] Drop redudant saveSetting calls --- frontend/apps/reader/modules/readerhighlight.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 1719fb95e..4820fb493 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -449,7 +449,6 @@ function ReaderHighlight:addToMainMenu(menu_items) default_provider = default_color, callback = function(radio) self.view.highlight.saved_color = radio.provider - self.ui.doc_settings:saveSetting("highlight_color", self.view.highlight.saved_color) UIManager:setDirty(self.dialog, "ui") if touchmenu_instance then touchmenu_instance:updateItems() end end, @@ -1833,7 +1832,6 @@ function ReaderHighlight:onCycleHighlightStyle() next_style_num = 1 end self.view.highlight.saved_drawer = highlight_style[next_style_num][2] - self.ui.doc_settings:saveSetting("highlight_drawer", self.view.highlight.saved_drawer) UIManager:show(Notification:new{ text = T(_("Default highlight style changed to '%1'."), highlight_style[next_style_num][1]), }) From 1d9fd2f764d97128436f5b946e2966c24ab67d25 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 03:02:23 +0100 Subject: [PATCH 13/28] Slightly less awful color highlights in sw nm --- frontend/apps/reader/modules/readerview.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 53d62d0b5..67bea0dda 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -636,7 +636,15 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note if not color or not Screen:isColorEnabled() then bb:darkenRect(x, y, w, h, self.highlight.lighten_factor or 0.2) else - bb:multiplyRectRGB(x, y, w, h, color) + if bb:getInverse() == 1 then + -- MUL doesn't really work on a black background, so, switch to OVER if we're in software nightmode... + -- NOTE: We do *not* invert the color here, which means it *will* get inverted by the blitter. + -- While not particularly pretty, this will (roughly) match with hardware nightmode, *and* how MuPDF renders highlights... + local c = Blitbuffer.ColorRGB32(color.r, color.g, color.b, 0xFF * (self.highlight.lighten_factor or 0.2)) + bb:blendRectRGB32(x, y, w, h, c) + else + bb:multiplyRectRGB(x, y, w, h, color) + end end elseif drawer == "underscore" then if not color or not Screen:isColorEnabled() then From bbb2d9d0de88f17fcc05995499598fa8ae6a5bf6 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 03:06:24 +0100 Subject: [PATCH 14/28] Hmm, pretty colors. --- frontend/apps/reader/modules/readerview.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 67bea0dda..3a0133c32 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -638,9 +638,10 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note else if bb:getInverse() == 1 then -- MUL doesn't really work on a black background, so, switch to OVER if we're in software nightmode... - -- NOTE: We do *not* invert the color here, which means it *will* get inverted by the blitter. - -- While not particularly pretty, this will (roughly) match with hardware nightmode, *and* how MuPDF renders highlights... - local c = Blitbuffer.ColorRGB32(color.r, color.g, color.b, 0xFF * (self.highlight.lighten_factor or 0.2)) + -- NOTE: If we do *not* invert the color here, it *will* get inverted by the blitter given that the target bb is inverted. + -- While not particularly pretty, this (roughly) matches with hardware nightmode, *and* how MuPDF renders highlights... + -- But it's *really* not pretty (https://github.com/koreader/koreader/pull/11044#issuecomment-1902886069), so we'll fix it ;p. + local c = Blitbuffer.ColorRGB32(color.r, color.g, color.b, 0xFF * (self.highlight.lighten_factor or 0.2)):invert() bb:blendRectRGB32(x, y, w, h, c) else bb:multiplyRectRGB(x, y, w, h, color) From c7a6cf5f128d3e8ce89aba72da05b02c9611637c Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 04:28:04 +0100 Subject: [PATCH 15/28] Restore colorful bg support in textBoxWidget And use it for the color sleection popup --- frontend/apps/reader/modules/readerhighlight.lua | 2 ++ frontend/ui/widget/textboxwidget.lua | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 4820fb493..1cb605d93 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -1,4 +1,5 @@ local BD = require("ui/bidi") +local BlitBuffer = require("ffi/blitbuffer") local ButtonDialog = require("ui/widget/buttondialog") local ConfirmBox = require("ui/widget/confirmbox") local Device = require("device") @@ -2179,6 +2180,7 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) { text = v[1], checked = item_color == v[2], + bgcolor = BlitBuffer.colorFromName(v[1]), provider = v[2], }, }) diff --git a/frontend/ui/widget/textboxwidget.lua b/frontend/ui/widget/textboxwidget.lua index 9f5ac062e..4652b6d4a 100644 --- a/frontend/ui/widget/textboxwidget.lua +++ b/frontend/ui/widget/textboxwidget.lua @@ -835,11 +835,15 @@ function TextBoxWidget:_renderText(start_row_idx, end_row_idx) h = h + self.line_glyph_extra_height if self._bb then self._bb:free() end local bbtype = nil - if self.line_num_to_image and self.line_num_to_image[start_row_idx] then + if (self.line_num_to_image and self.line_num_to_image[start_row_idx]) or not Blitbuffer.isColor8(self.bgcolor) then bbtype = Screen:isColorEnabled() and Blitbuffer.TYPE_BBRGB32 or Blitbuffer.TYPE_BB8 end self._bb = Blitbuffer.new(self.width, h, bbtype) - self._bb:fill(self.bgcolor) + if Blitbuffer.isColor8(self.bgcolor) then + self._bb:fill(self.bgcolor) + else + self._bb:paintRectRGB32(0, 0, self._bb:getWidth(), self._bb:getHeight(), self.bgcolor) + end local y = self.line_glyph_baseline if self.use_xtext then From c84de40c1f059a54051862920de49804b1d81d23 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 04:37:29 +0100 Subject: [PATCH 16/28] Cache the type check --- frontend/ui/widget/textboxwidget.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/ui/widget/textboxwidget.lua b/frontend/ui/widget/textboxwidget.lua index 4652b6d4a..27e8fa214 100644 --- a/frontend/ui/widget/textboxwidget.lua +++ b/frontend/ui/widget/textboxwidget.lua @@ -835,11 +835,12 @@ function TextBoxWidget:_renderText(start_row_idx, end_row_idx) h = h + self.line_glyph_extra_height if self._bb then self._bb:free() end local bbtype = nil - if (self.line_num_to_image and self.line_num_to_image[start_row_idx]) or not Blitbuffer.isColor8(self.bgcolor) then + local colorful_bg_pen = not Blitbuffer.isColor8(self.bgcolor) + if (self.line_num_to_image and self.line_num_to_image[start_row_idx]) or colorful_bg_pen then bbtype = Screen:isColorEnabled() and Blitbuffer.TYPE_BBRGB32 or Blitbuffer.TYPE_BB8 end self._bb = Blitbuffer.new(self.width, h, bbtype) - if Blitbuffer.isColor8(self.bgcolor) then + if not colorful_bg_pen then self._bb:fill(self.bgcolor) else self._bb:paintRectRGB32(0, 0, self._bb:getWidth(), self._bb:getHeight(), self.bgcolor) From ed6859da3ba9812bf2cb450cf0e82818374d048f Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 04:50:32 +0100 Subject: [PATCH 17/28] Add cyan, and make blue actually blue. --- frontend/apps/reader/modules/readerhighlight.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 1cb605d93..f8308de16 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -30,6 +30,7 @@ local ReaderHighlight = InputContainer:extend{ {_("Yellow"), "yellow"}, {_("Green"), "green"}, {_("Blue"), "blue"}, + {_("Cyan"), "cyan"}, {_("Purple"), "purple"}, {_("Gray"), "gray"}, } From fbde4edba8dd7830168ae058ea9ea1babc6b654c Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 05:13:41 +0100 Subject: [PATCH 18/28] More logical color order --- frontend/apps/reader/modules/readerhighlight.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index f8308de16..2d7f2031d 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -29,8 +29,8 @@ local ReaderHighlight = InputContainer:extend{ {_("Orange"), "orange"}, {_("Yellow"), "yellow"}, {_("Green"), "green"}, - {_("Blue"), "blue"}, {_("Cyan"), "cyan"}, + {_("Blue"), "blue"}, {_("Purple"), "purple"}, {_("Gray"), "gray"}, } From 8e1a97a0fa9cbb46ff2c680b4c05bd6c998590b3 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 18:15:17 +0100 Subject: [PATCH 19/28] This is always set, no need for a runtime fallback --- frontend/apps/reader/modules/readerview.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 3a0133c32..d0579e79e 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -634,14 +634,14 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note local x, y, w, h = rect.x, rect.y, rect.w, rect.h if drawer == "lighten" then if not color or not Screen:isColorEnabled() then - bb:darkenRect(x, y, w, h, self.highlight.lighten_factor or 0.2) + bb:darkenRect(x, y, w, h, self.highlight.lighten_factor) else if bb:getInverse() == 1 then -- MUL doesn't really work on a black background, so, switch to OVER if we're in software nightmode... -- NOTE: If we do *not* invert the color here, it *will* get inverted by the blitter given that the target bb is inverted. -- While not particularly pretty, this (roughly) matches with hardware nightmode, *and* how MuPDF renders highlights... -- But it's *really* not pretty (https://github.com/koreader/koreader/pull/11044#issuecomment-1902886069), so we'll fix it ;p. - local c = Blitbuffer.ColorRGB32(color.r, color.g, color.b, 0xFF * (self.highlight.lighten_factor or 0.2)):invert() + local c = Blitbuffer.ColorRGB32(color.r, color.g, color.b, 0xFF * self.highlight.lighten_factor):invert() bb:blendRectRGB32(x, y, w, h, c) else bb:multiplyRectRGB(x, y, w, h, color) From 32f3fbe8b0ab28c36f1e409a0d55b0ed60efbbb6 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 18:43:42 +0100 Subject: [PATCH 20/28] TextBoxWidget: Eh, handle color fgs, too. Bit silly to only do half when we can do both, even if nobody will ever use it ;p. --- frontend/ui/widget/textboxwidget.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/frontend/ui/widget/textboxwidget.lua b/frontend/ui/widget/textboxwidget.lua index 27e8fa214..d0dd35613 100644 --- a/frontend/ui/widget/textboxwidget.lua +++ b/frontend/ui/widget/textboxwidget.lua @@ -835,12 +835,14 @@ function TextBoxWidget:_renderText(start_row_idx, end_row_idx) h = h + self.line_glyph_extra_height if self._bb then self._bb:free() end local bbtype = nil - local colorful_bg_pen = not Blitbuffer.isColor8(self.bgcolor) - if (self.line_num_to_image and self.line_num_to_image[start_row_idx]) or colorful_bg_pen then + local color_fg = not Blitbuffer.isColor8(self.fgcolor) + local color_bg = not Blitbuffer.isColor8(self.bgcolor) + -- Color, whether from images or fg or bg, means we'll need an RGB32 buffer (if it makes sense, e.g., on a color screen). + if (self.line_num_to_image and self.line_num_to_image[start_row_idx]) or color_fg or color_bg then bbtype = Screen:isColorEnabled() and Blitbuffer.TYPE_BBRGB32 or Blitbuffer.TYPE_BB8 end self._bb = Blitbuffer.new(self.width, h, bbtype) - if not colorful_bg_pen then + if not color_bg then self._bb:fill(self.bgcolor) else self._bb:paintRectRGB32(0, 0, self._bb:getWidth(), self._bb:getHeight(), self.bgcolor) @@ -879,10 +881,17 @@ function TextBoxWidget:_renderText(start_row_idx, end_row_idx) if self._alt_color_for_rtl then color = xglyph.is_rtl and Blitbuffer.COLOR_DARK_GRAY or Blitbuffer.COLOR_BLACK end - self._bb:colorblitFrom(glyph.bb, - xglyph.x0 + glyph.l + xglyph.x_offset, - y - glyph.t - xglyph.y_offset, - 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight(), color) + if not color_fg then + self._bb:colorblitFrom(glyph.bb, + xglyph.x0 + glyph.l + xglyph.x_offset, + y - glyph.t - xglyph.y_offset, + 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight(), color) + else + self._bb:colorblitFromRGB32(glyph.bb, + xglyph.x0 + glyph.l + xglyph.x_offset, + y - glyph.t - xglyph.y_offset, + 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight(), color) + end end end end From 7ba32264f28ba36b4afac22b2ccf3d17bf6f2a7b Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 19:01:55 +0100 Subject: [PATCH 21/28] Make Gray our actual legacy grayscale highlights (i.e., it'll follow the opacity setting). --- frontend/apps/reader/modules/readerhighlight.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 2d7f2031d..dfd30e61e 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -467,7 +467,7 @@ function ReaderHighlight:addToMainMenu(menu_items) end table.insert(menu_items.highlight_options.sub_item_table, { text_func = function() - return T(_("Highlight opacity: %1"), G_reader_settings:readSetting("highlight_lighten_factor", 0.2)) + return T(_("Gray highlight opacity: %1"), G_reader_settings:readSetting("highlight_lighten_factor", 0.2)) end, enabled_func = function() return self.view.highlight.saved_drawer == "lighten" @@ -484,8 +484,8 @@ function ReaderHighlight:addToMainMenu(menu_items) value_hold_step = 0.25, default_value = 0.2, keep_shown_on_apply = true, - title_text = _("Highlight opacity"), - info_text = _("The higher the value, the darker the highlight."), + title_text = _("Gray highlight opacity"), + info_text = _("The higher the value, the darker the gray."), callback = function(spin) G_reader_settings:saveSetting("highlight_lighten_factor", spin.value) self.view.highlight.lighten_factor = spin.value @@ -2181,7 +2181,7 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) { text = v[1], checked = item_color == v[2], - bgcolor = BlitBuffer.colorFromName(v[1]), + bgcolor = BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), provider = v[2], }, }) From d314c12f34002117a45af9ade323429cf9b76cce Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 19:37:04 +0100 Subject: [PATCH 22/28] Move the Highlight color menu inside the Highlight Stule dialog And enable color even outside of isColorScreen, for interop --- .../apps/reader/modules/readerhighlight.lua | 250 +++++++++--------- frontend/apps/reader/modules/readerview.lua | 8 +- 2 files changed, 123 insertions(+), 135 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index dfd30e61e..8141830fc 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -416,55 +416,53 @@ function ReaderHighlight:addToMainMenu(menu_items) separator = i == #highlight_style, }) end - if Screen:isColorScreen() then - table.insert(menu_items.highlight_options.sub_item_table, { - text_func = function() - local saved_color = self.view.highlight.saved_color or "yellow" - for __, v in ipairs(self.highlight_colors) do - if v[2] == saved_color then - return T(_("Highlight color: %1"), string.lower(v[1])) - end - end - return T(_("Highlight color: %1"), saved_color) - end, - enabled_func = function() - return Screen:isColorEnabled() and self.view.highlight.saved_drawer ~= "invert" - end, - callback = function(touchmenu_instance) - local default_color = G_reader_settings:readSetting("highlight_color", "yellow") - local saved_color = self.view.highlight.saved_color or "yellow" - local radio_buttons = {} - for _, v in ipairs(self.highlight_colors) do - table.insert(radio_buttons, { - { - text = v[1], - checked = v[2] == saved_color, - provider = v[2], - }, - }) + table.insert(menu_items.highlight_options.sub_item_table, { + text_func = function() + local saved_color = self.view.highlight.saved_color or "yellow" + for __, v in ipairs(self.highlight_colors) do + if v[2] == saved_color then + return T(_("Highlight color: %1"), string.lower(v[1])) end - UIManager:show(require("ui/widget/radiobuttonwidget"):new{ - title_text = _("Highlight color"), - width_factor = 0.5, - keep_shown_on_apply = false, - radio_buttons = radio_buttons, - default_provider = default_color, - callback = function(radio) - self.view.highlight.saved_color = radio.provider - UIManager:setDirty(self.dialog, "ui") - if touchmenu_instance then touchmenu_instance:updateItems() end - end, - }) - end, - hold_callback = function(touchmenu_instance) - G_reader_settings:saveSetting("highlight_color", self.view.highlight.saved_color) - UIManager:show(Notification:new{ - text = T(_("Default highlight color changed to '%1'."), self.view.highlight.saved_color), + end + return T(_("Highlight color: %1"), saved_color) + end, + enabled_func = function() + return self.view.highlight.saved_drawer ~= "invert" + end, + callback = function(touchmenu_instance) + local default_color = G_reader_settings:readSetting("highlight_color", "yellow") + local saved_color = self.view.highlight.saved_color or "yellow" + local radio_buttons = {} + for _, v in ipairs(self.highlight_colors) do + table.insert(radio_buttons, { + { + text = v[1], + checked = v[2] == saved_color, + provider = v[2], + }, }) - if touchmenu_instance then touchmenu_instance:updateItems() end - end, - }) - end + end + UIManager:show(require("ui/widget/radiobuttonwidget"):new{ + title_text = _("Highlight color"), + width_factor = 0.5, + keep_shown_on_apply = false, + radio_buttons = radio_buttons, + default_provider = default_color, + callback = function(radio) + self.view.highlight.saved_color = radio.provider + UIManager:setDirty(self.dialog, "ui") + if touchmenu_instance then touchmenu_instance:updateItems() end + end, + }) + end, + hold_callback = function(touchmenu_instance) + G_reader_settings:saveSetting("highlight_color", self.view.highlight.saved_color) + UIManager:show(Notification:new{ + text = T(_("Default highlight color changed to '%1'."), self.view.highlight.saved_color), + }) + if touchmenu_instance then touchmenu_instance:updateItems() end + end, + }) table.insert(menu_items.highlight_options.sub_item_table, { text_func = function() return T(_("Gray highlight opacity: %1"), G_reader_settings:readSetting("highlight_lighten_factor", 0.2)) @@ -537,40 +535,35 @@ function ReaderHighlight:addToMainMenu(menu_items) }) end, }) - if Screen:isColorScreen() then - table.insert(menu_items.highlight_options.sub_item_table, { - text = _("Apply default style to all highlights"), - enabled_func = function() - return Screen:isColorEnabled() - end, - callback = function(touchmenu_instance) - UIManager:show(ConfirmBox:new{ - text = _("Are you sure you want to edit all highlights."), - icon = "texture-box", - ok_callback = function() - local count = 0 - for _, items in pairs(self.view.highlight.saved) do - if items then - count = count + #items - for i = 1, #items do - local item = items[i] - item.drawer = self.view.highlight.saved_drawer - item.color = self.view.highlight.saved_color - end + table.insert(menu_items.highlight_options.sub_item_table, { + text = _("Apply default style to all highlights"), + callback = function(touchmenu_instance) + UIManager:show(ConfirmBox:new{ + text = _("Are you sure you want to edit all highlights."), + icon = "texture-box", + ok_callback = function() + local count = 0 + for _, items in pairs(self.view.highlight.saved) do + if items then + count = count + #items + for i = 1, #items do + local item = items[i] + item.drawer = self.view.highlight.saved_drawer + item.color = self.view.highlight.saved_color end end - if count > 0 then - UIManager:setDirty(self.dialog, "ui") - UIManager:show(Notification:new{ - text = T(N_("Applied default style to 1 highlight", - "Applied default style to %1 highlights", count), count), - }) - end end - }) - end, - }) - end + if count > 0 then + UIManager:setDirty(self.dialog, "ui") + UIManager:show(Notification:new{ + text = T(N_("Applied default style to 1 highlight", + "Applied default style to %1 highlights", count), count), + }) + end + end + }) + end, + }) if self.document.info.has_pages then menu_items.panel_zoom_options = { text = _("Panel zoom (manga/comic)"), @@ -1073,58 +1066,43 @@ function ReaderHighlight:showHighlightNoteOrDialog(page, index, bookmark_note) end function ReaderHighlight:onShowHighlightDialog(page, index, is_auto_text) - local row = { - { - text = _("Delete"), - callback = function() - self:deleteHighlight(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, - }, + local buttons = { { - text = C_("Highlight", "Style"), - callback = function() - self:editHighlightStyle(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, + { + text = _("Delete"), + callback = function() + self:deleteHighlight(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }, + { + text = C_("Highlight", "Style"), + callback = function() + self:editHighlightStyle(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }, + { + text = is_auto_text and _("Add note") or _("Edit note"), + callback = function() + self:editHighlight(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }, + { + text = "…", + callback = function() + self.selected_text = self.view.highlight.saved[page][index] + self:onShowHighlightMenu(page, index) + UIManager:close(self.edit_highlight_dialog) + self.edit_highlight_dialog = nil + end, + }, }, } - if Screen:isColorScreen() then - table.insert(row, { - text = C_("Highlight", "Color"), - enabled_func = function() - return Screen:isColorEnabled() - end, - callback = function() - self:editHighlightColor(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, - }) - end - table.insert(row, { - text = is_auto_text and _("Add note") or _("Edit note"), - callback = function() - self:editHighlight(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, - }) - table.insert(row, { - text = "…", - callback = function() - self.selected_text = self.view.highlight.saved[page][index] - self:onShowHighlightMenu(page, index) - UIManager:close(self.edit_highlight_dialog) - self.edit_highlight_dialog = nil - end, - }) - - local buttons = { - row - } if self.ui.rolling then local start_prev = "◁▒▒" @@ -2113,7 +2091,7 @@ function ReaderHighlight:editHighlightStyle(page, i) datetime = item.datetime, }))) end - self:showHighlightStyleDialog(apply_drawer, item.drawer) + self:showHighlightStyleDialog(apply_drawer, item.drawer, page, i) end function ReaderHighlight:editHighlightColor(page, i) @@ -2138,7 +2116,7 @@ function ReaderHighlight:editHighlightColor(page, i) self:showHighlightColorDialog(apply_color, item.color) end -function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer) +function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer, page, i) local default_drawer, keep_shown_on_apply if item_drawer then -- called from editHighlightStyle default_drawer = self.view.highlight.saved_drawer or @@ -2156,7 +2134,7 @@ function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer) }) end local RadioButtonWidget = require("ui/widget/radiobuttonwidget") - UIManager:show(RadioButtonWidget:new{ + local ctor = { title_text = _("Highlight style"), width_factor = 0.5, keep_shown_on_apply = keep_shown_on_apply, @@ -2165,7 +2143,17 @@ function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer) callback = function(radio) caller_callback(radio.provider) end, - }) + } + if page and i then + -- called from editHighlightStyle + ctor.extra_text = _("Highlight color") + ctor.extra_callback = function(this) + -- Close the style dialog before showing the color dialog + this:onClose() + self:editHighlightColor(page, i) + end + end + UIManager:show(RadioButtonWidget:new(ctor)) end function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index d0579e79e..3e91fc6e9 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -633,7 +633,7 @@ end function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note_mark) local x, y, w, h = rect.x, rect.y, rect.w, rect.h if drawer == "lighten" then - if not color or not Screen:isColorEnabled() then + if not color then bb:darkenRect(x, y, w, h, self.highlight.lighten_factor) else if bb:getInverse() == 1 then @@ -648,7 +648,7 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note end end elseif drawer == "underscore" then - if not color or not Screen:isColorEnabled() then + if not color then color = Blitbuffer.COLOR_GRAY end if Blitbuffer.isColor8(color) then @@ -657,7 +657,7 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note bb:paintRectRGB32(x, y + h - 1, w, Size.line.medium, color) end elseif drawer == "strikeout" then - if not color or not Screen:isColorEnabled() then + if not color then color = Blitbuffer.COLOR_BLACK end local line_y = y + math.floor(h / 2) + 1 @@ -673,7 +673,7 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note bb:invertRect(x, y, w, h) end if draw_note_mark then - if not color or not Screen:isColorEnabled() then + if not color then color = Blitbuffer.COLOR_BLACK end if self.highlight.note_mark == "underline" then From 21d435fbc27673fd85345b6ec3f35be548e3153d Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 19:52:21 +0100 Subject: [PATCH 23/28] Don't allow changin colors if drawer is invert --- .../apps/reader/modules/readerhighlight.lua | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 8141830fc..2051bab7f 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -2113,7 +2113,7 @@ function ReaderHighlight:editHighlightColor(page, i) datetime = item.datetime, }))) end - self:showHighlightColorDialog(apply_color, item.color) + self:showHighlightColorDialog(apply_color, item.color, item.drawer) end function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer, page, i) @@ -2156,7 +2156,7 @@ function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer, UIManager:show(RadioButtonWidget:new(ctor)) end -function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) +function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color, item_drawer) local default_color, keep_shown_on_apply if item_color then -- called from editHighlightColor default_color = self.view.highlight.saved_color or @@ -2164,13 +2164,23 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) keep_shown_on_apply = true end local radio_buttons = {} - for _, v in ipairs(self.highlight_colors) do + if item_drawer ~= "invert" then + for _, v in ipairs(self.highlight_colors) do + table.insert(radio_buttons, { + { + text = v[1], + checked = item_color == v[2], + bgcolor = BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), + provider = v[2], + }, + }) + end + else + default_color = nil table.insert(radio_buttons, { { - text = v[1], - checked = item_color == v[2], - bgcolor = BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), - provider = v[2], + text = _("N/A"), + checked = false, }, }) end @@ -2182,7 +2192,9 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) radio_buttons = radio_buttons, default_provider = default_color, callback = function(radio) - caller_callback(radio.provider) + if radio.provider then + caller_callback(radio.provider) + end end, }) end From 447c92bea18aa99ed09b50f51a737bc448388c55 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 19:52:31 +0100 Subject: [PATCH 24/28] Revert "Don't allow changin colors if drawer is invert" This reverts commit 21d435fbc27673fd85345b6ec3f35be548e3153d. --- .../apps/reader/modules/readerhighlight.lua | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 2051bab7f..8141830fc 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -2113,7 +2113,7 @@ function ReaderHighlight:editHighlightColor(page, i) datetime = item.datetime, }))) end - self:showHighlightColorDialog(apply_color, item.color, item.drawer) + self:showHighlightColorDialog(apply_color, item.color) end function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer, page, i) @@ -2156,7 +2156,7 @@ function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer, UIManager:show(RadioButtonWidget:new(ctor)) end -function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color, item_drawer) +function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) local default_color, keep_shown_on_apply if item_color then -- called from editHighlightColor default_color = self.view.highlight.saved_color or @@ -2164,23 +2164,13 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color, i keep_shown_on_apply = true end local radio_buttons = {} - if item_drawer ~= "invert" then - for _, v in ipairs(self.highlight_colors) do - table.insert(radio_buttons, { - { - text = v[1], - checked = item_color == v[2], - bgcolor = BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), - provider = v[2], - }, - }) - end - else - default_color = nil + for _, v in ipairs(self.highlight_colors) do table.insert(radio_buttons, { { - text = _("N/A"), - checked = false, + text = v[1], + checked = item_color == v[2], + bgcolor = BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), + provider = v[2], }, }) end @@ -2192,9 +2182,7 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color, i radio_buttons = radio_buttons, default_provider = default_color, callback = function(radio) - if radio.provider then - caller_callback(radio.provider) - end + caller_callback(radio.provider) end, }) end From 9d7f70beea1cb76d95fecd93cee7fefa2437a61c Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 19:57:22 +0100 Subject: [PATCH 25/28] Less clunky and more user-friendly warning when you try to modify colors if style is set to underline. I can't really just disable the button AFAICT? --- frontend/apps/reader/modules/readerhighlight.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 8141830fc..2923e5e7c 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -2148,9 +2148,14 @@ function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer, -- called from editHighlightStyle ctor.extra_text = _("Highlight color") ctor.extra_callback = function(this) - -- Close the style dialog before showing the color dialog - this:onClose() - self:editHighlightColor(page, i) + local item = self.view.highlight.saved[page][i] + if item.drawer == "invert" then + UIManager:show(InfoMessage:new{ text = _("Colors unavailable when highlight style is set to 'Invert'") }) + else + -- Close the style dialog before showing the color dialog + this:onClose() + self:editHighlightColor(page, i) + end end end UIManager:show(RadioButtonWidget:new(ctor)) From e136c07f0a86225ac5cdbc6203b77728bb9bf52f Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 22 Jan 2024 20:38:02 +0100 Subject: [PATCH 26/28] Might want to drop the bg on actual eInk screens, will have to test --- frontend/apps/reader/modules/readerhighlight.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 2923e5e7c..f12bfb1a3 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -2175,6 +2175,7 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) text = v[1], checked = item_color == v[2], bgcolor = BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), + --bgcolor = Screen:isColorEnabled() and (BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF))) or nil, provider = v[2], }, }) From 0c6a453181370c294763104350758b777c5f9cb6 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 23 Jan 2024 13:17:34 +0100 Subject: [PATCH 27/28] Don't default to yellow HLs on grayscale screens --- frontend/apps/reader/modules/readerhighlight.lua | 10 +++++----- frontend/apps/reader/modules/readerview.lua | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index f12bfb1a3..9c9b7467a 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -67,6 +67,7 @@ function ReaderHighlight:init() self._current_indicator_pos = nil self._previous_indicator_pos = nil self._last_indicator_move_args = {dx = 0, dy = 0, distance = 0, time = time:now()} + self._fallback_color = Screen:isColorEnabled() and "yellow" or "gray" self:registerKeyEvents() @@ -418,7 +419,7 @@ function ReaderHighlight:addToMainMenu(menu_items) end table.insert(menu_items.highlight_options.sub_item_table, { text_func = function() - local saved_color = self.view.highlight.saved_color or "yellow" + local saved_color = self.view.highlight.saved_color or self._fallback_color for __, v in ipairs(self.highlight_colors) do if v[2] == saved_color then return T(_("Highlight color: %1"), string.lower(v[1])) @@ -430,8 +431,8 @@ function ReaderHighlight:addToMainMenu(menu_items) return self.view.highlight.saved_drawer ~= "invert" end, callback = function(touchmenu_instance) - local default_color = G_reader_settings:readSetting("highlight_color", "yellow") - local saved_color = self.view.highlight.saved_color or "yellow" + local default_color = G_reader_settings:readSetting("highlight_color", self._fallback_color) + local saved_color = self.view.highlight.saved_color or self._fallback_color local radio_buttons = {} for _, v in ipairs(self.highlight_colors) do table.insert(radio_buttons, { @@ -2165,7 +2166,7 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) local default_color, keep_shown_on_apply if item_color then -- called from editHighlightColor default_color = self.view.highlight.saved_color or - G_reader_settings:readSetting("highlight_color", "yellow") + G_reader_settings:readSetting("highlight_color", self._fallback_color) keep_shown_on_apply = true end local radio_buttons = {} @@ -2175,7 +2176,6 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) text = v[1], checked = item_color == v[2], bgcolor = BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), - --bgcolor = Screen:isColorEnabled() and (BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF))) or nil, provider = v[2], }, }) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 3e91fc6e9..a69d3fb55 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -93,10 +93,9 @@ function ReaderView:init() lighten_factor = G_reader_settings:readSetting("highlight_lighten_factor", 0.2), note_mark = G_reader_settings:readSetting("highlight_note_marker"), temp_drawer = "invert", - temp_color = "yellow", temp = {}, saved_drawer = "lighten", - saved_color = "yellow", + saved_color = Screen:isColorEnabled() and "yellow" or "gray", saved = {}, indicator = nil, -- geom: non-touch highlight position indicator: {x = 50, y=50} } @@ -518,7 +517,7 @@ function ReaderView:drawTempHighlight(bb, x, y) for i = 1, #boxes do local rect = self:pageToScreenTransform(page, boxes[i]) if rect then - self:drawHighlightRect(bb, x, y, rect, self.highlight.temp_drawer, self.highlight.temp_color) + self:drawHighlightRect(bb, x, y, rect, self.highlight.temp_drawer) end end end From 117d18d7c96c2eea40ae7a9556667aa84ee30b14 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 23 Jan 2024 13:19:41 +0100 Subject: [PATCH 28/28] Fancy bgcolor in the *other* popup, too And factually lookup the right color name, too; not the translated string --- frontend/apps/reader/modules/readerhighlight.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 9c9b7467a..e79c5e0ae 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -439,6 +439,7 @@ function ReaderHighlight:addToMainMenu(menu_items) { text = v[1], checked = v[2] == saved_color, + bgcolor = BlitBuffer.colorFromName(v[2]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), provider = v[2], }, }) @@ -2175,7 +2176,7 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color) { text = v[1], checked = item_color == v[2], - bgcolor = BlitBuffer.colorFromName(v[1]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), + bgcolor = BlitBuffer.colorFromName(v[2]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)), provider = v[2], }, })