Commit b3c9b13a by Edgar Hipp

qrcode decoding works with multiple images

parent 2cd4c09c
...@@ -79,12 +79,18 @@ class ImageModule ...@@ -79,12 +79,18 @@ class ImageModule
imR.popQrQueue=(num)=> imR.popQrQueue=(num)=>
found = @qrQueue.indexOf(num) found = @qrQueue.indexOf(num)
if found!=-1 if found!=-1
@qrQueue.splice(found) @qrQueue.splice(found,1)
else throw new Error("qrqueue #{num} is not in qrqueue") else @on('error',new Error("qrqueue #{num} is not in qrqueue"))
if @qrQueue.length==0 then @finished() if @qrQueue.length==0 then @finished()
try
imR imR
.findImages() .findImages()
.replaceImages() .replaceImages()
catch e
@on('error',e)
on:(event,data)->
if event=='error'
throw data
handle:(type,data)-> handle:(type,data)->
if type=='replaceTag' and data=='image' if type=='replaceTag' and data=='image'
@replaceTag() @replaceTag()
......
...@@ -7,6 +7,7 @@ fileNames=[ ...@@ -7,6 +7,7 @@ fileNames=[
'imageLoopExample.docx', 'imageLoopExample.docx',
'imageInlineExample.docx', 'imageInlineExample.docx',
'qrExample.docx', 'qrExample.docx',
'qrExample2.docx',
] ]
ImageModule=require('../js/index.js') ImageModule=require('../js/index.js')
...@@ -136,45 +137,62 @@ describe 'qrcode replacing',-> ...@@ -136,45 +137,62 @@ describe 'qrcode replacing',->
d d
imageModule.finished=()-> imageModule.finished=()->
zip=doc.getZip() zip=docX[name].getZip()
buffer=zip.generate({type:"nodebuffer"}) buffer=zip.generate({type:"nodebuffer"})
fs.writeFile("test_qr.docx",buffer); fs.writeFile("test_qr.docx",buffer);
done() done()
doc=docX[name] docX[name]=docX[name]
.load(docX[name].loadedContent) .load(docX[name].loadedContent)
.setData({image:'image'}) .setData({image:'image'})
doc.attachModule(imageModule) docX[name].attachModule(imageModule)
doc docX[name]
.render() .render()
it 'should work with simple',-> it 'should work with simple',->
images=zip.file(/media\/.*.png/) images=zip.file(/media\/.*.png/)
expect(images.length).to.equal(2) expect(images.length).to.equal(2)
expect(images[0].asText().length).to.equal(826) expect(images[0].asText().length).to.equal(826)
expect(images[1].asText().length).to.equal(17417) expect(images[1].asText().length).to.equal(17417)
describe 'should work with two',->
zip=null
before (done)->
name='qrExample2.docx'
# imageFile=zip.files['word/media/image_generated_1.png'] imageModule=new ImageModule({qrCode:true})
# expect(imageFile?).to.equal(true)
# expect(imageFile.asText().length).to.equal(17417)
# imageFile2=zip.files['word/media/image_generated_2.png'] imageModule.getImageFromData=(imgData)->
# expect(imageFile2?).to.equal(true) d=fs.readFileSync('examples/'+imgData,'binary')
# expect(imageFile2.asText().length).to.equal(7177) d
imageModule.finished=()->
zip=docX[name].getZip()
buffer=zip.generate({type:"nodebuffer"})
fs.writeFile("test_qr2.docx",buffer);
done()
# relsFile=zip.files['word/_rels/document.xml.rels']
# expect(relsFile?).to.equal(true)
# relsFileContent=relsFile.asText()
# expect(relsFileContent).to.equal("""<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"><Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\" Target=\"styles.xml\"/><Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering\" Target=\"numbering.xml\"/><Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\" Target=\"settings.xml\"/><Relationship Id=\"rId4\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes\" Target=\"footnotes.xml\"/><Relationship Id=\"rId5\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes\" Target=\"endnotes.xml\"/><Relationship Id=\"hId0\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header\" Target=\"header0.xml\"/><Relationship Id=\"rId6\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\" Target=\"media/image_generated_1.png\"/><Relationship Id=\"rId7\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\" Target=\"media/image_generated_2.png\"/></Relationships>""")
# documentFile=zip.files['word/document.xml'] docX[name]=docX[name]
# expect(documentFile?).to.equal(true) .load(docX[name].loadedContent)
# documentContent=documentFile.asText() .setData({image:'image',image2:'image2.png'})
# # expect(documentContent).to.equal("""<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:document xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:drawing>\n <wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">\n <wp:extent cx=\"1905000\" cy=\"1905000\"/>\n <wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>\n <wp:docPr id=\"2\" name=\"Image 2\" descr=\"description\"/>\n <wp:cNvGraphicFramePr>\n <a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/>\n </wp:cNvGraphicFramePr>\n <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">\n <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:nvPicPr>\n <pic:cNvPr id=\"0\" name=\"Picture 1\" descr=\"description\"/>\n <pic:cNvPicPr>\n <a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/>\n </pic:cNvPicPr>\n </pic:nvPicPr>\n <pic:blipFill>\n <a:blip r:embed=\"rId6\">\n <a:extLst>\n <a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\">\n <a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/>\n </a:ext>\n </a:extLst>\n </a:blip>\n <a:srcRect/>\n <a:stretch>\n <a:fillRect/>\n </a:stretch>\n </pic:blipFill>\n <pic:spPr bwMode=\"auto\">\n <a:xfrm>\n <a:off x=\"0\" y=\"0\"/>\n <a:ext cx=\"1905000\" cy=\"1905000\"/>\n </a:xfrm>\n <a:prstGeom prst=\"rect\">\n <a:avLst/>\n </a:prstGeom>\n <a:noFill/>\n <a:ln>\n <a:noFill/>\n </a:ln>\n </pic:spPr>\n </pic:pic>\n </a:graphicData>\n </a:graphic>\n </wp:inline>\n</w:drawing></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:drawing>\n <wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">\n <wp:extent cx=\"1905000\" cy=\"1905000\"/>\n <wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>\n <wp:docPr id=\"2\" name=\"Image 2\" descr=\"description\"/>\n <wp:cNvGraphicFramePr>\n <a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/>\n </wp:cNvGraphicFramePr>\n <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">\n <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:nvPicPr>\n <pic:cNvPr id=\"0\" name=\"Picture 1\" descr=\"description\"/>\n <pic:cNvPicPr>\n <a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/>\n </pic:cNvPicPr>\n </pic:nvPicPr>\n <pic:blipFill>\n <a:blip r:embed=\"rId7\">\n <a:extLst>\n <a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\">\n <a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/>\n </a:ext>\n </a:extLst>\n </a:blip>\n <a:srcRect/>\n <a:stretch>\n <a:fillRect/>\n </a:stretch>\n </pic:blipFill>\n <pic:spPr bwMode=\"auto\">\n <a:xfrm>\n <a:off x=\"0\" y=\"0\"/>\n <a:ext cx=\"1905000\" cy=\"1905000\"/>\n </a:xfrm>\n <a:prstGeom prst=\"rect\">\n <a:avLst/>\n </a:prstGeom>\n <a:noFill/>\n <a:ln>\n <a:noFill/>\n </a:ln>\n </pic:spPr>\n </pic:pic>\n </a:graphicData>\n </a:graphic>\n </wp:inline>\n</w:drawing></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r><w:bookmarkStart w:id=\"20\" w:name=\"_GoBack\"/><w:bookmarkEnd w:id=\"20\"/></w:p><w:sectPr><w:headerReference w:type=\"default\" r:id=\"hId0\"/><w:type w:val=\"continuous\"/><w:pgSz w:w=\"12240\" w:h=\"15840\" w:orient=\"portrait\"/><w:pgMar w:top=\"2810\" w:left=\"1800\" w:right=\"1800\" w:bottom=\"1440\"/><w:cols w:num=\"1\" w:sep=\"off\" w:equalWidth=\"1\"/></w:sectPr></w:body></w:document>""")
docX[name].attachModule(imageModule)
docX[name]
.render()
it 'should work with two',->
images=zip.file(/media\/.*.png/)
expect(images.length).to.equal(4)
expect(images[0].asText().length).to.equal(859)
expect(images[1].asText().length).to.equal(826)
expect(images[2].asText().length).to.equal(17417)
expect(images[3].asText().length).to.equal(7177)
# it 'should work with inline images',()-> # it 'should work with inline images',()->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment