Commit 2d0885bc119af035ab2df4d8c19000408223ae7f
1 parent
2712869c
Clarify documentation for copyForeignObject regarding pages
Make explicit that copyForeignObject can be used on page objects and will copy them properly but not update the pages tree.
Showing
5 changed files
with
32 additions
and
19 deletions
TODO
| ... | ... | @@ -3,12 +3,6 @@ Soon |
| 3 | 3 | |
| 4 | 4 | * Set up OSS-Fuzz (Google). See starred email in qpdf label. |
| 5 | 5 | |
| 6 | - * Update the docs for copyForeignObject and addPage to explain the | |
| 7 | - difference between copying a page in the two ways: using addPage | |
| 8 | - updates the pages tree, while using copyForeignObject does not. The | |
| 9 | - latter is appropriate when a page is being converted to a form | |
| 10 | - XObject. | |
| 11 | - | |
| 12 | 6 | Next ABI |
| 13 | 7 | ======== |
| 14 | 8 | |
| ... | ... | @@ -25,6 +19,9 @@ Do these things next time we have to break binary compatibility |
| 25 | 19 | * Collapse QPDF::pushInheritedAttributesToPageInternal* and |
| 26 | 20 | QPDF::getAllPagesInternal* into QPDF::*Internal. |
| 27 | 21 | |
| 22 | + * Get rid of the version of QPDF::copyForeignObject with the bool | |
| 23 | + unused parameter. | |
| 24 | + | |
| 28 | 25 | Lexical |
| 29 | 26 | ======= |
| 30 | 27 | ... | ... |
include/qpdf/QPDF.hh
| ... | ... | @@ -301,12 +301,18 @@ class QPDF |
| 301 | 301 | // |
| 302 | 302 | // The return value of this method is an indirect reference to the |
| 303 | 303 | // copied object in this file. This method is intended to be used |
| 304 | - // to copy non-page objects and will not copy page objects. To | |
| 305 | - // copy page objects, pass the foreign page object directly to | |
| 306 | - // addPage (or addPageAt). If you copy objects that contain | |
| 307 | - // references to pages, you should copy the pages first using | |
| 308 | - // addPage(At). Otherwise references to the pages that have not | |
| 309 | - // been copied will be replaced with nulls. | |
| 304 | + // to copy non-page objects. To copy page objects, pass the | |
| 305 | + // foreign page object directly to addPage (or addPageAt). If you | |
| 306 | + // copy objects that contain references to pages, you should copy | |
| 307 | + // the pages first using addPage(At). Otherwise references to the | |
| 308 | + // pages that have not been copied will be replaced with nulls. It | |
| 309 | + // is possible to use copyForeignObject on page objects if you are | |
| 310 | + // not going to use them as pages. Doing so copies the object | |
| 311 | + // normally but does not update the page structure. For example, | |
| 312 | + // it is a valid use case to use copyForeignObject for a page that | |
| 313 | + // you are going to turn into a form XObject, though you can also | |
| 314 | + // use QPDFPageObjectHelper::getFormXObjectForPage for that | |
| 315 | + // purpose. | |
| 310 | 316 | |
| 311 | 317 | // When copying objects with this method, object structure will be |
| 312 | 318 | // preserved, so all indirectly referenced indirect objects will |
| ... | ... | @@ -930,9 +936,10 @@ class QPDF |
| 930 | 936 | QPDFObjectHandle& stream_dict, bool is_attachment_stream, |
| 931 | 937 | std::vector<PointerHolder<Pipeline> >& heap); |
| 932 | 938 | |
| 933 | - // Methods to support object copying | |
| 939 | + // Unused copyForeignObject -- remove at next ABI change | |
| 934 | 940 | QPDFObjectHandle copyForeignObject( |
| 935 | - QPDFObjectHandle foreign, bool allow_page); | |
| 941 | + QPDFObjectHandle foreign, bool unused); | |
| 942 | + // Methods to support object copying | |
| 936 | 943 | void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, |
| 937 | 944 | bool top); |
| 938 | 945 | QPDFObjectHandle replaceForeignIndirectObjects( | ... | ... |
include/qpdf/QPDFPageDocumentHelper.hh
| ... | ... | @@ -73,7 +73,12 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper |
| 73 | 73 | // indirect. If it is an indirect object from another QPDF, this |
| 74 | 74 | // method will call pushInheritedAttributesToPage on the other |
| 75 | 75 | // file and then copy the page to this QPDF using the same |
| 76 | - // underlying code as copyForeignObject. | |
| 76 | + // underlying code as copyForeignObject. Note that you can call | |
| 77 | + // copyForeignObject directly to copy a page from a different | |
| 78 | + // file, but the resulting object will not be a page in the new | |
| 79 | + // file. You could do this, for example, to convert a page into a | |
| 80 | + // form XObject, though for that, you're better off using | |
| 81 | + // QPDFPageObjectHelper::getFormXObjectForPage. | |
| 77 | 82 | QPDF_DLL |
| 78 | 83 | void addPage(QPDFPageObjectHelper newpage, bool first); |
| 79 | 84 | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -2141,14 +2141,18 @@ QPDF::replaceReserved(QPDFObjectHandle reserved, |
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | QPDFObjectHandle |
| 2144 | -QPDF::copyForeignObject(QPDFObjectHandle foreign) | |
| 2144 | +QPDF::copyForeignObject(QPDFObjectHandle foreign, bool) | |
| 2145 | 2145 | { |
| 2146 | - return copyForeignObject(foreign, false); | |
| 2146 | + // This method will be removed next time the ABI is changed. | |
| 2147 | + return copyForeignObject(foreign); | |
| 2147 | 2148 | } |
| 2148 | 2149 | |
| 2149 | 2150 | QPDFObjectHandle |
| 2150 | -QPDF::copyForeignObject(QPDFObjectHandle foreign, bool allow_page) | |
| 2151 | +QPDF::copyForeignObject(QPDFObjectHandle foreign) | |
| 2151 | 2152 | { |
| 2153 | + // Do not preclude use of copyForeignObject on page objects. It is | |
| 2154 | + // a documented use case to copy pages this way if the intention | |
| 2155 | + // is to not update the pages tree. | |
| 2152 | 2156 | if (! foreign.isIndirect()) |
| 2153 | 2157 | { |
| 2154 | 2158 | QTC::TC("qpdf", "QPDF copyForeign direct"); | ... | ... |
libqpdf/QPDF_pages.cc
| ... | ... | @@ -221,7 +221,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) |
| 221 | 221 | { |
| 222 | 222 | QTC::TC("qpdf", "QPDF insert foreign page"); |
| 223 | 223 | newpage.getOwningQPDF()->pushInheritedAttributesToPage(); |
| 224 | - newpage = copyForeignObject(newpage, true); | |
| 224 | + newpage = copyForeignObject(newpage); | |
| 225 | 225 | } |
| 226 | 226 | else |
| 227 | 227 | { | ... | ... |