From bc004d99276155c0892b19965c967aeb2de01a1e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 26 Jul 2016 23:48:32 +0200 Subject: [fontloader] sync with Context as of 2016-07-26 --- src/fontloader/misc/fontloader-util-fil.lua | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/fontloader/misc/fontloader-util-fil.lua') diff --git a/src/fontloader/misc/fontloader-util-fil.lua b/src/fontloader/misc/fontloader-util-fil.lua index 47d9d03..eeb6856 100644 --- a/src/fontloader/misc/fontloader-util-fil.lua +++ b/src/fontloader/misc/fontloader-util-fil.lua @@ -6,8 +6,10 @@ if not modules then modules = { } end modules ['util-fil'] = { license = "see context related readme files" } -local byte = string.byte +local byte = string.byte +local char = string.char local extract = bit32.extract +local floor = math.floor -- Here are a few helpers (the starting point were old ones I used for parsing -- flac files). In Lua 5.3 we can probably do this better. Some code will move @@ -36,6 +38,8 @@ function files.size(f) return f:seek("end") end +files.getsize = files.size + function files.setposition(f,n) if zerobased[f] then f:seek("set",n) @@ -180,3 +184,32 @@ end function files.skiplong(f,n) f:read(4*(n or 1)) end + +-- writers (kind of slow) + +function files.writecardinal2(f,n) + local a = char(n % 256) + n = floor(n/256) + local b = char(n % 256) + f:write(b,a) +end + +function files.writecardinal4(f,n) + local a = char(n % 256) + n = floor(n/256) + local b = char(n % 256) + n = floor(n/256) + local c = char(n % 256) + n = floor(n/256) + local d = char(n % 256) + f:write(d,c,b,a) +end + +function files.writestring(f,s) + f:write(char(byte(s,1,#s))) +end + +function files.writebyte(f,b) + f:write(char(b)) +end + -- cgit v1.2.3