Commit Graph

244 Commits

Author SHA1 Message Date
m-holger 9c86ba40d8 Fix commit 805c1ad : Reset QPDFValue::qpdf and QPDFValue::og when ...
On destruction of the QPDF object replace all indirect object references
with direct nulls.

Remove all existing code to release resolved references.

Fixes performance issue due to interaction of resetting QPDFValue::qpdf and
og members and prior code.
2022-09-04 10:41:18 +01:00
Jay Berkenbilt f772c43de8 Stop including QPDFObject.hh from other than private files
This required moving some newly inlined functions back to the cc file,
but that seems to have had no measurable performance impact.
2022-09-01 18:19:47 -04:00
Jay Berkenbilt b663926538 Remove QPDFObject::object_type_e as alias for qpdf_object_type_e 2022-09-01 18:11:22 -04:00
m-holger 2b7e9ba2f5 Remove methods and parameters obsoleted by the last two commits 2022-09-01 17:20:02 +01:00
m-holger 1bb40238e0 Add method QPDFObject::getObjGen and remove QPDFObjectHandle::og 2022-09-01 17:19:40 +01:00
m-holger 5033e3b215 Add method QPDFObject::getQPDF and remove QPDFObjectHandle::qpdf 2022-09-01 17:19:31 +01:00
m-holger 356b582cec Remove QPDFObjectHandle::newIndirect
Modify QPDFParser::parse to call QPDF::getObject instead.
2022-09-01 16:59:01 +01:00
m-holger 23d50a2f14 Remove QPDFObjectHandle::initialized 2022-09-01 14:29:38 +01:00
m-holger 114bffa089 Add private methods QPDFObjectHandle::asArray etc
Centralise casting of QPDFObjects and reduce repeated dereferencing.
2022-09-01 00:10:04 +01:00
m-holger 2a2eebcaea Modify newIndirect to set QPDFObjectHandle::obj 2022-08-31 22:47:11 +01:00
m-holger 16841bec32 Remove QPDFObjectHandle::makeReserved 2022-08-31 22:46:55 +01:00
m-holger 07b66eb0b6 Remove QPDFObjectHandle::reserved 2022-08-31 22:46:25 +01:00
m-holger 9532dca3a5 Inline QPDFObjectHandle::setParsedOffset
Part of #729
2022-08-30 14:55:45 +01:00
m-holger 6fc982b71a Move QPDFObjectHandle::setObjectDescriptionFromInput to QPDFParser
Part of #729
2022-08-30 06:42:46 +01:00
m-holger 6670c685ab Move QPDFObjectHandle::parseInternal to new class QPDFParser
Part of #729
2022-08-30 05:56:23 +01:00
m-holger c53d54b13d Add optional parameter allow_nullptr to QPDFObjectHandle::getOwningQPDF
Also, inline method and add optional parameter error_msg.
2022-08-28 22:15:59 +01:00
m-holger 407b0766b8 Inline QPDFObjectHandle::getObjGen etc
Also, make QPDFObjectHandle::isIndirect const.
2022-08-01 15:08:48 +01:00
Jay Berkenbilt b3e6d445cb Tweak "AndGet" mutator functions again
Remove any ambiguity around whether old or new value is being
returned.
2022-07-24 15:42:23 -04:00
m-holger 8b4afa428e Revert making second parameter of QPDFObjGen::QPDFObjGen optional
Also, change test for QPDFObjGen::isIndirect to obj != 0.
Delete comment from commit afd35f9.
2022-07-24 16:55:10 +01:00
m-holger afd35f9a30 Overload StreamDataProvider::provideStreamData
Use 'QPDFObjGen const&' instead of 'int, int' in signature.
2022-07-24 16:02:35 +01:00
m-holger 3404ca8ac8 QPDFObjGen : tidy QPDFObjectHandle private methods
Change method signature to use QPDFObjGen.
2022-07-24 15:59:49 +01:00
m-holger b123f79dfd Replace QPDFObjectHandle::objid and generation with QPDFObjectHandle::og 2022-07-24 15:59:49 +01:00
m-holger eeb6162f76 Add optional parameter separator to QPDFObjGen::unparse
Also, revert inlining of unparse and operator << from commit 4c6640c in
order to avoid exposing QUtil.
2022-07-24 15:41:48 +01:00
Jay Berkenbilt a603c1e395 Run format-code 2022-06-27 12:50:35 -04:00
m-holger f0a8178091 Refactor QPDFObject creation and cloning
Move responsibility for creating shared pointers to objects and cloning from QPDFObjectHandle to QPDFObject.
2022-06-27 12:47:02 -04:00
m-holger 5aa8225f49 Refactor QPDFObjectTypeAccessor and QPDFObjectHandle::dereference 2022-06-27 10:39:04 -04:00
m-holger e9c1637353 Add private method QPDFObjectHandle::getObjGenAsStr
Also, use methods to access objid and generation.
2022-06-25 08:25:32 -04:00
Jay Berkenbilt e0720eaa78 Use the default logger for other writes to stdout/stderr
When there is no context for writing output or error messages, use the
default logger.
2022-06-18 10:38:50 -04:00
Jay Berkenbilt 63c7eefe9d replaceStreamData: accept uninitialized filter/decode_parms
These mean to leave the original values alone. This is needed for
reconstructing streams from JSON given that the stream data and stream
dictionary may appear in any order in the JSON.
2022-05-20 09:16:25 -04:00
Jay Berkenbilt 56f1b411fe Back out fluent QPDFObjectHandle methods. Keep the andGet methods.
I decided these were confusing and inconsistent with how JSON works.
They muddle the API rather than improving it.
2022-05-20 09:16:25 -04:00
Jay Berkenbilt 7e7a9c4379 Parse objects; stream data is not yet handled 2022-05-20 09:16:25 -04:00
Jay Berkenbilt 9064542b5f Add private methods for reserving specific objects 2022-05-20 07:54:09 -04:00
Jay Berkenbilt c76536dd9a Implement JSON v2 output 2022-05-08 13:45:20 -04:00
Jay Berkenbilt 1bc8abfdd3 Implement JSON v2 for Stream
Not fully exercised in this commit
2022-05-08 13:45:20 -04:00
Jay Berkenbilt 16f4f94cd9 Prepare code for JSON v2
Update getJSON() methods and calls to them
2022-05-07 11:12:01 -04:00
Jay Berkenbilt c365a26e9d Revert "Remove QPDFObjectHandle::replaceOrRemoveKey"
This reverts commit dc059560e7.

I changed my mind. There's no harm in leaving it deprecated for a
release cycle.
2022-04-30 14:15:07 -04:00
Jay Berkenbilt dc059560e7 Remove QPDFObjectHandle::replaceOrRemoveKey
See ChangeLog for rationale for not deprecating it as originally
planned.
2022-04-30 13:39:45 -04:00
Jay Berkenbilt e80fad86e9 Add new QPDFObjectHandle methods for more fluent programming 2022-04-29 20:09:10 -04:00
Jay Berkenbilt 4be2f36049 Deprecate replaceOrRemoveKey -- it's the same as replaceKey 2022-04-24 09:31:32 -04:00
Jay Berkenbilt 4925f0d18c Have dictionary/streams mutators take const& where possible 2022-04-24 09:05:50 -04:00
Jay Berkenbilt cdd0b4fb7d Use = default and = delete where possible in classes 2022-04-16 11:39:14 -04:00
Jay Berkenbilt 2a7d2b63c2 Make ABI-breaking changes that don't modify API at all
* Merge overloaded functions by adding default values
* Remove non-const methods that are identical to const methods
2022-04-16 10:41:46 -04:00
Jay Berkenbilt 5f4675bb24 Mark non-ABI symbols in exported class with QPDF_DLL_PRIVATE 2022-04-10 16:54:23 -04:00
Jay Berkenbilt 8c504c9a90 Tweak for clang-format and emacs font-lock 2022-04-10 12:49:50 -04:00
Jay Berkenbilt a68703b07e Replace PointerHolder with std::shared_ptr in library sources only
(patrepl and cleanpatch are my own utilities)

patrepl s/PointerHolder/std::shared_ptr/g {include,libqpdf}/qpdf/*.hh
patrepl s/PointerHolder/std::shared_ptr/g libqpdf/*.cc
patrepl s/make_pointer_holder/std::make_shared/g libqpdf/*.cc
patrepl s/make_array_pointer_holder/QUtil::make_shared_array/g libqpdf/*.cc
patrepl s,qpdf/std::shared_ptr,qpdf/PointerHolder, **/*.cc **/*.hh
git restore include/qpdf/PointerHolder.hh
cleanpatch
./format-code
2022-04-09 17:33:29 -04:00
Jay Berkenbilt 12f1eb15ca Programmatically apply new formatting to code
Run this:

for i in  **/*.cc **/*.c **/*.h **/*.hh; do
  clang-format < $i >| $i.new && mv $i.new $i
done
2022-04-04 08:10:40 -04:00
Jay Berkenbilt ec778ef98b Add additional comments about new accessor methods 2022-02-08 16:49:43 -05:00
Jay Berkenbilt 014dcb02c9 Revert an incorrect correction 2022-02-08 12:34:14 -05:00
Jay Berkenbilt cb769c62e5 WHITESPACE ONLY -- expand tabs in source code
This comment expands all tabs using an 8-character tab-width. You
should ignore this commit when using git blame or use git blame -w.

In the early days, I used to use tabs where possible for indentation,
since emacs did this automatically. In recent years, I have switched
to only using spaces, which means qpdf source code has been a mixture
of spaces and tabs. I have avoided cleaning this up because of not
wanting gratuitous whitespaces change to cloud the output of git
blame, but I changed my mind after discussing with users who view qpdf
source code in editors/IDEs that have other tab widths by default and
in light of the fact that I am planning to start applying automatic
code formatting soon.
2022-02-08 11:51:15 -05:00
m-holger 716381f65a Fix doc typos 2022-02-08 11:50:58 -05:00
Jay Berkenbilt 68e4aec054 Clarify qpdf's representation of names in the API
Clarify that names are to appear in canonical form with PDF escaping
resolved when used in non-parsing QPDFObjectHandle APIs and their C
API counterparts. See https://github.com/qpdf/qpdf/discussions/625.
2022-02-08 09:09:23 -05:00
Jay Berkenbilt c62e8e2b28 Update for clean compile with POINTERHOLDER_TRANSITION=2 2022-02-07 17:38:22 -05:00
Jay Berkenbilt 6a2456f732 Comment, ChangeLog, release note for new contribution 2022-02-06 11:27:02 -05:00
m-holger 8371060340 Add method QPDFObjectHandle::getKeyIfDict 2022-02-06 11:21:15 -05:00
Jay Berkenbilt af3f74de8c Stop using std::iterator (fixes #618)
Create the typedefs directly in iterators rather than deriving from
the deprecated std::iterator class.
2022-02-05 11:29:25 -05:00
Jay Berkenbilt 7fb22740e1 Add operator ""_qpdf for creating QPDFObjectHandle literals 2022-02-05 11:29:25 -05:00
m-holger e58b1174c7 Add new QPDFObjectHandle::getValueAs... accessors 2022-02-05 11:24:35 -05:00
Jay Berkenbilt cfaa2de804 Update copyright for 2022 2022-02-04 16:36:22 -05:00
m-holger 8a5ba5686c Add some doc comments for QPDFObjectHandle dictionary methods 2022-01-30 12:09:54 -06:00
m-holger 1b1b471ca9 Make a few whitespace fixes from last commit
Commit by ejb@ql.org using m-holger as author so git annotate gives
proper credit for changes.
2022-01-22 09:14:53 -05:00
m-holger 8593b9fdf7 Add new convenience methods QPDFObjectHandle::isNameAndEquals, etc
Add methods isNameAndEquals, isDictionaryOfType, isStreamOfType
2022-01-22 08:10:28 -06:00
Jay Berkenbilt 8e0b153332 Expose QPDFObjectHandle::addTokenFilter (fixes #580) 2021-12-10 13:37:07 -05:00
Jay Berkenbilt 3340dbe976 Use a specific error code for type warnings and clarify docs 2021-12-10 11:15:49 -05:00
Jay Berkenbilt 73d70902e0 Typos in comments 2021-12-09 10:33:31 -05:00
m-holger 0c705a882b Minor documentation updates 2021-12-09 10:24:14 -05:00
Jay Berkenbilt 9b28933647 Check object ownership when adding
When adding a QPDFObjectHandle to an array or dictionary, if possible,
check if the new object belongs to the same QPDF. This makes it much
easier to find incorrect code than waiting for the situation to be
detected when the file is written.
2021-11-04 12:29:42 -04:00
Jay Berkenbilt 0b77f2cf26 Revert non-binary-compatible handleWarning change -- see TODO (ABI) 2021-03-04 15:59:46 -05:00
Jay Berkenbilt d7ffdfa994 Add optional conflict detection to mergeResources
Also improve behavior around direct vs. indirect resources.
2021-03-04 15:08:36 -05:00
Jay Berkenbilt a15ec6967d Enhancements to ParserCallbacks 2021-03-03 17:05:49 -05:00
Jay Berkenbilt 7b3cbacf5d Change from QPDF{Array,Dict}Items to aitems() and ditems() 2021-02-22 11:05:39 -05:00
Jay Berkenbilt aa848126cb Comment about QPDFMatrix and QPDFObjectHandle::Matrix 2021-02-21 08:06:19 -05:00
Jay Berkenbilt 92fbc6fdf5 QPDFObjectHandle::copyStream 2021-02-21 06:36:30 -05:00
Jay Berkenbilt 901f1a788c Enhance QPDFMatrix API 2021-02-21 06:36:30 -05:00
Jay Berkenbilt a773f4c71d Add QPDFObjectHandle::parse for strings with context 2021-02-15 11:33:03 -05:00
Jay Berkenbilt efbb21673c Add functional versions of QPDFObjectHandle::replaceStreamData
Also fix a bug in checking consistency of length for stream data
providers. Length should not be checked or recorded if the provider
says it failed to generate the data.
2021-02-14 14:42:24 -05:00
Jay Berkenbilt 07f40bd254 QUtil::double_to_string: trim trailing zeroes with option to disable 2021-02-13 02:30:00 -05:00
Jay Berkenbilt 4ae93a73c5 Improve memory safety of dict/array iterators 2021-01-31 07:16:03 -05:00
Jay Berkenbilt 1fec40454e Add example of name/number trees and dictionary/array iteration 2021-01-30 15:52:16 -05:00
Jay Berkenbilt de0b11fc47 Add C++ iterator API around array and dictionary objects 2021-01-30 15:15:23 -05:00
Jay Berkenbilt 04edfe9fad QPDFObjectHandle::newUnicodeString to uses UTF-16 only when needed
Use the first of ASCII, PDFDocEncoding, or UTF-16 that is capable of
encoding the string.
2021-01-24 03:27:28 -05:00
Jay Berkenbilt bf8fd41fee Update copyright to 2021 2021-01-04 16:26:58 -05:00
Jay Berkenbilt 3be58f49e5 Make more QPDFPageObjectHelper methods work with form XObject 2021-01-02 14:08:53 -05:00
Jay Berkenbilt a139d2b36d Add several methods for working with form XObjects (fixes #436)
Make some more methods in QPDFPageObjectHelper work with form
XObjects, provide forEach methods to walk through nested form
XObjects, possibly recursively. This should make it easier to work
with form XObjects from user code.
2021-01-02 12:29:31 -05:00
Jay Berkenbilt 1562d34c09 Add QPDFObjectHandle::isFormXObject 2021-01-01 07:36:10 -05:00
Jay Berkenbilt d4d7630cf5 Add pdf-custom-filter example 2020-12-28 13:03:04 -05:00
Jay Berkenbilt 12ecd2019a Add QPDFObjectHandle::setFilterOnWrite 2020-12-28 12:58:19 -05:00
Jay Berkenbilt 0675a3f61a Decide not to allow stream data providers to modify dictionary 2020-12-26 08:48:20 -05:00
Jay Berkenbilt cc8895078a Add QPDFObjectHandle::makeDirect(bool allow_streams) 2020-12-26 08:48:18 -05:00
Jay Berkenbilt fd13fe74ef TODO and comments item for pipeContentStreams 2020-10-23 16:53:58 -04:00
Jay Berkenbilt 893d38b87e Allow propagation of errors and retry through StreamDataProvider
StreamDataProvider::provideStreamData now has a rich enough API for it
to effectively proxy to pipeStreamData.
2020-04-05 20:07:13 -04:00
Jay Berkenbilt 38afdcea7b Add QPDFObjectHandle::unsafeShallowCopy 2020-04-03 12:16:24 -04:00
Jay Berkenbilt 89f19b7099 Performance: remove Members indirection for QPDFObjectHandle 2020-04-03 12:16:24 -04:00
Jay Berkenbilt 278710fbe8 Refactor QPDFPageObjectHelper::removeUnreferencedResources()
Refactor removeUnreferencedResources to prepare for filtering form
XObjects.
2020-03-31 17:39:20 -04:00
Jay Berkenbilt e5cc065598 Update copyright to 2020 2020-01-26 16:57:27 -05:00
Masamichi Hosoda cdc46d78f4 Add QPDFObject::getParsedOffset() 2019-10-22 16:19:06 -04:00
Jay Berkenbilt 3f1ab64066 Pass offset and length to ParserCallbacks::handleObject 2019-08-22 22:54:29 -04:00
Jay Berkenbilt 4b2e72c4cd Test for direct, rather than resolved nulls in parser
Just because we know an indirect reference is null, doesn't mean we
shouldn't keep it indirect.
2019-08-22 17:55:16 -04:00
Jay Berkenbilt 4b674b42e4 Mention name tokens in TokenFilter comments 2019-08-22 17:55:16 -04:00
Jay Berkenbilt 42d396f1dd Handle invalid name tokens symmetrically for PDF < 1.2 (fixes #332) 2019-08-19 19:48:27 -04:00
Jay Berkenbilt e5f504b6c5 Use SparseOHArray in QPDF_Array 2019-08-17 23:02:41 -04:00