mirror of
https://github.com/koreader/koreader
synced 2024-10-31 21:20:20 +00:00
[Android] Don't ship Noto (#5310)
Follow-up to <https://github.com/koreader/koreader/pull/5252>. This greatly reduces the Android package size. See discussion in <https://github.com/koreader/koreader/pull/5264#issuecomment-525517001>.
This commit is contained in:
parent
48f20b2153
commit
2cd9b50137
1
Makefile
1
Makefile
@ -351,6 +351,7 @@ androidupdate: all
|
|||||||
cd $(INSTALL_DIR)/koreader && zip -r9 \
|
cd $(INSTALL_DIR)/koreader && zip -r9 \
|
||||||
../../$(ANDROID_LAUNCHER_DIR)/assets/module/koreader-$(VERSION).zip * \
|
../../$(ANDROID_LAUNCHER_DIR)/assets/module/koreader-$(VERSION).zip * \
|
||||||
--exclude=*fonts/droid* \
|
--exclude=*fonts/droid* \
|
||||||
|
--exclude=*fonts/noto* \
|
||||||
--exclude=*resources/fonts* \
|
--exclude=*resources/fonts* \
|
||||||
--exclude=*resources/icons/src* \
|
--exclude=*resources/icons/src* \
|
||||||
--exclude=*share/man* \
|
--exclude=*share/man* \
|
||||||
|
@ -74,13 +74,14 @@ local function getExternalFontDir()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function _readList(target, dir)
|
local function _readList(target, dir)
|
||||||
-- lfs.dir non-exsitent directory will give error, weird!
|
-- lfs.dir non-existent directory will give an error, weird!
|
||||||
local ok, iter, dir_obj = pcall(lfs.dir, dir)
|
local ok, iter, dir_obj = pcall(lfs.dir, dir)
|
||||||
if not ok then return end
|
if not ok then return end
|
||||||
for f in iter, dir_obj do
|
for f in iter, dir_obj do
|
||||||
if lfs.attributes(dir.."/"..f, "mode") == "directory" and f ~= "." and f ~= ".." then
|
local mode = lfs.attributes(dir.."/"..f, "mode")
|
||||||
|
if mode == "directory" and f ~= "." and f ~= ".." then
|
||||||
_readList(target, dir.."/"..f)
|
_readList(target, dir.."/"..f)
|
||||||
else
|
elseif mode == "file" or mode == "link" then
|
||||||
if string.sub(f, 1, 1) ~= "." then
|
if string.sub(f, 1, 1) ~= "." then
|
||||||
local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "")
|
local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "")
|
||||||
if file_type == "ttf" or file_type == "ttc"
|
if file_type == "ttf" or file_type == "ttc"
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
Font module.
|
Font module.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local is_android = pcall(require, "android")
|
||||||
|
|
||||||
local FontList = require("fontlist")
|
local FontList = require("fontlist")
|
||||||
local Freetype = require("ffi/freetype")
|
local Freetype = require("ffi/freetype")
|
||||||
local Screen = require("device").screen
|
local Screen = require("device").screen
|
||||||
@ -10,22 +12,22 @@ local logger = require("logger")
|
|||||||
local Font = {
|
local Font = {
|
||||||
fontmap = {
|
fontmap = {
|
||||||
-- default font for menu contents
|
-- default font for menu contents
|
||||||
cfont = "noto/NotoSans-Regular.ttf",
|
cfont = "NotoSans-Regular.ttf",
|
||||||
-- default font for title
|
-- default font for title
|
||||||
--tfont = "NimbusSanL-BoldItal.cff",
|
--tfont = "NimbusSanL-BoldItal.cff",
|
||||||
tfont = "noto/NotoSans-Bold.ttf",
|
tfont = "NotoSans-Bold.ttf",
|
||||||
smalltfont = "noto/NotoSans-Bold.ttf",
|
smalltfont = "NotoSans-Bold.ttf",
|
||||||
x_smalltfont = "noto/NotoSans-Bold.ttf",
|
x_smalltfont = "NotoSans-Bold.ttf",
|
||||||
-- default font for footer
|
-- default font for footer
|
||||||
ffont = "noto/NotoSans-Regular.ttf",
|
ffont = "NotoSans-Regular.ttf",
|
||||||
smallffont = "noto/NotoSans-Regular.ttf",
|
smallffont = "NotoSans-Regular.ttf",
|
||||||
largeffont = "noto/NotoSans-Regular.ttf",
|
largeffont = "NotoSans-Regular.ttf",
|
||||||
|
|
||||||
-- default font for reading position info
|
-- default font for reading position info
|
||||||
rifont = "noto/NotoSans-Regular.ttf",
|
rifont = "NotoSans-Regular.ttf",
|
||||||
|
|
||||||
-- default font for pagination display
|
-- default font for pagination display
|
||||||
pgfont = "noto/NotoSans-Regular.ttf",
|
pgfont = "NotoSans-Regular.ttf",
|
||||||
|
|
||||||
-- selectmenu: font for item shortcut
|
-- selectmenu: font for item shortcut
|
||||||
scfont = "DroidSansMono.ttf",
|
scfont = "DroidSansMono.ttf",
|
||||||
@ -33,7 +35,7 @@ local Font = {
|
|||||||
-- help page: font for displaying keys
|
-- help page: font for displaying keys
|
||||||
hpkfont = "DroidSansMono.ttf",
|
hpkfont = "DroidSansMono.ttf",
|
||||||
-- font for displaying help messages
|
-- font for displaying help messages
|
||||||
hfont = "noto/NotoSans-Regular.ttf",
|
hfont = "NotoSans-Regular.ttf",
|
||||||
|
|
||||||
-- font for displaying input content
|
-- font for displaying input content
|
||||||
-- we have to use mono here for better distance controlling
|
-- we have to use mono here for better distance controlling
|
||||||
@ -42,16 +44,16 @@ local Font = {
|
|||||||
smallinfont = "DroidSansMono.ttf",
|
smallinfont = "DroidSansMono.ttf",
|
||||||
|
|
||||||
-- font for info messages
|
-- font for info messages
|
||||||
infofont = "noto/NotoSans-Regular.ttf",
|
infofont = "NotoSans-Regular.ttf",
|
||||||
|
|
||||||
-- small font for info messages
|
-- small font for info messages
|
||||||
smallinfofont = "noto/NotoSans-Regular.ttf",
|
smallinfofont = "NotoSans-Regular.ttf",
|
||||||
-- small bold font for info messages
|
-- small bold font for info messages
|
||||||
smallinfofontbold = "noto/NotoSans-Bold.ttf",
|
smallinfofontbold = "NotoSans-Bold.ttf",
|
||||||
-- extra small font for info messages
|
-- extra small font for info messages
|
||||||
x_smallinfofont = "noto/NotoSans-Regular.ttf",
|
x_smallinfofont = "NotoSans-Regular.ttf",
|
||||||
-- extra extra small font for info messages
|
-- extra extra small font for info messages
|
||||||
xx_smallinfofont = "noto/NotoSans-Regular.ttf",
|
xx_smallinfofont = "NotoSans-Regular.ttf",
|
||||||
},
|
},
|
||||||
sizemap = {
|
sizemap = {
|
||||||
cfont = 24,
|
cfont = 24,
|
||||||
@ -75,8 +77,8 @@ local Font = {
|
|||||||
xx_smallinfofont = 18,
|
xx_smallinfofont = 18,
|
||||||
},
|
},
|
||||||
fallbacks = {
|
fallbacks = {
|
||||||
[1] = "noto/NotoSans-Regular.ttf",
|
[1] = "NotoSans-Regular.ttf",
|
||||||
[2] = "noto/NotoSansCJKsc-Regular.otf",
|
[2] = "NotoSansCJKsc-Regular.otf",
|
||||||
[3] = "freefont/FreeSans.ttf",
|
[3] = "freefont/FreeSans.ttf",
|
||||||
[4] = "freefont/FreeSerif.ttf",
|
[4] = "freefont/FreeSerif.ttf",
|
||||||
},
|
},
|
||||||
@ -85,6 +87,10 @@ local Font = {
|
|||||||
faces = {},
|
faces = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_android then
|
||||||
|
table.insert(Font.fallbacks, 3, "DroidSansFallback.ttf") -- for some ancient pre-4.4 Androids
|
||||||
|
end
|
||||||
|
|
||||||
--- Gets font face object.
|
--- Gets font face object.
|
||||||
-- @string font
|
-- @string font
|
||||||
-- @int size optional size
|
-- @int size optional size
|
||||||
@ -108,13 +114,38 @@ function Font:getFace(font, size)
|
|||||||
end
|
end
|
||||||
local builtin_font_location = FontList.fontdir.."/"..realname
|
local builtin_font_location = FontList.fontdir.."/"..realname
|
||||||
local ok, face = pcall(Freetype.newFace, builtin_font_location, size)
|
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.
|
-- 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.
|
-- 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 fonts = FontList:getFontList()
|
||||||
|
local escaped_realname = realname:gsub("[-]", "%%-")
|
||||||
|
|
||||||
for _k, _v in ipairs(fonts) do
|
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)
|
ok, face = pcall(Freetype.newFace, _v, size)
|
||||||
|
|
||||||
|
if ok then break end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user