Skip to content

Commit

Permalink
feat: Add set_grid for wasm (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuweb authored Dec 12, 2019
1 parent c518d73 commit c37c481
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docx-core/src/documents/elements/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::xml_builder::*;
#[derive(Debug, Clone)]
pub struct Table {
pub rows: Vec<TableRow>,
pub grid: Vec<usize>,
property: TableProperty,
grid: Vec<usize>,
}

impl Table {
Expand Down
2 changes: 1 addition & 1 deletion docx-wasm/pkg/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# *
*
5 changes: 5 additions & 0 deletions docx-wasm/pkg/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ export class Table {
* @returns {Table}
*/
add_row(row: TableRow): Table;
/**
* @param {Uint32Array} grid
* @returns {Table}
*/
set_grid(grid: Uint32Array): Table;
}
/**
*/
Expand Down
26 changes: 26 additions & 0 deletions docx-wasm/pkg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ export function createTable() {
return Table.__wrap(ret);
}

let cachegetUint32Memory = null;
function getUint32Memory() {
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
}
return cachegetUint32Memory;
}

function passArray32ToWasm(arg) {
const ptr = wasm.__wbindgen_malloc(arg.length * 4);
getUint32Memory().set(arg, ptr / 4);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
/**
* @param {number} id
* @returns {Numbering}
Expand Down Expand Up @@ -912,6 +926,18 @@ export class Table {
const ret = wasm.table_add_row(ptr, ptr0);
return Table.__wrap(ret);
}
/**
* @param {Uint32Array} grid
* @returns {Table}
*/
set_grid(grid) {
if (this.ptr == 0) throw new Error('Attempt to use a moved value');
const ptr = this.ptr;
this.ptr = 0;
_assertNum(ptr);
const ret = wasm.table_set_grid(ptr, passArray32ToWasm(grid), WASM_VECTOR_LEN);
return Table.__wrap(ret);
}
}
/**
*/
Expand Down
1 change: 1 addition & 0 deletions docx-wasm/pkg/index_bg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function createInsert(): number;
export function __wbg_table_free(a: number): void;
export function createTable(): number;
export function table_add_row(a: number, b: number): number;
export function table_set_grid(a: number, b: number, c: number): number;
export function __wbg_numbering_free(a: number): void;
export function createNumbering(a: number): number;
export function numbering_add_level(a: number, b: number): number;
Expand Down
Binary file modified docx-wasm/pkg/index_bg.wasm
Binary file not shown.
5 changes: 5 additions & 0 deletions docx-wasm/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ impl Table {
self.0.rows.push(row.take());
self
}

pub fn set_grid(mut self, grid: Vec<usize>) -> Table {
self.0.grid = grid;
self
}
}

0 comments on commit c37c481

Please sign in to comment.