Skip to content

Commit

Permalink
Merge pull request #829 from alerque/measurement-stragglers
Browse files Browse the repository at this point in the history
Cleanup measurement refactoring  stragglers
  • Loading branch information
alerque committed Feb 11, 2020
2 parents b52a622 + b3628b8 commit c4e040c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
37 changes: 21 additions & 16 deletions packages/pdf.lua
Expand Up @@ -26,7 +26,10 @@ SILE.registerCommand("pdf:bookmark", function (options, _)
-- European languages, we use UTF-16BE for internationalization.
local ustr = SU.utf8_to_utf16be_hexencoded(title)
SILE.typesetter:pushHbox({
value = nil, height = 0, width = 0, depth = 0,
value = nil,
height = SILE.measurement(0),
width = SILE.measurement(0),
depth = SILE.measurement(0),
outputYourself = function ()
local d = "<</Title<" .. ustr .. ">/A<</S/GoTo/D(" .. dest .. ")>>>>"
SILE.outputters.libtexpdf._init()
Expand All @@ -50,9 +53,9 @@ end
SILE.registerCommand("pdf:literal", function (_, content)
SILE.typesetter:pushHbox({
value = nil,
height = 0,
width = 0,
depth = 0,
height = SILE.measurement(0),
width = SILE.measurement(0),
depth = SILE.measurement(0),
outputYourself = function (_, _, _)
SILE.outputters.libtexpdf._init()
pdf.add_content(content[1])
Expand All @@ -66,12 +69,12 @@ SILE.registerCommand("pdf:link", function (options, content)
local llx, lly
SILE.typesetter:pushHbox({
value = nil,
height = 0,
width = 0,
depth = 0,
height = SILE.measurement(0),
width = SILE.measurement(0),
depth = SILE.measurement(0),
outputYourself = function (_, typesetter, _)
llx = typesetter.frame.state.cursorX
lly = SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY
llx = typesetter.frame.state.cursorX:tonumber()
lly = (SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY):tonumber()
SILE.outputters.libtexpdf._init()
pdf.begin_annotation()
end
Expand All @@ -81,12 +84,14 @@ SILE.registerCommand("pdf:link", function (options, content)

SILE.typesetter:pushHbox({
value = nil,
height = 0,
width = 0,
depth = 0,
height = SILE.measurement(0),
width = SILE.measurement(0),
depth = SILE.measurement(0),
outputYourself = function (_, typesetter, _)
local d = "<</Type/Annot/Subtype/Link/C [ 1 0 0 ]/A<<" .. target .. "(" .. dest .. ")>>>>"
pdf.end_annotation(d, llx, lly, typesetter.frame.state.cursorX, SILE.documentState.paperSize[2] -typesetter.frame.state.cursorY + hbox.height)
local x = typesetter.frame.state.cursorX:tonumber()
local y = (SILE.documentState.paperSize[2] - typesetter.frame.state.cursorY + hbox.height):tonumber()
pdf.end_annotation(d, llx, lly, x, y)
end
})
end)
Expand All @@ -96,9 +101,9 @@ SILE.registerCommand("pdf:metadata", function (options, _)
local val = SU.required(options, "val", "pdf:metadata")
SILE.typesetter:pushHbox({
value = nil,
height = 0,
width = 0,
depth = 0,
height = SILE.measurement(0),
width = SILE.measurement(0),
depth = SILE.measurement(0),
outputYourself = function (_, _, _)
SILE.outputter._init()
pdf.metadata(key, val)
Expand Down
3 changes: 3 additions & 0 deletions packages/ruby.lua
@@ -1,3 +1,6 @@
-- Japaneese language support defines units which are useful here
SILE.call("language", { main = "ja" }, {})

SILE.registerCommand("ruby:font", function (_, _)
SILE.call("font", { size = "0.6zw", weight = 800 })
end)
Expand Down
11 changes: 7 additions & 4 deletions packages/tate.lua
@@ -1,3 +1,6 @@
-- Japaneese language support defines units which are useful here
SILE.call("language", { main = "ja" }, {})

SILE.tateFramePrototype = pl.class({
_base = SILE.framePrototype,
direction = "TTB-RTL",
Expand Down Expand Up @@ -37,7 +40,7 @@ local outputLatinInTate = function (self, typesetter, line)
local vorigin = -typesetter.frame.state.cursorY
self:oldOutputYourself(typesetter,line)
typesetter.frame.state.cursorY = -vorigin
typesetter.frame:advanceWritingDirection(self:lineContribution().length)
typesetter.frame:advanceWritingDirection(self:lineContribution())
-- My baseline moved
typesetter.frame:advanceWritingDirection(SILE.measurement("0.5zw") )
typesetter.frame:advancePageDirection(-SILE.measurement("0.25zw"))
Expand All @@ -46,9 +49,9 @@ end

local outputTateChuYoko = function (self, typesetter, line)
-- My baseline moved
local em = SILE.toPoints("1zw")
typesetter.frame:advanceWritingDirection(-(em) + em/4 - self:lineContribution()/2)
typesetter.frame:advancePageDirection(2*self.height - self.width.length/2)
local em = SILE.measurement("1zw")
typesetter.frame:advanceWritingDirection(-em + em/4 - self:lineContribution()/2)
typesetter.frame:advancePageDirection(2*self.height - self.width/2)
self:oldOutputYourself(typesetter,line)
typesetter.frame:advanceWritingDirection(-self:lineContribution()*1.5+self.height*3/4)

Expand Down

0 comments on commit c4e040c

Please sign in to comment.