Page 1 of 1

How to get ContentCreator Rect as points?

Posted: Thu Nov 09, 2017 7:39 pm
by whoit
Hi -

I'm using ShowTextBlock from ContentCreator.

After I add text, RotateCS, and then TranslateCS, I'd like to determine if any part of the resulting rectangle is off the page.
I'd like to check the 4 corner points of the rect against the page to see if any are outside the left, top, right, or bottom values.

How can I do this?

Re: How to get ContentCreator Rect as points?

Posted: Fri Nov 10, 2017 9:16 am
by Sasha - Tracker Dev Team
Hello Wayne,

This is a very wrong way of doing this. The correct matrix should be specified BEFORE you add the text so that the text would be placed in the needed position.

Cheers,
Alex

Re: How to get ContentCreator Rect as points?

Posted: Wed Nov 15, 2017 4:48 pm
by whoit
Perhaps I haven't been clear with my goal...

I'm trying to position text angled across the face of a document (lower-left to upper-right, for example), as large as possible -
what would be considered a typical watermark.

If not, then I need to set a textblock, font size, angle, and position, then determine
if it is either too large or too small, make changes, test again....
I can easily get the angle and the max length, but the font size will vary based on the
length of the text and therefore the need for repetition/testing....

Is there an API to do this without my having to calculate everything?

Re: How to get ContentCreator Rect as points?

Posted: Mon Nov 20, 2017 2:31 pm
by whoit
OK, how about this then:

How can I get the corner points of ShowTextBlock
AFTER using RotateCS?

Thanks,
Wayne

Re: How to get ContentCreator Rect as points?

Posted: Tue Nov 21, 2017 4:53 pm
by Paul - Tracker Supp
Hi Wayne,

Alex was unable to get to our post today, you should hear from him tomorrow.

hth

Re: How to get ContentCreator Rect as points?

Posted: Wed Nov 22, 2017 3:43 pm
by Sasha - Tracker Dev Team
Hello Wayne,

Here's a sample that you can try in the FullDemo application:

Code: Select all

private void placeRotatedWatermarkToolStripMenuItem_Click(object sender, EventArgs e)
{
	PDFXEdit.IPXC_Document doc = pxcInst.NewDocument();

	PDFXEdit.PXC_Rect rcMedia;
	rcMedia.left = 0;
	rcMedia.bottom = 0;
	rcMedia.top = 800;
	rcMedia.right = 600;
	PDFXEdit.IPXC_UndoRedoData urData;
	PDFXEdit.IPXC_Page page = doc.Pages.InsertPage(0, ref rcMedia, out urData);

	PXC_Matrix mRot = new PXC_Matrix();
	auxInst.MathHelper.Matrix_Reset(ref mRot);
	mRot = auxInst.MathHelper.Matrix_Rotate(ref mRot, -page.Rotation);
	auxInst.MathHelper.Rect_Transform(ref mRot, ref rcMedia);
	var dX = rcMedia.left;
	var dY = rcMedia.bottom;
	auxInst.MathHelper.Matrix_Translate(ref mRot, -dX, -dY);
	rcMedia.left -= dX;
	rcMedia.right -= dX;
	rcMedia.top -= dY;
	rcMedia.bottom -= dY;

	PXC_Rect rcContentRect;
	PDFXEdit.IPXC_ContentCreator CC = doc.CreateContentCreator();
	CC.ShowTextBlock("Test Text", ref rcMedia, ref rcMedia, (uint)PXC_DrawTextFlags.DTF_CalcSizeOnly, -1, null, null, null, out rcContentRect);


	PXC_Rect rcS = rcMedia;
	double dRotation = 45.0;
	PXC_Rect rcR = rcContentRect;
	PXC_Matrix m = new PXC_Matrix();
	auxInst.MathHelper.Matrix_Reset(ref m);
	m = auxInst.MathHelper.Matrix_Rotate(ref m, dRotation);
	auxInst.MathHelper.Rect_Transform(ref m, ref rcR);
	PXC_Rect rcRes;
	//Fit rect to rect
	{
		var k1 = (rcR.right - rcR.left) / Math.Abs(rcR.top - rcR.bottom);
		var k2 = (rcS.right - rcS.left) / Math.Abs(rcS.top - rcS.bottom);
				
		if (k1 >= k2)
		{
			var h = (rcS.right - rcS.left) / k1;
			rcRes = rcS;
			rcRes.bottom += (Math.Abs(rcRes.top - rcRes.bottom) - h) / 2;
			rcRes.top = rcRes.bottom + h;
		}
		else
		{
			var w = (rcS.right - rcS.left) * k1;
			rcRes = rcS;
			rcRes.left += ((rcRes.right - rcRes.left) - w) / 2;
			rcRes.right = rcRes.left + w;
		}
	}
	PXC_Matrix mm = new PXC_Matrix();
	auxInst.MathHelper.Matrix_Reset(ref mm);
	mm = auxInst.MathHelper.Matrix_RectToRect(rcR, rcRes);
	PXC_Matrix mResMatrix = auxInst.MathHelper.Matrix_Multiply(ref m, ref mm);
	mRot = auxInst.MathHelper.Matrix_Invert(ref mRot);
	mResMatrix = auxInst.MathHelper.Matrix_Multiply(ref mResMatrix, ref mRot);
	CC.ConcatCS(mResMatrix);
	CC.ShowTextBlock("Test Text", ref rcMedia, ref rcMedia, 0, -1, null, null, null, out rcContentRect);

	page.PlaceContent(CC.Detach(), (UInt32)PDFXEdit.PXC_PlaceContentFlags.PlaceContent_After);

	pdfCtl.OpenDocFrom(doc);
}
Cheers,
Alex

Re: How to get ContentCreator Rect as points?

Posted: Mon Nov 27, 2017 2:12 pm
by whoit
Thanks Alex....I'll dig into the code this week....

Re: How to get ContentCreator Rect as points?

Posted: Mon Nov 27, 2017 2:13 pm
by Tracker Supp-Stefan
:D

Re: How to get ContentCreator Rect as points?

Posted: Mon Dec 11, 2017 9:41 pm
by whoit
OK, I finally tested the sample code from earlier in this thread.
It works, but I have two different problems now:

1) It distorts (shears) the text based on the rotation angle.
That is, if the text rotation angle is 0, 90, 180, 270 then everything is fine.
However, if the angle is something like 37, then the text gets sheared.

Here's a sample of the output at 37 degrees:
http://www.coastallogic.com/public/wayn ... fWEHTR.pdf

2) If the PDF pages are rotated (internally within the PDF) then the text is completely off the page, unlike within your Editor
(screenshot: http://www.coastallogic.com/public/wayn ... rkSnap.png )

Here's my code - I had to convert yours since we do not use the Editor SDK but other than SDK calls, it should be exactly the same:

Code: Select all

        private void placeRotatedWatermark(string wmText)
        {
            double pageHeight, pageWidth;
            currentPage.GetDimension(out pageWidth, out pageHeight);

            PXC_Rect rcMedia;
            rcMedia.left = 0;
            rcMedia.bottom = 0;
            rcMedia.top = pageHeight;
            rcMedia.right = pageWidth;

            PXC_Matrix mRot = new PXC_Matrix();
            auxInst.MathHelper.Matrix_Reset(ref mRot);
            mRot = auxInst.MathHelper.Matrix_Rotate(ref mRot, -currentPage.Rotation);
            auxInst.MathHelper.Rect_Transform(ref mRot, ref rcMedia);
            var dX = rcMedia.left;
            var dY = rcMedia.bottom;
            auxInst.MathHelper.Matrix_Translate(ref mRot, -dX, -dY);
            rcMedia.left -= dX;
            rcMedia.right -= dX;
            rcMedia.top -= dY;
            rcMedia.bottom -= dY;

            PXC_Rect rcContentRect;
            IPXC_ContentCreator CC = pDoc.CreateContentCreator();

            uint nFlags = (uint)PXC_DrawTextFlags.DTF_RichText; //default is 0
            nFlags = nFlags | (uint)PXC_DrawTextFlags.DTF_CalcSizeOnly;
            CC.ShowTextBlock(wmText, ref rcMedia, ref rcMedia, nFlags, -1, null, null, null, out rcContentRect);

            PXC_Rect rcS = rcMedia;
            double dRotation = 45.0;
            PXC_Rect rcR = rcContentRect;
            PXC_Matrix m = new PXC_Matrix();
            auxInst.MathHelper.Matrix_Reset(ref m);
            m = auxInst.MathHelper.Matrix_Rotate(ref m, dRotation);
            auxInst.MathHelper.Rect_Transform(ref m, ref rcR);
            PXC_Rect rcRes;
            //Fit rect to rect
            {
                var k1 = (rcR.right - rcR.left) / Math.Abs(rcR.top - rcR.bottom);
                var k2 = (rcS.right - rcS.left) / Math.Abs(rcS.top - rcS.bottom);

                if (k1 >= k2)
                {
                    var h = (rcS.right - rcS.left) / k1;
                    rcRes = rcS;
                    rcRes.bottom += (Math.Abs(rcRes.top - rcRes.bottom) - h) / 2;
                    rcRes.top = rcRes.bottom + h;
                }
                else
                {
                    var w = (rcS.right - rcS.left) * k1;
                    rcRes = rcS;
                    rcRes.left += ((rcRes.right - rcRes.left) - w) / 2;
                    rcRes.right = rcRes.left + w;
                }
            }

            PXC_Matrix mm = new PXC_Matrix();
            auxInst.MathHelper.Matrix_Reset(ref mm);
            mm = auxInst.MathHelper.Matrix_RectToRect(rcR, rcRes);
            PXC_Matrix mResMatrix = auxInst.MathHelper.Matrix_Multiply(ref m, ref mm);
            mRot = auxInst.MathHelper.Matrix_Invert(ref mRot);
            mResMatrix = auxInst.MathHelper.Matrix_Multiply(ref mResMatrix, ref mRot);
            CC.ConcatCS(mResMatrix);
            // Remove calcsize bit and show the text
            nFlags = nFlags ^ (uint)PXC_DrawTextFlags.DTF_CalcSizeOnly;
            CC.ShowTextBlock(wmText, ref rcMedia, ref rcMedia, nFlags, -1, null, null, null, out rcContentRect);

            currentPage.PlaceContent(CC.Detach(), (UInt32)PXC_PlaceContentFlags.PlaceContent_After);
        }

Re: How to get ContentCreator Rect as points?

Posted: Tue Dec 12, 2017 11:03 am
by Sasha - Tracker Dev Team
Hello whoit,

1)Our sample works fine - no distortions. Please provide a fully working sample project on this matter that we can test. Also, provide a file with the results (the link you gave us is broken).
As a piece of advice, try without the line-height parameter - if you are using it that is. Read Remarks here for more details:
https://sdkhelp.pdf-xchange.com/vi ... wTextBlock

2) Try commenting this piece of code and see whether it works:

Code: Select all

			//var dX = rcMedia.left;
			//var dY = rcMedia.bottom;
			//auxInst.MathHelper.Matrix_Translate(ref mRot, -dX, -dY);
			//rcMedia.left -= dX;
			//rcMedia.right -= dX;
			//rcMedia.top -= dY;
			//rcMedia.bottom -= dY;
Cheers,
Alex

Re: How to get ContentCreator Rect as points?

Posted: Tue Dec 12, 2017 10:14 pm
by whoit
Here is a link to sample C# code that shows the issue with skewed output.
www.coastallogic.com/wayne/TrackerTest_Watermark.zip

Here's a link to an example file where the text is skewed, and the angle of rotation is 45degrees which should not fit corner to corner!
(37 degrees is closer to the correct angle for a Letter size landscape page)
http://www.coastallogic.com/wayne/Lette ... eWEHTR.pdf

It also include my PDF test files which are rotated to various degrees (0, 90, 180, 270)

I've noticed that your Editor works perfectly when rotating the watermark, and when using a rotated PDF....

Thanks.

Re: How to get ContentCreator Rect as points?

Posted: Wed Dec 13, 2017 9:01 am
by Sasha - Tracker Dev Team
Hello Wayne,

Found a typo in my code:

Code: Select all

var w = Math.Abs(rcS.top - rcS.bottom) * k1; //this is correct
With this it should work correctly.

Cheers,
Alex

Re: How to get ContentCreator Rect as points?

Posted: Wed Dec 13, 2017 2:15 pm
by whoit
Perfect!

Thanks again...

Re: How to get ContentCreator Rect as points?

Posted: Wed Dec 13, 2017 2:43 pm
by Sasha - Tracker Dev Team
:)