Refactor to separate classes in their specific files an tests improuvements for styles

This commit is contained in:
Sergio Mendonça
2018-11-13 11:04:03 -02:00
parent ff443aa7c4
commit 7639b60b15
13 changed files with 1689 additions and 874 deletions

View File

@ -0,0 +1,53 @@
import { XmlComponent } from "file/xml-components";
import { BasedOn, UiPriority, UnhideWhenUsed, Link, SemiHidden } from "./components";
import * as formatting from "file/paragraph/run/formatting";
import { RunProperties } from "file/paragraph/run/properties";
import { Style } from "./style";
export class CharacterStyle extends Style {
private readonly runProperties: RunProperties;
constructor(styleId: string, name?: string) {
super({ type: "character", styleId: styleId }, name);
this.runProperties = new RunProperties();
this.root.push(this.runProperties);
this.root.push(new UiPriority("99"));
this.root.push(new UnhideWhenUsed());
}
public basedOn(parentId: string): CharacterStyle {
this.root.push(new BasedOn(parentId));
return this;
}
public addRunProperty(property: XmlComponent): CharacterStyle {
this.runProperties.push(property);
return this;
}
public color(color: string): CharacterStyle {
return this.addRunProperty(new formatting.Color(color));
}
public underline(underlineType?: string, color?: string): CharacterStyle {
return this.addRunProperty(new formatting.Underline(underlineType, color));
}
public superScript(): CharacterStyle {
return this.addRunProperty(new formatting.SuperScript());
}
public size(twips: number): CharacterStyle {
return this.addRunProperty(new formatting.Size(twips)).addRunProperty(new formatting.SizeComplexScript(twips));
}
public link(link: string): CharacterStyle {
this.root.push(new Link(link));
return this;
}
public semiHidden(): CharacterStyle {
this.root.push(new SemiHidden());
return this;
}
}