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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"unreleased": ["[New] Add `isSelected` method on a CurvePoint"],
"unreleased": [
"[New] Add `isSelected` method on a CurvePoint",
"[New] Add layer.layersByConvertingToOutlines method to Layer"
],
"releases": {
"54": [
"[New] Add `colors` and `gradients` properties on Document",
Expand Down
8 changes: 8 additions & 0 deletions Source/dom/layers/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ export class Layer extends WrappedObject {
})
}

/**
* 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.

const converted = this._object.layersByConvertingToOutlines()
return toArray(converted).map(l => wrapNativeObject(l))
}

// @deprecated
localRectToParentRect(rect) {
console.warn(
Expand Down
11 changes: 10 additions & 1 deletion Source/dom/layers/__tests__/Layer.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals expect, test */
import { Group, Rectangle, Artboard } from '../..'
import { Group, Rectangle, Artboard, Text } from '../..'

test('should set the name of the layer', (context, document) => {
// setting an existing name
Expand Down Expand Up @@ -326,3 +326,12 @@ test('should remove a flow from a layer', (context, document) => {

expect(rect.flow).toBe(undefined)
})

test('should create layer by converting to outlines', () => {
const shape = new Text({
text: 'Hello',
})
const outlines = shape.layersByConvertingToOutlines()
expect(outlines.length).toBe(1)
expect(outlines[0].type).toBe('Shape')
})
12 changes: 12 additions & 0 deletions docs/api/Layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ A new identical layer will be inserted into the parent of this layer.

A new [Layer](#layer).

## Convert the Layer to Outlines

```js
const layers = layer.layersByConvertingToOutlines()
```

Convert this layer to outlines.

### 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.


## Remove the Layer

```javascript
Expand Down