diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index dfb45715e..45c86b40d 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -14,10 +14,10 @@ local TextViewer = require("ui/widget/textviewer") local Translator = require("ui/translator") local UIManager = require("ui/uimanager") local dbg = require("dbg") +local ffiUtil = require("ffi/util") local logger = require("logger") local util = require("util") local Size = require("ui/size") -local ffiUtil = require("ffi/util") local time = require("ui/time") local _ = require("gettext") local C_ = _.pgettext @@ -483,6 +483,35 @@ function ReaderHighlight:addToMainMenu(menu_items) UIManager:show(spin_widget) end, }) + table.insert(hl_sub_item_table, { + text_func = function() + return T(_("Highlight line height: %1\xE2\x80\xAF%"), G_reader_settings:readSetting("highlight_height_pct") or 100) + end, + enabled_func = function() + return self.view.highlight.saved_drawer == "lighten" or self.view.highlight.saved_drawer == "invert" + end, + callback = function(touchmenu_instance) + local spin_widget = SpinWidget:new{ + value = G_reader_settings:readSetting("highlight_height_pct") or 100, + value_min = 0, + value_max = 100, + value_step = 1, + value_hold_step = 10, + default_value = 100, + unit = "%", + keep_shown_on_apply = true, + title_text = _("Highlight line height"), + info_text = _("Percentage of the text line height."), + callback = function(spin) + local value = spin.value ~= 100 and spin.value or nil + G_reader_settings:saveSetting("highlight_height_pct", value) + UIManager:setDirty(self.dialog, "ui") + touchmenu_instance:updateItems() + end, + } + UIManager:show(spin_widget) + end, + }) table.insert(hl_sub_item_table, { text_func = function() local notemark = self.view.highlight.note_mark or "none" @@ -1200,6 +1229,29 @@ function ReaderHighlight:showHighlightNoteOrDialog(index) width = math.floor(math.min(self.screen_w, self.screen_h) * 0.8), height = math.floor(math.max(self.screen_w, self.screen_h) * 0.4), buttons_table = { + { + { + text = _("Delete note"), + callback = function() + UIManager:close(textviewer) + local annotation = self.ui.annotation.annotations[index] + annotation.note = nil + self.ui:handleEvent(Event:new("AnnotationsModified", + { annotation, nb_highlights_added = 1, nb_notes_added = -1 })) + self:writePdfAnnotation("content", annotation, nil) + if self.view.highlight.note_mark then -- refresh note marker + UIManager:setDirty(self.dialog, "ui") + end + end, + }, + { + text = _("Edit note"), + callback = function() + UIManager:close(textviewer) + self:editNote(index) + end, + }, + }, { { text = _("Delete highlight"), @@ -1209,7 +1261,7 @@ function ReaderHighlight:showHighlightNoteOrDialog(index) end, }, { - text = _("Edit highlight"), + text = _("Highlight menu"), callback = function() UIManager:close(textviewer) self:onShowHighlightDialog(index) @@ -1256,7 +1308,7 @@ function ReaderHighlight:onShowHighlightDialog(index) { text = _("Note"), callback = function() - self:editHighlight(index) + self:editNote(index) UIManager:close(self.edit_highlight_dialog) self.edit_highlight_dialog = nil end, @@ -2157,10 +2209,10 @@ function ReaderHighlight:addNote(text) if text then -- called from Translator to save translation to note self:clear() end - self:editHighlight(index, true, text) + self:editNote(index, true, text) end -function ReaderHighlight:editHighlight(index, is_new_note, text) +function ReaderHighlight:editNote(index, is_new_note, text) local note_updated_callback = function() if self.view.highlight.note_mark then -- refresh note marker UIManager:setDirty(self.dialog, "ui") diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 2cf9697ea..f3b50995f 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -615,6 +615,13 @@ 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" or drawer == "invert" then + local pct = G_reader_settings:readSetting("highlight_height_pct") + if pct ~= nil then + h = math.floor(h * pct / 100) + y = y + math.ceil((rect.h - h) / 2) + end + end if drawer == "lighten" then if not color then bb:darkenRect(x, y, w, h, self.highlight.lighten_factor) @@ -674,9 +681,9 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note end if self.highlight.note_mark == "sideline" then if Blitbuffer.isColor8(color) then - bb:paintRect(note_mark_pos_x, y, self.note_mark_line_w, h, color) + bb:paintRect(note_mark_pos_x, y, self.note_mark_line_w, rect.h, color) else - bb:paintRectRGB32(note_mark_pos_x, y, self.note_mark_line_w, h, color) + bb:paintRectRGB32(note_mark_pos_x, y, self.note_mark_line_w, rect.h, color) end elseif self.highlight.note_mark == "sidemark" then self.note_mark_sign:paintTo(bb, note_mark_pos_x, y) diff --git a/frontend/ui/translator.lua b/frontend/ui/translator.lua index a1550424c..f1c3364e1 100644 --- a/frontend/ui/translator.lua +++ b/frontend/ui/translator.lua @@ -15,10 +15,10 @@ local TextViewer = require("ui/widget/textviewer") local UIManager = require("ui/uimanager") local JSON = require("json") local Screen = require("device").screen -local ffiutil = require("ffi/util") +local ffiUtil = require("ffi/util") local logger = require("logger") local util = require("util") -local T = ffiutil.template +local T = ffiUtil.template local _ = require("gettext") -- From https://cloud.google.com/translate/docs/languages @@ -225,7 +225,7 @@ end function Translator:genSettingsMenu() local function genLanguagesItems(setting_name, default_checked_item) local items_table = {} - for lang_key, lang_name in ffiutil.orderedPairs(SUPPORTED_LANGUAGES) do + for lang_key, lang_name in ffiUtil.orderedPairs(SUPPORTED_LANGUAGES) do table.insert(items_table, { text_func = function() return T("%1 (%2)", lang_name, lang_key) @@ -628,7 +628,7 @@ function Translator:_showTranslation(text, detailed_view, source_lang, target_la UIManager:close(ui.highlight.highlight_dialog) ui.highlight.highlight_dialog = nil if index then - ui.highlight:editHighlight(index, false, text_main) + ui.highlight:editNote(index, false, text_main) else ui.highlight:addNote(text_main) end @@ -641,7 +641,7 @@ function Translator:_showTranslation(text, detailed_view, source_lang, target_la UIManager:close(ui.highlight.highlight_dialog) ui.highlight.highlight_dialog = nil if index then - ui.highlight:editHighlight(index, false, text_all) + ui.highlight:editNote(index, false, text_all) else ui.highlight:addNote(text_all) end