mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:37:44 +00:00
LibPDF: Add accessor for the document's info dict
This dict contains some metadata in some files. Newer files also contain XMP metadata, but it's recommended to still include this dict as well, for compatibility with older readers. And it's much less complex than XMP, so let's support it.
This commit is contained in:
parent
826c0426f3
commit
c5c940b1c9
3 changed files with 93 additions and 0 deletions
|
@ -76,6 +76,41 @@ struct OutlineDict final : public RefCounted<OutlineDict> {
|
|||
OutlineDict() = default;
|
||||
};
|
||||
|
||||
class InfoDict {
|
||||
public:
|
||||
InfoDict(Document* document, NonnullRefPtr<DictObject> dict)
|
||||
: m_document(document)
|
||||
, m_info_dict(move(dict))
|
||||
{
|
||||
}
|
||||
|
||||
PDFErrorOr<Optional<DeprecatedString>> title() const;
|
||||
PDFErrorOr<Optional<DeprecatedString>> author() const;
|
||||
PDFErrorOr<Optional<DeprecatedString>> subject() const;
|
||||
PDFErrorOr<Optional<DeprecatedString>> keywords() const;
|
||||
|
||||
// Name of the program that created the original, non-PDF file.
|
||||
PDFErrorOr<Optional<DeprecatedString>> creator() const;
|
||||
|
||||
// Name of the program that converted the file to PDF.
|
||||
PDFErrorOr<Optional<DeprecatedString>> producer() const;
|
||||
|
||||
// FIXME: Provide some helper for parsing the date strings returned by these two methods.
|
||||
PDFErrorOr<Optional<DeprecatedString>> creation_date() const;
|
||||
PDFErrorOr<Optional<DeprecatedString>> modification_date() const;
|
||||
|
||||
private:
|
||||
PDFErrorOr<Optional<DeprecatedString>> get(DeprecatedFlyString const& name) const
|
||||
{
|
||||
if (!m_info_dict->contains(name))
|
||||
return OptionalNone {};
|
||||
return TRY(m_info_dict->get_string(m_document, name))->string();
|
||||
}
|
||||
|
||||
WeakPtr<Document> m_document;
|
||||
NonnullRefPtr<DictObject> m_info_dict;
|
||||
};
|
||||
|
||||
class Document final
|
||||
: public RefCounted<Document>
|
||||
, public Weakable<Document> {
|
||||
|
@ -124,6 +159,8 @@ public:
|
|||
/// dict is being read).
|
||||
bool can_resolve_references() { return m_parser->can_resolve_references(); }
|
||||
|
||||
PDFErrorOr<Optional<InfoDict>> info_dict();
|
||||
|
||||
private:
|
||||
explicit Document(NonnullRefPtr<DocumentParser> const& parser);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue