Commit 2d0885bc119af035ab2df4d8c19000408223ae7f

Authored by Jay Berkenbilt
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.
@@ -3,12 +3,6 @@ Soon @@ -3,12 +3,6 @@ Soon
3 3
4 * Set up OSS-Fuzz (Google). See starred email in qpdf label. 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 Next ABI 6 Next ABI
13 ======== 7 ========
14 8
@@ -25,6 +19,9 @@ Do these things next time we have to break binary compatibility @@ -25,6 +19,9 @@ Do these things next time we have to break binary compatibility
25 * Collapse QPDF::pushInheritedAttributesToPageInternal* and 19 * Collapse QPDF::pushInheritedAttributesToPageInternal* and
26 QPDF::getAllPagesInternal* into QPDF::*Internal. 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 Lexical 25 Lexical
29 ======= 26 =======
30 27
include/qpdf/QPDF.hh
@@ -301,12 +301,18 @@ class QPDF @@ -301,12 +301,18 @@ class QPDF
301 // 301 //
302 // The return value of this method is an indirect reference to the 302 // The return value of this method is an indirect reference to the
303 // copied object in this file. This method is intended to be used 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 // When copying objects with this method, object structure will be 317 // When copying objects with this method, object structure will be
312 // preserved, so all indirectly referenced indirect objects will 318 // preserved, so all indirectly referenced indirect objects will
@@ -930,9 +936,10 @@ class QPDF @@ -930,9 +936,10 @@ class QPDF
930 QPDFObjectHandle& stream_dict, bool is_attachment_stream, 936 QPDFObjectHandle& stream_dict, bool is_attachment_stream,
931 std::vector<PointerHolder<Pipeline> >& heap); 937 std::vector<PointerHolder<Pipeline> >& heap);
932 938
933 - // Methods to support object copying 939 + // Unused copyForeignObject -- remove at next ABI change
934 QPDFObjectHandle copyForeignObject( 940 QPDFObjectHandle copyForeignObject(
935 - QPDFObjectHandle foreign, bool allow_page); 941 + QPDFObjectHandle foreign, bool unused);
  942 + // Methods to support object copying
936 void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, 943 void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier,
937 bool top); 944 bool top);
938 QPDFObjectHandle replaceForeignIndirectObjects( 945 QPDFObjectHandle replaceForeignIndirectObjects(
include/qpdf/QPDFPageDocumentHelper.hh
@@ -73,7 +73,12 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper @@ -73,7 +73,12 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper
73 // indirect. If it is an indirect object from another QPDF, this 73 // indirect. If it is an indirect object from another QPDF, this
74 // method will call pushInheritedAttributesToPage on the other 74 // method will call pushInheritedAttributesToPage on the other
75 // file and then copy the page to this QPDF using the same 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 QPDF_DLL 82 QPDF_DLL
78 void addPage(QPDFPageObjectHelper newpage, bool first); 83 void addPage(QPDFPageObjectHelper newpage, bool first);
79 84
libqpdf/QPDF.cc
@@ -2141,14 +2141,18 @@ QPDF::replaceReserved(QPDFObjectHandle reserved, @@ -2141,14 +2141,18 @@ QPDF::replaceReserved(QPDFObjectHandle reserved,
2141 } 2141 }
2142 2142
2143 QPDFObjectHandle 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 QPDFObjectHandle 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 if (! foreign.isIndirect()) 2156 if (! foreign.isIndirect())
2153 { 2157 {
2154 QTC::TC("qpdf", "QPDF copyForeign direct"); 2158 QTC::TC("qpdf", "QPDF copyForeign direct");
libqpdf/QPDF_pages.cc
@@ -221,7 +221,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) @@ -221,7 +221,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
221 { 221 {
222 QTC::TC("qpdf", "QPDF insert foreign page"); 222 QTC::TC("qpdf", "QPDF insert foreign page");
223 newpage.getOwningQPDF()->pushInheritedAttributesToPage(); 223 newpage.getOwningQPDF()->pushInheritedAttributesToPage();
224 - newpage = copyForeignObject(newpage, true); 224 + newpage = copyForeignObject(newpage);
225 } 225 }
226 else 226 else
227 { 227 {