From 96dd4e3ae32e96596babd17043782785b1fd91e8 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 23 Apr 2013 13:54:01 +0200 Subject: add script to generate ``font-age.lua`` --- mkglyphlist | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 mkglyphlist (limited to 'mkglyphlist') diff --git a/mkglyphlist b/mkglyphlist new file mode 100755 index 0000000..954ffef --- /dev/null +++ b/mkglyphlist @@ -0,0 +1,141 @@ +#!/usr/bin/env texlua +----------------------------------------------------------------------- +-- FILE: mkglyphlist.lua +-- USAGE: ./mkglyphlist.lua +-- DESCRIPTION: part of the luaotfload package +-- REQUIREMENTS: lua, lpeg, luasocket, the lualibs package +-- AUTHOR: Philipp Gesang (Phg), +-- VERSION: 1.0 +-- CREATED: 04/23/2013 12:42:17 PM CEST +----------------------------------------------------------------------- +-- config +----------------------------------------------------------------------- +local glyphfile = "./glyphlist.txt" +local font_age = "./font-age.lua" +local glyph_source = "http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt" + +----------------------------------------------------------------------- +-- includes +----------------------------------------------------------------------- +require"lpeg" +require"socket" +require"lualibs-lua" +require"lualibs-lpeg" +require"lualibs-table" --- for serialization + +local C, Cf, Cg, Ct, P, R = + lpeg.C, lpeg.Cf, lpeg.Cg, lpeg.Ct, lpeg.P, lpeg.R + +local http = socket.http + +----------------------------------------------------------------------- +-- functionality +----------------------------------------------------------------------- + +local dec_of_hex = function (hex) return tonumber(hex, 16) end + +local separator = P";" +local gartenzaun = P"#" +local eol = P"\n\r" + P"\r\n" + P"\r" + P"\n" +local space = P" " +local alphanum = R("az", "AZ", "09") +local hexdigit = R("af", "AF", "09") +local eof_tag = gartenzaun * P"--end" +local header_line = gartenzaun * (1-eol)^0 * eol +local codepoint = hexdigit^1 +local glyphname = alphanum^1 + +local definition = Cg(C(glyphname) * separator * (C(codepoint)/ dec_of_hex)) + --- With combined glyphs we take only the first + --- value as char-def and font-age do, and skip + --- the rest. + * (space * codepoint)^0 + * eol +local definitions = Cf(Ct"" * definition^1, rawset) + +local p_glyphs = header_line^0 * definitions * eof_tag + +local get_glyphs = function (data) + local res = lpeg.match(p_glyphs, data) + if not res then + print("error: could not parse glyph list") + os.exit(-1) + end + return res +end + +local file_header = [==[ +if not modules then modules = { } end modules ["font-age"] = { + version = 2.200, + comment = "part of the luaotfload package", + author = "luaotfload team / mkglyphlist", + copyright = "derived from %s", + original = "Adobe Glyph List, version 2.0, September 20, 2002", + dataonly = true, +} + +if context then + logs.report("fatal error","this module is not for context") + os.exit(-1) +end + +--[[doc-- +Everything below has been autogenerated. Run mkglyphlist to rebuild +font-age.lua. +--doc]]-- + +]==] + +local writedata = function (data) + data = table.serialize(data, true) + data = string.format(file_header, glyph_source) .. data + local fh = io.open(font_age, "wb") + if not fh then + print(string.format("error: %s not writable", font_age)) + os.exit(-1) + end + print(string.format("saving %d bytes to %s", #data, font_age)) + fh:write(data) + fh:close() +end + + +local get_raw get_raw = function (retry) + local fh = io.open(glyphfile, "rb") + if fh then + local data = fh:read"*all" + fh:close() + if data then return data end + elseif not retry then --- attempt download + print"info: retrieving glyph list from" + print(glyph_source) + local glyphdata = http.request(glyph_source) + if glyphdata then + local fh = io.open(glyphfile, "wb") + if not fh then + print"error: glyph file not writable" + os.exit(-1) + end + fh:write(glyphdata) + fh:close() + return get_raw(true) + end + print"error: download failed" + os.exit(-1) + end + print("error: could not obtain glyph data from "..glyphfile) + os.exit(-1) +end + +local main = function () + if arg[1] then glyphfile = arg[1] end + if arg[2] then font_age = arg[2] end + + local data = get_raw() + local parsed = get_glyphs(data) + writedata(parsed) + return 0 +end + + +return main() -- cgit v1.2.3 From 25c75a54960bdacccb005d055ae5198298d07a8b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 23 Apr 2013 14:05:42 +0200 Subject: update Makefile --- mkglyphlist | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'mkglyphlist') diff --git a/mkglyphlist b/mkglyphlist index 954ffef..9ee1528 100755 --- a/mkglyphlist +++ b/mkglyphlist @@ -19,9 +19,11 @@ local glyph_source = "http://partners.adobe.com/public/developer/en/opentype/gl ----------------------------------------------------------------------- require"lpeg" require"socket" -require"lualibs-lua" -require"lualibs-lpeg" -require"lualibs-table" --- for serialization + +kpse.set_program_name"luatex" +dofile(kpse.find_file("lualibs-lua.lua", "lua")) +dofile(kpse.find_file("lualibs-lpeg.lua", "lua")) +dofile(kpse.find_file("lualibs-table.lua", "lua")) --- for serialization local C, Cf, Cg, Ct, P, R = lpeg.C, lpeg.Cf, lpeg.Cg, lpeg.Ct, lpeg.P, lpeg.R -- cgit v1.2.3