Skip to content

Commit c24fb10

Browse files
Merge branch 'master' into f/more-reliable-font-weight
2 parents a2f9292 + d92df69 commit c24fb10

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/jsonUtils/sketchImpl/makeSvgLayer.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ import { toSJSON } from './sketch-to-json';
44
import { LayoutInfo } from '../../types';
55

66
export default function makeSvgLayer(
7-
layout: LayoutInfo,
7+
_layout: LayoutInfo,
88
name: string,
99
svg: string,
1010
): FileFormat.Group {
1111
const svgString = NSString.stringWithString(svg);
1212
const svgData = svgString.dataUsingEncoding(NSUTF8StringEncoding);
1313
const svgImporter = MSSVGImporter.svgImporter();
1414
svgImporter.prepareToImportFromData(svgData);
15-
const svgLayer = svgImporter.importAsLayer();
16-
svgLayer.name = name;
17-
svgLayer.rect = {
18-
origin: {
19-
x: 0,
20-
y: 0,
21-
},
22-
size: {
23-
width: layout.width,
24-
height: layout.height,
25-
},
26-
};
27-
return toSJSON(svgLayer) as FileFormat.Group;
15+
16+
const frame = NSMakeRect(0, 0, svgImporter.graph().width(), svgImporter.graph().height());
17+
const root = MSLayerGroup.alloc().initWithFrame(frame);
18+
root.name = name;
19+
20+
svgImporter.graph().makeLayerWithParentLayer_progress(root, null);
21+
root.ungroupSingleChildDescendentGroups();
22+
svgImporter.scale_rootGroup(svgImporter.importer().scaleValue(), root);
23+
24+
return toSJSON(root) as FileFormat.Group;
2825
}

src/types/globals.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ declare const MSPage: any;
2929
declare const MOPointer: any;
3030
declare const MSJSONDictionaryUnarchiver: any;
3131
declare const MSJSONDataArchiver: any;
32+
declare const NSMakeRect: any;
33+
declare const MSLayerGroup: any;

src/utils/processTransform/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ function isRotation(a: number, b: number, c: number, d: number) {
1212

1313
const rad2deg = 180 / Math.PI;
1414

15-
function getRotation(a, b) {
15+
function getRotation(a: number, b: number) {
16+
const sketchFactor = -1;
1617
const possibleRotation = Math.acos(a);
1718
if (closeEnough(Math.sin(possibleRotation), b) || closeEnough(Math.sin(possibleRotation), -b)) {
18-
return possibleRotation * rad2deg;
19+
return sketchFactor * possibleRotation * rad2deg;
1920
}
20-
return (possibleRotation + Math.PI) * rad2deg;
21+
return sketchFactor * (possibleRotation + Math.PI) * rad2deg;
2122
}
2223

23-
export default function(layout: LayoutInfo, props: ViewStyle) {
24+
export default function(
25+
layout: LayoutInfo,
26+
props: ViewStyle,
27+
): { rotation?: number; isFlippedVertical?: boolean; isFlippedHorizontal?: boolean } {
2428
if (!props.transform) {
2529
return {};
2630
}

0 commit comments

Comments
 (0)