synopse / mORMot

Synopse mORMot 1 ORM/SOA/MVC framework - Please upgrade to mORMot 2 !
https://synopse.info
785 stars 323 forks source link

Fix text bugs in SynPDF #422

Open iadcode opened 2 years ago

iadcode commented 2 years ago

These changes fix some bugs in SynPDF:

Before the changes image After the changes image

This behaviour can be tested with code such as

  procedure EmfToPdf(EmfFilename: String; PdfFilename: String);
  const
    C_PDFPPI = 72;
    C_MMperInch = 25.4;
  var
    PDFDocument: TPdfDocument;
    Metafile: TMetafile;
    Scale: Single;
  begin
    Metafile := TMetafile.Create;
    try
      Metafile.LoadFromFile(EmfFilename);
      PDFDocument := TPdfDocument.Create(False, 0, False);
      try
        PDFDocument.DefaultPaperSize := psA4;
        PDFDocument.ScreenLogPixels := C_PDFPPI;
        PDFDocument.AddPage;
        Scale := C_PDFPPI / Trunc((Metafile.Width * 100) / (Metafile.MMWidth / C_MMperInch));
        PDFDocument.Canvas.RenderMetaFile(Metafile, Scale, Scale, 0, 0, tpSetTextJustification, 99, 101, tcAlwaysClip);
        PDFDocument.SaveToFile(PdfFilename);
      finally
        FreeAndNil(PDFDocument);
      end;
    finally
      FreeAndNil(Metafile);
    end;
  end;

And using an EMF such as the one in this zip: BugsEMF.zip