import { Part } from './part' import { Path } from './path' import { Pattern } from './pattern' import { Attributes } from './attributes' export class Svg { prefix: string; body: string = ''; style: string = ''; header: string = ''; footer: string = ''; defs: string = ''; attributes: Attributes = new Attributes(); tabs: number = 0; freeId: number = 1; openGroups: string[] = []; constructor() { this.prefix = ''; this.attributes.add this.attributes.add("xmlns", "http://www.w3.org/2000/svg"); this.attributes.add("xmlns:svg", "http://www.w3.org/2000/svg"); this.attributes.add("xmlns:xlink", "http://www.w3.org/1999/xlink"); this.attributes.add("xmlns:freesewing", "http://freesewing.org/namespaces/freesewing"); this.attributes.add("freesewing:foo", "bar"); return this; } /** Renders a draft object as SVG */ render(pattern: Pattern): string { let svg = this.prefix; svg += this.renderComments(this.header); svg += this.renderSvgTag(pattern); svg += this.renderStyle(); svg += this.renderDefs(); svg += this.openGroup('draftContainer'); for (let partId in pattern.parts) { let part = pattern.parts[partId]; if (part.render) { svg += this.openGroup(part.id, part.attributes); svg += this.renderPart(part); svg += this.closeGroup(); } } svg += this.closeGroup(); svg += this.nl()+''; svg += this.renderComments(this.footer); return svg; } /** Returns SVG code for the opening SVG tag */ renderSvgTag(pattern: Pattern) { let svg = ''+this.nl(); return svg; } /** Returns SVG code for the style block */ renderStyle() { let svg = '