mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
refactoring for display help page
This commit is contained in:
@@ -43,7 +43,7 @@ function clearGlyphCache()
|
||||
glyphcache = {}
|
||||
end
|
||||
|
||||
function sizeUtf8Text(face, facehash, text, kerning)
|
||||
function sizeUtf8Text(x, width, face, facehash, text, kerning)
|
||||
if text == nil then
|
||||
print("# sizeUtf8Text called without text");
|
||||
return
|
||||
@@ -51,28 +51,32 @@ function sizeUtf8Text(face, facehash, text, kerning)
|
||||
-- may still need more adaptive pen placement when kerning,
|
||||
-- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html
|
||||
local pen_x = 0
|
||||
local pen_y_top = 0
|
||||
local pen_y_bottom = 0
|
||||
local prevcharcode = 0
|
||||
--print("----------------- text:"..text)
|
||||
for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do
|
||||
if pen_x < buffer:getWidth() then
|
||||
if pen_x < (width - x) then
|
||||
local charcode = util.utf8charcode(uchar)
|
||||
local glyph = getglyph(face, facehash, charcode)
|
||||
local glyph = getGlyph(face, facehash, charcode)
|
||||
if kerning and prevcharcode then
|
||||
local kern = face:getKerning(prevcharcode, charcode)
|
||||
pen_x = pen_x + kern
|
||||
print("prev:"..string.char(prevcharcode+10).." curr:"..string.char(charcode).." kern:"..kern)
|
||||
buffer:addblitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight())
|
||||
print("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." kern:"..kern)
|
||||
else
|
||||
print("curr:"..string.char(charcode))
|
||||
buffer:blitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight())
|
||||
end
|
||||
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)
|
||||
--print("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
|
||||
end
|
||||
return pen_x
|
||||
return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom}
|
||||
end
|
||||
|
||||
function renderUtf8Text(buffer, x, y, face, facehash, text, kerning)
|
||||
function renderUtf8Text(buffer, x, y, face, facehash, text, kerning, backgroundColor)
|
||||
if text == nil then
|
||||
print("# renderUtf8Text called without text");
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user