Implement pdf.[gs]etpage{resources,s?attributes}
This commit is contained in:
parent
5262457cd8
commit
697f874089
@ -84,7 +84,7 @@ token.luacmd("shipout", function()
|
||||
local out, resources, annots = writer(pfile, list, fontdirs, usedglyphs, colorstacks)
|
||||
cur_page = nil
|
||||
local content = pfile:stream(nil, '', out)
|
||||
pfile:indirect(page, string.format([[<</Type/Page/Parent %i 0 R/Contents %i 0 R/MediaBox[0 %i %i %i]/Resources%s%s%s>>]], parent, content, -math.ceil(to_bp(list.depth)), math.ceil(to_bp(list.width)), math.ceil(to_bp(list.height)), resources(pdfvariable.pageresources), annots, pdfvariable.pageattr))
|
||||
pfile:indirect(page, string.format([[<</Type/Page/Parent %i 0 R/Contents %i 0 R/MediaBox[0 %i %i %i]/Resources%s%s%s%s>>]], parent, content, -math.ceil(to_bp(list.depth)), math.ceil(to_bp(list.width)), math.ceil(to_bp(list.height)), resources(pdfvariable.pageresources .. pdf.pageresources), annots, pdfvariable.pageattr, pdf.pageattributes))
|
||||
node.flush_list(list)
|
||||
token.put_next(reset_deadcycles)
|
||||
token.scan_token()
|
||||
@ -924,3 +924,13 @@ end, "protected", "value")
|
||||
token.luacmd("lastypos", function()
|
||||
return integer_code, (saved_pos_y+.5)//1
|
||||
end, "protected", "value")
|
||||
|
||||
local function pdf_register_funcs(name)
|
||||
pdf[name] = ""
|
||||
pdf['get' .. name] = function() return pdf[name] end
|
||||
pdf['set' .. name] = function(s) pdf[name] = assert(s) end
|
||||
end
|
||||
|
||||
pdf_register_funcs'pageattributes'
|
||||
pdf_register_funcs'pageresources'
|
||||
pdf_register_funcs'pagesattributes'
|
||||
|
@ -1,12 +1,13 @@
|
||||
local pdf = pdf
|
||||
local min = math.min
|
||||
local format = string.format
|
||||
local concat = table.concat
|
||||
local pdfvariable = pdf.variable
|
||||
local function write(pdf, tree, total, max)
|
||||
tree = tree or pdf.pages
|
||||
local function write(pfile, tree, total, max)
|
||||
tree = tree or pfile.pages
|
||||
if #tree == 0 then
|
||||
local id = pdf:getobj()
|
||||
pdf:indirect(id, '<</Type/Pages/Kids[]/Count 0>>')
|
||||
local id = pfile:getobj()
|
||||
pfile:indirect(id, '<</Type/Pages/Kids[]/Count 0>>')
|
||||
return id
|
||||
end
|
||||
max = max or 6 -- These defaults only work on the lowest level
|
||||
@ -20,37 +21,37 @@ local function write(pdf, tree, total, max)
|
||||
local id = tree[-i]
|
||||
newtree[i+1] = id
|
||||
if 0 == i % 6 and #tree > 6 then
|
||||
local parentid = pdf:getobj()
|
||||
local parentid = pfile:getobj()
|
||||
newtree[-(i//6)] = parentid
|
||||
parent = format("/Parent %i 0 R", parentid)
|
||||
elseif #tree <= 6 then
|
||||
parent = pdfvariable.pagesattr
|
||||
parent = pdfvariable.pagesattr .. pdf.pagesattributes
|
||||
end
|
||||
pdf:indirect(id, format('<</Type/Pages%s/Kids[%s 0 R]/Count %i>>', parent, concat(tree, ' 0 R ', 6*i+1, min(#tree, 6*i+6)), min(remaining, max)))
|
||||
pfile:indirect(id, format('<</Type/Pages%s/Kids[%s 0 R]/Count %i>>', parent, concat(tree, ' 0 R ', 6*i+1, min(#tree, 6*i+6)), min(remaining, max)))
|
||||
remaining = remaining - max
|
||||
end
|
||||
if newtree[0] then
|
||||
return write(pdf, newtree, total, max*6)
|
||||
return write(pfile, newtree, total, max*6)
|
||||
end
|
||||
return newtree[1]
|
||||
end
|
||||
local function newpage(pdf)
|
||||
local pages = pdf.pages
|
||||
local function newpage(pfile)
|
||||
local pages = pfile.pages
|
||||
local pagenumber = #pages+1
|
||||
local pageid = pages.reserved and pages.reserved[pagenumber]
|
||||
if pageid then
|
||||
pages.reserved[pagenumber] = nil
|
||||
else
|
||||
pageid = pdf:getobj()
|
||||
pageid = pfile:getobj()
|
||||
end
|
||||
pages[pagenumber] = pageid
|
||||
if 1 == pagenumber % 6 then
|
||||
pages[-((pagenumber-1)//6)] = pdf:getobj()
|
||||
pages[-((pagenumber-1)//6)] = pfile:getobj()
|
||||
end
|
||||
return pageid, pages[-((pagenumber-1)//6)]
|
||||
end
|
||||
local function reservepage(pdf, num)
|
||||
local pages = pdf.pages
|
||||
local function reservepage(pfile, num)
|
||||
local pages = pfile.pages
|
||||
if pages[num] then return pages[num] end
|
||||
local reserved = pages.reserved
|
||||
if reserved then
|
||||
@ -59,7 +60,7 @@ local function reservepage(pdf, num)
|
||||
reserved = {}
|
||||
pages.reserved = reserved
|
||||
end
|
||||
reserved[num] = pdf:getobj()
|
||||
reserved[num] = pfile:getobj()
|
||||
return reserved[num]
|
||||
end
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user