Add new placeFormXObject that takes a matrix reference

This commit is contained in:
Jay Berkenbilt 2021-02-22 16:02:47 -05:00
parent 61d41e2e88
commit 8e8c0d8290
4 changed files with 38 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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" +

View File

@ -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(