specification icon indicating copy to clipboard operation
specification copied to clipboard

[Proposal] Templates / Repeated elements

Open rsheeter opened this issue 3 years ago • 6 comments
trafficstars

QQ, from a quick skim it seems to me that repeated identical shapes must be fully reproduced? - apologies if I simply misunderstood.

If you provide the ability to reuse parts you may more significantly outperform svg on size in some cases. For example, in COLRv1 we allow reuse with a new fill and a transform applied.

rsheeter avatar Dec 21 '21 19:12 rsheeter

Yes, this is something i'm still considering as it can make repetetive graphics a lot smaller. SVG can do that as well

ikskuh avatar Dec 21 '21 21:12 ikskuh

I think this can be implemented reasonably easily by calling the parser/interpreter recursively. As it also reduces the file size, we can load complexer graphics in less memory, so seeking shouldn't be a huge problem.

My current idea would be two new commands:

  • recurse(offset, count): Replay commands starting at byte offset into the file and repay count commands
  • setOffset(x, y): Applies a global offset to all coordinates. This alone allows moving things more easily in a file.

ikskuh avatar Feb 03 '22 07:02 ikskuh

My current idea would be two new commands:

something like setRotation(angle, center_x, center_y) would be useful here.

neinseg avatar Feb 04 '22 16:02 neinseg

Oh yeah, that's a good idea. This would allow a lot of stuff to be made. I'll think a bit about precise semantics, but i'm already happy with the idea. With offset and rotation around point you can probably duplicate any part of the image into another position. Not sure if we should support scale/shearing, as those usually are more abused than used

ikskuh avatar Feb 04 '22 17:02 ikskuh

Reuse scaled is definitely useful. Shear ... I'm not sure how often it's used but IMO it's odd to have everything except shear. Maybe just off a setTransform that takes a full affine matrix as a fallback?

rsheeter avatar Feb 04 '22 18:02 rsheeter

Maybe just off a setTransform that takes a full affine matrix as a fallback?

This is something i wanna prevent, but maybe it's the smarter idea. Encoding-wise it would be better to have offset, rotate, scale tho

ikskuh avatar Feb 04 '22 19:02 ikskuh