fix
This commit is contained in:
@@ -48,6 +48,7 @@ void get_or_throw(std::expected<void, pdfengine::EngineError>&& res) {
|
||||
#include <parser/lexer.hpp>
|
||||
#include <parser/parser.hpp>
|
||||
#include <pdfengine/content_object.hpp>
|
||||
#include <pdfengine/ocr/ocr_coordinator.hpp>
|
||||
#include <qpdf/qpdf_extractor.hpp>
|
||||
#include <qpdf/qpdf_writer.hpp>
|
||||
#include <serializer/ast_serializer.hpp>
|
||||
@@ -316,6 +317,8 @@ PYBIND11_MODULE(pdfengine, m) {
|
||||
.def_readonly("font_size", &pdfengine::TextRun::fontSize)
|
||||
.def_readonly("internal_font_id", &pdfengine::TextRun::internalFontId)
|
||||
.def_readonly("is_embedded", &pdfengine::TextRun::isEmbedded)
|
||||
.def_readonly("is_embedded_font", &pdfengine::TextRun::isEmbeddedFont)
|
||||
.def_readonly("is_predicted_font", &pdfengine::TextRun::isPredictedFont)
|
||||
.def_readonly("type", &pdfengine::TextRun::type)
|
||||
.def_readonly("glyphs", &pdfengine::TextRun::glyphs)
|
||||
.def_readonly("x", &pdfengine::TextRun::x)
|
||||
@@ -605,4 +608,56 @@ PYBIND11_MODULE(pdfengine, m) {
|
||||
std::vector<uint8_t> res = get_or_throw(self.saveFullForExport());
|
||||
return py::bytes(reinterpret_cast<const char*>(res.data()), res.size());
|
||||
});
|
||||
|
||||
py::class_<pdfengine::ocr::OCRCoordinator>(m, "OCRCoordinator")
|
||||
.def(py::init<>())
|
||||
.def(
|
||||
"process_document",
|
||||
[](const pdfengine::ocr::OCRCoordinator& self, int pageIndex, double imgW, double imgH,
|
||||
double pdfW, double pdfH, const py::list& lines_list) {
|
||||
std::vector<pdfengine::document::RawOCRLine> cpp_lines;
|
||||
for (auto item : lines_list) {
|
||||
py::dict d = item.cast<py::dict>();
|
||||
pdfengine::document::RawOCRLine line;
|
||||
if (d.contains("text"))
|
||||
line.text = d["text"].cast<std::string>();
|
||||
if (d.contains("confidence"))
|
||||
line.confidence = d["confidence"].cast<double>();
|
||||
if (d.contains("fontSize"))
|
||||
line.fontSize = d["fontSize"].cast<double>();
|
||||
if (d.contains("fontName"))
|
||||
line.fontName = d["fontName"].cast<std::string>();
|
||||
if (d.contains("fontId"))
|
||||
line.fontId = d["fontId"].cast<std::string>();
|
||||
if (d.contains("isBold"))
|
||||
line.isBold = d["isBold"].cast<bool>();
|
||||
if (d.contains("isItalic"))
|
||||
line.isItalic = d["isItalic"].cast<bool>();
|
||||
if (d.contains("lineSpacing"))
|
||||
line.lineSpacing = d["lineSpacing"].cast<double>();
|
||||
if (d.contains("letterSpacing"))
|
||||
line.letterSpacing = d["letterSpacing"].cast<double>();
|
||||
|
||||
if (d.contains("box")) {
|
||||
py::dict box = d["box"].cast<py::dict>();
|
||||
line.x = box["x"].cast<double>();
|
||||
line.y = box["y"].cast<double>();
|
||||
line.width = box["width"].cast<double>();
|
||||
line.height = box["height"].cast<double>();
|
||||
} else {
|
||||
if (d.contains("x"))
|
||||
line.x = d["x"].cast<double>();
|
||||
if (d.contains("y"))
|
||||
line.y = d["y"].cast<double>();
|
||||
if (d.contains("width"))
|
||||
line.width = d["width"].cast<double>();
|
||||
if (d.contains("height"))
|
||||
line.height = d["height"].cast<double>();
|
||||
}
|
||||
cpp_lines.push_back(line);
|
||||
}
|
||||
return self.processDocument(pageIndex, imgW, imgH, pdfW, pdfH, cpp_lines);
|
||||
},
|
||||
py::arg("page_index"), py::arg("img_w"), py::arg("img_h"), py::arg("pdf_w"),
|
||||
py::arg("pdf_h"), py::arg("lines"));
|
||||
}
|
||||
Reference in New Issue
Block a user