@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,283 @@
|
|
|
1
|
+
import { ResultData, LayerPageBlock } from '../core/ofd-core/index.d';
|
|
2
|
+
import { getIntersection } from './ofd-utils';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
formatSTBox,
|
|
6
|
+
converterDpi,
|
|
7
|
+
parseColor,
|
|
8
|
+
getDrawParam,
|
|
9
|
+
parseCtm,
|
|
10
|
+
parseAbbreviatedData,
|
|
11
|
+
} from './ofd-utils';
|
|
12
|
+
|
|
13
|
+
const renderPathObject = function (
|
|
14
|
+
pathObject: LayerPageBlock & { [k: string]: any },
|
|
15
|
+
data: ResultData,
|
|
16
|
+
content: HTMLElement,
|
|
17
|
+
drawLineWidth?: number,
|
|
18
|
+
drawFillColor?: string,
|
|
19
|
+
drawStrokeColor?: string,
|
|
20
|
+
isStampAnnot?: boolean,
|
|
21
|
+
compositeObjectAlpha?: any,
|
|
22
|
+
compositeObjectBoundary?: any,
|
|
23
|
+
compositeObjectCTM?: any,
|
|
24
|
+
// isStampAnnot,
|
|
25
|
+
// compositeObjectAlpha,
|
|
26
|
+
// compositeObjectBoundary,
|
|
27
|
+
// compositeObjectCTM
|
|
28
|
+
) {
|
|
29
|
+
const {
|
|
30
|
+
Boundary,
|
|
31
|
+
AbbreviatedData,
|
|
32
|
+
CTM,
|
|
33
|
+
LineWidth: lineWidth,
|
|
34
|
+
DrawParam: pathDrawParam,
|
|
35
|
+
Clips,
|
|
36
|
+
} = pathObject;
|
|
37
|
+
if (Clips && Clips.clips) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const ar = Clips.clips.reduce((prevItem, nextItem) => {
|
|
40
|
+
const { Boundary: ClipBoundary } = prevItem.Area;
|
|
41
|
+
const { Boundary: NextClipBoundary } = nextItem.Area;
|
|
42
|
+
const [left, top, width, height] = ClipBoundary.split(' ');
|
|
43
|
+
const [nextLeft, nextTop, nextWidth, nextHeight] = NextClipBoundary.split(' ');
|
|
44
|
+
return getIntersection(
|
|
45
|
+
{ left: Math.abs(left), top: Math.abs(top), width, height },
|
|
46
|
+
{
|
|
47
|
+
left: Math.abs(nextLeft),
|
|
48
|
+
top: Math.abs(nextTop),
|
|
49
|
+
width: nextWidth,
|
|
50
|
+
height: nextHeight,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
const CliBoundaryArr: number[] = [];
|
|
55
|
+
Object.keys(ar).forEach(key => {
|
|
56
|
+
if (key === 'left') {
|
|
57
|
+
CliBoundaryArr[0] = ar[key];
|
|
58
|
+
}
|
|
59
|
+
if (key === 'top') {
|
|
60
|
+
CliBoundaryArr[1] = ar[key];
|
|
61
|
+
}
|
|
62
|
+
if (key === 'width') {
|
|
63
|
+
CliBoundaryArr[2] = ar[key];
|
|
64
|
+
}
|
|
65
|
+
if (key === 'height') {
|
|
66
|
+
CliBoundaryArr[3] = ar[key];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
Clips.clips.forEach((cItem, idx) => {
|
|
71
|
+
if (idx !== Clips.clips.length - 1) return;
|
|
72
|
+
renderPathObject(
|
|
73
|
+
{
|
|
74
|
+
...pathObject,
|
|
75
|
+
...cItem.Area,
|
|
76
|
+
Boundary: CliBoundaryArr?.length ? String(CliBoundaryArr).replace(/,/g, ' ') : Boundary,
|
|
77
|
+
Clips: undefined,
|
|
78
|
+
AbbreviatedData: { text: cItem.AbbreviatedData },
|
|
79
|
+
},
|
|
80
|
+
data,
|
|
81
|
+
content,
|
|
82
|
+
0.1,
|
|
83
|
+
drawFillColor,
|
|
84
|
+
drawStrokeColor,
|
|
85
|
+
isStampAnnot,
|
|
86
|
+
compositeObjectAlpha,
|
|
87
|
+
compositeObjectBoundary,
|
|
88
|
+
compositeObjectCTM,
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
96
|
+
svg.setAttribute('version', '1.1');
|
|
97
|
+
|
|
98
|
+
if (!Boundary) return svg;
|
|
99
|
+
let boundary = formatSTBox(Boundary);
|
|
100
|
+
|
|
101
|
+
let defaultLineWith = drawLineWidth || 1;
|
|
102
|
+
let defaultStrokeColor = drawStrokeColor;
|
|
103
|
+
let defaultFillColor = drawFillColor;
|
|
104
|
+
let path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
105
|
+
if (lineWidth) {
|
|
106
|
+
defaultLineWith = converterDpi(lineWidth);
|
|
107
|
+
}
|
|
108
|
+
let strokeColor = pathObject['StrokeColor'];
|
|
109
|
+
let fillColor = pathObject['FillColor'];
|
|
110
|
+
if (pathDrawParam) {
|
|
111
|
+
let dp = getDrawParam(data.Res, pathDrawParam);
|
|
112
|
+
if (dp?.LineWidth) {
|
|
113
|
+
defaultLineWith = converterDpi(dp.LineWidth);
|
|
114
|
+
}
|
|
115
|
+
if (dp?.StrokeColor?.Value) {
|
|
116
|
+
strokeColor = dp?.StrokeColor;
|
|
117
|
+
}
|
|
118
|
+
if (dp?.FillColor?.Value) {
|
|
119
|
+
fillColor = dp?.FillColor;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (CTM) {
|
|
123
|
+
const [a, b, c, d, e, f] = String(CTM).split(' ');
|
|
124
|
+
path.setAttribute(
|
|
125
|
+
'transform',
|
|
126
|
+
`matrix(${a} ${b} ${c} ${d} ${converterDpi(e)} ${converterDpi(f)})`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
// let isStrokeAxialShd = false;
|
|
130
|
+
if (strokeColor) {
|
|
131
|
+
if (strokeColor['Value']) {
|
|
132
|
+
defaultStrokeColor = parseColor(strokeColor['Value']);
|
|
133
|
+
}
|
|
134
|
+
const AxialShd = strokeColor['AxialShd'];
|
|
135
|
+
if (AxialShd) {
|
|
136
|
+
// isStrokeAxialShd = true;
|
|
137
|
+
let linearGradient = document.createElement('linearGradient');
|
|
138
|
+
linearGradient.setAttribute('id', `${pathObject['ID']}`);
|
|
139
|
+
linearGradient.setAttribute('x1', '0%');
|
|
140
|
+
linearGradient.setAttribute('y1', '0%');
|
|
141
|
+
linearGradient.setAttribute('x2', '100%');
|
|
142
|
+
linearGradient.setAttribute('y2', '100%');
|
|
143
|
+
if (AxialShd['ofd:Segment']?.length) {
|
|
144
|
+
for (const segment of AxialShd['ofd:Segment']) {
|
|
145
|
+
if (segment) {
|
|
146
|
+
let stop = document.createElement('stop');
|
|
147
|
+
stop.setAttribute('offset', `${segment['Position'] * 100}%`);
|
|
148
|
+
stop.setAttribute(
|
|
149
|
+
'style',
|
|
150
|
+
`stop-color:${parseColor(segment['Color']['Value'])};stop-opacity:1`,
|
|
151
|
+
);
|
|
152
|
+
linearGradient.appendChild(stop);
|
|
153
|
+
defaultStrokeColor = parseColor(segment['ofd:Color']['@_Value']);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
svg.appendChild(linearGradient);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// let isFillAxialShd = false;
|
|
162
|
+
if (fillColor) {
|
|
163
|
+
if (fillColor['Value']) {
|
|
164
|
+
defaultFillColor = parseColor(fillColor['Value']);
|
|
165
|
+
}
|
|
166
|
+
if (fillColor['Alpha'] && fillColor['Alpha'] == 0) {
|
|
167
|
+
defaultFillColor = 'none';
|
|
168
|
+
}
|
|
169
|
+
const AxialShd = fillColor['AxialShd'];
|
|
170
|
+
if (AxialShd) {
|
|
171
|
+
// isFillAxialShd = true;
|
|
172
|
+
let linearGradient = document.createElement('linearGradient');
|
|
173
|
+
linearGradient.setAttribute('id', `${pathObject['ID']}`);
|
|
174
|
+
linearGradient.setAttribute('x1', '0%');
|
|
175
|
+
linearGradient.setAttribute('y1', '0%');
|
|
176
|
+
linearGradient.setAttribute('x2', '100%');
|
|
177
|
+
linearGradient.setAttribute('y2', '100%');
|
|
178
|
+
if (AxialShd['ofd:Segment']?.length) {
|
|
179
|
+
for (const segment of AxialShd['ofd:Segment']) {
|
|
180
|
+
if (segment) {
|
|
181
|
+
let stop = document.createElement('stop');
|
|
182
|
+
stop.setAttribute('offset', `${segment['Position'] * 100}%`);
|
|
183
|
+
stop.setAttribute(
|
|
184
|
+
'style',
|
|
185
|
+
`stop-color:${parseColor(segment['Color']['Value'])};stop-opacity:1`,
|
|
186
|
+
);
|
|
187
|
+
linearGradient.appendChild(stop);
|
|
188
|
+
defaultFillColor = parseColor(segment['ofd:Color']['@_Value']);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
svg.appendChild(linearGradient);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (defaultLineWith > 0 && !defaultStrokeColor) {
|
|
196
|
+
defaultStrokeColor = defaultFillColor;
|
|
197
|
+
if (!defaultStrokeColor) {
|
|
198
|
+
defaultStrokeColor = 'rgb(0, 0, 0)';
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (compositeObjectAlpha) {
|
|
202
|
+
path.setAttribute('fill-opacity', `${compositeObjectAlpha / 255}`);
|
|
203
|
+
}
|
|
204
|
+
if (pathObject['Stroke']) {
|
|
205
|
+
path.setAttribute('stroke', `${defaultStrokeColor}`);
|
|
206
|
+
path.setAttribute('stroke-width', `${defaultLineWith}px`);
|
|
207
|
+
}
|
|
208
|
+
if (!pathObject['Fill']) {
|
|
209
|
+
path.setAttribute('fill', 'none');
|
|
210
|
+
} else {
|
|
211
|
+
path.setAttribute(
|
|
212
|
+
'fill',
|
|
213
|
+
`${isStampAnnot ? 'none' : defaultFillColor ? defaultFillColor : 'none'}`,
|
|
214
|
+
);
|
|
215
|
+
// console.log('isFillAxialShd:', isFillAxialShd);
|
|
216
|
+
// if (isFillAxialShd) {
|
|
217
|
+
// path.setAttribute('fill', `url(#${pathObject['ID']})`);
|
|
218
|
+
// }
|
|
219
|
+
}
|
|
220
|
+
if (pathObject['Join']) {
|
|
221
|
+
path.setAttribute('stroke-linejoin', `${pathObject['Join']}`);
|
|
222
|
+
}
|
|
223
|
+
if (pathObject['Cap']) {
|
|
224
|
+
path.setAttribute('stroke-linecap', `${pathObject['Cap']}`);
|
|
225
|
+
}
|
|
226
|
+
if (pathObject['DashPattern']) {
|
|
227
|
+
let dash = pathObject['DashPattern'];
|
|
228
|
+
const dashs = parseCtm(dash);
|
|
229
|
+
let offset = 0;
|
|
230
|
+
if (pathObject['DashOffset']) {
|
|
231
|
+
offset = pathObject['DashOffset'];
|
|
232
|
+
}
|
|
233
|
+
if (dashs) {
|
|
234
|
+
path.setAttribute('stroke-dasharray', `${converterDpi(dashs[0])},${converterDpi(dashs[1])}`);
|
|
235
|
+
}
|
|
236
|
+
path.setAttribute('stroke-dashoffset', `${converterDpi(offset)}px`);
|
|
237
|
+
}
|
|
238
|
+
if (AbbreviatedData?.text && (!Clips || !Clips.clips?.length)) {
|
|
239
|
+
const abbreviatedData = parseAbbreviatedData(AbbreviatedData.text) as string;
|
|
240
|
+
path.setAttribute('d', abbreviatedData);
|
|
241
|
+
}
|
|
242
|
+
svg.appendChild(path);
|
|
243
|
+
let width = isStampAnnot ? boundary.width : Math.ceil(boundary.width);
|
|
244
|
+
let height = isStampAnnot ? boundary.height : Math.ceil(boundary.height);
|
|
245
|
+
let left = boundary.left;
|
|
246
|
+
let top = boundary.top;
|
|
247
|
+
svg.setAttribute(
|
|
248
|
+
'style',
|
|
249
|
+
`overflow:hidden;position:absolute;width:${width}px;height:${height}px;left:${left}px;top:${top}px;`,
|
|
250
|
+
);
|
|
251
|
+
if (compositeObjectBoundary) {
|
|
252
|
+
let comSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
253
|
+
comSvg.setAttribute('version', '1.1');
|
|
254
|
+
|
|
255
|
+
// let width = Math.ceil(boundary.width);
|
|
256
|
+
// let height = Math.ceil(boundary.height);
|
|
257
|
+
// let left = boundary.left;
|
|
258
|
+
// let top = boundary.top;
|
|
259
|
+
comSvg.setAttribute(
|
|
260
|
+
'style',
|
|
261
|
+
`overflow:hidden;position:absolute;width:${width}px;height:${height}px;left:${left}px;top:${top}px;`,
|
|
262
|
+
);
|
|
263
|
+
if (compositeObjectCTM) {
|
|
264
|
+
const ctms = parseCtm(compositeObjectCTM);
|
|
265
|
+
if (ctms) {
|
|
266
|
+
svg.setAttribute(
|
|
267
|
+
'transform',
|
|
268
|
+
`matrix(${ctms[0]} ${ctms[1]} ${ctms[2]} ${ctms[3]} ${converterDpi(
|
|
269
|
+
ctms[4],
|
|
270
|
+
)} ${converterDpi(ctms[5])})`,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
comSvg.appendChild(svg);
|
|
275
|
+
return comSvg;
|
|
276
|
+
}
|
|
277
|
+
if (content) {
|
|
278
|
+
content.appendChild(svg);
|
|
279
|
+
}
|
|
280
|
+
return svg;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export default renderPathObject;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { ResultData, LayerPageBlock, Res } from '../core/ofd-core/index.d';
|
|
2
|
+
import {
|
|
3
|
+
parseColor,
|
|
4
|
+
calTextPoint,
|
|
5
|
+
converterDpi,
|
|
6
|
+
getFont,
|
|
7
|
+
getDrawParam,
|
|
8
|
+
getFontFamily,
|
|
9
|
+
formatSTBox,
|
|
10
|
+
} from './ofd-utils';
|
|
11
|
+
import LoadFontType from '../lib/load-opentype';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 绘制Text
|
|
15
|
+
*/
|
|
16
|
+
const renderTextObject = (
|
|
17
|
+
info: LayerPageBlock & { [k: string]: any },
|
|
18
|
+
data: ResultData,
|
|
19
|
+
content: HTMLElement,
|
|
20
|
+
drawFillColor?: string,
|
|
21
|
+
drawStrokeColor?: string,
|
|
22
|
+
) => {
|
|
23
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
24
|
+
svg.setAttribute('version', '1.1');
|
|
25
|
+
const {
|
|
26
|
+
TextCode = {},
|
|
27
|
+
CTM,
|
|
28
|
+
Boundary = '',
|
|
29
|
+
ID,
|
|
30
|
+
Fill = true,
|
|
31
|
+
FillColor,
|
|
32
|
+
Size,
|
|
33
|
+
Font,
|
|
34
|
+
HScale,
|
|
35
|
+
CGTransform,
|
|
36
|
+
DrawParam,
|
|
37
|
+
Weight: weight,
|
|
38
|
+
} = info;
|
|
39
|
+
//
|
|
40
|
+
const boundary = formatSTBox(String(Boundary));
|
|
41
|
+
|
|
42
|
+
// // 字体大小
|
|
43
|
+
const size = converterDpi(String(Size || 0));
|
|
44
|
+
const fillColor = FillColor as null | { [k: string]: any };
|
|
45
|
+
let defaultFillColor = drawFillColor;
|
|
46
|
+
let defaultStrokeColor = drawStrokeColor;
|
|
47
|
+
let defaultFillOpacity = 1;
|
|
48
|
+
const textCodePointList = calTextPoint(TextCode, CGTransform, CTM, Boundary);
|
|
49
|
+
let hScale = Number(HScale);
|
|
50
|
+
let isAxialShd = false;
|
|
51
|
+
let drawParam = DrawParam;
|
|
52
|
+
if (drawParam) {
|
|
53
|
+
let dp = getDrawParam(data.Res, drawParam);
|
|
54
|
+
if (dp?.FillColor && dp?.FillColor?.Value) {
|
|
55
|
+
defaultFillColor = parseColor(dp['FillColor']['Value']);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (fillColor) {
|
|
59
|
+
if (fillColor?.['Value']) {
|
|
60
|
+
defaultFillColor = parseColor(fillColor['Value']);
|
|
61
|
+
}
|
|
62
|
+
let alpha = parseFloat(fillColor['Alpha'] || '1');
|
|
63
|
+
|
|
64
|
+
const AxialShd = fillColor['AxialShd'] as null | { [k: string]: any };
|
|
65
|
+
if (alpha) {
|
|
66
|
+
defaultFillOpacity = alpha > 1 ? alpha / 255 : alpha;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!Fill) {
|
|
70
|
+
defaultFillOpacity = 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let xsize = size;
|
|
74
|
+
let ysize = size;
|
|
75
|
+
|
|
76
|
+
if (CTM) {
|
|
77
|
+
const [a, b, c, d] = String(CTM)
|
|
78
|
+
.split(' ')
|
|
79
|
+
.map(i => Number(i));
|
|
80
|
+
const sx = a > 0 ? Math.sign(a) * Math.sqrt(a * a + c * c) : Math.sqrt(a * a + c * c);
|
|
81
|
+
const sy = d > 0 ? Math.sign(d) * Math.sqrt(b * b + d * d) : Math.sqrt(b * b + d * d);
|
|
82
|
+
const angel = Math.atan2(-b, d);
|
|
83
|
+
if (!(angel == 0 && a != 0 && d == 1)) {
|
|
84
|
+
xsize = xsize * sx;
|
|
85
|
+
ysize = ysize * sy;
|
|
86
|
+
}
|
|
87
|
+
if (angel === 0) {
|
|
88
|
+
hScale = a / d;
|
|
89
|
+
if (hScale > 0) {
|
|
90
|
+
xsize = xsize * hScale;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// 颜色渐变
|
|
95
|
+
if (AxialShd) {
|
|
96
|
+
isAxialShd = true;
|
|
97
|
+
let linearGradient = document.createElement('linearGradient');
|
|
98
|
+
linearGradient.setAttribute('id', `${ID}`);
|
|
99
|
+
linearGradient.setAttribute('x1', '0%');
|
|
100
|
+
linearGradient.setAttribute('y1', '0%');
|
|
101
|
+
linearGradient.setAttribute('x2', '100%');
|
|
102
|
+
linearGradient.setAttribute('y2', '100%');
|
|
103
|
+
if (AxialShd['Segment']?.length) {
|
|
104
|
+
for (const segment of AxialShd['Segment']) {
|
|
105
|
+
if (segment) {
|
|
106
|
+
let stop = document.createElement('stop');
|
|
107
|
+
stop.setAttribute('offset', `${segment['Position'] * 100}%`);
|
|
108
|
+
stop.setAttribute(
|
|
109
|
+
'style',
|
|
110
|
+
`stop-color:${parseColor(segment['Color']['Value'])};stop-opacity:1`,
|
|
111
|
+
);
|
|
112
|
+
linearGradient.appendChild(stop);
|
|
113
|
+
defaultFillColor = parseColor(segment['Color']['Value']);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
svg.appendChild(linearGradient);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// 字体处理
|
|
121
|
+
const fontObj = getFont(data.Res, Font);
|
|
122
|
+
// 内置字体文件
|
|
123
|
+
if (fontObj?.Path) {
|
|
124
|
+
LoadFontType.setFontFile(
|
|
125
|
+
fontObj.ID,
|
|
126
|
+
data.OFDElements[fontObj.Path] as unknown as ArrayBuffer,
|
|
127
|
+
res => {
|
|
128
|
+
if (res === true && textCodePointList.length) {
|
|
129
|
+
let str = '';
|
|
130
|
+
let fontTypeY = textCodePointList?.length ? textCodePointList[0].y : 0;
|
|
131
|
+
let fontTypeX = textCodePointList?.length ? textCodePointList[0].x : 0;
|
|
132
|
+
for (const textCodePoint of textCodePointList) {
|
|
133
|
+
str += textCodePoint.text;
|
|
134
|
+
}
|
|
135
|
+
const resultFont = LoadFontType.getFontFile(fontObj.ID, str, fontTypeX, fontTypeY, size);
|
|
136
|
+
let svgG = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
137
|
+
let transform = '';
|
|
138
|
+
if (CTM) {
|
|
139
|
+
const [a, b, c, d, e, f] = CTM.split(' ');
|
|
140
|
+
transform = `matrix(${a} ${b} ${c} ${d} ${converterDpi(e)} ${converterDpi(f)})`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (hScale) {
|
|
144
|
+
transform = `${transform} matrix(${hScale}, 0, 0, 1, ${(1 - hScale) * fontTypeX}, 0)`;
|
|
145
|
+
}
|
|
146
|
+
svgG.setAttribute('transform', transform);
|
|
147
|
+
if (isAxialShd && defaultFillColor) {
|
|
148
|
+
svgG.setAttribute('fill', defaultFillColor);
|
|
149
|
+
} else {
|
|
150
|
+
defaultStrokeColor && svgG.setAttribute('fill', defaultStrokeColor);
|
|
151
|
+
defaultFillColor && svgG.setAttribute('fill', defaultFillColor);
|
|
152
|
+
defaultFillOpacity && svgG.setAttribute('fill-opacity', `${defaultFillOpacity}`);
|
|
153
|
+
}
|
|
154
|
+
svgG.innerHTML = resultFont;
|
|
155
|
+
svgG.setAttribute('transform', transform);
|
|
156
|
+
if (isAxialShd && defaultFillColor) {
|
|
157
|
+
svgG.setAttribute('fill', defaultFillColor);
|
|
158
|
+
} else {
|
|
159
|
+
defaultStrokeColor && svgG.setAttribute('fill', defaultStrokeColor);
|
|
160
|
+
defaultFillColor && svgG.setAttribute('fill', defaultFillColor);
|
|
161
|
+
defaultFillOpacity && svgG.setAttribute('fill-opacity', `${defaultFillOpacity}`);
|
|
162
|
+
}
|
|
163
|
+
svgG.setAttribute(
|
|
164
|
+
'style',
|
|
165
|
+
`font-weight: ${weight};font-size:${size}px;font-family: ${getFontFamily(
|
|
166
|
+
fontObj as Res,
|
|
167
|
+
)};`,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
svg.appendChild(svgG);
|
|
171
|
+
} else {
|
|
172
|
+
for (const textCodePoint of textCodePointList) {
|
|
173
|
+
let svgTxt = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
174
|
+
svgTxt.innerHTML = textCodePoint.text;
|
|
175
|
+
svgTxt.setAttribute('x', textCodePoint.x);
|
|
176
|
+
svgTxt.setAttribute('y', textCodePoint.y);
|
|
177
|
+
|
|
178
|
+
let transform = '';
|
|
179
|
+
if (CTM) {
|
|
180
|
+
const [a, b, c, d, e, f] = CTM.split(' ');
|
|
181
|
+
transform = `matrix(${a} ${b} ${c} ${d} ${converterDpi(e)} ${converterDpi(f)})`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (hScale) {
|
|
185
|
+
transform = `${transform} matrix(${hScale}, 0, 0, 1, ${
|
|
186
|
+
(1 - hScale) * textCodePoint.x
|
|
187
|
+
}, 0)`;
|
|
188
|
+
}
|
|
189
|
+
svgTxt.setAttribute('transform', transform);
|
|
190
|
+
if (isAxialShd && defaultFillColor) {
|
|
191
|
+
svgTxt.setAttribute('fill', defaultFillColor);
|
|
192
|
+
} else {
|
|
193
|
+
defaultStrokeColor && svgTxt.setAttribute('fill', defaultStrokeColor);
|
|
194
|
+
defaultFillColor && svgTxt.setAttribute('fill', defaultFillColor);
|
|
195
|
+
defaultFillOpacity && svgTxt.setAttribute('fill-opacity', `${defaultFillOpacity}`);
|
|
196
|
+
}
|
|
197
|
+
svgTxt.setAttribute(
|
|
198
|
+
'style',
|
|
199
|
+
`font-weight: ${weight};font-size:${size}px;font-family: ${getFontFamily(
|
|
200
|
+
fontObj as Res,
|
|
201
|
+
)};`,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
svg.appendChild(svgTxt);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const width = boundary.width;
|
|
209
|
+
const height = boundary.height;
|
|
210
|
+
const left = boundary.left;
|
|
211
|
+
const top = boundary.top;
|
|
212
|
+
svg.setAttribute(
|
|
213
|
+
'style',
|
|
214
|
+
`overflow:hidden;position:absolute;width:${width}px;height:${height}px;left:${left}px;top:${top}px;`,
|
|
215
|
+
);
|
|
216
|
+
if (content) {
|
|
217
|
+
content.appendChild(svg);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
for (const textCodePoint of textCodePointList) {
|
|
224
|
+
let text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
225
|
+
text.setAttribute('x', textCodePoint.x);
|
|
226
|
+
text.setAttribute('y', textCodePoint.y);
|
|
227
|
+
text.innerHTML = textCodePoint.text;
|
|
228
|
+
let transform = '';
|
|
229
|
+
if (CTM) {
|
|
230
|
+
const [a, b, c, d, e, f] = CTM.split(' ');
|
|
231
|
+
transform = `matrix(${a} ${b} ${c} ${d} ${converterDpi(e)} ${converterDpi(f)})`;
|
|
232
|
+
}
|
|
233
|
+
// if (compositeObjectCTM) {
|
|
234
|
+
// transform = `${transform} matrix(${compositeObjectCTM.a} ${
|
|
235
|
+
// compositeObjectCTM.b
|
|
236
|
+
// } ${compositeObjectCTM.c} ${compositeObjectCTM.d} ${converterDpi(
|
|
237
|
+
// compositeObjectCTM.e
|
|
238
|
+
// )} ${converterDpi(compositeObjectCTM.f)})`;
|
|
239
|
+
// }
|
|
240
|
+
if (hScale) {
|
|
241
|
+
transform = `${transform} matrix(${hScale}, 0, 0, 1, ${(1 - hScale) * textCodePoint.x}, 0)`;
|
|
242
|
+
}
|
|
243
|
+
text.setAttribute('transform', transform);
|
|
244
|
+
|
|
245
|
+
if (isAxialShd && defaultFillColor) {
|
|
246
|
+
text.setAttribute('fill', defaultFillColor);
|
|
247
|
+
} else {
|
|
248
|
+
defaultStrokeColor && text.setAttribute('fill', defaultStrokeColor);
|
|
249
|
+
defaultFillColor && text.setAttribute('fill', defaultFillColor);
|
|
250
|
+
defaultFillOpacity && text.setAttribute('fill-opacity', `${defaultFillOpacity}`);
|
|
251
|
+
}
|
|
252
|
+
text.setAttribute(
|
|
253
|
+
'style',
|
|
254
|
+
`font-weight: ${weight};font-size:${size}px;font-family: ${getFontFamily(fontObj as Res)};`,
|
|
255
|
+
);
|
|
256
|
+
svg.appendChild(text);
|
|
257
|
+
}
|
|
258
|
+
const width = boundary.width;
|
|
259
|
+
const height = boundary.height;
|
|
260
|
+
const left = boundary.left;
|
|
261
|
+
const top = boundary.top;
|
|
262
|
+
svg.setAttribute(
|
|
263
|
+
'style',
|
|
264
|
+
`overflow:hidden;position:absolute;width:${width}px;height:${height}px;left:${left}px;top:${top}px;`,
|
|
265
|
+
);
|
|
266
|
+
// svg.innerText = String(TextCode);
|
|
267
|
+
if (content) {
|
|
268
|
+
content.appendChild(svg);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export default renderTextObject;
|
package/src/xml/index.ts
ADDED