Skip to content

Commit d92df69

Browse files
fix svg viewbox (#451)
fix svg viewbox
2 parents d553ef6 + 009eaf8 commit d92df69

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
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;

0 commit comments

Comments
 (0)