mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
Merge pull request #2 from chrox/frankyifei-2015-10-22
code refactoring: use hash table index instead of loop
This commit is contained in:
commit
c955e71c84
@ -47,7 +47,6 @@ local Font = {
|
|||||||
faces = {},
|
faces = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function Font:getFace(font, size)
|
function Font:getFace(font, size)
|
||||||
-- default to content font
|
-- default to content font
|
||||||
if not font then font = self.cfont end
|
if not font then font = self.cfont end
|
||||||
@ -82,25 +81,23 @@ function Font:getFace(font, size)
|
|||||||
return face_obj
|
return face_obj
|
||||||
end
|
end
|
||||||
|
|
||||||
function checkfont(f)
|
--[[
|
||||||
|
These fonts from Kindle system cannot be loaded by Freetype.
|
||||||
|
--]]
|
||||||
|
local kindle_fonts_blacklist = {
|
||||||
|
["HYGothicBold.ttf"] = true,
|
||||||
|
["HYGothicMedium.ttf"] = true,
|
||||||
|
["HYMyeongJoBold.ttf"] = true,
|
||||||
|
["HYMyeongJoMedium.ttf"] = true,
|
||||||
|
["MYingHeiTBold.ttf"] = true,
|
||||||
|
["MYingHeiTMedium.ttf"] = true,
|
||||||
|
["SongTBold.ttf"] = true,
|
||||||
|
["SongTMedium.ttf"] = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function isInFontsBlacklist(f)
|
||||||
if Device:isKindle() then
|
if Device:isKindle() then
|
||||||
local exclusive_system_font = {
|
return kindle_fonts_blacklist[f]
|
||||||
--these kindle system fonts can not be used by freetype and will give error
|
|
||||||
"HYGothicBold.ttf",
|
|
||||||
"HYGothicMedium.ttf",
|
|
||||||
"HYMyeongJoBold.ttf",
|
|
||||||
"HYMyeongJoMedium.ttf",
|
|
||||||
"MYingHeiTBold.ttf",
|
|
||||||
"MYingHeiTMedium.ttf",
|
|
||||||
"SongTBold.ttf",
|
|
||||||
"SongTMedium.ttf"
|
|
||||||
}
|
|
||||||
for _,value in ipairs(exclusive_system_font) do
|
|
||||||
if value == f then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,7 +112,7 @@ function Font:_readList(target, dir)
|
|||||||
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"
|
||||||
or file_type == "cff" or file_type == "otf" then
|
or file_type == "cff" or file_type == "otf" then
|
||||||
if checkfont(f) ~=true then
|
if not isInFontsBlacklist(f) then
|
||||||
table.insert(target, dir.."/"..f)
|
table.insert(target, dir.."/"..f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user