diff options
| author | Khaled Hosny <khaledhosny@eglug.org> | 2010-11-12 07:05:22 +0200 | 
|---|---|---|
| committer | Khaled Hosny <khaledhosny@eglug.org> | 2010-11-12 07:17:06 +0200 | 
| commit | 5868b9d15ebca57f7ead09140e139dbec798e1ce (patch) | |
| tree | 4e672c28170c72db21bae5d666ff950bca52564c | |
| parent | db19f6314830be14197c947987532109fd7b56b1 (diff) | |
| download | luaotfload-5868b9d15ebca57f7ead09140e139dbec798e1ce.tar.gz | |
Remove --database-dir and --sys options
* --database-dir is useless anyway since we don't support loading names
  database from arbitrary path.
* --sys (and mkluatexfontdb-sys) are dangerous since we will load user
  specific fonts (in ~/.fonts for example) which can not be loaded by
  other users (can be security concern as well). If there is real need,
  we should then implement it properly.
+ some clean up and less code duplication in mkluatexfontdb.
| -rw-r--r-- | luaotfload.dtx | 3 | ||||
| -rwxr-xr-x | mkluatexfontdb.lua | 58 | ||||
| -rw-r--r-- | otfl-font-nms.lua | 24 | 
3 files changed, 26 insertions, 59 deletions
| diff --git a/luaotfload.dtx b/luaotfload.dtx index 30898f6..8cd09f2 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -565,8 +565,7 @@ luaotfload.loadmodule('font-dum.lua')  %  %    This is a patch for |otfl-font-def.lua|, that defines a reader for ofm  %    fonts, this is necessary if we set the forced field of the specification -%    to |ofm|, we use it only when using \textsf{luaotfload}, not -%    |mkluatexfontdb|. +%    to |ofm|.  %  %    \begin{macrocode}  if fonts and fonts.tfm and fonts.tfm.readers then diff --git a/mkluatexfontdb.lua b/mkluatexfontdb.lua index 98db095..dc46ac0 100755 --- a/mkluatexfontdb.lua +++ b/mkluatexfontdb.lua @@ -18,11 +18,6 @@ local version = '1.07' -- same version number as luaotfload  local names    = fonts.names --- the directory in which the database will be saved, can be overwritten -local output_directory = names.path.localdir - -local log      = logs.report -  local function help_msg()      texio.write(string.format([[  Usage: %s [OPTION]... @@ -30,14 +25,11 @@ Usage: %s [OPTION]...  Rebuild the LuaTeX font database.  Valid options: -  -d --database-dir=DIRECTORY  install the database in the specified directory    -f --force                   force re-indexing all fonts    -q --quiet                   don't output anything    -v --verbose=LEVEL           be more verbose (print the searched directories)    -vv                          print the loaded fonts    -vvv                         print all steps of directory searching -  --sys                        install the database system-wide -                               (default is only for the current user)    -V --version                 print version and exit    -h --help                    print this message @@ -60,9 +52,10 @@ the list. For example (using a bash shell),     export OSFONTDIR='/path/to/other/fonts:/Users/will/Library/Fonts:...' -The output database file is named otfl-fonts.lua. By default it is placed -in $TEXMFVAR/luatex-cache/generic/names." -]], name)) +The output database file is named otfl-fonts.lua and is placed under: + +   %s" +]], name, names.path.localdir))  end  local function version_msg() @@ -76,16 +69,14 @@ Here we fill cmdargs with the good values, and then analyze it.  --]]  local long_opts = { -    ['database-dir'] = "d",      force            = "f",      quiet            = "q",      help             = "h", -    sys              = 0  ,      verbose          = 1  ,      version          = "V",  } -local short_opts = "d:fqpvVh" +local short_opts = "fqpvVh"  local force_reload = nil @@ -107,50 +98,19 @@ local function process_cmdline()          elseif v == "h" then              help_msg()              os.exit(0) -        elseif v == "d" then -            output_directory = optarg [i]          elseif v == "f" then              force_reload = 1 -        elseif v == "sys" then -            output_directory = names.path.systemdir          end      end -    if string.match(arg[0], '-sys') then -        output_directory = names.path.systemdir -    end -    output_directory = fonts.path_normalize(output_directory)      names.set_log_level(log_level)  end -process_cmdline() -  local function generate(force) -    local savepath = output_directory -    if not lfs.isdir(savepath) then -        log("creating directory %s", savepath) -        dir.mkdirs(savepath) -        if not lfs.isdir(savepath) then -            texio.write_nl(string.format("Error: cannot create directory '%s', exiting.\n", savepath)) -            os.exit(1) -        end -    end -    savepath = file.join(savepath, names.path.basename) -    local fh = io.open(savepath, 'a+') -    if not fh then -        texio.write_nl(string.format("Error: cannot write file '%s', exiting.\n", savepath)) -        os.exit(1) -    end -    fh:close() -    local fontnames -    if not force_reload and file.isreadable(savepath) then -        fontnames = dofile(savepath) -    else -        fontnames = nil -    end +    local fontnames, saved      fontnames = names.update(fontnames, force) -    log("%s fonts in the database", #fontnames.mappings) -    table.tofile(savepath, fontnames, true) -    log("saved font names database in %s\n", savepath) +    logs.report("%s fonts in the database", #fontnames.mappings) +    saved = names.save(fontnames)  end +process_cmdline()  generate(force_reload) diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua index 938b6bd..b565aac 100644 --- a/otfl-font-nms.lua +++ b/otfl-font-nms.lua @@ -47,7 +47,7 @@ local function fontnames_init()      }  end -function names.load() +local function load_names()      local localpath  = file.join(names.path.localdir, names.path.basename)      local systempath = file.join(names.path.systemdir, names.path.basename)      local kpsefound  = kpse.find_file(names.path.basename) @@ -238,7 +238,7 @@ end  local lastislog = 0 -function log(fmt, ...) +local function log(fmt, ...)      lastislog = 1      texio.write_nl(format("luaotfload | %s", format(fmt,...)))      io.flush() @@ -248,8 +248,6 @@ logs        = logs or { }  logs.report = logs.report or log  logs.info   = logs.info or log -local log = names.log -  local function font_fullinfo(filename, subfont, texmf)      local t = { }      local f = fontloader.open(filename, subfont) @@ -635,9 +633,10 @@ local function update_names(fontnames, force)      if force then          fontnames = fontnames_init()      else -        if not fontnames -        or not fontnames.version -        or fontnames.version ~= names.version then +        if not fontnames then +            fontnames = names.load() +        end +        if fontnames.version ~= names.version then              fontnames = fontnames_init()              if trace_search then                  logs.report("No font names database or old one found; " @@ -659,7 +658,15 @@ local function save_names(fontnames)      if not lfs.isdir(savepath) then          dir.mkdirs(savepath)      end -    table.tofile(file.join(savepath, names.path.basename), fontnames, true) +    savepath = file.join(savepath, names.path.basename) +    if file.iswritable(savepath) then +        table.tofile(savepath, fontnames, true) +        logs.info("Font names database saved: %s \n", savepath) +        return savepath +    else +        logs.info("Failed to save names database\n") +        return nil +    end  end  local function scan_external_dir(dir) @@ -676,5 +683,6 @@ local function scan_external_dir(dir)  end  names.scan   = scan_external_dir +names.load   = load_names  names.update = update_names  names.save   = save_names | 
