Permalink
Browse files

Fix artboard positioning with tests

  • Loading branch information...
koenbok committed Dec 17, 2015
1 parent aa6f4fb commit 58ad551491c9f0191a5f30a124a2ed2b01f26bdd
Showing with 719 additions and 6 deletions.
  1. +18 −6 framer/Importer.coffee
  2. BIN test/static/ExternalDocument/Artboard.sketch
  3. +22 −0 test/static/ExternalDocument/Artboard@1x.out.json
  4. BIN .../static/ExternalDocument/Artboard@1x/images/Layer-square-8BC4660D-4A8B-483D-96A9-99F769C5C450.png
  5. +46 −0 test/static/ExternalDocument/Artboard@1x/layers.json
  6. +48 −0 test/static/ExternalDocument/Artboard@1x/layers.json.js
  7. +22 −0 test/static/ExternalDocument/Artboard@2x.out.json
  8. BIN .../static/ExternalDocument/Artboard@2x/images/Layer-square-8BC4660D-4A8B-483D-96A9-99F769C5C450.png
  9. +46 −0 test/static/ExternalDocument/Artboard@2x/layers.json
  10. +48 −0 test/static/ExternalDocument/Artboard@2x/layers.json.js
  11. BIN test/static/ExternalDocument/ImportFlatten.sketch
  12. +64 −0 test/static/ExternalDocument/ImportFlatten@2x.out.json
  13. BIN ...static/ExternalDocument/ImportFlatten@2x/images/Layer-bg-1C53688A-A166-40BD-8A23-5FB1C647AA51.png
  14. BIN ...static/ExternalDocument/ImportFlatten@2x/images/Layer-bg-2059E3B0-F259-4874-B7AD-333B9152EC60.png
  15. BIN ...ExternalDocument/ImportFlatten@2x/images/Layer-block.jpg-D2AF8B1A-9D62-404C-B9C3-11C9B854925A.jpg
  16. BIN ...ExternalDocument/ImportFlatten@2x/images/Layer-block.pdf-828BD7FA-6122-4FA8-B8C0-316723D80A81.pdf
  17. BIN ...atic/ExternalDocument/ImportFlatten@2x/images/Layer-flat-528CB68B-5AE1-4881-8EC7-9C50F415E45A.png
  18. BIN ...lDocument/ImportFlatten@2x/images/Layer-some___23layer__-D29589DF-4FD5-4A0D-B306-B632A58ED720.png
  19. +197 −0 test/static/ExternalDocument/ImportFlatten@2x/layers.json
  20. +199 −0 test/static/ExternalDocument/ImportFlatten@2x/layers.json.js
  21. +9 −0 test/tests/ImporterTest.coffee
View
@@ -54,15 +54,18 @@ class exports.Importer
layerInfo.map (layerItemInfo) =>
@_createLayer(layerItemInfo)
# Pass three, correct artboard positions, and reset top left
# to the minimum x, y of all artboards
# @_correctArtboards(@_createdLayers)
# Pass two. Adjust position on screen for all layers
# based on the hierarchy.
for layer in @_createdLayers
@_correctLayer(layer)
# Pass three, correct artboard positions, and reset top left
# to the minimum x, y of all artboards
@_correctArtboards(@_createdLayers)
# Pass three, insert the layers into the dom
# (they were not inserted yet because of the shadow keyword)
for layer in @_createdLayers
@@ -124,6 +127,10 @@ class exports.Importer
layerInfo.frame = info.image.frame
layerInfo.clip = false
if layerInfo.kind is "artboard"
layerInfo.frame.x = 0
layerInfo.frame.y = 0
# Figure out what the super layer should be. If this layer has a contentLayer
# (like a scroll view) we attach it to that instead.
if superLayer?.contentLayer
@@ -157,8 +164,14 @@ class exports.Importer
_.clone(info.children).reverse().map (info) =>
@_createLayer(info, layer)
# Not really sure what this was for, but I don't want to touch it now
if not layer.image and not info.maskFrame
# If this is an artboard we retain the size, but set the coordinates to zero
# because all coordinates within artboards are 0, 0 based.
if info.kind is "artboard"
layer.point = {x:0, y:0}
# If this is not an artboard, and does not have an image or mask, we clip the
# layer to its content size.
else if not layer.image and not info.maskFrame
layer.frame = layer.contentFrame()
layer._info = info
@@ -172,8 +185,7 @@ class exports.Importer
for layer in layers
if layer._info.kind is "artboard"
# We don't have to scale this, because the artboard positions are always in pixels.
layer.frame = layer._info.layerFrame
layer.point = layer._info.layerFrame
layer.visible = true
points.push(layer.point)
Binary file not shown.
@@ -0,0 +1,22 @@
{
"square": {
"frame": {
"x": 88,
"y": 234,
"width": 200,
"height": 200
},
"subLayerNames": []
},
"iPhone6": {
"frame": {
"x": 100,
"y": 100,
"width": 375,
"height": 667
},
"subLayerNames": [
"square"
]
}
}
@@ -0,0 +1,46 @@
[
{
"children": [
{
"children": [],
"id": "8BC4660D-4A8B-483D-96A9-99F769C5C450",
"image": {
"frame": {
"height": 200,
"width": 200,
"x": 88,
"y": 234
},
"path": "images/Layer-square-8BC4660D-4A8B-483D-96A9-99F769C5C450.png"
},
"imageType": "png",
"kind": "group",
"layerFrame": {
"height": 200,
"width": 200,
"x": 88,
"y": 234
},
"maskFrame": null,
"metadata": {
"opacity": 1
},
"name": "square",
"visible": true
}
],
"id": "A50DFB42-1703-4400-B0A6-F1FB1E7C2A94",
"imageType": "png",
"kind": "artboard",
"layerFrame": {
"height": 667,
"width": 375,
"x": 100,
"y": 100
},
"maskFrame": null,
"metadata": {},
"name": "iPhone6",
"visible": true
}
]
@@ -0,0 +1,48 @@
window.__imported__ = window.__imported__ || {};
window.__imported__["Artboard/layers.json.js"] = [
{
"children": [
{
"children": [],
"id": "8BC4660D-4A8B-483D-96A9-99F769C5C450",
"image": {
"frame": {
"height": 200,
"width": 200,
"x": 88,
"y": 234
},
"path": "images/Layer-square-8BC4660D-4A8B-483D-96A9-99F769C5C450.png"
},
"imageType": "png",
"kind": "group",
"layerFrame": {
"height": 200,
"width": 200,
"x": 88,
"y": 234
},
"maskFrame": null,
"metadata": {
"opacity": 1
},
"name": "square",
"visible": true
}
],
"id": "A50DFB42-1703-4400-B0A6-F1FB1E7C2A94",
"imageType": "png",
"kind": "artboard",
"layerFrame": {
"height": 667,
"width": 375,
"x": 100,
"y": 100
},
"maskFrame": null,
"metadata": {},
"name": "iPhone6",
"visible": true
}
]
@@ -0,0 +1,22 @@
{
"square": {
"frame": {
"x": 176,
"y": 468,
"width": 400,
"height": 400
},
"subLayerNames": []
},
"iPhone6": {
"frame": {
"x": 200,
"y": 200,
"width": 750,
"height": 1334
},
"subLayerNames": [
"square"
]
}
}
@@ -0,0 +1,46 @@
[
{
"children": [
{
"children": [],
"id": "8BC4660D-4A8B-483D-96A9-99F769C5C450",
"image": {
"frame": {
"height": 200,
"width": 200,
"x": 88,
"y": 234
},
"path": "images/Layer-square-8BC4660D-4A8B-483D-96A9-99F769C5C450.png"
},
"imageType": "png",
"kind": "group",
"layerFrame": {
"height": 200,
"width": 200,
"x": 88,
"y": 234
},
"maskFrame": null,
"metadata": {
"opacity": 1
},
"name": "square",
"visible": true
}
],
"id": "A50DFB42-1703-4400-B0A6-F1FB1E7C2A94",
"imageType": "png",
"kind": "artboard",
"layerFrame": {
"height": 667,
"width": 375,
"x": 100,
"y": 100
},
"maskFrame": null,
"metadata": {},
"name": "iPhone6",
"visible": true
}
]
@@ -0,0 +1,48 @@
window.__imported__ = window.__imported__ || {};
window.__imported__["Artboard/layers.json.js"] = [
{
"children": [
{
"children": [],
"id": "8BC4660D-4A8B-483D-96A9-99F769C5C450",
"image": {
"frame": {
"height": 200,
"width": 200,
"x": 88,
"y": 234
},
"path": "images/Layer-square-8BC4660D-4A8B-483D-96A9-99F769C5C450.png"
},
"imageType": "png",
"kind": "group",
"layerFrame": {
"height": 200,
"width": 200,
"x": 88,
"y": 234
},
"maskFrame": null,
"metadata": {
"opacity": 1
},
"name": "square",
"visible": true
}
],
"id": "A50DFB42-1703-4400-B0A6-F1FB1E7C2A94",
"imageType": "png",
"kind": "artboard",
"layerFrame": {
"height": 667,
"width": 375,
"x": 100,
"y": 100
},
"maskFrame": null,
"metadata": {},
"name": "iPhone6",
"visible": true
}
]
Binary file not shown.
@@ -0,0 +1,64 @@
{
"bg": {
"frame": {
"x": 0,
"y": 0,
"width": 750,
"height": 1334
},
"subLayerNames": []
},
"flat": {
"frame": {
"x": 40,
"y": 260,
"width": 180,
"height": 180
},
"subLayerNames": []
},
"block": {
"frame": {
"x": 260,
"y": 40,
"width": 180,
"height": 180
},
"subLayerNames": []
},
"some23layer": {
"frame": {
"x": 260,
"y": 260,
"width": 180,
"height": 180
},
"subLayerNames": []
},
"ScreenA": {
"frame": {
"x": 0,
"y": 0,
"width": 750,
"height": 1334
},
"subLayerNames": [
"bg",
"flat",
"block",
"block",
"some23layer"
]
},
"ScreenB": {
"frame": {
"x": 950,
"y": 0,
"width": 750,
"height": 1334
},
"subLayerNames": [
"bg"
]
}
}
Oops, something went wrong.

0 comments on commit 58ad551

Please sign in to comment.