Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/embedpdf/fork-ledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ saved.
edits, and the copy happens outside any transaction. On a frozen base it writes shared state.
**Where.** Const walks in the content parser, `cpdf_interactiveform.cpp`, `cpdf_nametree.cpp`
(`CreateForReading`), `cpdf_linklist.cpp` and `cpdf_annotlist.cpp`; in-memory appearances in
`cpdf_annot.cpp`. Writes that read first: the field pruning in `fpdf_flatten.cpp` compares fields
read const and takes an array mutable only when an entry goes.
`cpdf_annot.cpp`, and where one draws (`EPDFAnnot_GetDrawingRect` in `epdf_annot.cpp`). Writes
that read first: the field pruning in `fpdf_flatten.cpp` compares fields read const and takes an
array mutable only when an entry goes.
**Guarded by.** `cpdf_read_only_graph_guard_unittest.cpp`,
`EPDFAnnotEmbedderTest.DrawingARedactionMarkWithoutAppearanceWritesNone`,
`EPDFAnnotEmbedderTest.AskingWhereAMarkDrawsLeavesALayerAlone`,
`EPDFStampResizeEmbedderTest.ADrawingFromALayersPageLeavesTheLayerAlone`; layer mode's list of
tests that write (`testing/embedpdf_layer_mode_writers.txt`): a test that only reads must leave
nothing in a layer.
Expand Down
8 changes: 5 additions & 3 deletions fpdfsdk/epdf_annot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4537,13 +4537,15 @@ EPDFAnnot_GetDrawingRect(FPDF_ANNOTATION annot,
if (!context || !rect) {
return false;
}
RetainPtr<CPDF_Dictionary> dict = context->GetMutableAnnotDict();
const CPDF_Dictionary* dict = context->GetAnnotDict();
CPDF_Document* doc = context->GetPage()->GetDocument();
if (!dict || !doc) {
return false;
}
// Generating only when drawn: asking where it draws writes nothing.
CPDF_Annot drawn(std::move(dict), doc,
// Generating only when drawn, from a dictionary read as a render reads it:
// asking where it draws writes nothing. Taken for writing, the dictionary
// would be copied into a layer.
CPDF_Annot drawn(pdfium::WrapRetain(const_cast<CPDF_Dictionary*>(dict)), doc,
CPDF_Annot::MissingAppearance::kGenerateWhenDrawn);
std::optional<CFX_FloatRect> box = drawn.GetDrawingRect(
static_cast<CPDF_Annot::AppearanceMode>(appearanceMode));
Expand Down
29 changes: 29 additions & 0 deletions fpdfsdk/epdf_annot_embeddertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,35 @@ TEST_F(EPDFAnnotEmbedderTest, DrawingARedactionMarkWithoutAppearanceWritesNone)
EPDF_ReleaseBaseDocument(base);
}

// Asking where a mark without an appearance draws (redact_annot.pdf) only
// reads it: on a layer the mark's dictionary is not copied in, so the layer
// holds as little afterwards as before.
TEST_F(EPDFAnnotEmbedderTest, AskingWhereAMarkDrawsLeavesALayerAlone) {
FileAccessForTesting base_access("redact_annot.pdf");
EPDF_BASE_DOCUMENT base = EPDF_LoadBaseDocument(&base_access, nullptr);
ASSERT_TRUE(base);
{
ScopedFPDFDocument layer(
EPDFLayer_OpenLayer(base, nullptr, nullptr, nullptr));
ASSERT_TRUE(layer);
ScopedFPDFPage page(FPDF_LoadPage(layer.get(), 0));
ASSERT_TRUE(page);
ScopedFPDFAnnotation mark(FPDFPage_GetAnnot(page.get(), 0));
ASSERT_EQ(FPDF_ANNOT_REDACT, FPDFAnnot_GetSubtype(mark.get()));
ASSERT_FALSE(FPDFAnnot_HasKey(mark.get(), "AP"));
ASSERT_EQ(0u, EPDFLayer_GetPromotedObjectCount(layer.get()));

FS_RECTF drawn = {};
ASSERT_TRUE(EPDFAnnot_GetDrawingRect(
mark.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, &drawn));
EXPECT_GT(drawn.right, drawn.left);
EXPECT_GT(drawn.top, drawn.bottom);
EXPECT_FALSE(FPDFAnnot_HasKey(mark.get(), "AP"));
EXPECT_EQ(0u, EPDFLayer_GetPromotedObjectCount(layer.get()));
}
EPDF_ReleaseBaseDocument(base);
}

TEST_F(EPDFAnnotEmbedderTest, DrawingRectIsWhereTheAppearanceIsDrawn) {
embedpdf_test::ScopedTestDocument doc(NewTestDocument());
ASSERT_TRUE(doc);
Expand Down