|
|
@ -1,8 +1,8 @@
|
|
|
|
local CanvasContext = require("document/canvascontext")
|
|
|
|
local CanvasContext = require("document/canvascontext")
|
|
|
|
local DataStorage = require("datastorage")
|
|
|
|
local DataStorage = require("datastorage")
|
|
|
|
local dump = require("dump")
|
|
|
|
|
|
|
|
local FT = require("ffi/freetype")
|
|
|
|
local FT = require("ffi/freetype")
|
|
|
|
local HB = require("ffi/harfbuzz")
|
|
|
|
local HB = require("ffi/harfbuzz")
|
|
|
|
|
|
|
|
local Persist = require("persist")
|
|
|
|
local util = require("util")
|
|
|
|
local util = require("util")
|
|
|
|
local logger = require("logger")
|
|
|
|
local logger = require("logger")
|
|
|
|
local dbg = require("dbg")
|
|
|
|
local dbg = require("dbg")
|
|
|
@ -168,12 +168,15 @@ end
|
|
|
|
function FontList:getFontList()
|
|
|
|
function FontList:getFontList()
|
|
|
|
if #self.fontlist > 0 then return self.fontlist end
|
|
|
|
if #self.fontlist > 0 then return self.fontlist end
|
|
|
|
|
|
|
|
|
|
|
|
local cache_file = DataStorage:getDataDir() .. "/cache/fontinfo.dat"
|
|
|
|
local cache = Persist:new{
|
|
|
|
local ok
|
|
|
|
path = DataStorage:getDataDir() .. "/cache/fontinfo.dat"
|
|
|
|
ok, self.fontinfo = pcall(dofile, cache_file)
|
|
|
|
}
|
|
|
|
if not ok or not self.fontinfo then
|
|
|
|
|
|
|
|
self.fontinfo = {}
|
|
|
|
local t, err = cache:load()
|
|
|
|
|
|
|
|
if not t then
|
|
|
|
|
|
|
|
logger.info(cache.path, err, "initializing it")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.fontinfo = t or {}
|
|
|
|
|
|
|
|
|
|
|
|
-- used for marking fonts we're seeing
|
|
|
|
-- used for marking fonts we're seeing
|
|
|
|
local mark = { cache_dirty = false }
|
|
|
|
local mark = { cache_dirty = false }
|
|
|
@ -194,16 +197,10 @@ function FontList:getFontList()
|
|
|
|
|
|
|
|
|
|
|
|
if dbg.is_verbose then
|
|
|
|
if dbg.is_verbose then
|
|
|
|
-- when verbose debug is on, always dump the cache in plain text (to inspect the db output)
|
|
|
|
-- when verbose debug is on, always dump the cache in plain text (to inspect the db output)
|
|
|
|
local cache = io.open(cache_file, "w")
|
|
|
|
cache:save(self.fontinfo)
|
|
|
|
cache:write("return " .. dump(self.fontinfo))
|
|
|
|
|
|
|
|
cache:close()
|
|
|
|
|
|
|
|
elseif mark.cache_dirty then
|
|
|
|
elseif mark.cache_dirty then
|
|
|
|
-- otherwise dump the db in binary (more compact), and only if something has changed
|
|
|
|
-- otherwise dump the db in binary (more compact), and only if something has changed
|
|
|
|
local bc = load("return " .. dump(self.fontinfo))
|
|
|
|
cache:save(self.fontinfo, true)
|
|
|
|
bc = string.dump(bc, true)
|
|
|
|
|
|
|
|
local cache = io.open(cache_file, "wb")
|
|
|
|
|
|
|
|
cache:write(bc)
|
|
|
|
|
|
|
|
cache:close()
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local names = self.fontnames
|
|
|
|
local names = self.fontnames
|
|
|
|