DrawToIXCPage with Rotated Page

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, 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
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

DrawToIXCPage with Rotated Page

Post by jeffp »

When I draw a PDF Page to IIXC_Page using the following

APage.DrawToIXCPage(Result, xDestRect, pMatrix, ARenderParams, AOCContext, nil);

If the PDF Page is rotated before I make the call, it appears that the call automatically rotates the page back to 0 before drawing. Is there a way to force this to draw the page in its current rotation state, that is, the way it looks when you are viewing it?

Thanks.

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

Re: DrawToIXCPage with Rotated Page

Post by Sasha - Tracker Dev Team »

Hello Jeff,

All of the rotation and scaling is being done by the matrix that you have specified. Please provide all of the code where you are calculating the matrix and then we can advice further.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToIXCPage with Rotated Page

Post by jeffp »

Here is the relevant code (most of which I got from you a while back).

Currently, I'm just using

APage.Set_Rotation(0);

Before I do the drawing, which seems to work just fine, but would like to understand what part of the matrix code is doing the rotation if I don't call APage.Set_Rotation(0) first.

--Jeff

Code: Select all

procedure TransformRect(m1: PXC_Matrix; var rcPageBox: PXC_Rect);
var
  x, y, x1, x2, y1, y2: Double;
begin
  x := rcPageBox.left;
  y := rcPageBox.bottom;
  Transform(m1, x, y);
  x1 := x;
  x2 := x;
  y1 := y;
  y2 := y;
  x := rcPageBox.left;
  y := rcPageBox.top;
  Transform(m1, x, y);
  UpdateMinMax(x, x1, x2);
  UpdateMinMax(y, y1, y2);
  x := rcPageBox.right;
  y := rcPageBox.top;
  Transform(m1, x, y);
  UpdateMinMax(x, x1, x2);
  UpdateMinMax(y, y1, y2);
  x := rcPageBox.right;
  y := rcPageBox.bottom;
  Transform(m1, x, y);
  UpdateMinMax(x, x1, x2);
  UpdateMinMax(y, y1, y2);
  rcPageBox.left := x1;
  rcPageBox.right := x2;
  rcPageBox.bottom := y1;
  rcPageBox.top := y2;
end;

function RectToRectMatrix(from: PXC_Rect; to_: tagRECT): PXC_Matrix;
var
  m: PXC_Matrix;
begin
  if ((to_.right = to_.left) or (to_.top = to_.bottom) or (from.left = from.right) or (from.top = from.bottom)) then
  begin
    m.d := 1.0;
    m.a := m.d;
  end else
  begin
    m.a := ((to_.right - to_.left) / (from.right - from.left));
    m.d := ((to_.top - to_.bottom) / (from.top - from.bottom));
  end;
  m.b := 0;
  m.c := 0;
  m.e := (to_.left - from.left * m.a);
  m.f := (to_.bottom - from.bottom * m.d);
  Result := m;
end;

function Multiply(m1: PXC_Matrix; m2: PXC_Matrix): PXC_Matrix;
var
  t0, t2, t4: Double;
begin
   t0 := (m1.a * m2.a + m1.b * m2.c);
   t2 := (m1.c * m2.a + m1.d * m2.c);
   t4 := (m1.e * m2.a + m1.f * m2.c + m2.e);
   m1.b := (m1.a * m2.b + m1.b * m2.d);
   m1.d := (m1.c * m2.b + m1.d * m2.d);
   m1.f := (m1.e * m2.b + m1.f * m2.d + m2.f);
   m1.a := t0;
   m1.c := t2;
   m1.e := t4;
   Result := m1;
end;

function RectToMatrix(ARect: PXC_Rect): PXC_Matrix;
begin
  with Result, ARect do
  begin
    a := right - left;
    b := 0;
    c := 0;
    d := top - bottom;
    e := left;
    f := bottom;
  end;
end;

....

    APage.GetDimension(pWidth, pHeight);

    with pDrawRect do
    begin
      left := 0;
      top := pHeight;
      right := pWidth;
      bottom := 0;
    end;

    pMatrix := RectToMatrix(pDrawRect);

    with xDestRect do
    begin
      left := Round(P2X(pDrawRect.left, ADPI) * ARatio);
      top := Round(P2X(pHeight - pDrawRect.top, ADPI) * ARatio);
      right := Left + Round(P2X(pDrawRect.right - pDrawRect.left, ADPI) * ARatio);
      bottom := Top + Round(P2X(pDrawRect.top - pDrawRect.bottom, ADPI) * ARatio);
    end;

    TransformRect(pMatrix, pDrawRect);
    pTempMatrix := RectToRectMatrix(pDrawRect, xDestRect);
    pMatrix := Multiply(pMatrix, pTempMatrix);

    ARenderParams := nil;
    AOCContext := nil;
    APage.DrawToIXCPage(Result, xDestRect, pMatrix, ARenderParams, AOCContext, nil);

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

Re: DrawToIXCPage with Rotated Page

Post by Sasha - Tracker Dev Team »

Hello Jeff,

If you are using the APage.Set_Rotation(0); then it means that you have not set the matrix correctly. You will need to clearly understand and know what you are doing to set the matrix correctly.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToIXCPage with Rotated Page

Post by jeffp »

I thought that's why you wanted to see my code. So you can tell me where in my matrix code the page is being rotated.

You're correct. I don't fully understand how the Matrix code is working.

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

Re: DrawToIXCPage with Rotated Page

Post by Sasha - Tracker Dev Team »

The thing is that you will need to fully understand what do you have as an input and what do you want to have as an output (that I do not clearly see from the code thus it will be better if you explain).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToIXCPage with Rotated Page

Post by jeffp »

Until I can better understand the matrix code, I will just call

APage.Set_Rotation(0);

before drawing the page. Then I'll rotate it back to the original angle after I draw the page.

I assume that this will be fine too.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: DrawToIXCPage with Rotated Page

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Well that is not the correct way to do it though if works for you that's probably fine.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply