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

Add convert to outlines #431

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

WCByrne
Copy link
Contributor

@WCByrne WCByrne commented Mar 25, 2019

Addresses #408


### Returns

An array of new [Layer](#layer) objects representing the outlines of this layer.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to clarify when this has more than one layer. I'm still not sure when that would be.

@mathieudutour
Copy link
Contributor

Ah sorry, I didn't comment on this.

It feels a bit weird to me to have this method on a Layer instance. Ideally, I'd prefer to have something like Layer.fromOutlines(layer) but I'm not sure where it would go.

But you are right that it can sometimes create multiple layers (when a shape has multiple borders IIRC). So I'm still not sure

@WCByrne
Copy link
Contributor Author

WCByrne commented Apr 9, 2019

My opinion: The current name and location (layer.layersByConvertingtoOutlines) is more clear than having it on Layer. Layer.fromOutlines(layer) actually feels a little more awkward to me. If anything, maybe something like outlineLayersFromLayer(layer) but that still reads weird.

@mathieudutour
Copy link
Contributor

yeah, I meant more about having it as a class method (eg. more like a constructor) rather than an instance method

@WCByrne
Copy link
Contributor Author

WCByrne commented Apr 22, 2019

Any more thoughts on naming for this?

@WCByrne
Copy link
Contributor Author

WCByrne commented Apr 30, 2019

@mathieudutour Let me know if and how you want me to update this. Happy to do whatever you think makes the most sense.

@mathieudutour
Copy link
Contributor

Yeah sorry, I need to find some time to play with a few different namings. Sorry for the delay :/

@WCByrne
Copy link
Contributor Author

WCByrne commented Apr 30, 2019

No worries, just remembered this had been sitting here for a while. This is an easy one to drop in to the internals for now.

@iliakan
Copy link

iliakan commented Aug 10, 2019

Is there a way to convert to outlines for JS Sketch plugin right now?

Thank you.

@WCByrne
Copy link
Contributor Author

WCByrne commented Oct 23, 2019

This PR needs to address this issue that was brought up in Slack 👇 . @christianklotz any insight on how this can be achieved in code? I'd be happy to implement and get this PR moving again.

It looks like converting text to outlines is filling in letters in unexpected ways. I believe this started with 58 according my user’s reports.

image

Response: altering the fill type from Non-Zero to Even-Odd will likely achieve the intended result there (via the cog button in the Fills section within the Inspector)

@christianklotz christianklotz removed the request for review from mathieudutour October 24, 2019 01:57
@christianklotz
Copy link
Contributor

This is going to be fixed in Sketch 60. Once out it'd be a good time to pick up this PR again.

Copy link
Contributor

@christianklotz christianklotz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that this would actually fail on any layer that doesn't support conversion to outlines, e.g. symbol instances, groups, etc. There's a method canConvertToOutlines which returns true for anything that can be converted, posing the question of how this would be translated here. Does it only return itself wrapped in an array or null/undefined?

/**
* Return one or more layers the were converted to outlines.
*/
layersByConvertingToOutlines() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
layersByConvertingToOutlines() {
toOutlines() {

Maybe toOutlines, similar to String.toUppercase would suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

@WCByrne
Copy link
Contributor Author

WCByrne commented Sep 9, 2020

As for failing when canConvertToOutlines is false, do the internals return nil or itself? Should that check function be adde here as well?

@christianklotz
Copy link
Contributor

@WCByrne it gets never called because it's only implemented for layer subclasses that support it.

@WCByrne
Copy link
Contributor Author

WCByrne commented Sep 9, 2020

got it. I feel like returning nil then, or maybe even throw an error to make it clear why it didn't work. If you are trying to convert something to outlines, getting that layer back in an array seems like it could be confusing

@christianklotz
Copy link
Contributor

Returning nil works for me. Throwing an error is a bit harsh, especially if the method is on Layer. An alternative could be to put it on Text and ShapePath only?

@WCByrne
Copy link
Contributor Author

WCByrne commented Sep 9, 2020

If those are the only 2 that support it, that works for me. I was just kinda going with what the internals seemed to do. FWIW, I only use it for text layers so this is a bit of a none issue for my needs.

@christianklotz
Copy link
Contributor

👍 … feel free to make the change so only the two classes have the method and I'll review.

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

Successfully merging this pull request may close these issues.

None yet

5 participants