Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added circle and ellipse shapes #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

a-ludi
Copy link
Contributor

@a-ludi a-ludi commented Jul 13, 2021

I added circle and ellipse methods to the renderer interface. These are not part of the Canvas 2D context API but I feel they are useful features for many users/use cases.

As far as I can tell, the Canvas 2D context API only specifies arc to draw circles and ellipses which seems to be much complicated to handle in both SVG and PDF. At the same time, it is more powerful because it can create arcs (i.e. partial ellipses) and ellipses with non-perpendicular axes.

I am happy to discuss different options of including these type of objects into the interface.

@p0nce
Copy link
Collaborator

p0nce commented Jul 13, 2021

Hello,

This is going to be a bit painful.

fillRect is special and add points to a separate path than the one in beginPath/closePath.

From spec:
https://www.w3.org/TR/2dcontext/#dom-context-2d-fillrect
"Shapes are painted without affecting the current default path"

For example, consider this interleaved scenario, well defined in HTML5:
https://www.w3schools.com/code/tryit.asp?filename=GSFPBJJQ2EFY

If one replace fillRect by a fillCircle that starts a new path in the above example, will destroy the start of the path. If I merge your PR, then fillRect preserve the current path, but fillCircle will destroy it, which is surprising. (not for SVG, but possibly for PDF)

  • Any fillCircle or strokeEllipse function (that destroys the current path) should be imo implemented as an UFCS extension function outside of the IRenderingContext2D
  • You can put them in package.d or in an "extra" file.
  • Such drawing functions should not know about PDF or SVG internals.

This is a tricky part of HTMLCanvas that I did wrong in dplug:canvas.

EDIT: if it's inside IRenderingContext2D then it needs to preserve current path. Else it's an extension function that doesn't have to follow the spec spirit

@a-ludi
Copy link
Contributor Author

a-ludi commented Jul 17, 2021

This is going to be a bit painful.

Certainly. The canvas spec leves room for improvement IMHO.

fillRect is special and add points to a separate path than the one in beginPath/closePath.

I read that, too. SVG elements <circle> and <ellipse> do this as well – no surprises here. As for PDF, we just need to store the current path instead of outputting it immediately. Then it will match the specified behavior.

* Any `fillCircle` or `strokeEllipse` function (that destroys the current path) should be imo implemented as an UFCS extension function outside of the `IRenderingContext2D`

I will implement the proposed fix and keep it in the interface.

* Such drawing functions should not know about PDF or SVG internals.

I think such functions should not belong to this package at all but may be bundled in a separated package as a kind of "standard library":

It is intended to provide a barebones API […].

This standard library could also include a part for easier text layout [#19].

@p0nce
Copy link
Collaborator

p0nce commented Jul 18, 2021

Hello,

I think it's OK if the functions are just next in the same file, just after the IRenderingContext2D definition.
You can also create another sub-package if you prefer and see it as better for printed. I have no real preference myself.
Such a stdlib could build upon IRenderingContext2D for easier drawing indeed, with a more free design of your choosing.

Will be merged as is in one of these two cases.

If the new primitives break PDF path preserve just open a new Issue for the future, because to be fair I don't know if we already follow the spec wrt fillRect and preserving path. You can ignore this since it's a bit of an edge case in actual use.

(excuse me for swings as I've been confused lately)

@p0nce
Copy link
Collaborator

p0nce commented Mar 3, 2022

Regurlarly have "stroke-like" needs in DPlug plugins, with fillLine, fillVerticalLine, fillHorizontalLine being, fillSquare being the most common.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants