done the highlight

This commit is contained in:
azeeee05
2026-06-08 16:27:53 +05:30
parent 5ea14b6fd4
commit 988f6b90df
6 changed files with 181 additions and 9 deletions
+62 -1
View File
@@ -1204,7 +1204,68 @@ std::expected<void, EngineError> PdfiumDocument::applyEdits(const std::string& e
FPDFBitmap_Destroy(bitmap);
FPDF_ClosePage(page);
} else if (type == "highlight") {
spdlog::info("Parsed highlight edit operation (stub)");
if (!op.contains("data") || !op["data"].is_object()) {
spdlog::error("highlight operation missing 'data' object");
return std::unexpected(EngineError::InvalidFormat);
}
auto data = op["data"];
std::string color = data.value("color", "#ffeb3b");
std::string author = data.value("author", "");
std::string content = data.value("content", "");
if (!data.contains("quadPoints") || !data["quadPoints"].is_array()) {
spdlog::error("highlight operation missing 'quadPoints' array");
return std::unexpected(EngineError::InvalidFormat);
}
auto quadPoints = data["quadPoints"];
FPDF_PAGE page = FPDF_LoadPage(doc_, pageIndex);
if (!page) {
spdlog::error("Failed to load page index {} for highlight", pageIndex);
return std::unexpected(EngineError::Unknown);
}
FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_HIGHLIGHT);
if (!annot) {
spdlog::error("Failed to create highlight annotation");
FPDF_ClosePage(page);
return std::unexpected(EngineError::Unknown);
}
float minX = 999999, minY = 999999, maxX = -999999, maxY = -999999;
for (const auto& qp : quadPoints) {
FS_QUADPOINTSF quad;
quad.x1 = qp.value("x1", 0.0f); quad.y1 = qp.value("y1", 0.0f);
quad.x2 = qp.value("x2", 0.0f); quad.y2 = qp.value("y2", 0.0f);
quad.x3 = qp.value("x3", 0.0f); quad.y3 = qp.value("y3", 0.0f);
quad.x4 = qp.value("x4", 0.0f); quad.y4 = qp.value("y4", 0.0f);
FPDFAnnot_AppendAttachmentPoints(annot, &quad);
minX = (std::min)({minX, quad.x1, quad.x2, quad.x3, quad.x4});
minY = (std::min)({minY, quad.y1, quad.y2, quad.y3, quad.y4});
maxX = (std::max)({maxX, quad.x1, quad.x2, quad.x3, quad.x4});
maxY = (std::max)({maxY, quad.y1, quad.y2, quad.y3, quad.y4});
}
FS_RECTF rect;
rect.left = minX; rect.bottom = minY; rect.right = maxX; rect.top = maxY;
FPDFAnnot_SetRect(annot, &rect);
unsigned int r = 0, g = 0, b = 0;
parseHexColor(color, r, g, b);
FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, r, g, b, 255);
if (!content.empty()) {
auto utf16 = utf8_to_utf16le(content);
FPDFAnnot_SetStringValue(annot, "Contents", reinterpret_cast<FPDF_WIDESTRING>(utf16.data()));
}
if (!author.empty()) {
auto utf16 = utf8_to_utf16le(author);
FPDFAnnot_SetStringValue(annot, "T", reinterpret_cast<FPDF_WIDESTRING>(utf16.data()));
}
FPDFPage_CloseAnnot(annot);
FPDF_ClosePage(page);
} else if (type == "free_text") {
spdlog::info("Parsed free_text edit operation (stub)");
} else if (type == "comment") {