Skip to content

Commit

Permalink
fix(core): Don't instantiate objects in class definitions
Browse files Browse the repository at this point in the history
Without this the shared object table causes hideous side effects. New
nodes call for new lengths and measures!
  • Loading branch information
alerque committed Jan 4, 2020
1 parent 1267a1f commit 4cdb663
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
11 changes: 6 additions & 5 deletions core/length.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ end

return pl.class({
type = "length",
length = SILE.measurement(0),
stretch = SILE.measurement(0),
shrink = SILE.measurement(0),
length = nil,
stretch = nil,
shrink = nil,

_init = function (self, spec, stretch, shrink)
if stretch or shrink then
Expand All @@ -33,8 +33,9 @@ return pl.class({
self:_init(parsed)
end
end
self.stretch.amount = self.stretch.amount
self.shrink.amount = self.shrink.amount
if not self.length then self.length = SILE.measurement() end
if not self.stretch then self.stretch = SILE.measurement() end
if not self.shrink then self.shrink = SILE.measurement() end
end,

absolute = function (self)
Expand Down
29 changes: 20 additions & 9 deletions core/nodefactory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ local infinity = SILE.measurement(1e13)

nodefactory.box = pl.class({
type = "special",
height = SILE.length(0),
depth = SILE.length(0),
width = SILE.length(0),
height = nil,
depth = nil,
width = nil,
misfit = false,
explicit = false,
discardable = false,
Expand All @@ -37,6 +37,9 @@ nodefactory.box = pl.class({
elseif SU.type(spec) ~= "nil" then
SU.error("Unimplemented, creating " .. self.type .. " node from " .. SU.type(spec), 1)
end
if not self.height then self.height = SILE.length() end
if not self.depth then self.depth = SILE.length() end
if not self.width then self.width = SILE.length() end
end,

tostring = function (self)
Expand Down Expand Up @@ -352,13 +355,19 @@ nodefactory.glue = pl.class({

nodefactory.hfillglue = pl.class({
_base = nodefactory.glue,
width = SILE.length(0, infinity)
_init = function (self, spec)
self.width = SILE.length(0, infinity)
nodefactory.glue._init(self, spec)
end
})

nodefactory.hssglue = pl.class({
-- possible bug, deprecated constructor actually used vglue for this
_base = nodefactory.glue,
width = SILE.length(0, infinity, infinity)
_init = function (self, spec)
self.width = SILE.length(0, infinity, infinity)
nodefactory.glue._init(self, spec)
end
})

nodefactory.kern = pl.class({
Expand All @@ -376,7 +385,12 @@ nodefactory.vglue = pl.class({
type = "vglue",
discardable = true,
_default_length = "height",
adjustment = SILE.measurement(),
adjustment = nil,

_init = function (self, spec)
self.adjustment = SILE.measurement()
nodefactory.box._init(self, spec)
end,

__tostring = function (self)
return (self.explicit and "E:" or "") .. "VG<" .. self.height .. ">";
Expand All @@ -396,10 +410,7 @@ nodefactory.vglue = pl.class({

nodefactory.vfillglue = pl.class({
_base = nodefactory.vglue,
height = SILE.length(0, infinity),
_init = function (self, spec)
-- TODO this shouldn't be necessary, but without it somehow new vfillglues
-- are getting heights inherited from previous page metrics!
self.height = SILE.length(0, infinity)
nodefactory.vglue._init(self, spec)
end
Expand Down

0 comments on commit 4cdb663

Please sign in to comment.