Skip to content

Commit

Permalink
feat: add painter
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonov548 committed May 30, 2024
1 parent 327a82f commit 8366500
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ EMSCRIPTEN_BINDINGS(PODOFO)
.function("createPage", createPage, em::allow_raw_pointers())
;

em::class_<PoDoFo::PdfPage>("Page")
em::class_<PoDoFo::PdfPage, em::base<PoDoFo::PdfCanvas>>("Page")
.function("getRect", &getRect)
;

em::class_<PoDoFo::PdfCanvas>("Canvas")
;

em::class_<PoDoFo::PdfMemDocument>("Document")
.constructor()
.function("loadFromBuffer", &loadFromBuffer)
Expand All @@ -118,6 +121,21 @@ EMSCRIPTEN_BINDINGS(PODOFO)
.function("resetTitle", &resetTitle)
;

em::class_<PoDoFo::PdfPainter>("Painter")
.constructor()
.function("setCanvas", &PoDoFo::PdfPainter::SetCanvas)
.function("drawCircle", &PoDoFo::PdfPainter::DrawCircle)
.function("finishDrawing", &PoDoFo::PdfPainter::FinishDrawing)
;

em::enum_<PoDoFo::PdfPathDrawMode>("PathDrawMode")
.value("Stroke", PoDoFo::PdfPathDrawMode::Stroke)
.value("Fill", PoDoFo::PdfPathDrawMode::Fill)
.value("StrokeFill", PoDoFo::PdfPathDrawMode::StrokeFill)
.value("FillEvenOdd", PoDoFo::PdfPathDrawMode::FillEvenOdd)
.value("StrokeFillEvenOdd", PoDoFo::PdfPathDrawMode::StrokeFillEvenOdd)
;

em::function("makeBuffer", &makeBuffer);
em::function("getPageSize", &getPageSize);

Expand Down
16 changes: 16 additions & 0 deletions tests/unit_tests/painter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('podofo.js', () => {
it('simple paint', async () => {
const Podofo = global.Podofo;

const document = new Podofo.Document();
const size = Podofo.getPageSize(Podofo.PageSize.A4, false);
const page = document.getPages()
.createPage(size);


const painter = new Podofo.Painter();
painter.setCanvas(page);
painter.drawCircle(100, 500, 20, Podofo.PathDrawMode.Fill);
painter.finishDrawing();
});
});
9 changes: 9 additions & 0 deletions tests/unit_tests/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs');
const path = require('path');

const writeToFile = (buffer, name) => {
const filePath = path.join(__dirname, name);
fs.writeFileSync(filePath, buffer);
}

module.exports = { writeToFile };

0 comments on commit 8366500

Please sign in to comment.