#1 2016-06-27 11:19:00

Magnus
Member
Registered: 2015-05-27
Posts: 2

Text position with inverted y coordinates.

Hi,

On a page I am trying to print to pdf there is a metafile where the y-axis is inverted. It seems like the text is positioned with the starting point as lower left, instead of top left.

I am digging around in TPdfEnum.TextOut and looking at the H calculations. I dare not try to fix it myself since I do not know all the cases that the calculations are meant for, but

    if ASignY<0 then                            //inverted coordinates
      H := Abs(font.LogFont.lfHeight)+H;

is what finally destroys the H value.

Below is code for generating a metafile which shows the error. It is just a rectangle with text inside it.

When generating the pdf, the text is no longer inside the box.

var
  mf: TMetafile;
  mfc: TMetafileCanvas;
begin
  mf := TMetafile.Create;
  try
    mf.SetSize(100, 100);
    mfc := TMetafileCanvas.Create(mf, 0);
    try
      SetMapMode(mfc.Handle, MM_ANISOTROPIC);
      SetWindowExtEx(mfc.Handle, 100, 100, nil);
      SetViewportExtEx(mfc.Handle, 100, -100, nil);

      mfc.MoveTo(10, -10);
      mfc.LineTo(39, -10);
      mfc.LineTo(39, -26);
      mfc.LineTo(10, -26);
      mfc.LineTo(10, -10);
      mfc.TextOut(13, -12, 'Hello');
    finally
      mfc.Free;
    end;
  finally
    mf.free;
  end;
end;

Regards,

/Magnus

Offline

Board footer

Powered by FluxBB