@syzlm/ofdparser 0.0.1
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/.babelrc +14 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +18 -0
- package/.prettierrc.json +9 -0
- package/dist/OFD.d.ts +8 -0
- package/dist/Pages.d.ts +7 -0
- package/dist/RootDocumnet.d.ts +1 -0
- package/dist/bundle.cjs.js +64123 -0
- package/dist/bundle.esm.js +64115 -0
- package/dist/bundle.iife.js +14743 -0
- package/dist/bundle.umd.js +64045 -0
- package/dist/constant/index.d.ts +7 -0
- package/dist/constant.d.ts +6 -0
- package/dist/core/ofd-core/Annotations/AnnotationsXml.d.ts +16 -0
- package/dist/core/ofd-core/Asn.1Utils.d.ts +47 -0
- package/dist/core/ofd-core/Documents/DocumentResXml.d.ts +15 -0
- package/dist/core/ofd-core/Documents/DocumnetXml.d.ts +25 -0
- package/dist/core/ofd-core/Documents/PublicResXml.d.ts +15 -0
- package/dist/core/ofd-core/OFDElement.d.ts +232 -0
- package/dist/core/ofd-core/Ofd/OFDXml.d.ts +19 -0
- package/dist/core/ofd-core/Pages/PageXml.d.ts +20 -0
- package/dist/core/ofd-core/Signatures/Signatures.d.ts +20 -0
- package/dist/core/ofd-core/TemplatePages/TemplatePages.d.ts +20 -0
- package/dist/core/ofd-core/constant.d.ts +29 -0
- package/dist/core/ofd-core/utils.d.ts +21 -0
- package/dist/dicom/dicom.d.ts +15 -0
- package/dist/dicom/index.d.ts +1 -0
- package/dist/errors/ErrorHandle.d.ts +6 -0
- package/dist/errors/ErrorMsg.d.ts +16 -0
- package/dist/errors/FetchErrors.d.ts +4 -0
- package/dist/errors/MimeError.d.ts +4 -0
- package/dist/errors/OFDErrors.d.ts +4 -0
- package/dist/errors/UnzipErrors.d.ts +4 -0
- package/dist/errors/XmlErrors.d.ts +4 -0
- package/dist/errors/error-msg.d.ts +9 -0
- package/dist/es.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/lib/ParseFile.d.ts +7 -0
- package/dist/lib/UnitCoversion.d.ts +31 -0
- package/dist/lib/asn1/Asn.1.d.ts +34 -0
- package/dist/lib/asn1/Stream.d.ts +27 -0
- package/dist/lib/asn1/asn1.d.ts +4 -0
- package/dist/lib/asn1/base64.d.ts +4 -0
- package/dist/lib/asn1/hex.d.ts +5 -0
- package/dist/lib/asn1/index.d.ts +5 -0
- package/dist/lib/asn1/int10.d.ts +34 -0
- package/dist/lib/asn1/oids.d.ts +2 -0
- package/dist/lib/asn1/string-cut.d.ts +2 -0
- package/dist/lib/decode-html.d.ts +7 -0
- package/dist/lib/fetch.d.ts +17 -0
- package/dist/lib/is-element.d.ts +5 -0
- package/dist/lib/load-files.d.ts +3 -0
- package/dist/lib/load-opentype.d.ts +34 -0
- package/dist/lib/load-script.d.ts +1 -0
- package/dist/lib/mime.d.ts +8 -0
- package/dist/lib/read-buffer.d.ts +2 -0
- package/dist/lib/toFixeds.d.ts +7 -0
- package/dist/libs/Asn.1Utils.d.ts +47 -0
- package/dist/libs/asn1/Asn.1.d.ts +34 -0
- package/dist/libs/asn1/Stream.d.ts +27 -0
- package/dist/libs/asn1/asn1.d.ts +4 -0
- package/dist/libs/asn1/base64.d.ts +4 -0
- package/dist/libs/asn1/hex.d.ts +5 -0
- package/dist/libs/asn1/index.d.ts +5 -0
- package/dist/libs/asn1/int10.d.ts +34 -0
- package/dist/libs/asn1/oids.d.ts +2 -0
- package/dist/libs/asn1/string-cut.d.ts +2 -0
- package/dist/libs/decode-html.d.ts +7 -0
- package/dist/libs/fetch.d.ts +17 -0
- package/dist/libs/mime.d.ts +8 -0
- package/dist/libs/ofdArray.d.ts +10 -0
- package/dist/libs/ofdImageObject.d.ts +9 -0
- package/dist/libs/ofdLayer.d.ts +3 -0
- package/dist/libs/ofdName.d.ts +17 -0
- package/dist/libs/ofdPathObject.d.ts +11 -0
- package/dist/libs/ofdTextObject.d.ts +6 -0
- package/dist/libs/parseAnnotation.d.ts +5 -0
- package/dist/libs/parseColor.d.ts +5 -0
- package/dist/libs/parsePageArea.d.ts +17 -0
- package/dist/libs/parser-elements.d.ts +8 -0
- package/dist/libs/parserElements.d.ts +8 -0
- package/dist/libs/pipeExtensions.d.ts +4 -0
- package/dist/libs/read-buffer.d.ts +2 -0
- package/dist/main.d.ts +15 -0
- package/dist/ofd/ConverterDpi.d.ts +16 -0
- package/dist/ofd/index.d.ts +1 -0
- package/dist/ofd/ofd-utils.d.ts +137 -0
- package/dist/ofd/ofd.d.ts +35 -0
- package/dist/ofd/parse-ofd.d.ts +18 -0
- package/dist/ofd/render.d.ts +18 -0
- package/dist/ofd/svg-image.d.ts +12 -0
- package/dist/ofd/svg-path.d.ts +5 -0
- package/dist/ofd/svg-text.d.ts +8 -0
- package/dist/ofd.parse.d.ts +6 -0
- package/dist/ofd.xml.d.ts +1 -0
- package/dist/ofdParse.d.ts +6 -0
- package/dist/pipe/annotations.d.ts +13 -0
- package/dist/pipe/attachments.d.ts +13 -0
- package/dist/pipe/commonData.d.ts +18 -0
- package/dist/pipe/customTags.d.ts +14 -0
- package/dist/pipe/extensions.d.ts +14 -0
- package/dist/pipe/output.d.ts +7 -0
- package/dist/pipe/pages.d.ts +13 -0
- package/dist/pipe/permissions.d.ts +14 -0
- package/dist/pipe/pipeline.d.ts +63 -0
- package/dist/pipe/startPipe.d.ts +11 -0
- package/dist/xml/index.d.ts +2 -0
- package/dist/xml/render.d.ts +6 -0
- package/dist/xml/xml.d.ts +18 -0
- package/package.json +47 -0
- package/public/index.html +75 -0
- package/public/opentype.min.js +2 -0
- package/rollup.config.dev.mjs +47 -0
- package/rollup.config.mjs +70 -0
- package/src/constant/index.ts +13 -0
- package/src/core/ofd-core/Annotations/Annotation.km +206 -0
- package/src/core/ofd-core/Annotations/Annotations.km +59 -0
- package/src/core/ofd-core/Annotations/Annotations.md +13 -0
- package/src/core/ofd-core/Annotations/AnnotationsXml.ts +114 -0
- package/src/core/ofd-core/Asn.1Utils.ts +225 -0
- package/src/core/ofd-core/Documents/DocumentResXml.ts +55 -0
- package/src/core/ofd-core/Documents/Documnet.km +862 -0
- package/src/core/ofd-core/Documents/DocumnetXml.ts +118 -0
- package/src/core/ofd-core/Documents/Documnets.md +296 -0
- package/src/core/ofd-core/Documents/PublicResXml.ts +63 -0
- package/src/core/ofd-core/Documents//345/233/276/345/261/202/346/270/262/346/237/223/351/241/272/345/272/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25022/347/272/277/346/235/241/350/277/236/346/216/245/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25023/347/272/277/346/235/241/350/231/232/347/272/277/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25023/347/273/223/345/220/210/347/202/271/351/225/277/345/272/246.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25024/347/272/277/346/235/241/347/253/257/347/202/271/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//351/241/265/350/276/271/347/225/214/345/261/202/346/254/241/347/273/223/346/236/204.png +0 -0
- package/src/core/ofd-core/OFDElement.ts +724 -0
- package/src/core/ofd-core/Ofd/CT_DocInfo.km +197 -0
- package/src/core/ofd-core/Ofd/OFD.km +114 -0
- package/src/core/ofd-core/Ofd/OFD.md +99 -0
- package/src/core/ofd-core/Ofd/OFDXml.ts +69 -0
- package/src/core/ofd-core/Pages/PAGE.md +40 -0
- package/src/core/ofd-core/Pages/PageXml.ts +59 -0
- package/src/core/ofd-core/Signatures/Signature.km +308 -0
- package/src/core/ofd-core/Signatures/Signature.md +21 -0
- package/src/core/ofd-core/Signatures/Signatures.km +315 -0
- package/src/core/ofd-core/Signatures/Signatures.md +24 -0
- package/src/core/ofd-core/Signatures/Signatures.ts +247 -0
- package/src/core/ofd-core/TemplatePages/TemplatePages.ts +56 -0
- package/src/core/ofd-core/asn.md +60 -0
- package/src/core/ofd-core/constant.ts +35 -0
- package/src/core/ofd-core/index.d.ts +867 -0
- package/src/core/ofd-core/utils.ts +86 -0
- package/src/dicom/dicom.ts +42 -0
- package/src/dicom/index.ts +1 -0
- package/src/errors/ErrorHandle.ts +14 -0
- package/src/errors/FetchErrors.ts +8 -0
- package/src/errors/MimeError.ts +9 -0
- package/src/errors/OFDErrors.ts +11 -0
- package/src/errors/UnzipErrors.ts +9 -0
- package/src/errors/XmlErrors.ts +11 -0
- package/src/errors/error-msg.ts +17 -0
- package/src/es.ts +3 -0
- package/src/global.d.ts +7 -0
- package/src/index.ts +7 -0
- package/src/lib/ParseFile.ts +12 -0
- package/src/lib/README.md +69 -0
- package/src/lib/UnitCoversion.ts +55 -0
- package/src/lib/asn1/Asn.1.ts +284 -0
- package/src/lib/asn1/README.md +1 -0
- package/src/lib/asn1/Stream.ts +314 -0
- package/src/lib/asn1/asn1.ts +120 -0
- package/src/lib/asn1/base64.ts +97 -0
- package/src/lib/asn1/hex.ts +60 -0
- package/src/lib/asn1/index.ts +5 -0
- package/src/lib/asn1/int10.ts +103 -0
- package/src/lib/asn1/oids.ts +6164 -0
- package/src/lib/asn1/string-cut.ts +8 -0
- package/src/lib/decode-html.ts +37 -0
- package/src/lib/fetch.ts +70 -0
- package/src/lib/is-element.ts +13 -0
- package/src/lib/jbig/README.md +1 -0
- package/src/lib/jbig/arithmetic_decoder.js +184 -0
- package/src/lib/jbig/base_stream.js +117 -0
- package/src/lib/jbig/ccitt.js +1068 -0
- package/src/lib/jbig/ccitt_stream.js +60 -0
- package/src/lib/jbig/compatibility.js +108 -0
- package/src/lib/jbig/core_utils.js +591 -0
- package/src/lib/jbig/decode_stream.js +184 -0
- package/src/lib/jbig/is_node.js +28 -0
- package/src/lib/jbig/jbig2.js +2582 -0
- package/src/lib/jbig/jbig2_stream.js +78 -0
- package/src/lib/jbig/primitives.js +441 -0
- package/src/lib/jbig/stream.js +101 -0
- package/src/lib/jbig/util.js +1231 -0
- package/src/lib/load-files.ts +26 -0
- package/src/lib/load-opentype.ts +161 -0
- package/src/lib/load-script.ts +33 -0
- package/src/lib/mime.ts +97 -0
- package/src/lib/read-buffer.ts +19 -0
- package/src/lib/toFixeds.ts +56 -0
- package/src/ofd/ConverterDpi.ts +35 -0
- package/src/ofd/OFD.md +38 -0
- package/src/ofd/TODO.md +10 -0
- package/src/ofd/index.ts +1 -0
- package/src/ofd/ofd-utils.ts +627 -0
- package/src/ofd/ofd.demo.md +12 -0
- package/src/ofd/ofd.ts +200 -0
- package/src/ofd/ofdxml.km +162 -0
- package/src/ofd/parse-ofd.ts +103 -0
- package/src/ofd/render.ts +393 -0
- package/src/ofd/svg-image.ts +318 -0
- package/src/ofd/svg-path.ts +283 -0
- package/src/ofd/svg-text.ts +272 -0
- package/src/xml/index.ts +3 -0
- package/src/xml/render.ts +171 -0
- package/src/xml/xml.ts +136 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
import { Res } from '../core/ofd-core';
|
|
2
|
+
import ConverterDpi from './ConverterDpi';
|
|
3
|
+
import decodeHtml from '../lib/decode-html';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @desc 字体family
|
|
7
|
+
*/
|
|
8
|
+
export const FONT_FAMILY = {
|
|
9
|
+
楷体: '楷体, KaiTi, Kai, simkai',
|
|
10
|
+
kaiti: '楷体, KaiTi, Kai, simkai',
|
|
11
|
+
Kai: '楷体, KaiTi, Kai',
|
|
12
|
+
simsun: 'SimSun, simsun, Songti SC',
|
|
13
|
+
宋体: '宋体, SimSun, simsun, Songti SC',
|
|
14
|
+
黑体: '黑体, SimHei, STHeiti, simhei',
|
|
15
|
+
仿宋: 'FangSong, STFangsong, simfang',
|
|
16
|
+
小标宋体: 'sSun',
|
|
17
|
+
方正小标宋_gbk: 'sSun',
|
|
18
|
+
仿宋_gb2312: 'FangSong, STFangsong, simfang',
|
|
19
|
+
楷体_gb2312: '楷体, KaiTi, Kai, simkai',
|
|
20
|
+
华文楷体: '华文楷体, 楷体, KaiTi, Kai, simkai, 宋体',
|
|
21
|
+
华文中宋: '华文楷体, 楷体, KaiTi, Kai, simkai, 宋体',
|
|
22
|
+
couriernew: 'Courier New',
|
|
23
|
+
'courier new': 'Courier New',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const pageZIndex = {
|
|
27
|
+
Background: 2,
|
|
28
|
+
Body: 4,
|
|
29
|
+
WatermarkAnnot: 6,
|
|
30
|
+
Foreground: 8,
|
|
31
|
+
Stamp: 1,
|
|
32
|
+
Watermark: 6,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 设置style样式文件
|
|
37
|
+
* @param ele
|
|
38
|
+
* @param styles
|
|
39
|
+
*/
|
|
40
|
+
export const setStyle = (
|
|
41
|
+
ele: HTMLElement | SVGImageElement | SVGSVGElement,
|
|
42
|
+
styles: { [k: string]: string | number },
|
|
43
|
+
) => {
|
|
44
|
+
if (ele?.setAttribute && styles) {
|
|
45
|
+
let str = '';
|
|
46
|
+
Object.entries(styles).forEach(([keys, val]) => {
|
|
47
|
+
str += `${keys}:${val};`;
|
|
48
|
+
});
|
|
49
|
+
ele.setAttribute('style', str);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const converterDpi: (p: string | number) => number = millimeter => {
|
|
54
|
+
let defaultPx = ConverterDpi.getScreenPX(millimeter);
|
|
55
|
+
|
|
56
|
+
return defaultPx;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const parseCtm = (ctm: string) => {
|
|
60
|
+
if (ctm) {
|
|
61
|
+
return ctm.split(' ');
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const parseAbbreviatedData = (abbreviatedData: string) => {
|
|
67
|
+
if (abbreviatedData) {
|
|
68
|
+
const abbreviatedDataArray = abbreviatedData.split(' ');
|
|
69
|
+
const result: string[] = [];
|
|
70
|
+
abbreviatedDataArray.forEach(item => {
|
|
71
|
+
if (item) {
|
|
72
|
+
if (item && !/[A-Z]/i.test(item)) {
|
|
73
|
+
result.push(String(converterDpi(item).toFixed(4)));
|
|
74
|
+
} else {
|
|
75
|
+
let cit = item;
|
|
76
|
+
if (item === 'S') {
|
|
77
|
+
cit = 'M';
|
|
78
|
+
}
|
|
79
|
+
if (item === 'B') {
|
|
80
|
+
cit = 'C';
|
|
81
|
+
}
|
|
82
|
+
if (item === 'C') {
|
|
83
|
+
cit = 'Z';
|
|
84
|
+
}
|
|
85
|
+
result.push(String(cit));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return result.join(' ');
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 格式化ST_Box数据
|
|
97
|
+
* @param ST_Box
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
export const formatSTBox: (
|
|
101
|
+
a: string,
|
|
102
|
+
shouldAds?: boolean,
|
|
103
|
+
) => {
|
|
104
|
+
left: number;
|
|
105
|
+
top: number;
|
|
106
|
+
width: number;
|
|
107
|
+
height: number;
|
|
108
|
+
} = (ST_Box, shouldAds = true) => {
|
|
109
|
+
if (!ST_Box)
|
|
110
|
+
return {
|
|
111
|
+
left: 0,
|
|
112
|
+
top: 0,
|
|
113
|
+
width: 0,
|
|
114
|
+
height: 0,
|
|
115
|
+
};
|
|
116
|
+
const [left, top, width, height] = ST_Box.split(' ');
|
|
117
|
+
|
|
118
|
+
const returnLeft =
|
|
119
|
+
Number(width) < 0 ? converterDpi(Number(left) + Number(width)) : converterDpi(left);
|
|
120
|
+
const returnTop =
|
|
121
|
+
Number(height) < 0 ? converterDpi(Number(top) + Number(height)) : converterDpi(top);
|
|
122
|
+
|
|
123
|
+
const returnWidth = converterDpi(shouldAds ? Math.abs(Number(width)) : width);
|
|
124
|
+
const returnHeight = converterDpi(shouldAds ? Math.abs(Number(height)) : height);
|
|
125
|
+
return {
|
|
126
|
+
left: returnLeft,
|
|
127
|
+
top: returnTop,
|
|
128
|
+
width: returnWidth,
|
|
129
|
+
height: returnHeight,
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const getRes = (Res: Res[] | null, resId: string, type: string) => {
|
|
134
|
+
if (Res) {
|
|
135
|
+
for (let res of Res) {
|
|
136
|
+
if (res.ID == resId && res.OFDType === type) {
|
|
137
|
+
return res;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const getFont = (Fonts: Res[] | null, resId: string) => {
|
|
145
|
+
return getRes(Fonts, resId, 'Font');
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const getDrawParam = (DrawParam: Res[] | null, resId: string) => {
|
|
149
|
+
return getRes(DrawParam, resId, 'DrawParam');
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const getMultiMedia = (MultiMedias: Res[] | null, resId: string) => {
|
|
153
|
+
return getRes(MultiMedias, resId, 'MultiMedia');
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const calcDeltaPos: (k: string, text?: string) => number[] = (deltaPos, textStr) => {
|
|
157
|
+
const result: number[] = [];
|
|
158
|
+
let flagG = false;
|
|
159
|
+
let currentGIndex = 0;
|
|
160
|
+
if (deltaPos) {
|
|
161
|
+
const deltaPosArrays = deltaPos.split(' ').filter(Boolean);
|
|
162
|
+
deltaPosArrays.forEach((item, index) => {
|
|
163
|
+
if (item === 'g') {
|
|
164
|
+
flagG = true;
|
|
165
|
+
currentGIndex = index;
|
|
166
|
+
}
|
|
167
|
+
if (index > currentGIndex + 2) {
|
|
168
|
+
flagG = false;
|
|
169
|
+
}
|
|
170
|
+
if (!flagG) {
|
|
171
|
+
result.push(Number(item));
|
|
172
|
+
}
|
|
173
|
+
// 当循环 为g时, g后第一项为 长度,第二项为度量值,第三项及其后面值直接插入result,直到遇到g
|
|
174
|
+
if (flagG) {
|
|
175
|
+
if (index <= currentGIndex + 2 && index !== currentGIndex) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const max = Number(deltaPosArrays[currentGIndex + 1]);
|
|
179
|
+
for (let i = 0; i < max; i++) {
|
|
180
|
+
result.push(Number(deltaPosArrays[currentGIndex + 2]));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
// 优化空格文字
|
|
185
|
+
if (textStr && textStr.length !== result.length + 1) {
|
|
186
|
+
const diff = result[result.length - 1];
|
|
187
|
+
textStr
|
|
188
|
+
.split('')
|
|
189
|
+
.slice(result.length + 1)
|
|
190
|
+
.forEach((_, i) => {
|
|
191
|
+
result.splice(result.length + i, 0, diff + diff * i);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 替换html可识别family
|
|
200
|
+
* @param fontObj
|
|
201
|
+
* @returns
|
|
202
|
+
*/
|
|
203
|
+
export const getFontFamily = (fontInfo?: Res) => {
|
|
204
|
+
if (!fontInfo || (!fontInfo.FontName && !fontInfo.family)) {
|
|
205
|
+
return FONT_FAMILY['宋体'];
|
|
206
|
+
}
|
|
207
|
+
if (fontInfo?.Path) {
|
|
208
|
+
return `${fontInfo?.FontName || fontInfo.family}, ${FONT_FAMILY['宋体']}`;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
//@ts-ignore
|
|
213
|
+
FONT_FAMILY[fontInfo.FontName || fontInfo.family] || FONT_FAMILY['宋体']
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 计算坐标
|
|
219
|
+
* @param x
|
|
220
|
+
* @param y
|
|
221
|
+
* @param boundary
|
|
222
|
+
* @returns
|
|
223
|
+
*/
|
|
224
|
+
const adjustPos = function (
|
|
225
|
+
x: number,
|
|
226
|
+
y: number,
|
|
227
|
+
boundary: string | string[] | { top: number; left: number },
|
|
228
|
+
) {
|
|
229
|
+
let posX = 0;
|
|
230
|
+
let posY = 0;
|
|
231
|
+
if (boundary) {
|
|
232
|
+
if (typeof boundary === 'string') {
|
|
233
|
+
const [x, y] = boundary.split(' ');
|
|
234
|
+
posX = Number(x);
|
|
235
|
+
posY = Number(y);
|
|
236
|
+
}
|
|
237
|
+
if (typeof boundary === 'object') {
|
|
238
|
+
if (Array.isArray(boundary)) {
|
|
239
|
+
const [x, y] = boundary;
|
|
240
|
+
posX = Number(x);
|
|
241
|
+
posY = Number(y);
|
|
242
|
+
} else {
|
|
243
|
+
posX = boundary.left;
|
|
244
|
+
posY = boundary.top;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const realX = posX + x;
|
|
249
|
+
const realY = posY + y;
|
|
250
|
+
return { cx: realX, cy: realY };
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 格式化颜色
|
|
255
|
+
* @param color
|
|
256
|
+
* @returns
|
|
257
|
+
*/
|
|
258
|
+
export const parseColor = function (color: string) {
|
|
259
|
+
const cols = String(color);
|
|
260
|
+
if (cols && cols.length > 0) {
|
|
261
|
+
if (cols.indexOf('#') !== -1) {
|
|
262
|
+
let hexCols = cols.replace(/#/g, '');
|
|
263
|
+
hexCols = hexCols.replace(/ /g, '');
|
|
264
|
+
hexCols = '#' + hexCols.toString();
|
|
265
|
+
return hexCols;
|
|
266
|
+
}
|
|
267
|
+
const array = cols.split(' ');
|
|
268
|
+
return `rgb(${array[0]}, ${array[1]}, ${array[2]})`;
|
|
269
|
+
} else {
|
|
270
|
+
return `rgb(0, 0, 0)`;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const ctmCalPoint = function (x: number | string, y: number | string, ctm: string[] | string) {
|
|
275
|
+
const numX = Number(x);
|
|
276
|
+
const numY = Number(y);
|
|
277
|
+
if (Array.isArray(ctm)) {
|
|
278
|
+
const [a, b, c, d, e, f] = ctm.map(item => Number(item));
|
|
279
|
+
const ctmX = numX * a + numY * c + 1 * e;
|
|
280
|
+
const ctmY = numX * b + numY * d + 1 * f;
|
|
281
|
+
return { cx: ctmX, cy: ctmY };
|
|
282
|
+
}
|
|
283
|
+
const [a, b, c, d, e, f] = ctm.split(' ').map(item => Number(item));
|
|
284
|
+
const ctmX = numX * a + numY * c + 1 * e;
|
|
285
|
+
const ctmY = numX * b + numY * d + 1 * f;
|
|
286
|
+
return { cx: ctmX, cy: ctmY };
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const ctmCalDetalPoint = function (x: number | string, y: number | string, ctm: string | string[]) {
|
|
290
|
+
const numX = Number(x);
|
|
291
|
+
const numY = Number(y);
|
|
292
|
+
if (Array.isArray(ctm)) {
|
|
293
|
+
const [a, b, c, d] = ctm.map(item => Number(item));
|
|
294
|
+
const ctmX = numX * a + numY * c;
|
|
295
|
+
const ctmY = numX * b + numY * d;
|
|
296
|
+
return { ctmX, ctmY };
|
|
297
|
+
}
|
|
298
|
+
const [a, b, c, d] = ctm.split(' ').map(item => Number(item));
|
|
299
|
+
const ctmX = numX * a + numY * c;
|
|
300
|
+
const ctmY = numX * b + numY * d;
|
|
301
|
+
return { ctmX, ctmY };
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
*
|
|
306
|
+
* @param textCodes
|
|
307
|
+
* @param cgTransform
|
|
308
|
+
* @param ctm
|
|
309
|
+
* @param boundary
|
|
310
|
+
* @param compositeObjectBoundary
|
|
311
|
+
* @param compositeObjectCTM
|
|
312
|
+
* @returns
|
|
313
|
+
*/
|
|
314
|
+
export const calTextPoint = function (
|
|
315
|
+
textCode: { [k: string]: any },
|
|
316
|
+
cgTransform: { [k: string]: any },
|
|
317
|
+
ctm: string | string[],
|
|
318
|
+
Boundary: string,
|
|
319
|
+
compositeObjectCTM?: any,
|
|
320
|
+
/** 自定义字体 */
|
|
321
|
+
isSelfFont?: boolean,
|
|
322
|
+
) {
|
|
323
|
+
let x = 0;
|
|
324
|
+
let y = 0;
|
|
325
|
+
let cx = 0;
|
|
326
|
+
let cy = 0;
|
|
327
|
+
let textCodePointList: any[] = [];
|
|
328
|
+
|
|
329
|
+
if (!textCode) {
|
|
330
|
+
return textCodePointList;
|
|
331
|
+
}
|
|
332
|
+
const boundary = formatSTBox(Boundary, false);
|
|
333
|
+
// console.log('textCode:', textCode, boundary);
|
|
334
|
+
x = parseFloat(textCode['X']);
|
|
335
|
+
y = parseFloat(textCode['Y']);
|
|
336
|
+
|
|
337
|
+
// 存在负数宽度字体位置需要调整
|
|
338
|
+
if (isNaN(x) || (x < 0 && boundary.width < 0)) {
|
|
339
|
+
x = 0;
|
|
340
|
+
}
|
|
341
|
+
// 存在负数宽度字体位置需要调整
|
|
342
|
+
if (isNaN(y) || (y < 0 && boundary.height < 0)) {
|
|
343
|
+
y = 0;
|
|
344
|
+
}
|
|
345
|
+
cx = x;
|
|
346
|
+
cy = y;
|
|
347
|
+
if (ctm) {
|
|
348
|
+
const r = ctmCalPoint(cx, cy, ctm);
|
|
349
|
+
cx = r.cx;
|
|
350
|
+
cy = r.cy;
|
|
351
|
+
}
|
|
352
|
+
let textStr = textCode['text'];
|
|
353
|
+
if (textStr) {
|
|
354
|
+
textStr = decodeHtml(textStr);
|
|
355
|
+
textStr = textStr.replace(/ /g, ' ');
|
|
356
|
+
}
|
|
357
|
+
let deltaXList: number[] = [];
|
|
358
|
+
let deltaYList: number[] = [];
|
|
359
|
+
if (textCode['DeltaX']) {
|
|
360
|
+
Array.prototype.push.apply(deltaXList, calcDeltaPos(textCode['DeltaX'], textStr));
|
|
361
|
+
}
|
|
362
|
+
if (textCode['DeltaY']) {
|
|
363
|
+
// 确定文字排列位置
|
|
364
|
+
Array.prototype.push.apply(deltaYList, calcDeltaPos(textCode['DeltaY'], textStr));
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* @description 自定义字体需要逐个字符渲染
|
|
368
|
+
*/
|
|
369
|
+
if (isSelfFont) {
|
|
370
|
+
if (textStr) {
|
|
371
|
+
for (let i = 0; i < textStr.length; i++) {
|
|
372
|
+
if (i > 0 && deltaXList.length > 0) {
|
|
373
|
+
x += deltaXList[i - 1];
|
|
374
|
+
if (ctm) {
|
|
375
|
+
const r = ctmCalDetalPoint(deltaXList[i - 1], 0, ctm);
|
|
376
|
+
cx += r.ctmX;
|
|
377
|
+
} else {
|
|
378
|
+
cx = x;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (i > 0 && deltaYList.length > 0) {
|
|
382
|
+
y += deltaYList[i - 1];
|
|
383
|
+
if (ctm) {
|
|
384
|
+
const r = ctmCalDetalPoint(0, deltaYList[i - 1], ctm);
|
|
385
|
+
cy += r.ctmY;
|
|
386
|
+
} else {
|
|
387
|
+
cy = y;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
let realPos = adjustPos(cx, cy, boundary);
|
|
391
|
+
if (compositeObjectCTM) {
|
|
392
|
+
realPos = ctmCalPoint(realPos.cx, realPos.cy, compositeObjectCTM);
|
|
393
|
+
}
|
|
394
|
+
let text = textStr.substring(i, i + 1);
|
|
395
|
+
let textCodePoint = {
|
|
396
|
+
x: x,
|
|
397
|
+
y: y,
|
|
398
|
+
text: text,
|
|
399
|
+
cx: realPos.cx,
|
|
400
|
+
cy: realPos.cy,
|
|
401
|
+
};
|
|
402
|
+
textCodePointList.push(textCodePoint);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return textCodePointList;
|
|
406
|
+
}
|
|
407
|
+
if (textStr) {
|
|
408
|
+
let str = '';
|
|
409
|
+
// 批量渲染文字减少节点生成
|
|
410
|
+
let startX = 0;
|
|
411
|
+
let startY = 0;
|
|
412
|
+
// 判断 deltaXList 是否存在不同
|
|
413
|
+
const diffX = [...new Set(deltaXList)]?.length > 1;
|
|
414
|
+
const diffY = [...new Set(deltaYList)]?.length > 1;
|
|
415
|
+
if (diffX || diffY) {
|
|
416
|
+
for (let i = 0; i < textStr.length; i++) {
|
|
417
|
+
str += textStr[i];
|
|
418
|
+
if (deltaXList.length || deltaYList?.length) {
|
|
419
|
+
if (i === 0) {
|
|
420
|
+
startX = deltaXList[0];
|
|
421
|
+
startY = deltaXList[0];
|
|
422
|
+
}
|
|
423
|
+
if (i > 0) {
|
|
424
|
+
if (ctm) {
|
|
425
|
+
const realCtm = ctmCalDetalPoint(deltaXList[i - 1] || 0, deltaYList[i - 1] || 0, ctm);
|
|
426
|
+
cx += realCtm.ctmX;
|
|
427
|
+
cy += realCtm.ctmY;
|
|
428
|
+
} else {
|
|
429
|
+
cx = x;
|
|
430
|
+
cy = y;
|
|
431
|
+
}
|
|
432
|
+
x += deltaXList[i - 1] || 0;
|
|
433
|
+
y += deltaYList[i - 1] || 0;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
let realPos = adjustPos(cx, cy, boundary);
|
|
437
|
+
if (compositeObjectCTM) {
|
|
438
|
+
realPos = ctmCalPoint(realPos.cx, realPos.cy, compositeObjectCTM);
|
|
439
|
+
}
|
|
440
|
+
if (startX !== deltaXList[i]) {
|
|
441
|
+
startX = deltaXList[i];
|
|
442
|
+
const textCodePoint = {
|
|
443
|
+
x: converterDpi(x),
|
|
444
|
+
y: converterDpi(y),
|
|
445
|
+
text: str,
|
|
446
|
+
cx: converterDpi(realPos.cx),
|
|
447
|
+
cy: converterDpi(realPos.cy),
|
|
448
|
+
};
|
|
449
|
+
textCodePointList.push(textCodePoint);
|
|
450
|
+
str = '';
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (startY !== deltaYList[i]) {
|
|
454
|
+
const textCodePoint = {
|
|
455
|
+
x: converterDpi(x),
|
|
456
|
+
y: converterDpi(y),
|
|
457
|
+
text: str,
|
|
458
|
+
cx: converterDpi(realPos.cx),
|
|
459
|
+
cy: converterDpi(realPos.cy),
|
|
460
|
+
};
|
|
461
|
+
textCodePointList.push(textCodePoint);
|
|
462
|
+
str = '';
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
if (i === textStr.length - 1) {
|
|
466
|
+
const textCodePoint = {
|
|
467
|
+
x: converterDpi(x),
|
|
468
|
+
y: converterDpi(y),
|
|
469
|
+
text: str,
|
|
470
|
+
cx: converterDpi(realPos.cx),
|
|
471
|
+
cy: converterDpi(realPos.cy),
|
|
472
|
+
};
|
|
473
|
+
textCodePointList.push(textCodePoint);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
} else {
|
|
477
|
+
const textCodePoint = {
|
|
478
|
+
x: converterDpi(x),
|
|
479
|
+
y: converterDpi(y),
|
|
480
|
+
text: textStr,
|
|
481
|
+
cx: converterDpi(cx),
|
|
482
|
+
cy: converterDpi(cy),
|
|
483
|
+
};
|
|
484
|
+
textCodePointList.push(textCodePoint);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
// console.log(textCodePointList, 'cgTransform:', cgTransform);
|
|
488
|
+
// if (textCodePointList.length > 0 && cgTransform?.length) {
|
|
489
|
+
// for (const transform of cgTransform) {
|
|
490
|
+
// // console.log(transform)
|
|
491
|
+
// const pos = transform['CodePosition'];
|
|
492
|
+
// const glyphCount = transform['GlyphCount'];
|
|
493
|
+
// // const codeCount = transform['CodeCount']
|
|
494
|
+
// for (let i = pos; i < glyphCount + pos; i++) {
|
|
495
|
+
// if (textCodePointList.length <= i) {
|
|
496
|
+
// const glyphs = `${
|
|
497
|
+
// textCodePointList[textCodePointList.length - 1].glyph
|
|
498
|
+
// } ${transform['Glyphs'][i - pos]}`;
|
|
499
|
+
// textCodePointList[textCodePointList.length - 1].glyph = glyphs;
|
|
500
|
+
// } else {
|
|
501
|
+
// textCodePointList[i].glyph = transform['Glyphs'][i - pos];
|
|
502
|
+
// }
|
|
503
|
+
// }
|
|
504
|
+
// }
|
|
505
|
+
// }
|
|
506
|
+
return textCodePointList;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
export const drawBMPImage: (d: string) => Promise<string> = async (imgSrc: string) => {
|
|
510
|
+
try {
|
|
511
|
+
return await new Promise((resolve, reject) => {
|
|
512
|
+
const images = new Image();
|
|
513
|
+
images.src = imgSrc;
|
|
514
|
+
const devRatio = window.devicePixelRatio || 1;
|
|
515
|
+
images.onload = () => {
|
|
516
|
+
const canvas = document.createElement('canvas');
|
|
517
|
+
canvas.width = images.width * devRatio;
|
|
518
|
+
canvas.height = images.height * devRatio;
|
|
519
|
+
const context = canvas.getContext('2d') as CanvasRenderingContext2D;
|
|
520
|
+
context.drawImage(images, 0, 0, canvas.width, canvas.height);
|
|
521
|
+
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
522
|
+
for (let i = 0; i < imageData.data.length; i += 4) {
|
|
523
|
+
//rgb大于250的透明度y均设置成0
|
|
524
|
+
if (
|
|
525
|
+
imageData.data[i] > 250 &&
|
|
526
|
+
imageData.data[i + 1] > 250 &&
|
|
527
|
+
imageData.data[i + 2] > 250
|
|
528
|
+
) {
|
|
529
|
+
imageData.data[i + 3] = 0;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
context.putImageData(imageData, 0, 0);
|
|
533
|
+
resolve(canvas.toDataURL('image/png'));
|
|
534
|
+
};
|
|
535
|
+
images.onerror = reject;
|
|
536
|
+
});
|
|
537
|
+
} catch (err) {
|
|
538
|
+
console.error('渲染BMP图片异常');
|
|
539
|
+
}
|
|
540
|
+
return '';
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* 绘制自定义字体
|
|
545
|
+
* @param path
|
|
546
|
+
* @param horiUnderlinePosition
|
|
547
|
+
* @param units_per_EM
|
|
548
|
+
* @param xsize
|
|
549
|
+
* @param ysize
|
|
550
|
+
* @param color
|
|
551
|
+
* @param defaultFillOpacity
|
|
552
|
+
* @returns
|
|
553
|
+
*/
|
|
554
|
+
export const drawGlyph = function (
|
|
555
|
+
path: string,
|
|
556
|
+
horiUnderlinePosition: string,
|
|
557
|
+
units_per_EM: number,
|
|
558
|
+
xsize: number,
|
|
559
|
+
ysize: number,
|
|
560
|
+
color: string,
|
|
561
|
+
defaultFillOpacity: string,
|
|
562
|
+
) {
|
|
563
|
+
let xScale = xsize / units_per_EM;
|
|
564
|
+
let yScale = ysize / units_per_EM;
|
|
565
|
+
|
|
566
|
+
let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
567
|
+
svg.setAttribute('version', '1.1');
|
|
568
|
+
let svgPathElement = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
569
|
+
svgPathElement.setAttribute(
|
|
570
|
+
'transform',
|
|
571
|
+
`translate(0, ${ysize}) scale(${xScale}, ${-yScale}) translate(0, ${-horiUnderlinePosition})`,
|
|
572
|
+
);
|
|
573
|
+
svgPathElement.setAttribute('d', path);
|
|
574
|
+
if (color) {
|
|
575
|
+
svgPathElement.setAttribute('fill', color);
|
|
576
|
+
}
|
|
577
|
+
svgPathElement.setAttribute('fill-opacity', defaultFillOpacity);
|
|
578
|
+
svg.appendChild(svgPathElement);
|
|
579
|
+
return { img: svg, yScale };
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* @description 判断两个矩形是否交叉
|
|
584
|
+
* @param rect1
|
|
585
|
+
* @param rect2
|
|
586
|
+
* @returns
|
|
587
|
+
*/
|
|
588
|
+
export function doRectanglesIntersect(
|
|
589
|
+
rect1: { left: number; top: number; width: number; height: number },
|
|
590
|
+
rect2: { left: number; top: number; width: number; height: number },
|
|
591
|
+
) {
|
|
592
|
+
return !(
|
|
593
|
+
rect2.left >= rect1.left + rect1.width ||
|
|
594
|
+
rect2.left + rect2.width <= rect1.left ||
|
|
595
|
+
rect2.top >= rect1.top + rect1.height ||
|
|
596
|
+
rect2.top + rect2.height <= rect1.top
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* @description 计算两个矩形交叉位置
|
|
602
|
+
* @param rect1
|
|
603
|
+
* @param rect2
|
|
604
|
+
* @returns
|
|
605
|
+
*/
|
|
606
|
+
export function getIntersection(
|
|
607
|
+
rect1: { left: number; top: number; width: number; height: number },
|
|
608
|
+
rect2: { left: number; top: number; width: number; height: number },
|
|
609
|
+
) {
|
|
610
|
+
// 矩形的交集可能不存在,所以我们首先检查它们是否相交
|
|
611
|
+
if (!doRectanglesIntersect(rect1, rect2)) {
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
console.log('rect1:', rect1, rect2);
|
|
615
|
+
const x1 = Math.max(rect1.left, rect2.left);
|
|
616
|
+
const y1 = Math.max(rect1.top, rect2.top);
|
|
617
|
+
const x2 = Math.min(rect1.left + rect1.width, rect2.left + rect2.width);
|
|
618
|
+
const y2 = Math.min(rect1.top + rect1.height, rect2.top + rect2.height);
|
|
619
|
+
|
|
620
|
+
// 如果交集存在,返回交集的宽度和高度
|
|
621
|
+
return {
|
|
622
|
+
left: x1,
|
|
623
|
+
top: y1,
|
|
624
|
+
width: x2 - x1,
|
|
625
|
+
height: y2 - y1,
|
|
626
|
+
};
|
|
627
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Doc_0/Attachs/Attachments.xml: ZipObject$1 {name: 'Doc_0/Attachs/Attachments.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
2
|
+
Doc_0/Attachs/bker_issuer_20220101_01234567890123012345678900208989988989998896001.xml: ZipObject$1 {name: 'Doc_0/Attachs/bker_issuer_20220101_01234567890123012345678900208989988989998896001.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
3
|
+
Doc_0/Document.xml: ZipObject$1 {name: 'Doc_0/Document.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
4
|
+
Doc_0/DocumentRes.xml: ZipObject$1 {name: 'Doc_0/DocumentRes.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
5
|
+
Doc_0/Pages/Page_0/Content.xml: ZipObject$1 {name: 'Doc_0/Pages/Page_0/Content.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
6
|
+
Doc_0/PublicRes.xml: ZipObject$1 {name: 'Doc_0/PublicRes.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
7
|
+
Doc_0/Res/image_54_5.jpg: ZipObject$1 {name: 'Doc_0/Res/image_54_5.jpg', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
8
|
+
Doc_0/Signs/Sign_0/Signature.xml: ZipObject$1 {name: 'Doc_0/Signs/Sign_0/Signature.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
9
|
+
Doc_0/Signs/Sign_0/SignedValue.dat: ZipObject$1 {name: 'Doc_0/Signs/Sign_0/SignedValue.dat', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
10
|
+
Doc_0/Signs/Signatures.xml: ZipObject$1 {name: 'Doc_0/Signs/Signatures.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
11
|
+
Doc_0/Tpls/Tpl_0/Content.xml: ZipObject$1 {name: 'Doc_0/Tpls/Tpl_0/Content.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|
|
12
|
+
OFD.xml: ZipObject$1 {name: 'OFD.xml', dir: false, date: Sat Mar 19 2022 05:32:16 GMT+0800 (中国标准时间), comment: null, unixPermissions: null, …}
|