PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 6:58 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Apr 08, 2018 4:28 pm 
Offline

Joined: Thu Nov 11, 2010 10:03 am
Posts: 7
Hello

I use to work with GDI Graphics to draw Diagram, normaly the origin of coordinate is 0,0 : Bottom Left
XGraphix and GDI Graphics have the Origin on TOP Left

So when Using a GDI Graphic I set a Transformation Matrix
Code SetTransformMatrix below
But I'm trying do to Similar with
XGraphics like this :
Code:
     gfx.TranslateTransform(-offset_x, offset_y, XMatrixOrder.Append);
      gfx.ScaleTransform(scaleX, scaleY, XMatrixOrder.Append);


Full code below
Without any succes
What I'm doing wrong ??
Is it possible to invert Origin with Xgraphics
Thanks for any help

Code for GDI : (working well)
Code:
    // *************************************************************************
    public static Matrix SetTransformMatrix(RectangleF World, SizeF Dest, bool Centered)
    {
      double map_W = World.Width;
      double map_H = World.Height;

      double rh = Dest.Height / (map_H);
      double rw = Dest.Width / (map_W);

      double scaleX = rw;
      double scaleY = rh;

      double ofY = 0;
      double ofX = 0;


      ofX = ((Dest.Width / scaleX) - World.Width) / 2;
      ofY = ((Dest.Height / scaleY) - World.Height) / 2;


      double offset_x = World.X;
      double offset_y = World.Y + World.Height;

      if (Centered)
      {
        offset_x -= ofX;
        offset_y += ofY;
      }
      float offset_Xf = (float)offset_x;
      float offset_Yf = (float)offset_y;

      Matrix m = new Matrix(1.0f,
                            0.0f,
                            0.0f,
                            -1.0f,
                            0.0f,
                            0.0f);

      m.Translate(-offset_Xf, offset_Yf, MatrixOrder.Append);
      m.Scale((float)scaleX, (float)scaleY, MatrixOrder.Append);
      return m;
    }


Code for Xgraphics : Graph is Upside Down
Code:
   internal static void SetTransformMatrix(XRect World, XSize Dest, bool Centered, XGraphics gfx)
    {
      double map_W = World.Width;
      double map_H = World.Height;

      double rh = Dest.Height / (map_H);
      double rw = Dest.Width / (map_W);

      double scaleX = rw;
      double scaleY = rh;

      double ofY = 0;
      double ofX = 0;


      ofX = ((Dest.Width / scaleX) - World.Width) / 2;
      ofY = ((Dest.Height / scaleY) - World.Height) / 2;


      double offset_x = World.X;
      double offset_y = -World.Y;  // Not good but it shows something upsisde down

 

      gfx.TranslateTransform(-offset_x, offset_y, XMatrixOrder.Append);
      gfx.ScaleTransform(scaleX, scaleY, XMatrixOrder.Append);
    }


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 08, 2018 4:43 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 905
Location: CCAA
Hi!
olibara wrote:
Full code below
To provide "full code", please use the IssueSubmissionTemplate.
See also:
viewtopic.php?f=2&t=832

To me it is somewhat unclear what your code does versus what you expect.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 09, 2018 4:44 am 
Offline

Joined: Thu Nov 11, 2010 10:03 am
Posts: 7
Thank you TH-Soft

My issue was that the graph displayed using the Transformation I had was upside down
My difficulty was to understand how to set the transformation to Xgraphics to inver the Y axis the same way as I'm doing with the Matrix of GDI+

But in the meantime I've found the way : the trick is to change the sign of the Y scale

This is it :D

Code:
   
      double offset_x = World.X;
      double offset_y = (World.Y+World.Height);  // Offset is Y origin + Height

      gfx.TranslateTransform(-offset_x, -offset_y, XMatrixOrder.Append);
      gfx.ScaleTransform(scaleX, -scaleY, XMatrixOrder.Append);   // Y scale must be inverted


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group