Skip to content

Commit

Permalink
Merge 3522dac into ec258e1
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Oct 17, 2019
2 parents ec258e1 + 3522dac commit a09c452
Show file tree
Hide file tree
Showing 34 changed files with 464 additions and 439 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rules:
- package-manager
- travis
- azure
- github
- manual
- examples
- installation
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Luacheck

on: [push, pull_request]

jobs:
luacheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup Lua
uses: leafo/gh-actions-lua@v5
with:
luaVersion: 5.3
- name: Setup Lua Rocks
uses: leafo/gh-actions-luarocks@v2
- name: Instalal luacheck
run: luarocks install luacheck
- name: Lint all the Lua code
run: luacheck .
15 changes: 15 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
std = "min"
include_files = {
"**/*.lua",
"*.rockspec",
".luacheckrc"
}
exclude_files = {
"lua_modules",
"lua-libraries"
}
globals = {
"SILE",
"SU"
}
max_line_length = false
68 changes: 31 additions & 37 deletions packages/frametricks.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
local breakFrameVertical = function(after)
local breakFrameVertical = function (after)
local cFrame = SILE.typesetter.frame
local totalHeight
if after then
totalHeight = after
else
totalHeight = 0
SILE.typesetter:leaveHmode(1)
local q = SILE.typesetter.state.outputQueue
for i=1,#q do
totalHeight = totalHeight + q[i].height + q[i].depth
local queue = SILE.typesetter.state.outputQueue
for i = 1, #queue do
totalHeight = totalHeight + queue[i].height + queue[i].depth
end
SILE.typesetter:chuck()
end

if type(totalHeight) == "table" then totalHeight= totalHeight.length end
if type(totalHeight) == "table" then totalHeight = totalHeight.length end

local newFrame = SILE.newFrame({
bottom = cFrame:bottom(),
Expand Down Expand Up @@ -67,7 +68,7 @@ local breakFrameHorizontalAt = function (offset)
SILE.typesetter:initFrame(newFrame)
end

local shiftframeedge = function(frame, options)
local shiftframeedge = function (frame, options)
if options.left then
frame:constrain("left", frame:left() + SILE.length.parse(options.left).length)
end
Expand All @@ -82,7 +83,7 @@ local makecolumns = function (options)
local gutterWidth = options.gutter or "3%pw"
local right = cFrame:right()
local origId = cFrame.id
for i = 1,cols-1 do
for i = 1, cols-1 do
local gutter = SILE.newFrame({
width = gutterWidth,
left = "right("..cFrame.id..")",
Expand All @@ -108,7 +109,7 @@ local makecolumns = function (options)
cFrame:constrain("right", right)
end

local mergeColumns = function(options)
local mergeColumns = function ()
SILE.require("packages/balanced-frames")

-- 1) Balance all remaining material.
Expand All @@ -117,13 +118,13 @@ local mergeColumns = function(options)
SILE.typesetter:pageBuilder()

-- 1.2) Find out the shape of the columnset. (It will change after we balance it)
t = SILE.typesetter.frame
local left = t:left()
local bottom = t:bottom()
while t.next and SILE.getFrame(t.next).balanced do
t = SILE.getFrame(t.next)
local frame = SILE.typesetter.frame
local left = frame:left()
local bottom = frame:bottom()
while frame.next and SILE.getFrame(frame.next).balanced do
frame = SILE.getFrame(frame.next)
end
local right = t:right()
local right = frame:right()

-- 1.3) Now force a balance, which will resize the frames
SILE.call("balancecolumns")
Expand All @@ -132,52 +133,45 @@ local mergeColumns = function(options)
-- 2) Add a new frame, the width of the old frameset and the height of
-- old frameset - new height, at the end of the current frame
local newId = SILE.typesetter.frame.id .. "_"
local newFrame = SILE.newFrame({
left = left,
right = right,
top = SILE.typesetter.frame:bottom(),
bottom = bottom,
id = newId
})
SILE.typesetter.frame.next = newId
SILE.typesetter:initNextFrame()
end

SILE.registerCommand("mergecolumns", function ( options, content )
mergeColumns(options)
SILE.registerCommand("mergecolumns", function (_, _)
mergeColumns()
end, "Merge multiple columns into one")

SILE.registerCommand("showframe", function(options, content)
SILE.registerCommand("showframe", function (options, _)
local id = options.id or SILE.typesetter.frame.id
if id == "all" then
for _,f in pairs(SILE.frames) do
for _, f in pairs(SILE.frames) do
SILE.outputter:debugFrame(f)
end
else
SILE.outputter:debugFrame(SILE.getFrame(id))
end
end)

SILE.registerCommand("shiftframeedge", function(options, content)
SILE.registerCommand("shiftframeedge", function (options, _)
local cFrame = SILE.typesetter.frame
shiftframeedge(cFrame, options)
SILE.typesetter:initFrame(cFrame)
--SILE.outputter:debugFrame(cFrame)
end, "Adjusts the edge of the frame horizontally by amounts specified in <left> and <right>")

SILE.registerCommand("breakframevertical", function ( options, content )
SILE.registerCommand("breakframevertical", function (options, _)
breakFrameVertical(options.offset and SILE.length.parse(options.offset).length)
end, "Breaks the current frame in two vertically at the current location or at a point <offset> below the current location")

SILE.registerCommand("makecolumns", function ( options, content )
SILE.registerCommand("makecolumns", function (options, _)
makecolumns(options)
end, "Split the current frame into multiple columns")

SILE.registerCommand("breakframehorizontal", function ( options, content )
SILE.registerCommand("breakframehorizontal", function (options, _)
breakFrameHorizontalAt(options.offset and SILE.length.parse(options.offset).length)
end, "Breaks the current frame in two horizontally either at the current location or at a point <offset> from the left of the current frame")

SILE.registerCommand("float", function(options, content)
SILE.registerCommand("float", function (options, content)
SILE.typesetter:leaveHmode()
local hbox = SILE.call("hbox", {}, content)
table.remove(SILE.typesetter.state.nodes) -- steal it back
Expand All @@ -189,8 +183,8 @@ SILE.registerCommand("float", function(options, content)
breakFrameVertical()
local boundary = hbox.width.length + SILE.toAbsoluteMeasurement(SILE.length.parse(options.rightboundary).length)
breakFrameHorizontalAt(boundary)
SILE.typesetNaturally(SILE.typesetter.frame.previous, function()
table.insert(SILE.typesetter.state.nodes,hbox)
SILE.typesetNaturally(SILE.typesetter.frame.previous, function ()
table.insert(SILE.typesetter.state.nodes, hbox)
end)
local undoSkip = SILE.settings.get("document.baselineskip").height:negate().length + SILE.length.parse("1ex")
undoSkip.stretch = hbox.height
Expand All @@ -201,24 +195,24 @@ SILE.registerCommand("float", function(options, content)
--SILE.outputter:debugFrame(SILE.typesetter.frame)
end, "Sets the given content in its own frame, flowing the remaining content around it")

SILE.registerCommand("typeset-into", function(options,content)
SILE.registerCommand("typeset-into", function (options, content)
SU.required(options, "frame", "calling \\typeset-into")
if not SILE.frames[options.frame] then
SU.error("Can't find frame "..options.frame.." to typeset into")
end
SILE.typesetNaturally(SILE.frames[options.frame], function() SILE.process(content) end)
SILE.typesetNaturally(SILE.frames[options.frame], function () SILE.process(content) end)
end)

SILE.registerCommand("fit-frame", function(options, content)
SILE.registerCommand("fit-frame", function (options, _)
SU.required(options, "frame", "calling \\fit-frame")
if not SILE.frames[options.frame] then
SU.error("Can't find frame "..options.frame.." to fit")
end
local f = SILE.frames[options.frame]
local h = SILE.length.new()
SILE.typesetNaturally(f, function()
SILE.typesetNaturally(f, function ()
SILE.typesetter:leaveHmode()
for i =1,#SILE.typesetter.state.outputQueue do
for i = 1, #SILE.typesetter.state.outputQueue do
h = h + SILE.typesetter.state.outputQueue[i].height
end
end)
Expand Down
51 changes: 25 additions & 26 deletions packages/grid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ local makeUp = function ()
return SILE.nodefactory.newVglue({ height = SILE.length.new({ length = toadd }) })
end

local leadingFor = function(this, vbox, previous)
if not this.frame.state.totals.gridCursor then this.frame.state.totals.gridCursor = 0 end
local leadingFor = function (self, vbox, previous)
if not self.frame.state.totals.gridCursor then self.frame.state.totals.gridCursor = 0 end
if not previous then return SILE.nodefactory.newVglue({height=SILE.length.new({})}) end
if type(vbox.height) == "table" then
this.frame.state.totals.gridCursor = this.frame.state.totals.gridCursor + vbox.height.length + previous.depth
self.frame.state.totals.gridCursor = self.frame.state.totals.gridCursor + vbox.height.length + previous.depth
else
this.frame.state.totals.gridCursor = this.frame.state.totals.gridCursor + vbox.height + previous.depth
self.frame.state.totals.gridCursor = self.frame.state.totals.gridCursor + vbox.height + previous.depth
end
return makeUp()
end

local pushVglue = function(this, spec)
if not this.frame.state.totals.gridCursor then
this.frame.state.totals.gridCursor = 0
local pushVglue = function (self, spec)
if not self.frame.state.totals.gridCursor then
self.frame.state.totals.gridCursor = 0
end
spec.height.stretch = 0
spec.height.shrink = 0
this.frame.state.totals.gridCursor = this.frame.state.totals.gridCursor + SILE.toAbsoluteMeasurement(spec.height.length)
SILE.defaultTypesetter.pushVglue(this, spec)
SILE.defaultTypesetter.pushVglue(this, makeUp())
self.frame.state.totals.gridCursor = self.frame.state.totals.gridCursor + SILE.toAbsoluteMeasurement(spec.height.length)
SILE.defaultTypesetter.pushVglue(self, spec)
SILE.defaultTypesetter.pushVglue(self, makeUp())
end

local debugGrid = function()
local debugGrid = function ()
local t = SILE.typesetter
if not t.frame.state.totals.gridCursor then t.frame.state.totals.gridCursor = 0 end
local g = t.frame.state.totals.gridCursor
Expand All @@ -40,7 +40,7 @@ local debugGrid = function()
end

local oldPageBuilder = SILE.pagebuilder
local gridFindBestBreak = function(options)
local gridFindBestBreak = function (options)
local vboxlist = SU.required(options, "vboxlist", "in findBestBreak")
local target = SU.required(options, "target", "in findBestBreak")
local i = 0
Expand Down Expand Up @@ -80,24 +80,23 @@ local gridFindBestBreak = function(options)
end
if badness > 0 then
local onepage = {}
for j=1,bestBreak do
onepage[j] = table.remove(vboxlist,1)
for j=1, bestBreak do
onepage[j] = table.remove(vboxlist, 1)
end
while(#onepage > 1 and onepage[#onepage].discardable) do onepage[#onepage] = nil end
return onepage, 1000
end
bestBreak = i
end
local left = target - totalHeight.length
return false, false
end

SILE.registerCommand("grid:debug", function(o,c)
SILE.registerCommand("grid:debug", function (_, _)
debugGrid()
SILE.typesetter:registerNewFrameHook(debugGrid)
end)

SILE.registerCommand("grid", function(options, content)
SILE.registerCommand("grid", function (options, _)
SILE.typesetter.state.grid = true
SU.required(options, "spacing", "grid package")
gridSpacing = SILE.parseComplexFrameDimension(options.spacing)
Expand All @@ -110,22 +109,22 @@ SILE.registerCommand("grid", function(options, content)
SILE.typesetter.pushVglue = pushVglue
if SILE.typesetter.frame then
SILE.typesetter.frame.state.totals.gridCursor = 0
SILE.typesetter.state.previousVbox = SILE.defaultTypesetter.pushVbox(SILE.typesetter,{})
SILE.typesetter.state.previousVbox = SILE.defaultTypesetter.pushVbox(SILE.typesetter, {})
end
SILE.typesetter:registerNewFrameHook(function (this)
this.frame.state.totals.gridCursor = 0
while this.state.outputQueue[1] and this.state.outputQueue[1].discardable do
table.remove(this.state.outputQueue,1)
SILE.typesetter:registerNewFrameHook(function (self)
self.frame.state.totals.gridCursor = 0
while self.state.outputQueue[1] and self.state.outputQueue[1].discardable do
table.remove(self.state.outputQueue, 1)
end
if this.state.outputQueue[1] then
table.insert(this.state.outputQueue, 1, SILE.nodefactory.newVbox({}))
table.insert(this.state.outputQueue, 2, leadingFor(this, this.state.outputQueue[2], this.state.outputQueue[1]))
if self.state.outputQueue[1] then
table.insert(self.state.outputQueue, 1, SILE.nodefactory.newVbox({}))
table.insert(self.state.outputQueue, 2, leadingFor(self, self.state.outputQueue[2], self.state.outputQueue[1]))
end
end)

end, "Begins typesetting on a grid spaced at <spacing> intervals.")

SILE.registerCommand("no-grid", function (options, content)
SILE.registerCommand("no-grid", function (_, _)
SILE.typesetter.state.grid = false
SILE.typesetter.leadingFor = SILE.defaultTypesetter.leadingFor
SILE.typesetter.pushVglue = SILE.defaultTypesetter.pushVglue
Expand Down
10 changes: 5 additions & 5 deletions packages/gutenberg.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
SILE.registerCommand("alt", function(o, c)
SILE.registerCommand("alt", function (_, content)
local options = {}
for i=1,#c do
SILE.call("hbox", {}, {c[i]})
for _, fragment in ipairs(content) do
SILE.call("hbox", {}, { fragment })
options[#options + 1] = SILE.typesetter.state.nodes[#SILE.typesetter.state.nodes]
SILE.typesetter.state.nodes[#SILE.typesetter.state.nodes] = nil
end
alt = SILE.nodefactory.newAlternative({
local alt = SILE.nodefactory.newAlternative({
options=options,
selected=1
})
alt.width=nil
SILE.typesetter.state.nodes[#SILE.typesetter.state.nodes+1] = alt
end)
end)

0 comments on commit a09c452

Please sign in to comment.