From a1b4facb403168502518c0cec811ac6fa6d38614 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Sun, 8 May 2016 17:01:20 +0100 Subject: [PATCH] added heading styles --- .../run.ts => docx/run/formatting.ts} | 4 +- ts/docx/run/index.ts | 2 +- ts/styles/defaults/index.ts | 6 +- ts/styles/style/components.ts | 7 +- ts/styles/style/index.ts | 71 ++++++++++++++++++- 5 files changed, 79 insertions(+), 11 deletions(-) rename ts/{styles/formatting/run.ts => docx/run/formatting.ts} (95%) diff --git a/ts/styles/formatting/run.ts b/ts/docx/run/formatting.ts similarity index 95% rename from ts/styles/formatting/run.ts rename to ts/docx/run/formatting.ts index 5d48f7e7e8..09a8cec201 100644 --- a/ts/styles/formatting/run.ts +++ b/ts/docx/run/formatting.ts @@ -1,4 +1,4 @@ -import {XmlComponent, Attributes} from "../../docx/xml-components"; +import {XmlComponent, Attributes} from "../xml-components"; export class Bold extends XmlComponent { @@ -121,7 +121,7 @@ export class Size extends XmlComponent { } } -// needs work +// needs work. Add more types of vertical align export class VerticalAlign extends XmlComponent { constructor() { diff --git a/ts/docx/run/index.ts b/ts/docx/run/index.ts index 5c36dce064..a1e1c2aaa2 100644 --- a/ts/docx/run/index.ts +++ b/ts/docx/run/index.ts @@ -1,6 +1,6 @@ import {XmlComponent, Attributes} from "../xml-components"; import {RunProperties} from "./properties"; -import {Bold, Italics, Underline} from "../../styles/formatting/run"; +import {Bold, Italics, Underline} from "./formatting"; export class Run extends XmlComponent { private properties: RunProperties; diff --git a/ts/styles/defaults/index.ts b/ts/styles/defaults/index.ts index be03e40908..0af193af48 100644 --- a/ts/styles/defaults/index.ts +++ b/ts/styles/defaults/index.ts @@ -4,9 +4,9 @@ import {RunPropertiesDefaults} from "./run-properties"; export class DocumentDefaults extends XmlComponent { - constructor() { + constructor(runPropertiesDefaults: RunPropertiesDefaults, paragraphPropertiesDefaults: ParagraphPropertiesDefaults) { super("w:docDefaults"); - this.root.push(new RunPropertiesDefaults()); - this.root.push(new ParagraphPropertiesDefaults()); + this.root.push(runPropertiesDefaults); + this.root.push(paragraphPropertiesDefaults); } } \ No newline at end of file diff --git a/ts/styles/style/components.ts b/ts/styles/style/components.ts index a58ecd61d6..e815a99600 100644 --- a/ts/styles/style/components.ts +++ b/ts/styles/style/components.ts @@ -56,8 +56,11 @@ export class UnhideWhenUsed extends XmlComponent { } -export class QFormat extends XmlComponent { - +export class QuickFormat extends XmlComponent { + + constructor() { + super("w:qFormat"); + } } export class TableProperties extends XmlComponent { diff --git a/ts/styles/style/index.ts b/ts/styles/style/index.ts index b80e234f1c..02cca5a22a 100644 --- a/ts/styles/style/index.ts +++ b/ts/styles/style/index.ts @@ -1,18 +1,83 @@ import {XmlComponent} from "../../docx/xml-components"; import {StyleAttributes} from "./attributes"; +import {ParagraphProperties} from "../../docx/paragraph/properties"; +import {RunProperties} from "../../docx/run/properties"; +import {Name, BasedOn, Next, QuickFormat} from "./components"; export class Style extends XmlComponent { - + constructor(attributes: StyleAttributes) { super("w:style"); this.root.push(attributes); } - + push(styleSegment: XmlComponent): void { this.root.push(styleSegment); } } -export class ParagraphStyle extends XmlComponent { +export class ParagraphStyle extends Style { + + constructor(styleId: string, paragraphProperties: ParagraphProperties, runProperties: RunProperties) { + var attributes = new StyleAttributes({ + type: "paragraph", + styleId: styleId + }); + super(attributes); + this.root.push(paragraphProperties); + this.root.push(runProperties); + } +} + +export class HeadingStyle extends ParagraphStyle { + + constructor(styleId: string, name: string, paragraphProperties: ParagraphProperties, runProperties: RunProperties) { + super(styleId, paragraphProperties, runProperties); + this.root.push(new Name(name)); + this.root.push(new BasedOn("Normal")); + this.root.push(new Next("Normal")); + this.root.push(new QuickFormat()); + } +} + +export class Heading1Style extends HeadingStyle { + constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) { + super("Heading1", "Heading 1", paragraphProperties, runProperties); + } +} + +export class Heading2Style extends HeadingStyle { + + constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) { + super("Heading2", "Heading 2", paragraphProperties, runProperties); + } +} + +export class Heading3Style extends HeadingStyle { + + constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) { + super("Heading3", "Heading 3", paragraphProperties, runProperties); + } +} + +export class Heading4Style extends HeadingStyle { + + constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) { + super("Heading4", "Heading 4", paragraphProperties, runProperties); + } +} + +export class Heading5Style extends HeadingStyle { + + constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) { + super("Heading5", "Heading 5", paragraphProperties, runProperties); + } +} + +export class Heading6Style extends HeadingStyle { + + constructor(paragraphProperties: ParagraphProperties, runProperties: RunProperties) { + super("Heading6", "Heading 6", paragraphProperties, runProperties); + } } \ No newline at end of file