Skip to content

Commit

Permalink
Tests for FileAttachment annotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMatthias committed Jun 5, 2021
1 parent 3bb33ab commit 1ddbb32
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ See [examples/](examples) for more advanced examples.
Following annotations are implemented so far:

- Square, Circle
- Highlight, Underline, StrikeOut, Squiggly
- TextMarkup (Highlight, Underline, Squiggly, StrikeOut)
- Text, FreeText
- Link
- Line
- FileAttachment

## Requirements
Flare is designed for LuaTeX. Other TeX engines are not supported.
Expand Down
Binary file added test/pdf/fileattachment-01.pdf
Binary file not shown.
Binary file added test/pdf/fileattachment-02.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions test/pdf/fileattachment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is referenced from fileattachment-01.pdf.
63 changes: 63 additions & 0 deletions test/test-flare-annot3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,67 @@ test('Page:getAnnotLine()',
end)


test('Page:getAnnotFileAttachment() #ok',
function()

--
-- pdf/fileattachment-01.pdf
--
local pdf_fn = createTestFile(
'fileattachment-01',
'\\includegraphics[scale=0.5]{pdf/fileattachment-01.pdf}')

local d = Doc:new()
local p = Page:new(d)
local pagenum = 1
p:setGinKV('filename', pdf_fn)
p:setGinKV('page', pagenum)
p:openFile()
local pdf = pdfe.open(pdf_fn)
local annot = pdfe.getpage(pdf, 1).Annots[1]
local page_objnum = p:getPageObjNum(pagenum)

assert.same('Annot', annot.Type)
assert.same('FileAttachment', annot.Subtype)
assert.same(page_objnum, luatex.getreference(annot, 'P'))
assert.same('PushPin', annot.Name)

assert.same('Filespec', annot.FS.Type)
assert.same('fileattachment.txt', annot.FS.F)


--
-- pdf/fileattachment-02.pdf
--
local pdf_fn = createTestFile(
'fileattachment-02',
'\\includegraphics[scale=0.5]{pdf/fileattachment-02.pdf}')

local d = Doc:new()
local p = Page:new(d)
local pagenum = 1
p:setGinKV('filename', pdf_fn)
p:setGinKV('page', pagenum)
p:openFile()
local pdf = pdfe.open(pdf_fn)
local annot = pdfe.getpage(pdf, 1).Annots[1]
local page_objnum = p:getPageObjNum(pagenum)

assert.same('Annot', annot.Type)
assert.same('FileAttachment', annot.Subtype)
assert.same(page_objnum, luatex.getreference(annot, 'P'))
assert.same('PushPin', annot.Name)

assert.same('Filespec', annot.FS.Type)
assert.same('foo.txt', annot.FS.F)

local stream, len = pdfe.readwholestream(annot.FS.EF.F)
assert.same('This is an embedded file.\n' ..
'Just testing.\n\n',
stream)
assert.same(41, len)

end)


end) -- describe

0 comments on commit 1ddbb32

Please sign in to comment.