rtf-codec 4.0.9 → 4.1.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.
- package/README.md +4 -3
- package/dist/codepage-dbcs.cjs +523 -0
- package/dist/codepage-dbcs.d.cts +5 -0
- package/dist/codepage-dbcs.d.ts +5 -0
- package/dist/codepage-dbcs.js +521 -0
- package/dist/codepage.cjs +28 -1
- package/dist/codepage.js +28 -1
- package/package.json +1 -1
package/dist/codepage.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_diagnostics = require("./diagnostics.cjs");
|
|
3
|
+
const require_codepage_dbcs = require("./codepage-dbcs.cjs");
|
|
3
4
|
//#region src/codepage.ts
|
|
4
5
|
const DEFAULT_CODEPAGE = 1252;
|
|
5
6
|
const UTF8_CODEPAGE = 65001;
|
|
@@ -71,11 +72,13 @@ function codepageForFontCharset(charset) {
|
|
|
71
72
|
return FCHARSET_CODEPAGES.get(charset);
|
|
72
73
|
}
|
|
73
74
|
function isSupportedCodepage(codepage) {
|
|
74
|
-
return codepage === 65001 || SINGLE_BYTE_PAGES.has(codepage);
|
|
75
|
+
return codepage === 65001 || SINGLE_BYTE_PAGES.has(codepage) || require_codepage_dbcs.DBCS_LEAD_BYTE_TABLES.has(codepage);
|
|
75
76
|
}
|
|
76
77
|
function decodeCodepageBytes(input, codepage, sink) {
|
|
77
78
|
if (input.length === 0) return "";
|
|
78
79
|
if (codepage === 65001) return new TextDecoder("utf-8").decode(input);
|
|
80
|
+
const leadTable = require_codepage_dbcs.DBCS_LEAD_BYTE_TABLES.get(codepage);
|
|
81
|
+
if (leadTable !== void 0) return decodeDbcsBytes(input, codepage, leadTable);
|
|
79
82
|
const table = SINGLE_BYTE_PAGES.get(codepage);
|
|
80
83
|
if (table === void 0) {
|
|
81
84
|
sink({
|
|
@@ -89,6 +92,30 @@ function decodeCodepageBytes(input, codepage, sink) {
|
|
|
89
92
|
for (const byte of input) out += byte < 128 ? String.fromCharCode(byte) : table[byte - 128] ?? "�";
|
|
90
93
|
return out;
|
|
91
94
|
}
|
|
95
|
+
function decodeDbcsBytes(input, codepage, leadTable) {
|
|
96
|
+
const singleByteExtras = require_codepage_dbcs.DBCS_SINGLE_BYTE_EXTRAS.get(codepage);
|
|
97
|
+
let out = "";
|
|
98
|
+
let i = 0;
|
|
99
|
+
while (i < input.length) {
|
|
100
|
+
const byte = input[i];
|
|
101
|
+
if (byte === void 0) break;
|
|
102
|
+
if (byte < 128) {
|
|
103
|
+
out += String.fromCharCode(byte);
|
|
104
|
+
i += 1;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const trailTable = leadTable.get(byte);
|
|
108
|
+
if (trailTable !== void 0) {
|
|
109
|
+
const trail = input[i + 1];
|
|
110
|
+
out += trail === void 0 ? "�" : trailTable[trail] ?? "�";
|
|
111
|
+
i += trail === void 0 ? 1 : 2;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
out += singleByteExtras?.[byte - 128] ?? "�";
|
|
115
|
+
i += 1;
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
92
119
|
//#endregion
|
|
93
120
|
exports.DEFAULT_CODEPAGE = DEFAULT_CODEPAGE;
|
|
94
121
|
exports.DOCUMENT_CHARSET_CODEPAGES = DOCUMENT_CHARSET_CODEPAGES;
|
package/dist/codepage.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RtfDiagnosticCodes } from "./diagnostics.js";
|
|
2
|
+
import { DBCS_LEAD_BYTE_TABLES, DBCS_SINGLE_BYTE_EXTRAS } from "./codepage-dbcs.js";
|
|
2
3
|
//#region src/codepage.ts
|
|
3
4
|
const DEFAULT_CODEPAGE = 1252;
|
|
4
5
|
const UTF8_CODEPAGE = 65001;
|
|
@@ -70,11 +71,13 @@ function codepageForFontCharset(charset) {
|
|
|
70
71
|
return FCHARSET_CODEPAGES.get(charset);
|
|
71
72
|
}
|
|
72
73
|
function isSupportedCodepage(codepage) {
|
|
73
|
-
return codepage === 65001 || SINGLE_BYTE_PAGES.has(codepage);
|
|
74
|
+
return codepage === 65001 || SINGLE_BYTE_PAGES.has(codepage) || DBCS_LEAD_BYTE_TABLES.has(codepage);
|
|
74
75
|
}
|
|
75
76
|
function decodeCodepageBytes(input, codepage, sink) {
|
|
76
77
|
if (input.length === 0) return "";
|
|
77
78
|
if (codepage === 65001) return new TextDecoder("utf-8").decode(input);
|
|
79
|
+
const leadTable = DBCS_LEAD_BYTE_TABLES.get(codepage);
|
|
80
|
+
if (leadTable !== void 0) return decodeDbcsBytes(input, codepage, leadTable);
|
|
78
81
|
const table = SINGLE_BYTE_PAGES.get(codepage);
|
|
79
82
|
if (table === void 0) {
|
|
80
83
|
sink({
|
|
@@ -88,5 +91,29 @@ function decodeCodepageBytes(input, codepage, sink) {
|
|
|
88
91
|
for (const byte of input) out += byte < 128 ? String.fromCharCode(byte) : table[byte - 128] ?? "�";
|
|
89
92
|
return out;
|
|
90
93
|
}
|
|
94
|
+
function decodeDbcsBytes(input, codepage, leadTable) {
|
|
95
|
+
const singleByteExtras = DBCS_SINGLE_BYTE_EXTRAS.get(codepage);
|
|
96
|
+
let out = "";
|
|
97
|
+
let i = 0;
|
|
98
|
+
while (i < input.length) {
|
|
99
|
+
const byte = input[i];
|
|
100
|
+
if (byte === void 0) break;
|
|
101
|
+
if (byte < 128) {
|
|
102
|
+
out += String.fromCharCode(byte);
|
|
103
|
+
i += 1;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const trailTable = leadTable.get(byte);
|
|
107
|
+
if (trailTable !== void 0) {
|
|
108
|
+
const trail = input[i + 1];
|
|
109
|
+
out += trail === void 0 ? "�" : trailTable[trail] ?? "�";
|
|
110
|
+
i += trail === void 0 ? 1 : 2;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
out += singleByteExtras?.[byte - 128] ?? "�";
|
|
114
|
+
i += 1;
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
91
118
|
//#endregion
|
|
92
119
|
export { DEFAULT_CODEPAGE, DOCUMENT_CHARSET_CODEPAGES, UTF8_CODEPAGE, codepageForFontCharset, decodeCodepageBytes, isSupportedCodepage };
|
package/package.json
CHANGED