TextBlock - Rect vs RectF  SOLVED

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
JesseH
User
Posts: 18
Joined: Fri Jul 22, 2016 8:47 pm
Location: TN

TextBlock - Rect vs RectF

Post by JesseH » Tue Dec 13, 2016 3:52 pm

How can I translate a PXC_Rect to a PXC_RectF?

So far I'm having a lot of success in identifying text locations via PXC_Rect, using x,y coords with an origin at the lower left corner and in units of pixels.

However when I run an analysis on the characters in PageText, I get this output: (Note: each entry is a '<' found the PageText. The output is CharBBox and CharRect and printed out as [bottom], , , [top])

Code: Select all

Carrot found:
  BBox: [-2.904, 0.000, 5.335, 9.526]
  Rect: [714.681, 438.729, 444.065, 727.111]

Carrot found:
  BBox: [-2.904, 0.000, 5.335, 9.526]
  Rect: [703.802, 438.729, 444.065, 716.232]

Carrot found:
  BBox: [-2.904, 0.000, 5.335, 9.526]
  Rect: [751.387, 438.729, 444.065, 763.817]
It appears the CharBBox is associated with the TextBlock, but I can't see how the values are derived. As the Rect values suggest, these are three lines near the upper-right corner.
Attachments
SI4_template - Copy.pdf
Redacted copy of the file being analyzed
(172.77 KiB) Downloaded 92 times

User avatar
Sasha - Tracker Dev Team
User
Posts: 4433
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: TextBlock - Rect vs RectF

Post by Sasha - Tracker Dev Team » Tue Dec 13, 2016 3:59 pm

Hello JesseH,

Well you can write a small method that would do that by yourself - you will need to convert four doubles into floats.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

JesseH
User
Posts: 18
Joined: Fri Jul 22, 2016 8:47 pm
Location: TN

Re: TextBlock - Rect vs RectF

Post by JesseH » Tue Dec 13, 2016 4:04 pm

As a followup, is the answer to the question above the same for determining the values of a PXC_PointF?

JesseH
User
Posts: 18
Joined: Fri Jul 22, 2016 8:47 pm
Location: TN

Re: TextBlock - Rect vs RectF

Post by JesseH » Tue Dec 13, 2016 4:06 pm

But how are the values converted? Casting them to doubles is pointless when the numbers themselves aren't the same.

User avatar
Sasha - Tracker Dev Team
User
Posts: 4433
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: TextBlock - Rect vs RectF

Post by Sasha - Tracker Dev Team » Wed Dec 14, 2016 12:32 pm

Hello Jesse,

If you would look at these properties description on the wiki page you would see this:
Property CharBBox of interface IPXC_PageText returns Value of PXC_RectF containing the character's bound box in the line's coordinate system.
Property CharRect of interface IPXC_PageText returns Value of PXC_Rect containing the character's bound box in the page's coordinate system.
That's the difference between these two properties.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

JesseH
User
Posts: 18
Joined: Fri Jul 22, 2016 8:47 pm
Location: TN

Re: TextBlock - Rect vs RectF

Post by JesseH » Wed Dec 14, 2016 2:35 pm

Thanks, I suspected they were relative to different planes, but hadn't noticed the distinction on the wiki pages.

One more thing, what about IPXC_TextBlockInfo.BBox? It appears to not be on plane with a lower-left origin as well. That's what initially set me on this tangent of double vs float. I wasn't sure float and double coordinates weren't treated differently like, for example, OpenGL in the early 2000's.

The wiki simply says
Property stBBox of interface IPXC_TextBlockInfo returns Value of PXC_RectF ...
Basically, I'm trying to find the coordinates of a text block on the page's plane to guide a scripted content replacement process. I've already built a workaround using multiple lines, but being able to work with paragraphs and alignment options would be nice. :D

User avatar
Sasha - Tracker Dev Team
User
Posts: 4433
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: TextBlock - Rect vs RectF  SOLVED

Post by Sasha - Tracker Dev Team » Wed Dec 14, 2016 3:29 pm

Hello Jesse,

The IPXC_TextBlockInfo.BBox contains the text block's bound box in the block's coordinate system. Having the text block's matrix you cant transform this rectangle so that you will have the box in the page's coordinate system.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1937
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: TextBlock - Rect vs RectF

Post by Vasyl-Tracker Dev Team » Wed Dec 14, 2016 5:25 pm

Hi, Jesse.

Also helpful tip for you about translation coordinates from text-block coord. space to the page's coord. space:

Code: Select all

PDFXEdit.IAUX_Inst auxInst = (PDFXEdit.IAUX_Inst)pdfCtl.Inst.GetExtension("AUX");

PDFXEdit.IMathHelper mh = auxInst.MathHelper;

txtBBoxOnThePage = IPXC_TextBlockInfo.BBox;
mh.Rect_Transform(IPXC_TextBlockInfo.Matrix, txtBBoxOnThePage);
HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

JesseH
User
Posts: 18
Joined: Fri Jul 22, 2016 8:47 pm
Location: TN

Re: TextBlock - Rect vs RectF

Post by JesseH » Tue Dec 20, 2016 2:18 pm

Thanks. Both of the last posts helped immensely.

User avatar
Sasha - Tracker Dev Team
User
Posts: 4433
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: TextBlock - Rect vs RectF

Post by Sasha - Tracker Dev Team » Tue Dec 20, 2016 2:51 pm

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply