added more styles
This commit is contained in:
@ -4,9 +4,21 @@ import {RunPropertiesDefaults} from "./run-properties";
|
||||
|
||||
export class DocumentDefaults extends XmlComponent {
|
||||
|
||||
constructor(runPropertiesDefaults: RunPropertiesDefaults, paragraphPropertiesDefaults: ParagraphPropertiesDefaults) {
|
||||
private runPropertiesDefaults: RunPropertiesDefaults;
|
||||
private paragraphPropertiesDefaults: ParagraphPropertiesDefaults;
|
||||
|
||||
constructor() {
|
||||
super("w:docDefaults");
|
||||
this.root.push(runPropertiesDefaults);
|
||||
this.root.push(paragraphPropertiesDefaults);
|
||||
this.runPropertiesDefaults = new RunPropertiesDefaults();
|
||||
this.paragraphPropertiesDefaults = new ParagraphPropertiesDefaults();
|
||||
this.root.push(this.runPropertiesDefaults);
|
||||
this.root.push(this.paragraphPropertiesDefaults);
|
||||
}
|
||||
|
||||
clearVariables(): void {
|
||||
this.runPropertiesDefaults.clearVariables();
|
||||
this.paragraphPropertiesDefaults.clearVariables();
|
||||
delete this.runPropertiesDefaults;
|
||||
delete this.paragraphPropertiesDefaults;
|
||||
}
|
||||
}
|
@ -2,29 +2,32 @@ import {Styles} from "./";
|
||||
import {DocumentDefaults} from "./defaults";
|
||||
import {ParagraphPropertiesDefaults} from "./defaults/paragraph-properties";
|
||||
import {RunPropertiesDefaults} from "./defaults/run-properties";
|
||||
import {Heading1Style} from "./style";
|
||||
import {Heading1Style, Heading2Style, TitleStyle} 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";
|
||||
import {Color, Size} 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));
|
||||
styles.push(new DocumentDefaults());
|
||||
|
||||
var heading1ParagraphProperties = new ParagraphProperties();
|
||||
var heading1RunProperties = new RunProperties();
|
||||
heading1RunProperties.push(new Color("365F91"));
|
||||
var heading1Style = new Heading1Style(heading1ParagraphProperties, heading1RunProperties);
|
||||
var titleStyle = new TitleStyle();
|
||||
titleStyle.addRunProperty(new Size(56));
|
||||
styles.push(titleStyle);
|
||||
|
||||
var heading1Style = new Heading1Style();
|
||||
heading1Style.addRunProperty(new Color("2E74B5"));
|
||||
heading1Style.addRunProperty(new Size(32));
|
||||
styles.push(heading1Style);
|
||||
|
||||
var heading2Style = new Heading2Style();
|
||||
heading2Style.addRunProperty(new Color("2E74B5"));
|
||||
heading2Style.addRunProperty(new Size(26));
|
||||
styles.push(heading2Style);
|
||||
|
||||
console.log(JSON.stringify(styles, null, " "));
|
||||
return styles;
|
||||
}
|
||||
|
@ -27,4 +27,12 @@ export class Styles extends XmlComponent {
|
||||
push(style: XmlComponent): void {
|
||||
this.root.push(style);
|
||||
}
|
||||
|
||||
clearVariables() {
|
||||
console.log(this);
|
||||
console.log(this.root);
|
||||
this.root.forEach(element => {
|
||||
element.clearVariables();
|
||||
})
|
||||
}
|
||||
}
|
@ -18,21 +18,42 @@ export class Style extends XmlComponent {
|
||||
|
||||
export class ParagraphStyle extends Style {
|
||||
|
||||
constructor(styleId: string, paragraphProperties: ParagraphProperties, runProperties: RunProperties) {
|
||||
private paragraphProperties: ParagraphProperties;
|
||||
private runProperties: RunProperties;
|
||||
|
||||
constructor(styleId: string) {
|
||||
|
||||
var attributes = new StyleAttributes({
|
||||
type: "paragraph",
|
||||
styleId: styleId
|
||||
});
|
||||
super(attributes);
|
||||
this.root.push(paragraphProperties);
|
||||
this.root.push(runProperties);
|
||||
this.paragraphProperties = new ParagraphProperties();
|
||||
this.runProperties = new RunProperties();
|
||||
this.root.push(this.paragraphProperties);
|
||||
this.root.push(this.runProperties);
|
||||
}
|
||||
|
||||
clearVariables(): void {
|
||||
this.paragraphProperties.clearVariables();
|
||||
this.runProperties.clearVariables();
|
||||
delete this.paragraphProperties;
|
||||
delete this.runProperties;
|
||||
}
|
||||
|
||||
addParagraphProperty(property: XmlComponent): void {
|
||||
this.paragraphProperties.push(property);
|
||||
}
|
||||
|
||||
addRunProperty(property: XmlComponent): void {
|
||||
this.runProperties.push(property);
|
||||
}
|
||||
}
|
||||
|
||||
export class HeadingStyle extends ParagraphStyle {
|
||||
|
||||
constructor(styleId: string, name: string, paragraphProperties: ParagraphProperties, runProperties: RunProperties) {
|
||||
super(styleId, paragraphProperties, runProperties);
|
||||
constructor(styleId: string, name: string) {
|
||||
super(styleId);
|
||||
this.root.push(new Name(name));
|
||||
this.root.push(new BasedOn("Normal"));
|
||||
this.root.push(new Next("Normal"));
|
||||
@ -40,44 +61,51 @@ export class HeadingStyle extends ParagraphStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class TitleStyle extends HeadingStyle {
|
||||
|
||||
constructor() {
|
||||
super("Title", "Title");
|
||||
}
|
||||
}
|
||||
|
||||
export class Heading1Style extends HeadingStyle {
|
||||
|
||||
constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) {
|
||||
super("Heading1", "Heading 1", paragraphProperties, runProperties);
|
||||
|
||||
constructor() {
|
||||
super("Heading1", "Heading 1");
|
||||
}
|
||||
}
|
||||
|
||||
export class Heading2Style extends HeadingStyle {
|
||||
|
||||
constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) {
|
||||
super("Heading2", "Heading 2", paragraphProperties, runProperties);
|
||||
|
||||
constructor() {
|
||||
super("Heading2", "Heading 2");
|
||||
}
|
||||
}
|
||||
|
||||
export class Heading3Style extends HeadingStyle {
|
||||
|
||||
constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) {
|
||||
super("Heading3", "Heading 3", paragraphProperties, runProperties);
|
||||
|
||||
constructor() {
|
||||
super("Heading3", "Heading 3");
|
||||
}
|
||||
}
|
||||
|
||||
export class Heading4Style extends HeadingStyle {
|
||||
|
||||
constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) {
|
||||
super("Heading4", "Heading 4", paragraphProperties, runProperties);
|
||||
|
||||
constructor() {
|
||||
super("Heading4", "Heading 4");
|
||||
}
|
||||
}
|
||||
|
||||
export class Heading5Style extends HeadingStyle {
|
||||
|
||||
constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) {
|
||||
super("Heading5", "Heading 5", paragraphProperties, runProperties);
|
||||
|
||||
constructor() {
|
||||
super("Heading5", "Heading 5");
|
||||
}
|
||||
}
|
||||
|
||||
export class Heading6Style extends HeadingStyle {
|
||||
|
||||
constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) {
|
||||
super("Heading6", "Heading 6", paragraphProperties, runProperties);
|
||||
|
||||
constructor() {
|
||||
super("Heading6", "Heading 6");
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import {DefaultStyle} from "../styles/sample"
|
||||
import {Paragraph} from "../docx/paragraph"
|
||||
import {DefaultStylesFactory} from "../styles/factory"
|
||||
|
||||
describe("Packer", () => {
|
||||
describe.only("Packer", () => {
|
||||
var packer: LocalPacker;
|
||||
var stylesFactory: DefaultStylesFactory;
|
||||
|
||||
@ -19,7 +19,9 @@ describe("Packer", () => {
|
||||
var document = new Document();
|
||||
var paragraph = new Paragraph("test text");
|
||||
var heading = new Paragraph("Hello world").heading1();
|
||||
document.addParagraph(new Paragraph("title").title());
|
||||
document.addParagraph(heading);
|
||||
document.addParagraph(new Paragraph("heading 2").heading2());
|
||||
document.addParagraph(paragraph);
|
||||
var properties = new Properties({
|
||||
creator: "Shan Fu",
|
||||
|
Reference in New Issue
Block a user