Skip to main content
Skip table of contents

Transforming objects without shifting their location

📌 Overview

This article explains how to transform objects without shifting their location on the page. In FMatrix and transforms, we learned that the point of rotation is always the top left of the page when rotating using FMatrix::rotate(). This leads to an apparent shift in the object’s location. Below are some screenshots that demonstrate this effect when rotating some text.

Original

Boxes added

Green box moved

a9639738-db6c-41ea-b4ed-dd8a17abb564.png
Screenshot 2025-06-10 161430.png

Boxes are added to demonstrate how the rotation is applied

image-20250610-152459.png

When the green (rotated) box is moved you can see that the top left corner of the box was still in the top left corner of the page.

(question) Issue Description

A customer reported that when they rotated some text, it would also be shifted from its original location. They wanted to know how to calculate the translation needed to counteract this shift so that the top left corner of the text would not move.

💡 Solution

The easiest way to avoid this is to move the group containing the text to the top corner of the page first before rotating, and then moving it back afterwards.

⌨️ Sample Code

Here is a code snippet in C# that uses the above formula to return text in an ILayout back to its original position after rotating to achieve the desired result below.

Screenshot 2025-06-10 161443.png

C#
//get the position of the text on the page
var layoutNode = layout.layout(paragraphs);
var bounds = layoutNode.getBounds();
  
//create an FMatrix and add the rotation
var rotate = new FMatrix();   
var angle = text.Rotation * (Math.PI / 180.0);
rotate.rotate(angle);

//use the formula to add the translation back to the original position on the page
rotate.setDX(bounds.x*(1-Math.Cos(angle)) + bounds.y*Math.Sin(angle));
rotate.setDY(bounds.y*(1-Math.Cos(angle)) - bounds.x*Math.Sin(angle));

//create a group with the transformations and add the layout to it 
var group = IDOMGroup.create(mako, rotate);
group.appendChild(layoutNode);

//add the group to the fixedPage
fixedPage.appendChild(group);

☑️ Conclusion

Rotating text without shifting its location is a common requirement for maintaining the visual integrity of a document. By applying the provided formula and utilizing the sample C# code, users can effectively manage text rotation while keeping the text in its original position

📚 Additional Resources

If you need additional help, see our API documentation for detailed information on class/method usage, or raise a support ticket via our customer portal.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.