|
|
@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
|
|
|
|
Text rendering module.
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local Cache = require("cache")
|
|
|
|
local Cache = require("cache")
|
|
|
|
local CacheItem = require("cacheitem")
|
|
|
|
local CacheItem = require("cacheitem")
|
|
|
@ -118,6 +122,18 @@ function RenderText:getSubTextByWidth(text, face, width, kerning, bold)
|
|
|
|
return table.concat(char_list)
|
|
|
|
return table.concat(char_list)
|
|
|
|
end
|
|
|
|
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)
|
|
|
|
function RenderText:sizeUtf8Text(x, width, face, text, kerning, bold)
|
|
|
|
if not text then
|
|
|
|
if not text then
|
|
|
|
DEBUG("sizeUtf8Text called without text");
|
|
|
|
DEBUG("sizeUtf8Text called without text");
|
|
|
@ -139,10 +155,15 @@ function RenderText:sizeUtf8Text(x, width, face, text, kerning, bold)
|
|
|
|
pen_x = pen_x + glyph.ax
|
|
|
|
pen_x = pen_x + glyph.ax
|
|
|
|
pen_y_top = math.max(pen_y_top, glyph.t)
|
|
|
|
pen_y_top = math.max(pen_y_top, glyph.t)
|
|
|
|
pen_y_bottom = math.max(pen_y_bottom, glyph.bb:getHeight() - 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
|
|
|
|
prevcharcode = charcode
|
|
|
|
end -- if pen_x < (width - x)
|
|
|
|
end -- if pen_x < (width - x)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--- 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 }
|
|
|
|
return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|