Merge pull request #10 from DLTech21/dev

Dev
This commit is contained in:
Donal 2020-09-29 14:45:37 +08:00 committed by GitHub
commit 4768b2fb5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 18 deletions

View File

@ -1,6 +1,6 @@
{
"name": "ofd.js",
"version": "0.1.8",
"version": "0.2.1",
"main": "lib/ofd.umd.min.js",
"author": "dltech21",
"description": "ofd渲染",

View File

@ -71,7 +71,8 @@ export const doGetDocRoot = async function (zip, docbody) {
for (const stamp of stampAnnot) {
if (stamp.sealObj && Object.keys(stamp.sealObj).length > 0) {
if (stamp.sealObj.type === 'ofd') {
const stampObj = await getSealDocumentObj(stamp);
const stampObjs = await getSealDocumentObj(stamp);
for (let stampObj of stampObjs) {
stamp.stampAnnot.boundary = parseStBox(stamp.stampAnnot['@_Boundary']);
//console.log(stamp.stampAnnot.boundary)
stamp.stampAnnot.pageRef = stamp.stampAnnot['@_PageRef'];
@ -79,6 +80,7 @@ export const doGetDocRoot = async function (zip, docbody) {
stampAnnotArray[stamp.stampAnnot['@_PageRef']] = [];
}
stampAnnotArray[stamp.stampAnnot['@_PageRef']].push({type: 'ofd', obj: stampObj, stamp});
}
} else if (stamp.sealObj.type === 'png') {
let img = 'data:image/png;base64,' + btoa(String.fromCharCode.apply(null, stamp.sealObj.ofdArray));
let stampArray = [];
@ -397,8 +399,7 @@ const getSignatureData = async function (zip, signature, signatureID) {
const getSealDocumentObj = function (stampAnnot) {
return new Promise((resolve, reject) => {
pipeline.call(this, async () => await unzipOfd(stampAnnot.sealObj.ofdArray), getDocRoot, getDocument,
getDocumentRes, getPublicRes, getTemplatePage, getPage)
pipeline.call(this, async () => await unzipOfd(stampAnnot.sealObj.ofdArray), getDocRoots, parseSingleDoc)
.then(res => {
resolve(res)
})

View File

@ -281,13 +281,13 @@ export const renderImageObject = function (pageWidth, pageHeight, multiMediaResO
const img = multiMediaResObj[resId].img;
const width = multiMediaResObj[resId].width;
const height = multiMediaResObj[resId].height;
return renderImageOnCanvas(img, width, height, boundary);
return renderImageOnCanvas(img, width, height, boundary, imageObject['@_ID']);
} else {
return renderImageOnDiv(pageWidth, pageHeight, multiMediaResObj[resId].img, boundary, false);
return renderImageOnDiv(pageWidth, pageHeight, multiMediaResObj[resId].img, boundary, false, false, null, null, imageObject['@_ID']);
}
}
const renderImageOnCanvas = function (img, imgWidth, imgHeight, boundary){
const renderImageOnCanvas = function (img, imgWidth, imgHeight, boundary, oid){
const arr = new Uint8ClampedArray(4 * imgWidth * imgHeight);
for (var i = 0; i < img.length; i++) {
arr[4 * i] = img[i];
@ -301,12 +301,12 @@ const renderImageOnCanvas = function (img, imgWidth, imgHeight, boundary){
canvas.height = imgHeight;
let context = canvas.getContext('2d');
context.putImageData(imageData, 0, 0);
canvas.setAttribute('style', `left: ${boundary.x}px; top: ${boundary.y}px; width: ${boundary.w}px; height: ${boundary.h}px`)
canvas.setAttribute('style', `left: ${boundary.x}px; top: ${boundary.y}px; width: ${boundary.w}px; height: ${boundary.h}px;z-index: ${oid}`)
canvas.style.position = 'absolute';
return canvas;
}
export const renderImageOnDiv = function (pageWidth, pageHeight, imgSrc, boundary, clip, isStampAnnot, SES_Signature, signedInfo) {
export const renderImageOnDiv = function (pageWidth, pageHeight, imgSrc, boundary, clip, isStampAnnot, SES_Signature, signedInfo, oid) {
let div = document.createElement('div');
if(isStampAnnot)
{
@ -328,7 +328,7 @@ export const renderImageOnDiv = function (pageWidth, pageHeight, imgSrc, boundar
clip = converterBox(clip);
c = `clip: rect(${clip.y}px, ${clip.w + clip.x}px, ${clip.h + clip.y}px, ${clip.x}px)`
}
div.setAttribute('style', `cursor: pointer; overflow: hidden; position: absolute; left: ${c ? boundary.x : boundary.x < 0 ? 0 : boundary.x}px; top: ${c ? boundary.y : boundary.y < 0 ? 0 : boundary.y}px; width: ${w}px; height: ${h}px; ${c}`)
div.setAttribute('style', `cursor: pointer; overflow: hidden; position: absolute; left: ${c ? boundary.x : boundary.x < 0 ? 0 : boundary.x}px; top: ${c ? boundary.y : boundary.y < 0 ? 0 : boundary.y}px; width: ${w}px; height: ${h}px; ${c};z-index: ${oid}`)
return div;
}
@ -380,7 +380,7 @@ export const renderTextObject = function (fontResObj, textObject, defaultFillCol
let height = boundary.h;
let left = boundary.x;
let top = boundary.y;
svg.setAttribute('style', `overflow:visible;position:absolute;width:${width}px;height:${height}px;left:${left}px;top:${top}px`);
svg.setAttribute('style', `overflow:visible;position:absolute;width:${width}px;height:${height}px;left:${left}px;top:${top}px;z-index:${textObject['@_Id']}`);
return svg;
}
@ -450,6 +450,6 @@ export const renderPathObject = function (drawParamResObj, pathObject, defaultFi
let height = isStampAnnot ? boundary.h : Math.ceil(boundary.h);
let left = boundary.x;
let top = boundary.y;
svg.setAttribute('style', `overflow:visible;position:absolute;width:${width}px;height:${height}px;left:${left}px;top:${top}px`);
svg.setAttribute('style', `overflow:visible;position:absolute;width:${width}px;height:${height}px;left:${left}px;top:${top}px;z-index:${pathObject['@_Id']}`);
return svg;
}