Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect stroke color bug in SynPDF #421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iadcode
Copy link

@iadcode iadcode commented Dec 22, 2021

This fix ensures that the stroke colour is reset when GRestore is called. The incorrect behaviour is triggered by the underline being rendered before the latter stroke.
Before the change
image
After the change
image

NB: The underline bug is being submitted as a separate PR (#422)

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

@iadcode iadcode marked this pull request as ready for review December 22, 2021 03:19
@synopse
Copy link
Owner

synopse commented Nov 15, 2024

Update: Why is this not merged yet?

We have merged a lot of fixes from third parties, and it almost every time broke the code working for other users of the library.
PDF generation is a tricky matter, and it is easy to break the existing.

From our point of view:

  1. Since we don't actively support mORMot 1.18 any more, you are welcome to switch to mORMot 2 and its https://github.com/synopse/mORMot2/blob/master/src/ui/mormot.ui.pdf.pas unit
  2. Fixing for one EMF input is likely to break existing code, which works for most users, so we would rather be very conservative, and only accept pull request with demonstrated compatibility
  3. You should also ensure that the code strictly follow mORMot formatting and types, and also that it compiles on both FPC and Delphi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants