doc: types/functions for font and rendertext module

This commit is contained in:
Qingping Hou
2016-02-15 16:14:15 -08:00
parent d7879db90f
commit e410ce14df
3 changed files with 34 additions and 4 deletions

View File

@@ -1,3 +1,7 @@
--[[--
Text rendering module.
]]
local Font = require("ui/font")
local Cache = require("cache")
local CacheItem = require("cacheitem")
@@ -118,6 +122,18 @@ function RenderText:getSubTextByWidth(text, face, width, kerning, bold)
return table.concat(char_list)
end
--- Measure rendered size for a given text.
--
-- Note this function does not render the text into a bitmap. Use it if you
-- only care about the size for the rendered result.
--
---- @int x start position for a given text (within maxium width)
---- @int width maxium rendering width (think of it as size of the bitmap)
---- @tparam ui.font.FontFaceObj face font face that will be used for rendering
---- @string text text to measure
---- @bool[opt=false] kerning whether the text should be measured with kerning
---- @bool[opt=false] bold whether the text should be measured as bold
---- @treturn RenderTextSize
function RenderText:sizeUtf8Text(x, width, face, text, kerning, bold)
if not text then
DEBUG("sizeUtf8Text called without text");
@@ -139,11 +155,16 @@ function RenderText:sizeUtf8Text(x, width, face, text, kerning, bold)
pen_x = pen_x + glyph.ax
pen_y_top = math.max(pen_y_top, glyph.t)
pen_y_bottom = math.max(pen_y_bottom, glyph.bb:getHeight() - glyph.t)
--DEBUG("ax:"..glyph.ax.." t:"..glyph.t.." r:"..glyph.r.." h:"..glyph.bb:getHeight().." w:"..glyph.bb:getWidth().." yt:"..pen_y_top.." yb:"..pen_y_bottom)
prevcharcode = charcode
end -- if pen_x < (width - x)
end
return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom}
--- RenderText size information
-- @table RenderTextSize
-- @field x length of the text on x coordinates
-- @field y_top top offset for the text (relative to center of the text)
-- @field y_bottom bottom offset for the text (relative to center of the text)
return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom }
end
function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bold, fgcolor, width)