dict/wiki: definitions' text justification

This can be disabled by adding ["dict_justify"] = false to settings.reader.lua
This commit is contained in:
poire-z
2017-01-01 10:24:49 +01:00
committed by Qingping Hou
parent fc8d26ad89
commit ebe0c08bfb
4 changed files with 75 additions and 10 deletions

View File

@@ -192,8 +192,9 @@ end
-- @bool[opt=false] bold whether the text should be measured as bold
-- @tparam[opt=BlitBuffer.COLOR_BLACK] BlitBuffer.COLOR fgcolor foreground color
-- @int[opt=nil] width maximum rendering width
-- @tparam[opt] table char_pads array of integers, nb of pixels to add, one for each utf8 char in text
-- @return int width of rendered bitmap
function RenderText:renderUtf8Text(dest_bb, x, baseline, face, text, kerning, bold, fgcolor, width)
function RenderText:renderUtf8Text(dest_bb, x, baseline, face, text, kerning, bold, fgcolor, width, char_pads)
if not text then
logger.warn("renderUtf8Text called without text");
return 0
@@ -211,6 +212,7 @@ function RenderText:renderUtf8Text(dest_bb, x, baseline, face, text, kerning, bo
if width and width < text_width then
text_width = width
end
local char_idx = 0
for _, charcode, uchar in utf8Chars(text) do
if pen_x < text_width then
local glyph = self:getGlyph(face, charcode, bold)
@@ -227,6 +229,11 @@ function RenderText:renderUtf8Text(dest_bb, x, baseline, face, text, kerning, bo
pen_x = pen_x + glyph.ax
prevcharcode = charcode
end -- if pen_x < text_width
if char_pads then
char_idx = char_idx + 1
pen_x = pen_x + char_pads[char_idx] -- or 0
-- will fail if we didnt count the same number of chars, we'll see
end
end
return pen_x