Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates a IDOMFixedPage from an IPage, rotating content and cropbox as needed
// Create a IDOMFixedPage from an IPage, rotating content and cropbox as needed
static bool applyPageRotation(IJawsMakoPtr jawsMako, IPagePtr page, IDOMFixedPagePtr& fixedPage, FRect& cropBox)
{
if (!page)
return false;
// Does the page have crop margins?
// Note: page->getCropBox() will return the cropbox dimensions if set, or the mediabox (absolute page size) dimensions if not
// A fixedPage() does not offer this guarantee, so fixedPage->getCropBox() may return an empty FRect() (ie one or more values < 0)
cropBox = page->getCropBox();
// Is the page rotated?
const int32 rotationDegrees = (page->getRotate() + 360) % 360;
// Create a fixed page from the page contents, editable if content is to be rotated
fixedPage = rotationDegrees ? page->clone()->edit() : page->getContent();
// Rotate content as required
if (rotationDegrees)
{
const double width = fixedPage->getWidth();
const double height = fixedPage->getHeight();
FMatrix rotate;
switch (rotationDegrees / 90)
{
case 1: // 90 degrees
fixedPage->setWidth(height);
fixedPage->setHeight(width);
rotate.setDX(height);
break;
case 2: // 180 degrees
rotate.setDX(width);
rotate.setDY(height);
break;
case 3: // 270 degrees
fixedPage->setWidth(height);
fixedPage->setHeight(width);
rotate.setDY(width);
break;
default:
break;
}
rotate.rotate(rotationDegrees * PI / 180.0);
// Extract page objects into a group with the transform matrix at its root
IDOMGroupPtr transformGroup = IDOMGroup::create(jawsMako, rotate);
IDOMNodePtr node;
while ((node = fixedPage->extractChild(IDOMNodePtr())) != nullptr)
transformGroup->appendChild(node);
// Add rotated objects to page
fixedPage->appendChild(transformGroup);
// Rotate cropbox
rotate.transformRect(cropBox);
}
fixedPage->setCropBox(cropBox);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment