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
8 changes: 8 additions & 0 deletions core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,14 @@ CPDF_PageContentGenerator::GenerateModifiedStreams() {
for (int32_t i = 0; i <= last_index; ++i) {
all_dirty_streams.insert(i);
}
// Every stream is written again from objects that carry their whole
// matrix, so no stream takes a CTM from the one before it or leaves one
// for the next: where the content was cut into streams stops mattering.
// Without this, each stream would undo the CTM the old stream began with
// and re-create the one it ended with, which fails where that CTM has no
// inverse, and upstream's `cm` for it below multiplies the wrong way
// round (see EPDFContentRewriteEmbedderTest.KeepsContentCutIntoStreams).
obj_holder_->ForgetStreamCTMs();
}
// --- end embedpdf

Expand Down
5 changes: 5 additions & 0 deletions core/fpdfapi/page/cpdf_pageobjectholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ CFX_Matrix CPDF_PageObjectHolder::GetCTMAtEndOfStream(int32_t stream) {
return it != all_ctms_.end() ? it->second : all_ctms_.rbegin()->second;
}

// EmbedPDF(faithful-content-rewrite): see the header.
void CPDF_PageObjectHolder::ForgetStreamCTMs() {
all_ctms_.clear();
}

void CPDF_PageObjectHolder::LoadTransparencyInfo() {
RetainPtr<const CPDF_Dictionary> pGroup = dict_->GetDictFor("Group");
if (!pGroup) {
Expand Down
6 changes: 6 additions & 0 deletions core/fpdfapi/page/cpdf_pageobjectholder.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ class CPDF_PageObjectHolder {
// `stream` must be non-negative.
CFX_Matrix GetCTMAtEndOfStream(int32_t stream);

// EmbedPDF(faithful-content-rewrite): for a rewrite of every content
// stream. The parser recorded the CTM each stream ended at, which the next
// one began with. Streams written again take nothing from each other, so
// every stream now begins and ends at the CTM the content begins with.
void ForgetStreamCTMs();

AllRemovedResourcesMap& all_removed_resources_map() {
return all_removed_resources_map_;
}
Expand Down
16 changes: 12 additions & 4 deletions docs/embedpdf/fork-ledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,21 @@ neither is secret: the `/Perms` filler bytes (encrypted under the file key) and
### faithful-content-rewrite
**Rule.** Regenerating a page's or form's content writes back what the parser read: colour spaces
by their names, the matrix a form's content starts at, soft-mask matrices, Type3 glyphs, `TJ`
arrays, a form XObject's own resource names.
arrays, a form XObject's own resource names. A change to existing content writes every stream
again, and each stands alone (`q ... Q`, no `cm` outside it): where the content was cut into
streams makes no difference.
**Why.** Redaction and editing rewrite content, and anything the writer drops shows up far from the
edit (embedpdf/runtime#58, #59).
edit (embedpdf/runtime#58, #59). Upstream writes only the streams that changed and gives each next
stream its CTM with a `cm` whose matrix product is the wrong way round. On a page cut into streams
inside `q ... cm ... Q`, as "Microsoft: Print To PDF" writes them, a redaction moved everything
from the third stream on.
**Where.** `CPDF_PageContentGenerator`, `CPDF_PageContentManager`, `CPDF_StreamContentParser`,
`CPDF_ColorState`, `CPDF_Type3Font`.
**Guarded by.** `epdf_content_rewrite_embeddertest.cpp`, `cpdf_contentnames_unittest.cpp`.
`CPDF_ColorState`, `CPDF_Type3Font`, `CPDF_PageObjectHolder::ForgetStreamCTMs`.
**Guarded by.** `epdf_content_rewrite_embeddertest.cpp` (`WhereContentIsCutIntoStreamsChangesNothing`
runs every case page again with its content cut into streams), `cpdf_contentnames_unittest.cpp`.
**When upstream touches this.** The content generator, and what the parser records about state.
The fork never reaches upstream's `cm` between streams: a pass appends a stream or writes them all.
If upstream corrects or moves it, a rewrite of every stream still forgets the stream CTMs first.

### redaction
**Rule.** Redaction removes text, paths, images and marked content under its regions, and draws
Expand Down
Loading