style factory added and fixed bug allowing styles to work
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
|
||||
<Default Extension="xml" ContentType="application/xml" />
|
||||
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" />
|
||||
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" />
|
||||
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
|
||||
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" />
|
||||
</Types>
|
||||
</Types>
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||
</Relationships>
|
||||
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml" />
|
||||
</Relationships>
|
||||
|
@ -3,7 +3,7 @@ import {XmlComponent, Attributes} from "../xml-components";
|
||||
export class ParagraphProperties extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:rPr");
|
||||
super("w:pPr");
|
||||
this.root.push(new Attributes());
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,11 @@ export abstract class Packer {
|
||||
prefix: "root"
|
||||
});*/
|
||||
var xmlDocument = xml(this.formatter.format(this.document));
|
||||
console.log(xmlDocument);
|
||||
var xmlStyle = xml(this.style);
|
||||
var xmlStyle = xml(this.formatter.format(this.style));
|
||||
//var xmlStyle = xml(this.style);
|
||||
var xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: 'yes', encoding: 'UTF-8' } });
|
||||
|
||||
console.log(xmlStyle);
|
||||
//console.log(JSON.stringify(this.formatter.format(this.document), null, " "));
|
||||
//console.log(xmlDocument);
|
||||
|
||||
@ -57,9 +58,9 @@ export abstract class Packer {
|
||||
name: 'word/document.xml'
|
||||
});
|
||||
|
||||
//this.archive.append(xmlStyle, {
|
||||
// name: 'word/newStyle.xml'
|
||||
//});
|
||||
this.archive.append(xmlStyle, {
|
||||
name: 'word/styles.xml'
|
||||
});
|
||||
|
||||
this.archive.append(xmlProperties, {
|
||||
name: 'docProps/core.xml'
|
||||
|
31
ts/styles/factory.ts
Normal file
31
ts/styles/factory.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import {Styles} from "./";
|
||||
import {DocumentDefaults} from "./defaults";
|
||||
import {ParagraphPropertiesDefaults} from "./defaults/paragraph-properties";
|
||||
import {RunPropertiesDefaults} from "./defaults/run-properties";
|
||||
import {Heading1Style} from "./style";
|
||||
//import {StyleAttributes} from "./style/attributes";
|
||||
import {ParagraphProperties} from "../docx/paragraph/properties";
|
||||
import {RunProperties} from "../docx/run/properties";
|
||||
import {Color} from "../docx/run/formatting";
|
||||
|
||||
export class DefaultStylesFactory {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
newInstance(): Styles {
|
||||
var styles = new Styles();
|
||||
var paragraphProperties = new ParagraphPropertiesDefaults();
|
||||
var runProperties = new RunPropertiesDefaults();
|
||||
styles.push(new DocumentDefaults(paragraphProperties, runProperties));
|
||||
|
||||
var heading1ParagraphProperties = new ParagraphProperties();
|
||||
var heading1RunProperties = new RunProperties();
|
||||
heading1RunProperties.push(new Color("365F91"));
|
||||
var heading1Style = new Heading1Style(heading1ParagraphProperties, heading1RunProperties);
|
||||
styles.push(heading1Style);
|
||||
|
||||
console.log(JSON.stringify(styles, null, " "));
|
||||
return styles;
|
||||
}
|
||||
}
|
@ -17,12 +17,11 @@ export class Styles extends XmlComponent {
|
||||
w15: 'http://schemas.microsoft.com/office/word/2012/wordml',
|
||||
Ignorable: 'w14 w15'
|
||||
}))
|
||||
this.root.push(new DocumentDefaults());
|
||||
var latentStyles = new LatentStyles();
|
||||
//var latentStyles = new LatentStyles();
|
||||
//latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({
|
||||
// name: "Normal"
|
||||
//})));
|
||||
this.root.push(latentStyles);
|
||||
//this.root.push(latentStyles);
|
||||
}
|
||||
|
||||
push(style: XmlComponent): void {
|
||||
|
@ -82,8 +82,6 @@ export function DefaultStyle() {
|
||||
}
|
||||
}, {
|
||||
'w:lsdException': createLsdException('Normal', 0, 1)
|
||||
}, {
|
||||
'w:lsdException': createLsdException("heading 1", 9, 1)
|
||||
}, {
|
||||
'w:lsdException': createLsdException("heading 1", 9, 1, 1, 1)
|
||||
}, {
|
||||
|
@ -9,25 +9,31 @@ import {Document} from "../docx/document"
|
||||
import {Properties} from "../properties"
|
||||
import {DefaultStyle} from "../styles/sample"
|
||||
import {Paragraph} from "../docx/paragraph"
|
||||
import {DefaultStylesFactory} from "../styles/factory"
|
||||
|
||||
describe("Packer", () => {
|
||||
var packer: LocalPacker;
|
||||
var stylesFactory: DefaultStylesFactory;
|
||||
|
||||
beforeEach(() => {
|
||||
var document = new Document();
|
||||
var paragraph = new Paragraph("test text");
|
||||
var heading = new Paragraph("Hello world").heading1();
|
||||
document.addParagraph(heading);
|
||||
document.addParagraph(paragraph);
|
||||
var properties = new Properties({
|
||||
creator: "Shan Fu",
|
||||
revision: "1",
|
||||
lastModifiedBy: "Shan Fu"
|
||||
});
|
||||
packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx");
|
||||
stylesFactory = new DefaultStylesFactory();
|
||||
packer = new LocalPacker(document, stylesFactory.newInstance(), properties, "build/tests/test.docx");
|
||||
//packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx");
|
||||
});
|
||||
|
||||
describe('#pack()', () => {
|
||||
|
||||
it("should create a standard docx file", (done) => {
|
||||
|
||||
it("should create a standard docx file", (done) => {
|
||||
packer.pack();
|
||||
setTimeout(done, 1900);
|
||||
});
|
||||
|
Reference in New Issue
Block a user