Add more run properties and Universal measure
This commit is contained in:
@ -9,11 +9,11 @@
|
||||
// </xsd:sequence>
|
||||
// </xsd:complexType>
|
||||
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { twipsMeasureValue } from "@util/values";
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||
|
||||
export class TableGrid extends XmlComponent {
|
||||
public constructor(widths: readonly number[] | readonly string[]) {
|
||||
public constructor(widths: readonly number[] | readonly PositiveUniversalMeasure[]) {
|
||||
super("w:tblGrid");
|
||||
for (const width of widths) {
|
||||
this.root.push(new GridCol(width));
|
||||
@ -21,15 +21,15 @@ export class TableGrid extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
class GridColAttributes extends XmlAttributeComponent<{ readonly w: number | string }> {
|
||||
protected readonly xmlKeys = { w: "w:w" };
|
||||
}
|
||||
|
||||
export class GridCol extends XmlComponent {
|
||||
public constructor(width?: number | string) {
|
||||
public constructor(width?: number | PositiveUniversalMeasure) {
|
||||
super("w:gridCol");
|
||||
if (width !== undefined) {
|
||||
this.root.push(new GridColAttributes({ w: twipsMeasureValue(width) }));
|
||||
this.root.push(
|
||||
new NextAttributeComponent<{ readonly width: number | PositiveUniversalMeasure }>({
|
||||
width: { key: "w:w", value: twipsMeasureValue(width) },
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// http://officeopenxml.com/WPtableWidth.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { measurementOrPercentValue } from "@util/values";
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { measurementOrPercentValue, Percentage, UniversalMeasure } from "@util/values";
|
||||
|
||||
// <xsd:simpleType name="ST_TblWidth">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
@ -25,14 +25,10 @@ export enum WidthType {
|
||||
// <xsd:attribute name="w" type="ST_MeasurementOrPercent"/>
|
||||
// <xsd:attribute name="type" type="ST_TblWidth"/>
|
||||
// </xsd:complexType>
|
||||
export interface ITableWidthProperties {
|
||||
readonly size: string | number;
|
||||
export type ITableWidthProperties = {
|
||||
readonly size: number | Percentage | UniversalMeasure;
|
||||
readonly type?: WidthType;
|
||||
}
|
||||
|
||||
class TableWidthAttributes extends XmlAttributeComponent<ITableWidthProperties> {
|
||||
protected readonly xmlKeys = { type: "w:type", size: "w:w" };
|
||||
}
|
||||
};
|
||||
|
||||
export class TableWidthElement extends XmlComponent {
|
||||
public constructor(name: string, { type = WidthType.AUTO, size }: ITableWidthProperties) {
|
||||
@ -42,6 +38,12 @@ export class TableWidthElement extends XmlComponent {
|
||||
if (type === WidthType.PERCENTAGE && typeof size === "number") {
|
||||
tableWidthValue = `${size}%`;
|
||||
}
|
||||
this.root.push(new TableWidthAttributes({ type: type, size: measurementOrPercentValue(tableWidthValue) }));
|
||||
|
||||
this.root.push(
|
||||
new NextAttributeComponent<ITableWidthProperties>({
|
||||
type: { key: "w:type", value: type },
|
||||
size: { key: "w:w", value: measurementOrPercentValue(tableWidthValue) },
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user