From 55ba1450d4351124b720780c3a527e3caa2a6c65 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 22 Oct 2015 23:15:41 +0800 Subject: [PATCH] code refactoring: use hash table index instead of loop --- frontend/ui/font.lua | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/frontend/ui/font.lua b/frontend/ui/font.lua index 4553e6d3b..d42222108 100644 --- a/frontend/ui/font.lua +++ b/frontend/ui/font.lua @@ -47,7 +47,6 @@ local Font = { faces = {}, } - function Font:getFace(font, size) -- default to content font if not font then font = self.cfont end @@ -82,25 +81,23 @@ function Font:getFace(font, size) return face_obj 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 - local exclusive_system_font = { - --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 + return kindle_fonts_blacklist[f] end end @@ -115,7 +112,7 @@ function Font:_readList(target, dir) local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "") if file_type == "ttf" or file_type == "ttc" or file_type == "cff" or file_type == "otf" then - if checkfont(f) ~=true then + if not isInFontsBlacklist(f) then table.insert(target, dir.."/"..f) end end