diff --git a/ChangeLog b/ChangeLog index 4a758b54..76340fb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2021-02-18 Jay Berkenbilt + * Add QPDFPageObjectHelper::getMatrixForFormXObjectPlacement, + which returns the transformation matrix required to map from a + form field's coordinate system into a specific rectangle within + the page. + * Add QUtil::path_basename to get last element of a path. * Add examples/pdf-attach-file.cc to illustrate new file diff --git a/include/qpdf/QPDFPageObjectHelper.hh b/include/qpdf/QPDFPageObjectHelper.hh index 73344caf..76f42dbd 100644 --- a/include/qpdf/QPDFPageObjectHelper.hh +++ b/include/qpdf/QPDFPageObjectHelper.hh @@ -24,6 +24,7 @@ #include #include +#include #include @@ -306,6 +307,16 @@ class QPDFPageObjectHelper: public QPDFObjectHelper bool allow_shrink = true, bool allow_expand = false); + // Return the transformation matrix that translates from the given + // form XObject's coordinate system into the given rectangular + // region on the page. The parameters have the same meaning as for + // placeFormXObject. + QPDF_DLL + QPDFMatrix getMatrixForFormXObjectPlacement( + QPDFObjectHandle fo, QPDFObjectHandle::Rectangle rect, + bool invert_transformations = true, + bool allow_shrink = true, bool allow_expand = false); + // If a page is rotated using /Rotate in the page's dictionary, // instead rotate the page by the same amount by altering the // contents and removing the /Rotate key. This method adjusts the diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index da8b3919..e744457b 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -947,10 +947,9 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) return result; } -std::string -QPDFPageObjectHelper::placeFormXObject( - QPDFObjectHandle fo, std::string const& name, - QPDFObjectHandle::Rectangle rect, +QPDFMatrix +QPDFPageObjectHelper::getMatrixForFormXObjectPlacement( + QPDFObjectHandle fo, QPDFObjectHandle::Rectangle rect, bool invert_transformations, bool allow_shrink, bool allow_expand) { @@ -971,7 +970,7 @@ QPDFPageObjectHelper::placeFormXObject( QPDFObjectHandle bbox_obj = fdict.getKey("/BBox"); if (! bbox_obj.isRectangle()) { - return ""; + return QPDFMatrix(); } QPDFMatrix wmatrix; // work matrix @@ -1014,7 +1013,7 @@ QPDFPageObjectHelper::placeFormXObject( if ((T.urx == T.llx) || (T.ury == T.lly)) { // avoid division by zero - return ""; + return QPDFMatrix(); } double rect_w = rect.urx - rect.llx; double rect_h = rect.ury - rect.lly; @@ -1060,6 +1059,18 @@ QPDFPageObjectHelper::placeFormXObject( cm.translate(tx, ty); cm.scale(scale, scale); cm.concat(tmatrix); + return cm; +} + +std::string +QPDFPageObjectHelper::placeFormXObject( + QPDFObjectHandle fo, std::string const& name, + QPDFObjectHandle::Rectangle rect, + bool invert_transformations, + bool allow_shrink, bool allow_expand) +{ + QPDFMatrix cm = getMatrixForFormXObjectPlacement( + fo, rect, invert_transformations, allow_shrink, allow_expand); return ( "q\n" + cm.unparse() + " cm\n" + diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index 2c1c235a..83d178a7 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -5283,6 +5283,15 @@ print "\n"; matrices. + + + Add + QPDFPageObjectHelper::getMatrixForFormXObjectPlacement + which returns the transformation matrix required to map from + a form field's coordinate system into a specific rectangle + within the page. + + Add QUtil::path_basename to return the