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, Chris - Tracker Supp, Sean - Tracker, 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 »

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 191 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: TextBlock - Rect vs RectF

Post by Sasha - Tracker Dev Team »

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

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 »

But how are the values converted? Casting them to doubles is pointless when the numbers themselves aren't the same.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: TextBlock - Rect vs RectF

Post by Sasha - Tracker Dev Team »

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

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
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: TextBlock - Rect vs RectF  SOLVED

Post by Sasha - Tracker Dev Team »

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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: TextBlock - Rect vs RectF

Post by Vasyl-Tracker Dev Team »

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 »

Thanks. Both of the last posts helped immensely.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: TextBlock - Rect vs RectF

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply