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 fill region bugs in SynPDF #423

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iadcode
Copy link

@iadcode iadcode commented Dec 22, 2021

These changes fix some bugs in SynPDF relating to filling regions.

  • The first commit ensures complex regions are filled using the defined region rather than the bounding rectangle
  • The second commit fixes a bug where the current brush is incorrectly changed when filling a region

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

Fix a bug in SynPDF where filling a complex region uses the
bounding rectangle rather than the defined region.
Fix a bug in SynPDF where it incorrectly changes the current brush when filling a region.
@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