#1 2025-07-16 08:50:36

hukmac
Member
Registered: 2025-06-30
Posts: 6

SynPdf with alpha blending control passed through EMF (published)

Hello smile

I have created a version of SynPdf in which alpha blending control can be performed not only with 'low-level' PDF commands in methods of TPdfCanvas, but also through EMF by drawing with GDI to TMetafileCanvas. Thus, the great strength of SynPdf – the ability to create PDF content with GDI methods – happened to be extended with ability to manipulate an alpha channel and blending mode.

SynPdf is somehow deprecated, but the proposed solution seems to be simple and straightforward, and if it is found useful and 'good enough', then it can also be included in a dedicated version of mormot.ui.pdf.pas.

I would be very grateful for comments related to the weak sides of the added code, propositions of changes, and discussions about implemented ideas (especially about MetaExtChannel).

Link to the detailed description of the solution and to the project on GitHub: https://github.com/hukmac/SynPDF/tree/h … g-with-gdi
Changes are limited to SynPdf.pas file. Basic example project is in \examples directory.

BR,
hukmac

Offline

#2 2025-07-16 11:12:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,090
Website

Re: SynPdf with alpha blending control passed through EMF (published)

Waouh...
big_smile

This is some huge work!

In order to make it more compliant with existing code, could you try to fix the following small issues:
1) use PdfString and its associated mormot.core.base functions, instead of plain string (also for FPC compatibility)?
2) try to fix the spacing in the code, like between function parameters or within the source begin/end, to be more consistent with existing code?

About VCL TCanvas compatibility, I did not look very deep, but couldn't we just use the following standard API, which should be part of the EMF/WMF structures, for bitmaps?
https://learn.microsoft.com/en-us/windo … alphablend
We already have an EMR_ALPHABLEND: entry in the EnumEMFFunc() parser.

And outside of bitmap rendering, since the plain GDI (therefore the TCanvas) has no transparency API, perhaps a way similar to GdiComment() could be used.

Offline

#3 2025-07-17 00:26:12

hukmac
Member
Registered: 2025-06-30
Posts: 6

Re: SynPdf with alpha blending control passed through EMF (published)

Dear ab, thank you for your valuable comments.

Usage of GdiComment (EMR_GDICOMMENT/TPdfEnum.HandleComment) looks like a great idea. I overlooked EMR_GDICOMMENT in the SynPdf code, and I had not heard about it earlier. In fact, using it would allow the code to be much simpler and to not reinvent the wheel. Probably, I will use EMR_GDICOMMENT soon.

EMR_ALPHABLEND - I have seen it but it is not a good idea to use it as a communication channel.

PdfString/spacing - will try to find time to do it when the code will be in acceptable shape smile

Last edited by hukmac (2025-07-17 00:37:08)

Offline

#4 2025-07-17 07:43:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,090
Website

Re: SynPdf with alpha blending control passed through EMF (published)

I have made some refactoring of the GdiComment*() functions of mormot.ui.pdf.
https://github.com/synopse/mORMot2/commit/ddd324c0e
There is a new TSynTempAdder which is perfect for this task, and make code cleaner.

For SynPDF, you would have to do the binary formatting by hand.

Side note:
Perhaps BlendModeId2Str() could be just replaced by your PdfBlendModeNames array constant.

Offline

#5 2025-07-17 08:26:35

hukmac
Member
Registered: 2025-06-30
Posts: 6

Re: SynPdf with alpha blending control passed through EMF (published)

Good point! I will remove this redundancy smile

Offline

Board footer

Powered by FluxBB