@mlightcad/libredwg-web 0.6.9 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -556,6 +556,17 @@ export class LibreDwgConverter {
556
556
  .data;
557
557
  const color = libredwg.dwg_dynapi_entity_value(item, 'color')
558
558
  .data;
559
+ const ltypeRef = libredwg.dwg_dynapi_entity_value(item, 'ltype')
560
+ .data;
561
+ let ltypeName = 'Continuous';
562
+ if (ltypeRef) {
563
+ try {
564
+ ltypeName = libredwg.dwg_ref_get_object_name(ltypeRef);
565
+ }
566
+ catch {
567
+ // ref may be invalid in some DWG files
568
+ }
569
+ }
559
570
  // - 0xc0 for ByLayer (also c3 and rgb of 0x100)
560
571
  // - 0xc1 for ByBlock (also c3 and rgb of 0)
561
572
  // - 0xc2 for entities (default), with names with an additional name flag RC
@@ -583,7 +594,7 @@ export class LibreDwgConverter {
583
594
  color: rgbColor,
584
595
  colorName: color.name,
585
596
  transparency: color.alpha,
586
- lineType: '',
597
+ lineType: ltypeName,
587
598
  frozen: frozen != 0,
588
599
  off: off != 0,
589
600
  frozenInNew: frozenInNew != 0,
package/lib/libredwg.d.ts CHANGED
@@ -19,6 +19,12 @@ export declare class LibreDwg {
19
19
  private decoder?;
20
20
  private constructor();
21
21
  dwg_read_data(fileContent: string | ArrayBuffer, fileType: number): number | undefined;
22
+ /**
23
+ * Converts DWG file content to DXF file content.
24
+ * @param fileContent DWG file content.
25
+ * @returns Returns DXF file content if conversion succeeds. Otherwise returns null.
26
+ */
27
+ dwg_write_dxf(fileContent: string | ArrayBuffer): Uint8Array | null;
22
28
  /**
23
29
  * Gets the version of the dwg.
24
30
  * @param data Pointer to Dwg_Data instance.
package/lib/libredwg.js CHANGED
@@ -29,13 +29,19 @@ export class LibreDwg {
29
29
  dwg_read_data(fileContent, fileType) {
30
30
  if (fileType == Dwg_File_Type.DWG) {
31
31
  const fileName = 'tmp.dwg';
32
- this.wasmInstance.FS.writeFile(fileName, new Uint8Array(fileContent));
33
- const result = this.wasmInstance.dwg_read_file(fileName);
34
- if (result.error != 0) {
35
- console.log('Open dwg file with error code: ', result.error);
32
+ try {
33
+ this.wasmInstance.FS.writeFile(fileName, new Uint8Array(fileContent));
34
+ const result = this.wasmInstance.dwg_read_file(fileName);
35
+ if (result.error != 0) {
36
+ console.log('Open dwg file with error code: ', result.error);
37
+ }
38
+ return result.data;
39
+ }
40
+ finally {
41
+ if (this.wasmInstance.FS.analyzePath(fileName, false).exists) {
42
+ this.wasmInstance.FS.unlink(fileName);
43
+ }
36
44
  }
37
- this.wasmInstance.FS.unlink(fileName);
38
- return result.data;
39
45
  }
40
46
  // else if (fileType == Dwg_File_Type.DXF) {
41
47
  // const fileName = "tmp.dxf";
@@ -48,6 +54,32 @@ export class LibreDwg {
48
54
  // return result.data as Dwg_Data_Ptr;
49
55
  // }
50
56
  }
57
+ /**
58
+ * Converts DWG file content to DXF file content.
59
+ * @param fileContent DWG file content.
60
+ * @returns Returns DXF file content if conversion succeeds. Otherwise returns null.
61
+ */
62
+ dwg_write_dxf(fileContent) {
63
+ const inputFileName = 'tmp.dwg';
64
+ const outputFileName = 'tmp.dxf';
65
+ try {
66
+ this.wasmInstance.FS.writeFile(inputFileName, new Uint8Array(fileContent));
67
+ const error = this.wasmInstance.dwg_write_dxf(inputFileName, outputFileName);
68
+ if (error != 0) {
69
+ console.log('Convert dwg to dxf with error code: ', error);
70
+ return null;
71
+ }
72
+ return this.wasmInstance.FS.readFile(outputFileName);
73
+ }
74
+ finally {
75
+ if (this.wasmInstance.FS.analyzePath(inputFileName, false).exists) {
76
+ this.wasmInstance.FS.unlink(inputFileName);
77
+ }
78
+ if (this.wasmInstance.FS.analyzePath(outputFileName, false).exists) {
79
+ this.wasmInstance.FS.unlink(outputFileName);
80
+ }
81
+ }
82
+ }
51
83
  /**
52
84
  * Gets the version of the dwg.
53
85
  * @param data Pointer to Dwg_Data instance.
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@mlightcad/libredwg-web",
3
3
  "description": "A DWG/DXF JavaScript parser based on libredwg",
4
- "license": "GPL-2.0-only",
4
+ "license": "GPL-3.0",
5
5
  "private": false,
6
- "version": "0.6.9",
6
+ "version": "0.7.0",
7
7
  "author": "MLight Lee <mlight.lee@outlook.com>",
8
8
  "type": "module",
9
9
  "repository": {
@@ -70,9 +70,9 @@
70
70
  "demo": "live-server examples --entry-file=index.html",
71
71
  "doc": "typedoc",
72
72
  "build": "tsc && vite build && cp -rf wasm examples/ && cp -rf dist examples/",
73
- "build:prepare": "mkdir -p ../../build-wasm && cd ../../build-wasm && emconfigure ../configure CFLAGS=\"-O2 -sUSE_ZLIB=1\" CC=emcc --enable-release --disable-docs --disable-write --disable-python --disable-bindings --disable-shared --disable-json --disable-dxf --enable-partial --enable-experimental",
73
+ "build:prepare": "mkdir -p ../../build-wasm && cd ../../build-wasm && emconfigure ../configure CFLAGS=\"-O2 -sUSE_ZLIB=1\" CC=emcc --enable-release --disable-docs --disable-write --disable-python --disable-bindings --disable-shared --disable-json --enable-partial --enable-experimental",
74
74
  "build:obj": "cd ../../build-wasm && emmake make",
75
- "build:wasm": "cd ../../build-wasm && emcc ../bindings/javascript/embind/*.cpp src/*.o -O2 -lembind -std=c++11 -Isrc -I../src -I../include -o libredwg-web.js -s ALLOW_MEMORY_GROWTH=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME=\"createModule\" -sEXPORTED_RUNTIME_METHODS=FS,ENV,ccall,cwrap,UTF8ToString,stringToNewUTF8,setValue --emit-tsd libredwg-web.d.ts",
75
+ "build:wasm": "cd ../../build-wasm && emcc ../bindings/javascript/embind/*.cpp src/*.o -O2 -lembind -std=c++17 -Isrc -I../src -I../include -o libredwg-web.js -s ALLOW_MEMORY_GROWTH=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME=\"createModule\" -sEXPORTED_RUNTIME_METHODS=FS,ENV,ccall,cwrap,UTF8ToString,stringToNewUTF8,setValue --emit-tsd libredwg-web.d.ts",
76
76
  "clean": "rm -rf ../../build-wasm ./docs ./dist ./lib",
77
77
  "copy": "cp -f ../../build-wasm/libredwg-web.d.ts ../../build-wasm/libredwg-web.js ../../build-wasm/libredwg-web.wasm wasm/ && cp -f ../../build-wasm/libredwg-web.js src/",
78
78
  "format": "prettier --config ./.prettierrc.js --write src/**/*.{ts,js}",
@@ -439,6 +439,7 @@ interface EmbindModule {
439
439
  dwg_dynapi_entity_set_value(_0: number, _1: EmbindString, _2: EmbindString, _3: number, _4: boolean): boolean;
440
440
  dwg_dynapi_common_set_value(_0: number, _1: EmbindString, _2: number, _3: boolean): boolean;
441
441
  dwg_dynapi_handle_name(_0: number, _1: number, _2: number): string;
442
+ dwg_write_dxf(_0: EmbindString, _1: EmbindString): number;
442
443
  dwg_find_tablehandle(_0: number, _1: EmbindString, _2: EmbindString): number;
443
444
  dwg_find_tablehandle_index(_0: number, _1: number, _2: EmbindString): number;
444
445
  dwg_handle_name(_0: number, _1: EmbindString, _2: number): string;
Binary file