-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WASM module and NPM library (javascript bindings) #892
Open
fr-an-k
wants to merge
7
commits into
LibreDWG:master
Choose a base branch
from
fr-an-k:js2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f97acc3
npm, convert library and wasm action
fr-an-k 11d928b
npm, convert library and wasm action
fr-an-k 4cc7e64
npm, convert library and wasm action
fr-an-k 81e74cb
manually test workflow
fr-an-k 20fdec6
flag still not working
fr-an-k 4836dff
undo
fr-an-k 16e8294
undo
fr-an-k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
These are the (initial) Javascript bindings for GNU LibreDWG. | ||
You can convert between DWG, DXF, DXFB (binary) and JSON and output GeoJSON. | ||
You can output multiple files after reading a single file. | ||
It is based on WASM (emscripten). | ||
|
||
Please wait for the official release before using this in production. | ||
|
||
GNU LibreDWG is a free C library to handle DWG files. It aims to be a free replacement for the OpenDWG libraries. DWG is the native file format of AutoCAD. | ||
|
||
LibreDWG is based on LibDWG, originally written by Felipe Castro. | ||
|
||
LibreDWG is in beta development stage. Not all planned features are yet completed, but the API should stay mostly stable. At the moment our decoder (i.e. reader) is done, just some very advanced R2010+ and pre-R13 entities fail to read and are skipped over. The writer is good enough for R2000. Among the example applications we wrote using LibreDWG is a reader (from dwg, dxf, json), a writer (convert from dwg, dxf, json or add from scratch), a rewriter (i.e. saveas), an initial SVG and Postscript conversion, converters from and to DXF and JSON, dwggrep to search for text, and dwglayer to print the list of layers. | ||
|
||
More information: https://www.gnu.org/software/libredwg/ | ||
|
||
Usage: | ||
|
||
```js | ||
import { convert } from 'libredwg' | ||
|
||
let input = /* ... obtain a DWG ArrayBuffer using upload, fetch or IndexedDB */ | ||
|
||
/* | ||
* Available inputs/outputs (case sensitive): dwg, dxf, dxfb, json, jsonString | ||
* jsonString is json as a string, without the cost of internal (de)serialization | ||
* Available DWG/DXF/DXFB versions: [TODO], true = detect / don't care, falsy = no export | ||
* Available log levels: falsy: none, 1/error, 2/warn, 3/info, 4/trace, 5/insane, 9/all | ||
* [TODO buffer sizes including log] | ||
* | ||
* default: | ||
* { | ||
* input: <required> | ||
* from: { dwg: true }, // detect | ||
* json: true, | ||
* level: 'warn' | ||
* } | ||
*/ | ||
const res = convert({input, from: { dwg: 'R_2000' }, json: true, dxfb: 'R_2004', level: 'warn'}) | ||
|
||
/* Result: | ||
* { | ||
* error: 'INVALIDDWG', | ||
* log: '...', | ||
* } | ||
* or: | ||
* { | ||
* log: '...', | ||
* json: {...} | ||
* dxfb: <ArrayBuffer> | ||
* } | ||
* [TODO list of codes] | ||
*/ | ||
console.log('result', res) | ||
``` | ||
|
||
Later versions might add the actual API, native node.js, streams, promises and Typescript. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exports.convert = (args) => { | ||
const { input, from, to } = args; | ||
console.log("from cjs", args); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function convert(args) { | ||
const { input, from, to } = args; | ||
console.log("from mjs", args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "libredwg", | ||
"version": "0.0.0-dev.0", | ||
"description": "GNU LibreDWG is a free library to handle DWG/DXF files", | ||
"main": "index.js", | ||
"repository": "git://fr-an-k/libredwg.git", | ||
"author": "Frank van Leeuwen", | ||
"keywords": [ | ||
"DWG", | ||
"DXF", | ||
"DXFB" | ||
], | ||
"license": "ISC", | ||
"private": false, | ||
"exports": { | ||
".": { | ||
"require": "./index.cjs", | ||
"import": "./index.mjs" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/*****************************************************************************/ | ||
/* LibreDWG - free implementation of the DWG file format */ | ||
/* */ | ||
/* Copyright (C) 2018-2023 Free Software Foundation, Inc. */ | ||
/* */ | ||
/* This library is free software, licensed under the terms of the GNU */ | ||
/* General Public License as published by the Free Software Foundation, */ | ||
/* either version 3 of the License, or (at your option) any later version. */ | ||
/* You should have received a copy of the GNU General Public License */ | ||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
/*****************************************************************************/ | ||
|
||
/* convert.c: simple API to read/write any format. | ||
* Single read, multiple write supported. | ||
* You should call done() once you're done. | ||
* | ||
* written by Frank van Leeuwen | ||
*/ | ||
|
||
#include "dwg.h" | ||
#include "decode.h" | ||
#ifndef DISABLE_JSON | ||
# include "in_json.h" | ||
# include "out_json.h" | ||
#endif | ||
#ifndef DISABLE_DXF | ||
# include "in_dxf.h" | ||
# include "out_dxf.h" | ||
#endif | ||
|
||
Dwg_Data dwg; | ||
int readError = DWG_ERR_IOERROR; | ||
|
||
EXPORT | ||
void done() { | ||
if (!readError) | ||
dwg_free(&dwg); | ||
} | ||
|
||
EXPORT | ||
void read(unsigned char* buf, size_t size, const char* type, unsigned char level) { | ||
Bit_Chain dat = EMPTY_CHAIN (0); | ||
dat.chain = buf; | ||
dat.size = size; | ||
dat.opts = level & DWG_OPTS_LOGLEVEL; | ||
memset (&dwg, 0, sizeof (Dwg_Data)); | ||
|
||
if (!readError) | ||
done(); | ||
|
||
int error = 0; | ||
if (!strcmp(type, "dwg")) { | ||
error = dwg_decode (&dat, &dwg); | ||
if (error) | ||
dwg_free(&dwg); | ||
} | ||
#ifndef DISABLE_DXF | ||
else if (!strcmp(type, "dxf")) { | ||
error = dwg_read_dxf (&dat, &dwg); | ||
} | ||
else if (!strcmp(type, "dxfb")) { | ||
error = dwg_read_dxfb (&dat, &dwg); | ||
} | ||
#endif | ||
#ifndef DISABLE_JSON | ||
else if (!strcmp(type, "json")) { | ||
error = dwg_read_json (&dat, &dwg); | ||
} | ||
#endif | ||
else if (!strcmp(type, "geojson")) { | ||
error = DWG_ERR_NOTYETSUPPORTED; | ||
} | ||
else if (!strcmp(type, "yaml")) { | ||
error = DWG_ERR_NOTYETSUPPORTED; | ||
} | ||
else if (!strcmp(type, "xml")) { | ||
error = DWG_ERR_NOTYETSUPPORTED; | ||
} | ||
else { | ||
error = DWG_ERR_INVALIDTYPE; | ||
} | ||
readError = error; | ||
return error; | ||
} | ||
|
||
EXPORT | ||
void write(unsigned char* buf, size_t size, const char* type, const char* version, int level, bool minimal) { | ||
Bit_Chain dat = EMPTY_CHAIN (0); | ||
dat.chain = buf; | ||
dat.size = size; | ||
dat.opts = (level & DWG_OPTS_LOGLEVEL) | (minimal ? DWG_OPTS_MINIMAL : 0); | ||
|
||
if (readError) | ||
return DWG_ERR_IOERROR; | ||
if (version && *version) | ||
dwg.header.version = dwg_version_as(version); | ||
if (dwg.header.version == R_INVALID) { | ||
return DWG_ERR_INVALIDTYPE; | ||
} | ||
|
||
int error = 0; | ||
if (!type) { | ||
error = DWG_ERR_INVALIDTYPE; | ||
} | ||
else if (!strcmp(type, "dwg")) { | ||
error = dwg_encode(&dat, &dwg); | ||
} | ||
#ifndef DISABLE_DXF | ||
else if (!strcmp(type, "dxf")) { | ||
error = dwg_write_dxf(&dat, &dwg); | ||
} | ||
else if (!strcmp(type, "dxfb")) { | ||
error = dwg_write_dxfb(&dat, &dwg); | ||
} | ||
#endif | ||
#ifndef DISABLE_JSON | ||
else if (!strcmp(type, "json")) { | ||
error = dwg_write_json(&dat, &dwg); | ||
} | ||
else if (!strcmp(type, "geojson")) { | ||
error = dwg_write_geojson(&dat, &dwg); | ||
} | ||
#endif | ||
else if (!strcmp(type, "yaml")) { | ||
error = DWG_ERR_NOTYETSUPPORTED; | ||
} | ||
else if (!strcmp(type, "xml")) { | ||
error = DWG_ERR_NOTYETSUPPORTED; | ||
} | ||
else { | ||
error = DWG_ERR_INVALIDTYPE; | ||
} | ||
return error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just a test through my fork and reservation of the library name, of course I will transfer ownership if desired. I just need auto updates in my production environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a valid Url mostly. The domain is missing