Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
20 changes: 20 additions & 0 deletions core/fpdfapi/parser/cpdf_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ class CPDF_Document : public Observable,
epdf_attachment_ = std::move(attachment);
}

// EmbedPDF(fonts): the document's font index (CPDF_DocumentFonts in
// core/fpdfdoc), made on first use: what each embedded font program is,
// and the session's font state. Destroyed before the parser.
class FontIndex {
public:
virtual ~FontIndex() = default;
// A layer's transaction ended, committed or aborted: |objnums| are every
// object number it wrote, created or hid, and the overlay epoch was
// |epoch_at_begin| when it began and is |epoch| now.
virtual void TransactionEnded(const std::set<uint32_t>& objnums,
uint64_t epoch_at_begin,
uint64_t epoch) {}
};
FontIndex* font_index() const { return font_index_.get(); }
void SetFontIndex(std::unique_ptr<FontIndex> index) {
font_index_ = std::move(index);
}

// EmbedPDF(fonts): session-scoped provenance for a resource name this
// document instance handed out for a registered runtime font (a /DA font
// alias reserved before its /DR entry exists). Never written to the file; a
Expand Down Expand Up @@ -438,6 +456,8 @@ class CPDF_Document : public Observable,
// EmbedPDF(signatures): destroyed before everything declared above it (the
// parser included), after the extension and the stock font clearer.
std::unique_ptr<Attachment> epdf_attachment_;
// EmbedPDF(fonts): see font_index(); destroyed before the attachment.
std::unique_ptr<FontIndex> font_index_;

// Must be second to last.
StockFontClearer stock_font_clearer_;
Expand Down
7 changes: 7 additions & 0 deletions core/fpdfapi/parser/cpdf_layer_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ bool CPDF_LayerDocument::BeginTransaction() {
CPDF_WriteGeneration::SetCurrent(transaction_->generation);
transaction_->root_before = GetCachedRootDict();
transaction_->info_before = GetCachedInfoDict();
transaction_->epoch_at_begin = overlay_epoch_;
return true;
}

Expand Down Expand Up @@ -541,6 +542,9 @@ bool CPDF_LayerDocument::CommitTransaction() {
}
last_transaction_stats_ = tx->stats;
++overlay_epoch_;
if (FontIndex* index = font_index()) {
index->TransactionEnded(tx->touched, tx->epoch_at_begin, overlay_epoch_);
}
return true;
}

Expand Down Expand Up @@ -569,6 +573,9 @@ bool CPDF_LayerDocument::AbortTransaction() {
ForgetDerivedDataOf(unreachable);
last_transaction_stats_ = tx->stats;
++overlay_epoch_;
if (FontIndex* index = font_index()) {
index->TransactionEnded(tx->touched, tx->epoch_at_begin, overlay_epoch_);
}
// tx->written and tx->hidden are dropped with tx. Nothing is undone.
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions core/fpdfapi/parser/cpdf_layer_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class CPDF_LayerDocument final : public CPDF_Document {
bool CommitTransaction();
bool AbortTransaction();
bool InTransaction() const { return !!transaction_; }
// EmbedPDF(fonts): the open transaction, for a derived cache that reads
// mid-write (what it has touched so far); null outside one.
const CPDF_LayerTransaction* open_transaction() const {
return transaction_.get();
}
// What the last ended (or the open) transaction cost.
const CPDF_LayerTransactionStats& GetTransactionStats() const {
return transaction_ ? transaction_->stats : last_transaction_stats_;
Expand Down
4 changes: 4 additions & 0 deletions core/fpdfapi/parser/cpdf_layer_transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ struct CPDF_LayerTransaction {
RetainPtr<CPDF_Dictionary> root_before;
RetainPtr<CPDF_Dictionary> info_before;

// EmbedPDF(fonts): the overlay epoch at begin, for the font index to tell
// what changed outside any transaction.
uint64_t epoch_at_begin = 0;

CPDF_LayerTransactionStats stats;
};

Expand Down
9 changes: 9 additions & 0 deletions core/fpdfdoc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ source_set("fpdfdoc") {
# EmbedPDF: a font as a face (family, weight, italic), one reader for all.
"cpdf_fontface.cpp",
"cpdf_fontface.h",
# EmbedPDF: the fonts a document uses and what each program is, a
# document font as a browser can draw it, and the fonts a write would
# draw text with (a resolver read).
"cpdf_displayprogram.cpp",
"cpdf_displayprogram.h",
"cpdf_documentfonts.cpp",
"cpdf_documentfonts.h",
"cpdf_fontresolver.cpp",
"cpdf_fontresolver.h",
"cpdf_richtext.h",
"cpdf_richtextjson.cpp",
"cpdf_richtextjson.h",
Expand Down
Loading