Commit 5cec6b4c3df09b59464c9a492b60b86ffd0d5311
1 parent
07658722
Add QPDFPageObjectHelper::getMatrixForFormXObjectPlacement
Showing
4 changed files
with
42 additions
and
6 deletions
ChangeLog
| 1 | 1 | 2021-02-18 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | |
| 3 | + * Add QPDFPageObjectHelper::getMatrixForFormXObjectPlacement, | |
| 4 | + which returns the transformation matrix required to map from a | |
| 5 | + form field's coordinate system into a specific rectangle within | |
| 6 | + the page. | |
| 7 | + | |
| 3 | 8 | * Add QUtil::path_basename to get last element of a path. |
| 4 | 9 | |
| 5 | 10 | * Add examples/pdf-attach-file.cc to illustrate new file | ... | ... |
include/qpdf/QPDFPageObjectHelper.hh
| ... | ... | @@ -24,6 +24,7 @@ |
| 24 | 24 | |
| 25 | 25 | #include <qpdf/QPDFObjectHelper.hh> |
| 26 | 26 | #include <qpdf/QPDFAnnotationObjectHelper.hh> |
| 27 | +#include <qpdf/QPDFMatrix.hh> | |
| 27 | 28 | |
| 28 | 29 | #include <qpdf/DLL.h> |
| 29 | 30 | |
| ... | ... | @@ -306,6 +307,16 @@ class QPDFPageObjectHelper: public QPDFObjectHelper |
| 306 | 307 | bool allow_shrink = true, |
| 307 | 308 | bool allow_expand = false); |
| 308 | 309 | |
| 310 | + // Return the transformation matrix that translates from the given | |
| 311 | + // form XObject's coordinate system into the given rectangular | |
| 312 | + // region on the page. The parameters have the same meaning as for | |
| 313 | + // placeFormXObject. | |
| 314 | + QPDF_DLL | |
| 315 | + QPDFMatrix getMatrixForFormXObjectPlacement( | |
| 316 | + QPDFObjectHandle fo, QPDFObjectHandle::Rectangle rect, | |
| 317 | + bool invert_transformations = true, | |
| 318 | + bool allow_shrink = true, bool allow_expand = false); | |
| 319 | + | |
| 309 | 320 | // If a page is rotated using /Rotate in the page's dictionary, |
| 310 | 321 | // instead rotate the page by the same amount by altering the |
| 311 | 322 | // contents and removing the /Rotate key. This method adjusts the | ... | ... |
libqpdf/QPDFPageObjectHelper.cc
| ... | ... | @@ -947,10 +947,9 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) |
| 947 | 947 | return result; |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | -std::string | |
| 951 | -QPDFPageObjectHelper::placeFormXObject( | |
| 952 | - QPDFObjectHandle fo, std::string const& name, | |
| 953 | - QPDFObjectHandle::Rectangle rect, | |
| 950 | +QPDFMatrix | |
| 951 | +QPDFPageObjectHelper::getMatrixForFormXObjectPlacement( | |
| 952 | + QPDFObjectHandle fo, QPDFObjectHandle::Rectangle rect, | |
| 954 | 953 | bool invert_transformations, |
| 955 | 954 | bool allow_shrink, bool allow_expand) |
| 956 | 955 | { |
| ... | ... | @@ -971,7 +970,7 @@ QPDFPageObjectHelper::placeFormXObject( |
| 971 | 970 | QPDFObjectHandle bbox_obj = fdict.getKey("/BBox"); |
| 972 | 971 | if (! bbox_obj.isRectangle()) |
| 973 | 972 | { |
| 974 | - return ""; | |
| 973 | + return QPDFMatrix(); | |
| 975 | 974 | } |
| 976 | 975 | |
| 977 | 976 | QPDFMatrix wmatrix; // work matrix |
| ... | ... | @@ -1014,7 +1013,7 @@ QPDFPageObjectHelper::placeFormXObject( |
| 1014 | 1013 | if ((T.urx == T.llx) || (T.ury == T.lly)) |
| 1015 | 1014 | { |
| 1016 | 1015 | // avoid division by zero |
| 1017 | - return ""; | |
| 1016 | + return QPDFMatrix(); | |
| 1018 | 1017 | } |
| 1019 | 1018 | double rect_w = rect.urx - rect.llx; |
| 1020 | 1019 | double rect_h = rect.ury - rect.lly; |
| ... | ... | @@ -1060,6 +1059,18 @@ QPDFPageObjectHelper::placeFormXObject( |
| 1060 | 1059 | cm.translate(tx, ty); |
| 1061 | 1060 | cm.scale(scale, scale); |
| 1062 | 1061 | cm.concat(tmatrix); |
| 1062 | + return cm; | |
| 1063 | +} | |
| 1064 | + | |
| 1065 | +std::string | |
| 1066 | +QPDFPageObjectHelper::placeFormXObject( | |
| 1067 | + QPDFObjectHandle fo, std::string const& name, | |
| 1068 | + QPDFObjectHandle::Rectangle rect, | |
| 1069 | + bool invert_transformations, | |
| 1070 | + bool allow_shrink, bool allow_expand) | |
| 1071 | +{ | |
| 1072 | + QPDFMatrix cm = getMatrixForFormXObjectPlacement( | |
| 1073 | + fo, rect, invert_transformations, allow_shrink, allow_expand); | |
| 1063 | 1074 | return ( |
| 1064 | 1075 | "q\n" + |
| 1065 | 1076 | cm.unparse() + " cm\n" + | ... | ... |
manual/qpdf-manual.xml
| ... | ... | @@ -5285,6 +5285,15 @@ print "\n"; |
| 5285 | 5285 | </listitem> |
| 5286 | 5286 | <listitem> |
| 5287 | 5287 | <para> |
| 5288 | + Add | |
| 5289 | + <function>QPDFPageObjectHelper::getMatrixForFormXObjectPlacement</function> | |
| 5290 | + which returns the transformation matrix required to map from | |
| 5291 | + a form field's coordinate system into a specific rectangle | |
| 5292 | + within the page. | |
| 5293 | + </para> | |
| 5294 | + </listitem> | |
| 5295 | + <listitem> | |
| 5296 | + <para> | |
| 5288 | 5297 | Add <function>QUtil::path_basename</function> to return the |
| 5289 | 5298 | last element of a path. |
| 5290 | 5299 | </para> | ... | ... |