#1 2025-04-15 12:17:08

Juergen_Bauer
Member
Registered: 2025-02-06
Posts: 6

Missing EMR_ALPHABLEND in mormot.ui.pdf

Hello,
I would love to use the great PDF creating component as I create EMF files in my application and need to convert them into PDF.
Unfortunately, when I paint a TWicImage on my MetaFileCanvas and want to convert it, is uses the EMR_ALPHABLEND call which is not yet implemented.

Any idea how to fix this?

I already tried to implement it on my own - but the image does not find its way into the PDF ...

Thanks a lot!

Offline

#2 2025-04-16 07:48:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,965
Website

Re: Missing EMR_ALPHABLEND in mormot.ui.pdf

EMR_ALPHABLEND was not implemented because there is no direct/easy way of handling transparency with PDF commands.

The usual trick is to pre-render the bitmap before adding it to the PDF.

Online

#3 2025-04-16 11:48:09

Juergen_Bauer
Member
Registered: 2025-02-06
Posts: 6

Re: Missing EMR_ALPHABLEND in mormot.ui.pdf

Hello,
thanks for the reply.

I managed to get it working on my side with the following code:

      EMR_ALPHABLEND:
        begin
          ARect := PEMRAlphaBlend(R)^.rclBounds;

          with PEMRAlphaBlend(R)^ do // only handle RGB bitmaps (no palette)
            if (offBmiSrc <> 0) and
               (offBitsSrc <> 0) then
            begin
              E.DrawBitmap (xSrc, ySrc, cxSrc, cySrc, xDest, yDest,
                cxDest, cyDest, iUsageSrc, pointer(PtrUInt(R) + offBmiSrc),
                pointer(PtrUInt(R) + offBitsSrc), @PEMRAlphaBlend(R)^.rclBounds,
                @PEMRAlphaBlend(R)^.xformSrc, SRCCOPY, PEMRAlphaBlend(R)^.dwRop);
            end
            else
              case PEMRBitBlt(R)^.dwRop of // we only handle PATCOPY = fillrect
                PATCOPY:
                  with PEMRBitBlt(R)^ do
                    E.FillRectangle(Rect(xDest, yDest,
                      xDest + cxDest, yDest + cyDest), true);
              end;
        end;

In difference to the previous code, the parameters of the call "DrawBitmap" were changed.
Now the image is correctly shown in the created PDF :-).

Offline

#4 2025-04-16 12:19:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,965
Website

Re: Missing EMR_ALPHABLEND in mormot.ui.pdf

Make sense.

Please try
https://github.com/synopse/mORMot2/commit/26afa29e5

Thanks for sharing!

Online

Board footer

Powered by FluxBB