feat: implement PDF annotation extraction and inspector API endpoints via C++ bindings

This commit is contained in:
azeeee05
2026-07-09 10:38:26 +05:30
parent 62ad42b116
commit 82a07d2e6e
7 changed files with 28 additions and 1 deletions
@@ -198,6 +198,7 @@ public:
std::string content;
std::string timestamp;
int pageIndex = 0;
double thickness = 0.0;
std::vector<std::vector<Point2D>> paths;
std::vector<std::array<Point2D, 4>> quadPoints;
@@ -384,6 +384,10 @@ std::expected<void, EngineError> PdfiumDocument::applyOp_freehand(const nlohmann
float thickness = static_cast<float>(data.value("thickness", 2.0));
FPDFAnnot_SetBorder(annot, 0.0f, 0.0f, thickness);
std::string tStr = std::to_string(thickness);
auto tUtf16 = utf8_to_utf16le(tStr);
FPDFAnnot_SetStringValue(annot, "CustomThickness", reinterpret_cast<FPDF_WIDESTRING>(tUtf16.data()));
float minX = 1e9f, minY = 1e9f, maxX = -1e9f, maxY = -1e9f;
bool anyPoints = false;
@@ -550,6 +554,10 @@ std::expected<void, EngineError> PdfiumDocument::applyOp_updateAnnotation(const
if (data.contains("thickness")) {
float thickness = static_cast<float>(data["thickness"].get<double>());
FPDFAnnot_SetBorder(targetAnnot, 0.0f, 0.0f, thickness);
std::string tStr = std::to_string(thickness);
auto tUtf16 = utf8_to_utf16le(tStr);
FPDFAnnot_SetStringValue(targetAnnot, "CustomThickness", reinterpret_cast<FPDF_WIDESTRING>(tUtf16.data()));
}
if (data.contains("text")) {
+15
View File
@@ -600,6 +600,21 @@ std::expected<std::vector<PdfPage::AnnotationInfo>, EngineError> PdfiumPage::ext
}
if (subtype == FPDF_ANNOT_INK) {
float h_radius = 0, v_radius = 0, border_width = 1.0f;
info.thickness = 2.0; // default
unsigned long ctLen = FPDFAnnot_GetStringValue(annot, "CustomThickness", nullptr, 0);
if (ctLen > 2) {
std::vector<char16_t> ctBuf(ctLen / 2);
FPDFAnnot_GetStringValue(annot, "CustomThickness", reinterpret_cast<FPDF_WCHAR*>(ctBuf.data()), ctLen);
std::string ctStr = utf16le_to_utf8(ctBuf.data(), ctBuf.size());
try {
info.thickness = std::stod(ctStr);
} catch (...) {}
} else if (FPDFAnnot_GetBorder(annot, &h_radius, &v_radius, &border_width)) {
info.thickness = border_width;
}
const double pageH = height();
unsigned long strokeCount = FPDFAnnot_GetInkListCount(annot);
for (unsigned long s = 0; s < strokeCount; ++s) {