aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-02-22 22:02:47 +0100
committerJay Berkenbilt <ejb@ql.org>2021-02-23 00:42:06 +0100
commit8e8c0d8290409358488b2a04af81771989944552 (patch)
tree49b330543ab82067d256e574a6b7efea7d2df044
parent61d41e2e8858d8c51e097d8f993291dc210f30a5 (diff)
downloadqpdf-8e8c0d8290409358488b2a04af81771989944552.tar.zst
Add new placeFormXObject that takes a matrix reference
-rw-r--r--ChangeLog7
-rw-r--r--include/qpdf/QPDFPageObjectHelper.hh11
-rw-r--r--libqpdf/QPDFPageObjectHelper.cc17
-rw-r--r--qpdf/qpdf.cc10
4 files changed, 38 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index bb9c8003..a3de5ecb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-02-22 Jay Berkenbilt <ejb@ql.org>
+
+ * Add a new version of QPDFPageObjectHelper::placeFormXObject that
+ initializes the transformation matrix that was used so you don't
+ have to call both placeFormXObject and
+ getMatrixForFormXObjectPlacement.
+
2021-02-21 Jay Berkenbilt <ejb@ql.org>
* From qpdf CLI, --overlay and --underlay will copy annotations
diff --git a/include/qpdf/QPDFPageObjectHelper.hh b/include/qpdf/QPDFPageObjectHelper.hh
index 1e3bdb3e..2feb1199 100644
--- a/include/qpdf/QPDFPageObjectHelper.hh
+++ b/include/qpdf/QPDFPageObjectHelper.hh
@@ -309,6 +309,17 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
bool allow_shrink = true,
bool allow_expand = false);
+ // Alternative version that also fills in the transformation
+ // matrix that was used.
+ QPDF_DLL
+ std::string placeFormXObject(
+ QPDFObjectHandle fo, std::string const& name,
+ QPDFObjectHandle::Rectangle rect,
+ QPDFMatrix& cm,
+ bool invert_transformations = true,
+ 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
diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc
index aa7eb912..4460415b 100644
--- a/libqpdf/QPDFPageObjectHelper.cc
+++ b/libqpdf/QPDFPageObjectHelper.cc
@@ -1070,7 +1070,22 @@ QPDFPageObjectHelper::placeFormXObject(
bool invert_transformations,
bool allow_shrink, bool allow_expand)
{
- QPDFMatrix cm = getMatrixForFormXObjectPlacement(
+ QPDFMatrix cm;
+ return placeFormXObject(
+ fo, name, rect, cm, invert_transformations,
+ allow_shrink, allow_expand);
+}
+
+std::string
+QPDFPageObjectHelper::placeFormXObject(
+ QPDFObjectHandle fo, std::string const& name,
+ QPDFObjectHandle::Rectangle rect,
+ QPDFMatrix& cm,
+ bool invert_transformations,
+ bool allow_shrink,
+ bool allow_expand)
+{
+ cm = getMatrixForFormXObjectPlacement(
fo, rect, invert_transformations, allow_shrink, allow_expand);
return (
"q\n" +
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index 6f587d57..0935e4f8 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -5191,20 +5191,18 @@ static void do_under_overlay_for_page(
pdf.copyForeignObject(
from_page.getFormXObjectForPage());
}
- auto cm = dest_page.getMatrixForFormXObjectPlacement(
- fo[from_pageno],
- dest_page.getTrimBox().getArrayAsRectangle());
- dest_page.copyAnnotations(
- from_page, cm, dest_afdh, make_afdh(from_page));
// If the same page is overlaid or underlaid multiple times,
// we'll generate multiple names for it, but that's harmless
// and also a pretty goofy case that's not worth coding
// around.
std::string name = resources.getUniqueResourceName("/Fx", min_suffix);
+ QPDFMatrix cm;
std::string new_content = dest_page.placeFormXObject(
fo[from_pageno], name,
- dest_page.getTrimBox().getArrayAsRectangle());
+ dest_page.getTrimBox().getArrayAsRectangle(), cm);
+ dest_page.copyAnnotations(
+ from_page, cm, dest_afdh, make_afdh(from_page));
if (! new_content.empty())
{
resources.mergeResources(