mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Fix: truncateTextByWidth() should respect kerning and bold (#3139)
This commit is contained in:
@@ -241,7 +241,7 @@ end
|
||||
|
||||
local ellipsis, space = "…", " "
|
||||
local ellipsis_width, space_width
|
||||
function RenderText:truncateTextByWidth(text, face, max_width, prepend_space)
|
||||
function RenderText:truncateTextByWidth(text, face, max_width, kerning, bold, prepend_space)
|
||||
if not ellipsis_width then
|
||||
ellipsis_width = self:sizeUtf8Text(0, max_width, face, ellipsis).x
|
||||
end
|
||||
@@ -249,7 +249,7 @@ function RenderText:truncateTextByWidth(text, face, max_width, prepend_space)
|
||||
space_width = self:sizeUtf8Text(0, max_width, face, space).x
|
||||
end
|
||||
local new_txt_width = max_width - ellipsis_width - space_width
|
||||
local sub_txt = self:getSubTextByWidth(text, face, new_txt_width)
|
||||
local sub_txt = self:getSubTextByWidth(text, face, new_txt_width, kerning, bold)
|
||||
if prepend_space then
|
||||
return space.. sub_txt .. ellipsis
|
||||
else
|
||||
|
||||
@@ -155,7 +155,8 @@ function KeyValueItem:init()
|
||||
self.show_value = self.value
|
||||
else
|
||||
key_w = key_w_rendered + space_w_rendered
|
||||
self.show_value = RenderText:truncateTextByWidth(self.value, self.cface, frame_internal_width - key_w_rendered, true)
|
||||
self.show_value = RenderText:truncateTextByWidth(self.value, self.cface, frame_internal_width - key_w_rendered,
|
||||
false, false, true)
|
||||
self.show_key = self.key
|
||||
end
|
||||
-- allow for displaying the non-truncated texts with Hold
|
||||
|
||||
Reference in New Issue
Block a user