diff --git a/frontend/apps/reader/modules/readerstyletweak.lua b/frontend/apps/reader/modules/readerstyletweak.lua index 50af5919d..e82f902aa 100644 --- a/frontend/apps/reader/modules/readerstyletweak.lua +++ b/frontend/apps/reader/modules/readerstyletweak.lua @@ -439,13 +439,11 @@ You can enable individual tweaks on this book with a tap, or view more details a callback = function() UIManager:show(InfoMessage:new{ text = item.info_text, - face = Font:getFace(item.smaller_font and "x_smallinfofont" or "smallinfofont"), }) end, hold_callback = function() UIManager:show(InfoMessage:new{ text = item.info_text, - face = Font:getFace(item.smaller_font and "x_smallinfofont" or "smallinfofont"), }) end, separator = item.separator, diff --git a/frontend/ui/data/css_tweaks.lua b/frontend/ui/data/css_tweaks.lua index 751c54116..ef427b179 100644 --- a/frontend/ui/data/css_tweaks.lua +++ b/frontend/ui/data/css_tweaks.lua @@ -263,7 +263,6 @@ width: 100% !important; title = _("Alternative TOC hints"), { title = _("About alternative TOC"), - smaller_font = true, info_text = _([[ An alternative table of content can be built with a long-press on the "Table of content" menu item. diff --git a/frontend/ui/font.lua b/frontend/ui/font.lua index a5ba6af5f..e056bba03 100644 --- a/frontend/ui/font.lua +++ b/frontend/ui/font.lua @@ -117,11 +117,13 @@ function Font:getFace(font, size) end --- Freetype font face wrapper object -- @table FontFaceObj + -- @field orig_font font name requested -- @field size size of the font face (after scaled by screen size) -- @field orig_size raw size of the font face (before scale) -- @field ftface font face object from freetype -- @field hash hash key for this font face face_obj = { + orig_font = font, size = size, orig_size = orig_size, ftface = face, diff --git a/frontend/ui/widget/infomessage.lua b/frontend/ui/widget/infomessage.lua index 49246965d..25e1a0066 100644 --- a/frontend/ui/widget/infomessage.lua +++ b/frontend/ui/widget/infomessage.lua @@ -129,21 +129,46 @@ function InfoMessage:init() width = text_width, } end - self.movable = MovableContainer:new{ - FrameContainer:new{ - background = Blitbuffer.COLOR_WHITE, - HorizontalGroup:new{ - align = "center", - image_widget, - HorizontalSpan:new{ width = (self.show_icon and Size.span.horizontal_default or 0) }, - text_widget, - } + local frame = FrameContainer:new{ + background = Blitbuffer.COLOR_WHITE, + HorizontalGroup:new{ + align = "center", + image_widget, + HorizontalSpan:new{ width = (self.show_icon and Size.span.horizontal_default or 0) }, + text_widget, } } + self.movable = MovableContainer:new{ + frame, + } self[1] = CenterContainer:new{ dimen = Screen:getSize(), self.movable, } + if not self.height then + -- Reduce font size until widget fit screen height if needed + local cur_size = frame:getSize() + if cur_size and cur_size.h > 0.95 * Screen:getHeight() then + local orig_font = text_widget.face.orig_font + local orig_size = text_widget.face.orig_size + local real_size = text_widget.face.size + if orig_size > 10 then -- don't go too small + while true do + orig_size = orig_size - 1 + self.face = Font:getFace(orig_font, orig_size) + -- scaleBySize() in Font:getFace() may give the same + -- real font size even if we decreased orig_size, + -- so check we really got a smaller real font size + if self.face.size < real_size then + break + end + end + -- re-init this widget + self:free() + self:init() + end + end + end end function InfoMessage:onCloseWidget()