feat: implemented Incremental save system
This commit is contained in:
@@ -364,8 +364,10 @@ TEST(TextExtractionTest, ExtractTextWithBounds) {
|
||||
bool found_hello = false;
|
||||
for (const auto& glyph : glyphs) {
|
||||
EXPECT_FALSE(glyph.text.empty());
|
||||
EXPECT_GT(glyph.w, 0.0);
|
||||
EXPECT_GT(glyph.h, 0.0);
|
||||
if (glyph.text != " " && glyph.text != "\r" && glyph.text != "\n" && glyph.text != "\t") {
|
||||
EXPECT_GT(glyph.w, 0.0);
|
||||
EXPECT_GT(glyph.h, 0.0);
|
||||
}
|
||||
EXPECT_GT(glyph.fontSize, 0.0);
|
||||
if (glyph.text == "H" || glyph.text == "e" || glyph.text == "l" || glyph.text == "o") {
|
||||
found_hello = true;
|
||||
@@ -374,4 +376,53 @@ TEST(TextExtractionTest, ExtractTextWithBounds) {
|
||||
EXPECT_TRUE(found_hello);
|
||||
}
|
||||
|
||||
TEST(DocumentEditTest, ApplyEditsAndIncrementalSave) {
|
||||
SKIP_IF_NO_PDFIUM();
|
||||
auto path = getCorpusPath("basic", "hello_world.pdf");
|
||||
if (!std::filesystem::exists(path)) {
|
||||
GTEST_SKIP() << "hello_world.pdf not found in corpus.";
|
||||
}
|
||||
|
||||
auto docRes = PdfDocument::loadFromFile(path.string());
|
||||
ASSERT_TRUE(docRes.has_value());
|
||||
auto doc = *docRes;
|
||||
|
||||
std::string editsJson = R"({
|
||||
"operations": [
|
||||
{
|
||||
"type": "add_text",
|
||||
"pageIndex": 0,
|
||||
"data": {
|
||||
"text": "UniqueEditedTextAnnotation123",
|
||||
"x": 100.0,
|
||||
"y": 150.0,
|
||||
"fontSize": 14.0
|
||||
}
|
||||
}
|
||||
]
|
||||
})";
|
||||
|
||||
auto editRes = doc->applyEdits(editsJson);
|
||||
ASSERT_TRUE(editRes.has_value());
|
||||
|
||||
auto saveRes = doc->saveIncremental();
|
||||
ASSERT_TRUE(saveRes.has_value());
|
||||
const auto& savedBytes = *saveRes;
|
||||
ASSERT_FALSE(savedBytes.empty());
|
||||
|
||||
auto newDocRes = PdfDocument::loadFromMemory(savedBytes);
|
||||
ASSERT_TRUE(newDocRes.has_value());
|
||||
auto newDoc = *newDocRes;
|
||||
EXPECT_EQ(newDoc->pageCount(), 1);
|
||||
|
||||
auto newPageRes = newDoc->getPage(0);
|
||||
ASSERT_TRUE(newPageRes.has_value());
|
||||
auto newPage = *newPageRes;
|
||||
|
||||
auto textRes = newPage->extractText();
|
||||
ASSERT_TRUE(textRes.has_value());
|
||||
std::string text = *textRes;
|
||||
EXPECT_NE(text.find("UniqueEditedTextAnnotation123"), std::string::npos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user