From 93afaacb9a5e835f397a46a16286282f19fcf113 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Mon, 24 May 2010 22:53:50 +0300 Subject: First attempt to read fonts.conf This seems to work OK... the code don't actually use it as there are other things to debug before, but the function that reads the file works ok on mine (please test on yours if you have time). --- otfl-font-nms.lua | 63 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua index bfc463a..c01922d 100644 --- a/otfl-font-nms.lua +++ b/otfl-font-nms.lua @@ -38,6 +38,7 @@ local splitpath, expandpath = file.split_path, kpse.expand_path local glob, basename = dir.glob, file.basename local upper, lower, format = string.upper, string.lower, string.format local gsub, match, rpadd = string.gsub, string.match, string.rpadd +local gmatch, sub = string.gmatch, string.sub local utfgsub = unicode.utf8.gsub local trace_short = false --tracing adapted to rebuilding of the database inside a document @@ -607,16 +608,57 @@ local function read_fcdata(data) end --[[ - Under Mac OSX, fc-list does not exist and there is no guaranty that OSFONTDIR - is correctly filled, so for now we use static paths. + TODO: doc ]] -local static_osx_dirs = { - kpse.expand_path('~') .. "/Library/Fonts", - "/Library/Fonts", - "/System/Library/Fonts", - "/Network/Library/Fonts", -} +--[[ + This function parses /etc/fonts/fonts.conf and returns all the dir it finds. + The code is minimal, please report any error it may generate. +]] + +local function read_fonts_conf() + local f = io.open("/etc/fonts/fonts.conf") + if not f then + error("Cannot open the file /etc/fonts/fonts.conf") + end + local results = {} + local incomments = false + for line in f:lines() do + -- spaghetti code... hmmm... + if incomments and sub(line, 1, 3) == '-->' then + incomments = false + elseif sub(line, 1, 4) == '