Open doctormo opened 1 week ago
sh
seems to be the only supported one. I have not done proper SCN/scn
support, probably because I did not have pattern support available at all at the time. That needs to be added.
You can see the kind of construction from this cairo output: test-sf-grad.pdf
So constructing a pattern from a shading object is going to be pretty critical, because I'll also need to construct soft masks for transparencies and trying to layer a individual transparency groups with soft masks is going to be a real PITA. But if I can SCN/scn the gradient, then the transparency will just mirror that same structure without extra groups.
Yes, that is definitely a thing that should be supported. However I will most likely be unable to work on that until next week.
Looking at the code, I can see patterns are handled differently from other objects and are constructed in-stream from the given draw context.
If the same code pattern is used we might end up with:
rvoe<CapyPDF_PatternId> PdfDocument::add_pattern(PdfShading sh, double a, double b, double c, double d, double e, double f) {
std::string shading_commands = serialise_shading(sh);
auto pattern_dict = std::format(R"(<<
/Type /Pattern
/PatternType 2
/Matrix {:f} {:f} {:f} {:f} {:f} {:f}
>>
)", a, b, c, d, e, f);
return CapyPDF_PatternId{
add_object(FullPDFObject{std::move(pattern_dict), std::string(shading_commands)})};
}
The refactoring needed, would be:
serialise_shading
do the switch between each of the shading type variantsadd_shading
so it just calls serialise_shading
and adds the shading object itself.Before I do any of this work, I'd like your input @jpakkane
I created an MR for the refactoring work so you can see what it looks like in situ
I took a quick glance at this and it seems that this needs some more fundamental refactoring like the fact that pattern DCs should probably also have a transformation matrix. I would not want anyone else to work on this until I have managed to properly review how the architecture would need to work. Sadly I won't have time until Monday at the earliest. It is also entirely possible that the only real way to work out the architecture myself is to actually code it.
Which is sad, but such is reality. :(
This makes sense. I suspect you want to upgrade the Pattern to a full fat object so a matrix or other settings can be applied.
I feel like I've run this up to the line of what you find comfortable me contributing. So I'll leave this with you can work on something else for now.
I did work out how to do reflection and repeat gradient patterns though. So many things to test!
There seems to be two ways to describe a gradient in PDF, either the PDF 1.2 SCN/scn method that sets a Pattern Type 2 as a gradient, or the sh command that directly links to a shading object.
The big difference is that SCN/scn can be used in strokes and fill, while sh is only available for fill, making it much more limited.
Do you know which capypdf is currently supporting?