|
|
|
@ -2,6 +2,8 @@
|
|
|
|
|
Font module.
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
local is_android = pcall(require, "android")
|
|
|
|
|
|
|
|
|
|
local FontList = require("fontlist")
|
|
|
|
|
local Freetype = require("ffi/freetype")
|
|
|
|
|
local Screen = require("device").screen
|
|
|
|
@ -10,22 +12,22 @@ local logger = require("logger")
|
|
|
|
|
local Font = {
|
|
|
|
|
fontmap = {
|
|
|
|
|
-- default font for menu contents
|
|
|
|
|
cfont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
cfont = "NotoSans-Regular.ttf",
|
|
|
|
|
-- default font for title
|
|
|
|
|
--tfont = "NimbusSanL-BoldItal.cff",
|
|
|
|
|
tfont = "noto/NotoSans-Bold.ttf",
|
|
|
|
|
smalltfont = "noto/NotoSans-Bold.ttf",
|
|
|
|
|
x_smalltfont = "noto/NotoSans-Bold.ttf",
|
|
|
|
|
tfont = "NotoSans-Bold.ttf",
|
|
|
|
|
smalltfont = "NotoSans-Bold.ttf",
|
|
|
|
|
x_smalltfont = "NotoSans-Bold.ttf",
|
|
|
|
|
-- default font for footer
|
|
|
|
|
ffont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
smallffont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
largeffont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
ffont = "NotoSans-Regular.ttf",
|
|
|
|
|
smallffont = "NotoSans-Regular.ttf",
|
|
|
|
|
largeffont = "NotoSans-Regular.ttf",
|
|
|
|
|
|
|
|
|
|
-- default font for reading position info
|
|
|
|
|
rifont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
rifont = "NotoSans-Regular.ttf",
|
|
|
|
|
|
|
|
|
|
-- default font for pagination display
|
|
|
|
|
pgfont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
pgfont = "NotoSans-Regular.ttf",
|
|
|
|
|
|
|
|
|
|
-- selectmenu: font for item shortcut
|
|
|
|
|
scfont = "DroidSansMono.ttf",
|
|
|
|
@ -33,7 +35,7 @@ local Font = {
|
|
|
|
|
-- help page: font for displaying keys
|
|
|
|
|
hpkfont = "DroidSansMono.ttf",
|
|
|
|
|
-- font for displaying help messages
|
|
|
|
|
hfont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
hfont = "NotoSans-Regular.ttf",
|
|
|
|
|
|
|
|
|
|
-- font for displaying input content
|
|
|
|
|
-- we have to use mono here for better distance controlling
|
|
|
|
@ -42,16 +44,16 @@ local Font = {
|
|
|
|
|
smallinfont = "DroidSansMono.ttf",
|
|
|
|
|
|
|
|
|
|
-- font for info messages
|
|
|
|
|
infofont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
infofont = "NotoSans-Regular.ttf",
|
|
|
|
|
|
|
|
|
|
-- small font for info messages
|
|
|
|
|
smallinfofont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
smallinfofont = "NotoSans-Regular.ttf",
|
|
|
|
|
-- small bold font for info messages
|
|
|
|
|
smallinfofontbold = "noto/NotoSans-Bold.ttf",
|
|
|
|
|
smallinfofontbold = "NotoSans-Bold.ttf",
|
|
|
|
|
-- extra small font for info messages
|
|
|
|
|
x_smallinfofont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
x_smallinfofont = "NotoSans-Regular.ttf",
|
|
|
|
|
-- extra extra small font for info messages
|
|
|
|
|
xx_smallinfofont = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
xx_smallinfofont = "NotoSans-Regular.ttf",
|
|
|
|
|
},
|
|
|
|
|
sizemap = {
|
|
|
|
|
cfont = 24,
|
|
|
|
@ -75,8 +77,8 @@ local Font = {
|
|
|
|
|
xx_smallinfofont = 18,
|
|
|
|
|
},
|
|
|
|
|
fallbacks = {
|
|
|
|
|
[1] = "noto/NotoSans-Regular.ttf",
|
|
|
|
|
[2] = "noto/NotoSansCJKsc-Regular.otf",
|
|
|
|
|
[1] = "NotoSans-Regular.ttf",
|
|
|
|
|
[2] = "NotoSansCJKsc-Regular.otf",
|
|
|
|
|
[3] = "freefont/FreeSans.ttf",
|
|
|
|
|
[4] = "freefont/FreeSerif.ttf",
|
|
|
|
|
},
|
|
|
|
@ -85,6 +87,10 @@ local Font = {
|
|
|
|
|
faces = {},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if is_android then
|
|
|
|
|
table.insert(Font.fallbacks, 3, "DroidSansFallback.ttf") -- for some ancient pre-4.4 Androids
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Gets font face object.
|
|
|
|
|
-- @string font
|
|
|
|
|
-- @int size optional size
|
|
|
|
@ -108,13 +114,38 @@ function Font:getFace(font, size)
|
|
|
|
|
end
|
|
|
|
|
local builtin_font_location = FontList.fontdir.."/"..realname
|
|
|
|
|
local ok, face = pcall(Freetype.newFace, builtin_font_location, size)
|
|
|
|
|
|
|
|
|
|
-- We don't ship Droid and Noto on Android because they're system fonts.
|
|
|
|
|
-- This cuts package size in half, but 4.4 and older systems
|
|
|
|
|
-- might not ship Noto.
|
|
|
|
|
if not ok and is_android and realname:match("^Noto") then
|
|
|
|
|
local system_font_location = "/system/fonts"
|
|
|
|
|
logger.dbg("Font:", realname, "not found. Trying system location.")
|
|
|
|
|
|
|
|
|
|
ok, face = pcall(Freetype.newFace, system_font_location.."/"..realname, size)
|
|
|
|
|
|
|
|
|
|
-- Relevant Noto font not found on this device, fall back to Droid
|
|
|
|
|
if not ok then
|
|
|
|
|
if realname:match("Bold") then
|
|
|
|
|
realname = "DroidSans-Bold.ttf"
|
|
|
|
|
else
|
|
|
|
|
realname = "DroidSans.ttf"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Not all fonts are bundled on all platforms because they come with the system.
|
|
|
|
|
-- In that case, search through all font folders for the requested font.
|
|
|
|
|
if not ok and font ~= realname then
|
|
|
|
|
if not ok then
|
|
|
|
|
local fonts = FontList:getFontList()
|
|
|
|
|
local escaped_realname = realname:gsub("[-]", "%%-")
|
|
|
|
|
|
|
|
|
|
for _k, _v in ipairs(fonts) do
|
|
|
|
|
if _v:find(realname) then
|
|
|
|
|
if _v:find(escaped_realname) then
|
|
|
|
|
logger.dbg("Found font:", realname, "in", _v)
|
|
|
|
|
ok, face = pcall(Freetype.newFace, _v, size)
|
|
|
|
|
|
|
|
|
|
if ok then break end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|