Avoid off-limits dictionary title and make font size adjustable

This commit is contained in:
Paulo Matias
2014-01-10 01:12:51 -02:00
parent 2052c1efb3
commit 9072a30cb5
4 changed files with 13 additions and 7 deletions

View File

@@ -143,7 +143,7 @@ function RenderText:sizeUtf8Text(x, width, face, text, kerning)
return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom}
end
function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bgcolor, fgcolor)
function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bgcolor, fgcolor, width)
if not text then
DEBUG("renderUtf8Text called without text");
return 0
@@ -153,9 +153,12 @@ function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bgcolor, f
-- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html
local pen_x = 0
local prevcharcode = 0
local buffer_width = buffer:getWidth()
local text_width = buffer:getWidth() - x
if width and width < text_width then
text_width = width
end
for _, charcode, uchar in utf8Chars(text) do
if pen_x < buffer_width then
if pen_x < text_width then
local glyph = self:getGlyph(face, charcode, bgcolor, fgcolor)
if kerning and (prevcharcode ~= 0) then
pen_x = pen_x + face.ftface:getKerning(prevcharcode, charcode)
@@ -167,7 +170,7 @@ function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bgcolor, f
glyph.bb:getWidth(), glyph.bb:getHeight(), 1)
pen_x = pen_x + glyph.ax
prevcharcode = charcode
end -- if pen_x < buffer_width
end -- if pen_x < text_width
end
return pen_x