#1 2023-07-19 13:57:53

padule
Member
Registered: 2023-07-19
Posts: 24

VCLCanvas and Optional Content (layers)

Hello everyone,

I can't seem to find a way to use optional content (layers) when drawing with VCLCanvas.

All content drawn in VCLCanvas is always saved outside any optional content, regardless of the use of BeginMarkedContent/EndMarkedContent.

Am I missing anything? Any pointer on the correct way to use it?

Thanks,
Regards,
Padule

Offline

#2 2023-07-19 16:11:04

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

Re: VCLCanvas and Optional Content (layers)

You are right: BeginMarkedContent is at the PDF canvas level, and is not available from the VCL canvas.

It is technically possible to enhance the library by adding a new TPdfGdiComment kind of custom message, and a GdiCommentMarkContent() generation function.
But it is not yet supported.
You are free to propose a pull request for this.

Offline

#3 2023-07-19 17:37:16

padule
Member
Registered: 2023-07-19
Posts: 24

Re: VCLCanvas and Optional Content (layers)

Thank you for your prompt reply, and for pointing out a possible solution.
I specifically need this for a project, so if I don't find an alternative I will probably try to implement it in SynPDF myself some time in the next months.
If so, I will contribute with a pull request.
Thank you.

Offline

#4 2023-07-19 18:31:29

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

Re: VCLCanvas and Optional Content (layers)

I could add to mormot.ui.pdf.pas from mORMot 2 easily I guess.

Offline

#5 2023-07-20 13:59:04

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

Re: VCLCanvas and Optional Content (layers)

Offline

#6 2023-07-20 14:50:00

padule
Member
Registered: 2023-07-19
Posts: 24

Re: VCLCanvas and Optional Content (layers)

Hello ab, I gave a look, interesting solution.
Am I wrong or it creates a new group at each call? I would much prefer to pass the TPdfOptionalContentGroup object that references the group, maybe saving in the comment the pdf group object id instead of the title.

Offline

#7 2023-07-20 15:12:49

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

Re: VCLCanvas and Optional Content (layers)

The problem is that the TPdfOptionalContentGroup instance is local to the page PDF canvas, and we don't have any page PDF context at the level of the VCL canvas.
We may enhance the code to reuse an existing GroupTitle in the page.

Offline

#8 2023-07-20 15:26:10

padule
Member
Registered: 2023-07-19
Posts: 24

Re: VCLCanvas and Optional Content (layers)

Since the CreateOptionalContentGroup is a method of the TPdfDocument class I thought it was global to the document and not local to the page.
If every page has its own layers then it is not useful for my project, even though I am pretty sure the PDF specification supports layers that span through multiple pages.

Offline

#9 2023-07-20 15:48:00

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

Re: VCLCanvas and Optional Content (layers)

You are right.
We can safely use a group instance for the whole current document.

Please try https://github.com/synopse/mORMot2/commit/9472f88c

Offline

#10 2023-07-20 17:58:13

padule
Member
Registered: 2023-07-19
Posts: 24

Re: VCLCanvas and Optional Content (layers)

Looks great *thumbs up*.

About mormot.ui.pdf.pas, can it be used standalone? Otherwise I will port the modifications to SynPDF.

Offline

#11 2023-07-20 18:22:41

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

Re: VCLCanvas and Optional Content (layers)

No, you need other units from mORMot 2.

Note that SynPDF is not stand-alone since a lot of time, and trying to extract it from mORMot 1 tends to make confusion and compillation errors if you want to use mORMot otherwise...

So I would suggest to use mormot.ui.pdf.pas from the whole mORMot 2 framework.
The compiler will compile only what is needed for your project. The DB, ORM and such is clearly distinct from the PDF unit.

Offline

#12 2023-07-21 09:06:40

padule
Member
Registered: 2023-07-19
Posts: 24

Re: VCLCanvas and Optional Content (layers)

Thank you ab, I'll give a look at the framework then.

Offline

#13 2023-07-25 12:23:16

padule
Member
Registered: 2023-07-19
Posts: 24

Re: VCLCanvas and Optional Content (layers)

Hello again ab,

Regarding the latest commit above, I spotted a bug that doesn't mark the end of the optional content.

The GdiComment for pgcEndMarkContent has a size of 1 (just the identifier) while in the EnumEMFFunc for the EMR_GDICOMMENT checks the data size to be >1, thus failing in case of the pgcEndMarkContent. (mortmot.ui.pdf.pas ~line 10939)

I hope my explanation is clear, if you need further info let me know.

Last edited by padule (2023-07-25 12:30:59)

Offline

#14 2023-07-25 15:51:13

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

Re: VCLCanvas and Optional Content (layers)

You are right.

Please try
https://github.com/synopse/mORMot2/commit/ae5c91a6

Sorry for the issue.

Offline

#15 2023-07-26 10:29:46

padule
Member
Registered: 2023-07-19
Posts: 24

Re: VCLCanvas and Optional Content (layers)

Yes, same fix I did on my side smile

Offline

Board footer

Powered by FluxBB