summaryrefslogtreecommitdiff
path: root/src/fontloader/misc/fontloader-util-fil.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/fontloader/misc/fontloader-util-fil.lua')
-rw-r--r--src/fontloader/misc/fontloader-util-fil.lua68
1 files changed, 57 insertions, 11 deletions
diff --git a/src/fontloader/misc/fontloader-util-fil.lua b/src/fontloader/misc/fontloader-util-fil.lua
index eeb6856..0f9731a 100644
--- a/src/fontloader/misc/fontloader-util-fil.lua
+++ b/src/fontloader/misc/fontloader-util-fil.lua
@@ -8,7 +8,7 @@ if not modules then modules = { } end modules ['util-fil'] = {
local byte = string.byte
local char = string.char
-local extract = bit32.extract
+local extract = bit32 and bit32.extract
local floor = math.floor
-- Here are a few helpers (the starting point were old ones I used for parsing
@@ -109,6 +109,10 @@ function files.readcardinal2(f)
local a, b = byte(f:read(2),1,2)
return 0x100 * a + b
end
+function files.readcardinal2le(f)
+ local b, a = byte(f:read(2),1,2)
+ return 0x100 * a + b
+end
function files.readinteger2(f)
local a, b = byte(f:read(2),1,2)
@@ -120,11 +124,25 @@ function files.readinteger2(f)
return n
end
end
+function files.readinteger2le(f)
+ local b, a = byte(f:read(2),1,2)
+ local n = 0x100 * a + b
+ if n >= 0x8000 then
+ -- return n - 0xFFFF - 1
+ return n - 0x10000
+ else
+ return n
+ end
+end
function files.readcardinal3(f)
local a, b, c = byte(f:read(3),1,3)
return 0x10000 * a + 0x100 * b + c
end
+function files.readcardinal3le(f)
+ local c, b, a = byte(f:read(3),1,3)
+ return 0x10000 * a + 0x100 * b + c
+end
function files.readinteger3(f)
local a, b, c = byte(f:read(3),1,3)
@@ -136,11 +154,25 @@ function files.readinteger3(f)
return n
end
end
+function files.readinteger3le(f)
+ local c, b, a = byte(f:read(3),1,3)
+ local n = 0x10000 * a + 0x100 * b + c
+ if n >= 0x80000 then
+ -- return n - 0xFFFFFF - 1
+ return n - 0x1000000
+ else
+ return n
+ end
+end
function files.readcardinal4(f)
local a, b, c, d = byte(f:read(4),1,4)
return 0x1000000 * a + 0x10000 * b + 0x100 * c + d
end
+function files.readcardinal4le(f)
+ local d, c, b, a = byte(f:read(4),1,4)
+ return 0x1000000 * a + 0x10000 * b + 0x100 * c + d
+end
function files.readinteger4(f)
local a, b, c, d = byte(f:read(4),1,4)
@@ -152,6 +184,16 @@ function files.readinteger4(f)
return n
end
end
+function files.readinteger4le(f)
+ local d, c, b, a = byte(f:read(4),1,4)
+ local n = 0x1000000 * a + 0x10000 * b + 0x100 * c + d
+ if n >= 0x8000000 then
+ -- return n - 0xFFFFFFFF - 1
+ return n - 0x100000000
+ else
+ return n
+ end
+end
function files.readfixed4(f)
local a, b, c, d = byte(f:read(4),1,4)
@@ -164,17 +206,21 @@ function files.readfixed4(f)
end
end
-function files.read2dot14(f)
- local a, b = byte(f:read(2),1,2)
- local n = 0x100 * a + b
- local m = extract(n,0,30)
- if n > 0x7FFF then
- n = extract(n,30,2)
- return m/0x4000 - 4
- else
- n = extract(n,30,2)
- return n + m/0x4000
+if extract then
+
+ function files.read2dot14(f)
+ local a, b = byte(f:read(2),1,2)
+ local n = 0x100 * a + b
+ local m = extract(n,0,30)
+ if n > 0x7FFF then
+ n = extract(n,30,2)
+ return m/0x4000 - 4
+ else
+ n = extract(n,30,2)
+ return n + m/0x4000
+ end
end
+
end
function files.skipshort(f,n)