From 835defc1fdace23c0c41c2df617de5b9b12fedea Mon Sep 17 00:00:00 2001 From: Donal Date: Sun, 13 Sep 2020 21:36:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=89=8B=E6=9C=BA=E7=AB=AF?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/HelloWorld.vue | 33 +++++++++++++++++++++++++-------- src/utils/ofd_util.js | 7 ++++++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue index 877bc75..431d6fa 100644 --- a/src/components/HelloWorld.vue +++ b/src/components/HelloWorld.vue @@ -17,7 +17,7 @@ import JsZip from 'jszip' import {Jbig2Image} from '../utils/jbig2' import {pipeline} from "../utils/pipeline" -import {getFontFamily, getExtensionByPath, replaceFirstSlash, converterDpi, convertPathAbbreviatedDatatoPoint, calPathPoint, calTextPoint} from "../utils/ofd_util" +import {setPageScal,getFontFamily, getExtensionByPath, replaceFirstSlash, converterDpi, convertPathAbbreviatedDatatoPoint, calPathPoint, calTextPoint} from "../utils/ofd_util" let parser = require('fast-xml-parser'); import ASN1 from '@lapo/asn1js'; import Base64 from '@lapo/asn1js/base64'; @@ -231,7 +231,6 @@ export default { text.setAttribute('transform', `scale(${hScale}, 1)`) text.setAttribute('transform-origin', `${textCodePoint.x}`); } - console.log(text.style.width) text.setAttribute('fill', defaultStrokeColor); text.setAttribute('fill', defaultFillColor); text.setAttribute('style', `font-weight: ${weight};font-size:${size}px;font-family: ${getFontFamily(this.fontResObj[font])};`) @@ -347,6 +346,23 @@ export default { } }, + parsePageBox(obj) { + if (obj) { + let array = obj.split(' '); + let width = converterDpi(parseFloat(array[2])); + if (width > screen.width) { + const scale = (screen.width-5) / parseFloat(array[2]); + setPageScal(scale>0?scale:1); + } + return { + x: converterDpi(parseFloat(array[0])), y: converterDpi(parseFloat(array[1])), + w: converterDpi(parseFloat(array[2])), h: converterDpi(parseFloat(array[3])) + }; + } else { + return null; + } + }, + parseStBox(obj) { if (obj) { let array = obj.split(' '); @@ -366,15 +382,15 @@ export default { if (area) { const physicalBox = area['ofd:PhysicalBox'] if (physicalBox) { - box = this.parseStBox(physicalBox); + box = (physicalBox); } else { const applicationBox = area['ofd:ApplicationBox'] if (applicationBox) { - box = this.parseStBox(applicationBox); + box = (applicationBox); } else { const contentBox = area['ofd:ContentBox'] if (contentBox) { - box = this.parseStBox(contentBox); + box = (contentBox); } } } @@ -382,19 +398,20 @@ export default { let documentArea = this.documentObj['ofd:CommonData']['ofd:PageArea'] const physicalBox = documentArea['ofd:PhysicalBox'] if (physicalBox) { - box = this.parseStBox(physicalBox); + box = (physicalBox); } else { const applicationBox = documentArea['ofd:ApplicationBox'] if (applicationBox) { - box = this.parseStBox(applicationBox); + box = (applicationBox); } else { const contentBox = documentArea['ofd:ContentBox'] if (contentBox) { - box = this.parseStBox(contentBox); + box = (contentBox); } } } } + box = this.parsePageBox(box); let boxObj = {}; boxObj['id'] = Object.keys(page)[0]; boxObj['box'] = box; diff --git a/src/utils/ofd_util.js b/src/utils/ofd_util.js index ff4b706..7d62ceb 100644 --- a/src/utils/ofd_util.js +++ b/src/utils/ofd_util.js @@ -78,9 +78,14 @@ const millimetersToPixel = function (mm, dpi) { //毫米转像素:mm * dpi / 25.4 return ((mm * dpi / 25.4)); } +let Scale = 5; + +export const setPageScal = function (scale) { + Scale = scale; +} export const converterDpi = function (width) { - return millimetersToPixel(width, 3.78*25.4); + return millimetersToPixel(width, Scale*25.4); } export const deltaFormatter = function (delta) {