Skip to content

Commit

Permalink
refactor(core): Use bitwise functions shim instead of assuming bit32
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jul 18, 2020
1 parent 670aed1 commit e4d0774
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ globals = {
"SU",
"std",
"pl",
"bit",
"SYSTEM_SILE_PATH",
"SHARED_LIB_EXT",
"ProFi"
Expand Down
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ AX_LUA_HEADERS
AX_LUA_LIBS

AS_IF([test "x$with_system_luarocks" = "xyes"], [
AX_LUA_MODULE([bit32], [bit32])
AS_IF([test "$LUA_SHORT_VERSION" -lt 52],
AX_LUA_MODULE([bit32], [bit32])
)
AX_LUA_MODULE([lpeg], [lpeg])
AX_LUA_MODULE([cassowary], [cassowary])
AS_IF([test "$LUA_SHORT_VERSION" -lt 53],
Expand Down
8 changes: 5 additions & 3 deletions core/harfbuzz-shaper.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
if not SILE.shapers then SILE.shapers = { } end
local hb = require("justenoughharfbuzz")
local icu = require("justenoughicu")
local bitshim = require("bitshim")

if not SILE.shapers then SILE.shapers = { } end

SILE.settings.declare({
name = "harfbuzz.subshapers",
Expand Down Expand Up @@ -62,9 +64,9 @@ SILE.shapers.harfbuzz = pl.class({
SU.debug("fonts", "Resolved font family '"..opts.family.."' -> "..(face and face.filename))
if not face or not face.filename then SU.error("Couldn't find face '"..opts.family.."'") end
if SILE.makeDeps then SILE.makeDeps:add(face.filename) end
if bit32.rshift(face.index, 16) ~= 0 then
if bitshim.rshift(face.index, 16) ~= 0 then
SU.warn("GX feature in '"..opts.family.."' is not supported, fallback to regular font face.")
face.index = bit32.band(face.index, 0xff)
face.index = bitshim.band(face.index, 0xff)
end
local fh, err = io.open(face.filename, "rb")
if err then SU.error("Can't open font file '"..face.filename.."': "..err) end
Expand Down
1 change: 0 additions & 1 deletion core/sile.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-- Initialize Lua environment and global utilities
local lua_version = _VERSION:sub(-3)
if lua_version < "5.3" then require("compat53") end -- Backport of lots of Lua 5.3 features to Lua 5.[12]
bit32 = bit32 or require("bit32") -- Backport of Lua 5.2+ bitwise functions to Lua 5.1
pl = require("pl.import_into")() -- Penlight on-demand module loader
if (os.getenv("SILE_COVERAGE")) then require("luacov") end

Expand Down
9 changes: 5 additions & 4 deletions core/utilities.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local bitshim = require("bitshim")
local utilities = {}

local epsilon = 1E-12
Expand Down Expand Up @@ -314,9 +315,9 @@ utilities.codepoint = function (uchar)
seq = c < 0x80 and 1 or c < 0xE0 and 2 or c < 0xF0 and 3 or
c < 0xF8 and 4 or --c < 0xFC and 5 or c < 0xFE and 6 or
error("invalid UTF-8 character sequence")
val = bit32.band(c, 2^(8-seq) - 1)
val = bitshim.band(c, 2^(8-seq) - 1)
else
val = bit32.bor(bit32.lshift(val, 6), bit32.band(c, 0x3F))
val = bitshim.bor(bitshim.lshift(val, 6), bitshim.band(c, 0x3F))
end
seq = seq - 1
end
Expand Down Expand Up @@ -403,10 +404,10 @@ utilities.splitUtf8 = function (str) -- Return an array of UTF8 strings each rep
seq = c < 0x80 and 1 or c < 0xE0 and 2 or c < 0xF0 and 3 or
c < 0xF8 and 4 or --c < 0xFC and 5 or c < 0xFE and 6 or
error("invalid UTF-8 character sequence")
val = bit32.band(c, 2^(8-seq) - 1)
val = bitshim.band(c, 2^(8-seq) - 1)
this = this .. str[i]
else
val = bit32.bor(bit32.lshift(val, 6), bit32.band(c, 0x3F))
val = bitshim.bor(bitshim.lshift(val, 6), bitshim.band(c, 0x3F))
this = this .. str[i]
end
seq = seq - 1
Expand Down

0 comments on commit e4d0774

Please sign in to comment.