diff --git a/docx-core/src/documents/elements/table_cell.rs b/docx-core/src/documents/elements/table_cell.rs index 4e89e58..4650c26 100644 --- a/docx-core/src/documents/elements/table_cell.rs +++ b/docx-core/src/documents/elements/table_cell.rs @@ -43,6 +43,11 @@ impl TableCell { self.property = self.property.grid_span(v); self } + + pub fn width(mut self, v: usize) -> TableCell { + self.property = self.property.width(v, WidthType::DXA); + self + } } impl BuildXML for TableCell { diff --git a/docx-wasm/pkg/docx_rs.d.ts b/docx-wasm/pkg/docx_rs.d.ts index 41e1f92..af0526d 100644 --- a/docx-wasm/pkg/docx_rs.d.ts +++ b/docx-wasm/pkg/docx_rs.d.ts @@ -1,8 +1,13 @@ /* tslint:disable */ /** -* @returns {TableCell} +* @param {number} id +* @param {number} start +* @param {string} format +* @param {string} text +* @param {string} jc +* @returns {Level} */ -export function createTableCell(): TableCell; +export function createLevel(id: number, start: number, format: string, text: string, jc: string): Level; /** * @returns {Docx} */ @@ -33,23 +38,18 @@ export function createParagraph(): Paragraph; */ export function createRun(): Run; /** -* @param {number} id -* @returns {Comment} +* @returns {TableCell} */ -export function createComment(id: number): Comment; +export function createTableCell(): TableCell; /** * @returns {TableRow} */ export function createTableRow(): TableRow; /** * @param {number} id -* @param {number} start -* @param {string} format -* @param {string} text -* @param {string} jc -* @returns {Level} +* @returns {Comment} */ -export function createLevel(id: number, start: number, format: string, text: string, jc: string): Level; +export function createComment(id: number): Comment; export enum StyleType { Paragraph, Character, @@ -365,6 +365,11 @@ export class TableCell { * @returns {TableCell} */ grid_span(v: number): TableCell; +/** +* @param {number} v +* @returns {TableCell} +*/ + width(v: number): TableCell; } /** */ diff --git a/docx-wasm/pkg/docx_rs.js b/docx-wasm/pkg/docx_rs.js index e0aaa55..582eea3 100644 --- a/docx-wasm/pkg/docx_rs.js +++ b/docx-wasm/pkg/docx_rs.js @@ -1,18 +1,74 @@ import * as wasm from './docx_rs_bg.wasm'; -/** -* @returns {TableCell} -*/ -export function createTableCell() { - const ret = wasm.createTableCell(); - return TableCell.__wrap(ret); +let WASM_VECTOR_LEN = 0; + +let cachedTextEncoder = new TextEncoder('utf-8'); + +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}); + +let cachegetUint8Memory = null; +function getUint8Memory() { + if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) { + cachegetUint8Memory = new Uint8Array(wasm.memory.buffer); + } + return cachegetUint8Memory; } -function _assertClass(instance, klass) { - if (!(instance instanceof klass)) { - throw new Error(`expected instance of ${klass.name}`); +function passStringToWasm(arg) { + + let len = arg.length; + let ptr = wasm.__wbindgen_malloc(len); + + const mem = getUint8Memory(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; } - return instance.ptr; + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = wasm.__wbindgen_realloc(ptr, len, len = offset + arg.length * 3); + const view = getUint8Memory().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} +/** +* @param {number} id +* @param {number} start +* @param {string} format +* @param {string} text +* @param {string} jc +* @returns {Level} +*/ +export function createLevel(id, start, format, text, jc) { + const ret = wasm.createLevel(id, start, passStringToWasm(format), WASM_VECTOR_LEN, passStringToWasm(text), WASM_VECTOR_LEN, passStringToWasm(jc), WASM_VECTOR_LEN); + return Level.__wrap(ret); +} + +function isLikeNone(x) { + return x === undefined || x === null; } /** * @returns {Docx} @@ -22,6 +78,13 @@ export function createDocx() { return Docx.__wrap(ret); } +function _assertClass(instance, klass) { + if (!(instance instanceof klass)) { + throw new Error(`expected instance of ${klass.name}`); + } + return instance.ptr; +} + let cachegetInt32Memory = null; function getInt32Memory() { if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) { @@ -30,14 +93,6 @@ function getInt32Memory() { return cachegetInt32Memory; } -let cachegetUint8Memory = null; -function getUint8Memory() { - if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) { - cachegetUint8Memory = new Uint8Array(wasm.memory.buffer); - } - return cachegetUint8Memory; -} - function getArrayU8FromWasm(ptr, len) { return getUint8Memory().subarray(ptr / 1, ptr / 1 + len); } @@ -82,8 +137,6 @@ function getUint32Memory() { return cachegetUint32Memory; } -let WASM_VECTOR_LEN = 0; - function passArray32ToWasm(arg) { const ptr = wasm.__wbindgen_malloc(arg.length * 4); getUint32Memory().set(arg, ptr / 4); @@ -98,54 +151,6 @@ export function createParagraph() { return Paragraph.__wrap(ret); } -let cachedTextEncoder = new TextEncoder('utf-8'); - -const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' - ? function (arg, view) { - return cachedTextEncoder.encodeInto(arg, view); -} - : function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length - }; -}); - -function passStringToWasm(arg) { - - let len = arg.length; - let ptr = wasm.__wbindgen_malloc(len); - - const mem = getUint8Memory(); - - let offset = 0; - - for (; offset < len; offset++) { - const code = arg.charCodeAt(offset); - if (code > 0x7F) break; - mem[ptr + offset] = code; - } - - if (offset !== len) { - if (offset !== 0) { - arg = arg.slice(offset); - } - ptr = wasm.__wbindgen_realloc(ptr, len, len = offset + arg.length * 3); - const view = getUint8Memory().subarray(ptr + offset, ptr + len); - const ret = encodeString(arg, view); - - offset += ret.written; - } - - WASM_VECTOR_LEN = offset; - return ptr; -} - -function isLikeNone(x) { - return x === undefined || x === null; -} /** * @returns {Run} */ @@ -155,12 +160,11 @@ export function createRun() { } /** -* @param {number} id -* @returns {Comment} +* @returns {TableCell} */ -export function createComment(id) { - const ret = wasm.createComment(id); - return Comment.__wrap(ret); +export function createTableCell() { + const ret = wasm.createTableCell(); + return TableCell.__wrap(ret); } /** @@ -173,15 +177,11 @@ export function createTableRow() { /** * @param {number} id -* @param {number} start -* @param {string} format -* @param {string} text -* @param {string} jc -* @returns {Level} +* @returns {Comment} */ -export function createLevel(id, start, format, text, jc) { - const ret = wasm.createLevel(id, start, passStringToWasm(format), WASM_VECTOR_LEN, passStringToWasm(text), WASM_VECTOR_LEN, passStringToWasm(jc), WASM_VECTOR_LEN); - return Level.__wrap(ret); +export function createComment(id) { + const ret = wasm.createComment(id); + return Comment.__wrap(ret); } let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); @@ -861,6 +861,16 @@ export class TableCell { const ret = wasm.tablecell_grid_span(ptr, v); return TableCell.__wrap(ret); } + /** + * @param {number} v + * @returns {TableCell} + */ + width(v) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.tablecell_width(ptr, v); + return TableCell.__wrap(ret); + } } /** */ diff --git a/docx-wasm/pkg/docx_rs_bg.d.ts b/docx-wasm/pkg/docx_rs_bg.d.ts index 9886d60..59c0824 100644 --- a/docx-wasm/pkg/docx_rs_bg.d.ts +++ b/docx-wasm/pkg/docx_rs_bg.d.ts @@ -1,10 +1,8 @@ /* tslint:disable */ export const memory: WebAssembly.Memory; -export function __wbg_tablecell_free(a: number): void; -export function createTableCell(): number; -export function tablecell_add_paragraph(a: number, b: number): number; -export function tablecell_vertical_merge(a: number, b: number): number; -export function tablecell_grid_span(a: number, b: number): number; +export function __wbg_level_free(a: number): void; +export function createLevel(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; +export function level_indent(a: number, b: number, c: number, d: number, e: number): number; export function __wbg_docx_free(a: number): void; export function createDocx(): number; export function docx_add_paragraph(a: number, b: number): number; @@ -51,18 +49,21 @@ export function run_bold(a: number): number; export function run_italic(a: number): number; export function run_underline(a: number, b: number, c: number): number; export function run_vanish(a: number): number; +export function __wbg_tablecell_free(a: number): void; +export function createTableCell(): number; +export function tablecell_add_paragraph(a: number, b: number): number; +export function tablecell_vertical_merge(a: number, b: number): number; +export function tablecell_grid_span(a: number, b: number): number; +export function tablecell_width(a: number, b: number): number; +export function __wbg_tablerow_free(a: number): void; +export function createTableRow(): number; +export function tablerow_add_cell(a: number, b: number): number; export function __wbg_comment_free(a: number): void; export function createComment(a: number): number; export function comment_author(a: number, b: number, c: number): number; export function comment_date(a: number, b: number, c: number): number; export function comment_paragraph(a: number, b: number): number; export function comment_id(a: number): number; -export function __wbg_tablerow_free(a: number): void; -export function createTableRow(): number; -export function tablerow_add_cell(a: number, b: number): number; -export function __wbg_level_free(a: number): void; -export function createLevel(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; -export function level_indent(a: number, b: number, c: number, d: number, e: number): number; export function __wbindgen_malloc(a: number): number; export function __wbindgen_realloc(a: number, b: number, c: number): number; export function __wbindgen_free(a: number, b: number): void; diff --git a/docx-wasm/pkg/docx_rs_bg.wasm b/docx-wasm/pkg/docx_rs_bg.wasm index 7732110..73559ca 100644 Binary files a/docx-wasm/pkg/docx_rs_bg.wasm and b/docx-wasm/pkg/docx_rs_bg.wasm differ diff --git a/docx-wasm/src/table_cell.rs b/docx-wasm/src/table_cell.rs index b0b9ad6..c23c835 100644 --- a/docx-wasm/src/table_cell.rs +++ b/docx-wasm/src/table_cell.rs @@ -35,4 +35,9 @@ impl TableCell { self.0.property = self.0.property.grid_span(v); self } + + pub fn width(mut self, v: usize) -> TableCell { + self.0.property = self.0.property.width(v, docx_core::WidthType::DXA); + self + } }