mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
doc: types/functions for font and rendertext module
This commit is contained in:
@@ -8,5 +8,5 @@ use_markdown_titles = true
|
||||
readme = '../README.md'
|
||||
package = ''
|
||||
format = 'markdown'
|
||||
sort_modules=true
|
||||
sort_modules = true
|
||||
file = '../frontend'
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
--[[--
|
||||
Font module.
|
||||
]]
|
||||
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local Freetype = require("ffi/freetype")
|
||||
local Screen = require("device").screen
|
||||
@@ -82,6 +86,12 @@ function Font:getFace(font, size)
|
||||
DEBUG("#! Font "..font.." ("..realname..") not supported: "..face)
|
||||
return nil
|
||||
end
|
||||
--- Freetype font face wrapper object
|
||||
-- @table FontFaceObj
|
||||
-- @field size size of the font face (after scaled by screen size)
|
||||
-- @field orig_size raw size of the font face (before scale)
|
||||
-- @field ftface font face object from freetype
|
||||
-- @field hash hash key for this font face
|
||||
face_obj = {
|
||||
size = size,
|
||||
orig_size = orig_size,
|
||||
@@ -89,7 +99,6 @@ function Font:getFace(font, size)
|
||||
hash = hash
|
||||
}
|
||||
self.faces[hash] = face_obj
|
||||
-- DEBUG("getFace, found: "..realname.." size:"..size)
|
||||
end
|
||||
return face_obj
|
||||
end
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user