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

Fixes & optimizations #66

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Fixes & optimizations #66

wants to merge 29 commits into from

Conversation

mudcube
Copy link
Contributor

@mudcube mudcube commented Mar 9, 2018

This pull request:

- Remove inefficient format() for template strings
- Remove inefficient lineTo indexOf on large strings
Example:
```
	ctx.rect(75, 75, 100, 100)

	ctx.lineWidth = 30
	ctx.strokeStyle = '#0074D9'
	ctx.stroke()

	ctx.fillStyle = '#FF4136'
	ctx.fill()

	ctx.lineWidth = 10
	ctx.strokeStyle = '#FFDC00'
	ctx.stroke()
```
The while loop was crashing my browser, so converted into a for loop. The issue is when appendChild does not remove the child from __defs.childNodes, I’m not entirely sure why this was happening, but this method also is slightly more optimized as you don’t recalculate the length upon each interation.
When patternUnits uses the default `objectBoundingBox` patterns are parsed incorrectly for me (they do not repeat, and are incorrectly scaled). Adding this line fixes this issue.
- Support multiple fills w/ single path. Ex.
```js
ctx.rect(0, 0, 100, 100);
ctx.fill();
ctx.translate(50, 50);
ctx.fill();
```

- Support `gradientTransform` and `patternTransform`. Ex.
```js
ctx.rect(0, 0, 100, 100);
ctx.translate(50, 50);
ctx.fillStyle = ctx.createPattern($image, ‘repeat’)
ctx.fill();
```

- Support switching between transforms and path operations. Ex.
```js
ctx.rect(0, 0, 100, 100);
ctx.translate(50, 50);
ctx.rect(0, 0, 100, 100);
ctx.fill();
```

- Fix clearRect() so <svg> is emptied if requested cleared area covers the entire canvas area. This update takes into account the current matrix, as well as accounts for rectangles outside of canvas bounds.
```
ctx.translate(10, 10)
ctx.fillRect(0, 0, 10, 10)
ctx.save()
ctx.restore()
ctx.translate(10, 10)
ctx.fillRect(0, 0, 10, 10)
```
This patch creates smaller exported svgs by creating <def> entries for paths references more than one. This kicks into gear when a fill or stroke is used multiple times on a single path.
@jods4
Copy link

jods4 commented Jun 3, 2018

I tried this patch because the fill=evenodd bug hit me hard.

I can confirm that the evenodd fix works.

Unfortunately I also have to report that some of the other optimisations broke other stuff, I get funny results that were previously ok.

@mudcube
Copy link
Contributor Author

mudcube commented Jun 3, 2018 via email

@jods4
Copy link

jods4 commented Jun 4, 2018

@mudcube in my document many lines end up at the origin after your patch, they were drawn correctly before.

Unfortunately it's real documents with around 10K calls to context, that I cannot easily share or reduce.

That said, some tests are currently falling, could that be related?
I can gladly retest my docs when they are fixed.

@mudcube mudcube changed the title Fixes and optimizations Fixes & optimizations Jul 7, 2018
- Clip would sometimes report that group was not the parent of currentElement. So, instead calling `.remove()` on the element.
- Create path if does not exist when calling `getOrCreateElementToApplyStyleTo`
- Revert support switching between transforms and path operations… this needs to be rethought as it was causing other transformation issues.
@mudcube
Copy link
Contributor Author

mudcube commented Jul 7, 2018

@jods4 The transformation issue should be sorted out, let me know if you're still running into the issue. There's still a couple failing tests, but part of that is due to slight formatting changes (ex. spacing), and doesn't actually affect what's visually exported.

This allows the intention behind commit c228ba4 to work once again. Note, this commit contains MPL code, so if this pull request is accepted an MPL license would need to be added to the repository.
@jods4
Copy link

jods4 commented Jul 9, 2018

@mudcube I tried again and the "all lines go to origin" problem is fixed on your master.

But it's not completely fixed.
Paths are now at their correct position, but they are way too wide. There is still a regression inside that PR.

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