Recent

Author Topic: [SOLVED]Y Coordinates rvrse when Using FPVectorialtoCanvas to draw SVG Canvas  (Read 5456 times)

Schmitty2005

  • Jr. Member
  • **
  • Posts: 65
I was unable to get a picture, but my Y coordinates are reversed when using FPVtoCanvas Unit from FPVectorial located in Lazaruas Source  / components directory. Top is on bottom and bottom is on top.  I was simply creating a Vectorial Page, and passing that to DrawFPVectorialToCanvas.

Code: Pascal  [Select][+][-]
  1. Uses ..., ..., fpvtocanvas, ... , ...;
  2.  
  3. ...
  4. ...
  5.  
  6. DrawFPVectorialToCanvas(vec, Panel1.canvas, 50, 50, 2,2)
  7.  
Any Suggestions ?
« Last Edit: January 11, 2025, 10:34:47 pm by Schmitty2005 »

VisualLab

  • Hero Member
  • *****
  • Posts: 742
This suggests that you may have taken as your reference point (i.e. origin, x= 0, y = 0) the top left corner of the canvas (the default in GDI, although this can be changed). However, from the description in the TPVectorial* documentation, it would seem that it should be the bottom left corner of the canvas.



*) Section: "Adding paths, bezier lines and text" and "Coordinates in FPVectorial".



Schmitty2005

  • Jr. Member
  • **
  • Posts: 65
Thank you for the reply.  I am aware of the difference in the coordinate systems. The SVG looks as it should when viewed in a web browser, with the top on top and bottom on the bottom.  However, when drawing the vector to the canvas, it is reversed Y coordinates, looking like  a mirrored imaged.  The top is on the bottom, and the bottom is on the top.  The X coordinates are correct.  So, yes, it is something to do with the coordinate systems of SVG and Canvas.

  I would think that the DrawFPVectorialToCanvas() should automatically translate between the two different coordinate systems., properly, as it is the one  drawing the SVG to the canvas  I was trying to make it as simple as possible by drawing the SVG on the canvas, without having to have two routines or another method  for each coordinate system.     

wp

  • Hero Member
  • *****
  • Posts: 13552
Felipe at some point decided to support both positions of the origin, left/top or left/bottom, because every format his its own preferences, and partly even on the same page writing direction may change (drawings with left/bottom origin, but text grows from top to bottom!) There is a property UseTopLeftCoordinates of the page. In the call to create the page (AddPage) you can specify which coordinate system you want for it (AddPage(true) --> UseTopLeftCoordinates is true). There are also some element which have their own setting for it.

And when you render the drawing there is another option to flip the y coordinate: in unit fpvToCanvas, DrawFPVectorialToCanvas you have scaling factors for x and y, and when you select a negative value for the y multiplier, you'll flip the direction again.

Code: Pascal  [Select][+][-]
  1. procedure DrawFPVectorialToCanvas(ASource: TvVectorialPage;
  2.   ADest: TFPCustomCanvas;
  3.   ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
  4. begin
  5.   ASource.Render(ADest, ADestX, ADestY, AMulX, AMulY);
  6. end;

I gave up understand all the combinations. Just play with the settings until you found the combination that you need.

Schmitty2005

  • Jr. Member
  • **
  • Posts: 65
And when you render the drawing there is another option to flip the y coordinate: in unit fpvToCanvas, DrawFPVectorialToCanvas you have scaling factors for x and y, and when you select a negative value for the y multiplier, you'll flip the direction again.

Using the -y multiplier fixes the issue !  Thank you!

It was also on the doc wiki in the code comments for fpvToCanvas that I did not notice previously.

Code: Pascal  [Select][+][-]
  1. unit fpvtocanvas;
  2. //..
  3. {@@
  4.   This function draws a FPVectorial vectorial image to a TFPCustomCanvas
  5.   descendent, such as TCanvas from the LCL.
  6.  
  7.   Be careful that by default this routine does not execute coordinate transformations,
  8.   and that FPVectorial works with a start point in the bottom-left corner, with
  9.   the X growing to the right and the Y growing to the top. This will result in
  10.   an image in TFPCustomCanvas mirrored in the Y axis in relation with the document
  11.   as seen in a PDF viewer, for example. This can be easily changed with the
  12.   provided parameters. To have the standard view of an image viewer one could
  13.   use this function like this:
  14.  
  15.   DrawFPVectorialToCanvas(ASource, ADest, 0, ASource.Height, 1.0, -1.0);
  16. }
  17. procedure DrawFPVectorialToCanvas(ASource: TvVectorialPage;
  18.   ADest: TFPCustomCanvas;
  19.   ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
  20.  

Schmitty2005

  • Jr. Member
  • **
  • Posts: 65
Is there a way to mark this topic as solved ?  Or do I just manually Edit the Thread title ?

440bx

  • Hero Member
  • *****
  • Posts: 6528
Is there a way to mark this topic as solved ?  Or do I just manually Edit the Thread title ?
Answer: manually edit the thread title
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

cdbc

  • Hero Member
  • *****
  • Posts: 2808
    • http://www.cdbc.dk
In the first post in the thread.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

VisualLab

  • Hero Member
  • *****
  • Posts: 742
Using the -y multiplier fixes the issue !  Thank you!

Maybe it would be a good idea to be able to explicitly set the reference point for the coordinate system (origin)? For example:
  • a read-write property, or
  • a method and read-only property (object state).
It seems to me that this would be a more elegant (and clearer) solution than having to "manually" multiply by a specific factor. Especially since it would then be possible to verify the reference point very easily in the code. But that is up to the library author (i.e. if he finds it useful or wants to add it to his code).

 

TinyPortal © 2005-2018