Commit 8e8c0d8290409358488b2a04af81771989944552
1 parent
61d41e2e
Add new placeFormXObject that takes a matrix reference
Showing
4 changed files
with
38 additions
and
7 deletions
ChangeLog
| 1 | +2021-02-22 Jay Berkenbilt <ejb@ql.org> | ||
| 2 | + | ||
| 3 | + * Add a new version of QPDFPageObjectHelper::placeFormXObject that | ||
| 4 | + initializes the transformation matrix that was used so you don't | ||
| 5 | + have to call both placeFormXObject and | ||
| 6 | + getMatrixForFormXObjectPlacement. | ||
| 7 | + | ||
| 1 | 2021-02-21 Jay Berkenbilt <ejb@ql.org> | 8 | 2021-02-21 Jay Berkenbilt <ejb@ql.org> |
| 2 | 9 | ||
| 3 | * From qpdf CLI, --overlay and --underlay will copy annotations | 10 | * From qpdf CLI, --overlay and --underlay will copy annotations |
include/qpdf/QPDFPageObjectHelper.hh
| @@ -309,6 +309,17 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | @@ -309,6 +309,17 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | ||
| 309 | bool allow_shrink = true, | 309 | bool allow_shrink = true, |
| 310 | bool allow_expand = false); | 310 | bool allow_expand = false); |
| 311 | 311 | ||
| 312 | + // Alternative version that also fills in the transformation | ||
| 313 | + // matrix that was used. | ||
| 314 | + QPDF_DLL | ||
| 315 | + std::string placeFormXObject( | ||
| 316 | + QPDFObjectHandle fo, std::string const& name, | ||
| 317 | + QPDFObjectHandle::Rectangle rect, | ||
| 318 | + QPDFMatrix& cm, | ||
| 319 | + bool invert_transformations = true, | ||
| 320 | + bool allow_shrink = true, | ||
| 321 | + bool allow_expand = false); | ||
| 322 | + | ||
| 312 | // Return the transformation matrix that translates from the given | 323 | // Return the transformation matrix that translates from the given |
| 313 | // form XObject's coordinate system into the given rectangular | 324 | // form XObject's coordinate system into the given rectangular |
| 314 | // region on the page. The parameters have the same meaning as for | 325 | // region on the page. The parameters have the same meaning as for |
libqpdf/QPDFPageObjectHelper.cc
| @@ -1070,7 +1070,22 @@ QPDFPageObjectHelper::placeFormXObject( | @@ -1070,7 +1070,22 @@ QPDFPageObjectHelper::placeFormXObject( | ||
| 1070 | bool invert_transformations, | 1070 | bool invert_transformations, |
| 1071 | bool allow_shrink, bool allow_expand) | 1071 | bool allow_shrink, bool allow_expand) |
| 1072 | { | 1072 | { |
| 1073 | - QPDFMatrix cm = getMatrixForFormXObjectPlacement( | 1073 | + QPDFMatrix cm; |
| 1074 | + return placeFormXObject( | ||
| 1075 | + fo, name, rect, cm, invert_transformations, | ||
| 1076 | + allow_shrink, allow_expand); | ||
| 1077 | +} | ||
| 1078 | + | ||
| 1079 | +std::string | ||
| 1080 | +QPDFPageObjectHelper::placeFormXObject( | ||
| 1081 | + QPDFObjectHandle fo, std::string const& name, | ||
| 1082 | + QPDFObjectHandle::Rectangle rect, | ||
| 1083 | + QPDFMatrix& cm, | ||
| 1084 | + bool invert_transformations, | ||
| 1085 | + bool allow_shrink, | ||
| 1086 | + bool allow_expand) | ||
| 1087 | +{ | ||
| 1088 | + cm = getMatrixForFormXObjectPlacement( | ||
| 1074 | fo, rect, invert_transformations, allow_shrink, allow_expand); | 1089 | fo, rect, invert_transformations, allow_shrink, allow_expand); |
| 1075 | return ( | 1090 | return ( |
| 1076 | "q\n" + | 1091 | "q\n" + |
qpdf/qpdf.cc
| @@ -5191,20 +5191,18 @@ static void do_under_overlay_for_page( | @@ -5191,20 +5191,18 @@ static void do_under_overlay_for_page( | ||
| 5191 | pdf.copyForeignObject( | 5191 | pdf.copyForeignObject( |
| 5192 | from_page.getFormXObjectForPage()); | 5192 | from_page.getFormXObjectForPage()); |
| 5193 | } | 5193 | } |
| 5194 | - auto cm = dest_page.getMatrixForFormXObjectPlacement( | ||
| 5195 | - fo[from_pageno], | ||
| 5196 | - dest_page.getTrimBox().getArrayAsRectangle()); | ||
| 5197 | - dest_page.copyAnnotations( | ||
| 5198 | - from_page, cm, dest_afdh, make_afdh(from_page)); | ||
| 5199 | 5194 | ||
| 5200 | // If the same page is overlaid or underlaid multiple times, | 5195 | // If the same page is overlaid or underlaid multiple times, |
| 5201 | // we'll generate multiple names for it, but that's harmless | 5196 | // we'll generate multiple names for it, but that's harmless |
| 5202 | // and also a pretty goofy case that's not worth coding | 5197 | // and also a pretty goofy case that's not worth coding |
| 5203 | // around. | 5198 | // around. |
| 5204 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); | 5199 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); |
| 5200 | + QPDFMatrix cm; | ||
| 5205 | std::string new_content = dest_page.placeFormXObject( | 5201 | std::string new_content = dest_page.placeFormXObject( |
| 5206 | fo[from_pageno], name, | 5202 | fo[from_pageno], name, |
| 5207 | - dest_page.getTrimBox().getArrayAsRectangle()); | 5203 | + dest_page.getTrimBox().getArrayAsRectangle(), cm); |
| 5204 | + dest_page.copyAnnotations( | ||
| 5205 | + from_page, cm, dest_afdh, make_afdh(from_page)); | ||
| 5208 | if (! new_content.empty()) | 5206 | if (! new_content.empty()) |
| 5209 | { | 5207 | { |
| 5210 | resources.mergeResources( | 5208 | resources.mergeResources( |