多单位版国产化地质资料管理系统
zs
2025-12-18 4f0d9bde31a80f6279e26466250da7716eec627f
src/main/webapp/static/plugins/pdfjs-newest/web/viewer.js
@@ -18099,7 +18099,12 @@
        };
      }();
      var paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
      var paintTask = null;
      if (secretPageNumber.indexOf("," + pdfPage.pageNumber + ",") != -1) {
          paintTask = this.paintSecretPageOnCanvas(canvasWrapper);
      } else {
          paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
      }
      paintTask.onRenderContinue = renderContinueCallback;
      this.paintTask = paintTask;
      var resultPromise = paintTask.promise.then(function () {
@@ -18262,35 +18267,97 @@
            wmCanvas.setAttribute("style", "position:absolute;border:1px solid blank");
            const wmContext = wmCanvas.getContext('2d');
            wmContext.globalAlpha = watermarkTransparency;
            // get fontsize
            //var fontSize = (canvas.height + canvas.width) / 20;
            //get fontsize
            const fontSize = watermarkFontsize * this.scale;
            // setup text for filling
            wmContext.font = fontSize + "px Microsoft YaHei";
            wmContext.fillStyle = "black";
            wmContext.textAlign = 'center';
            wmContext.textBaseline = 'middle';
            // get the metrics with font settings
            const metrics = wmContext.measureText(watermarkText);
            console.log(metrics);
            let width = (viewport.height + viewport.width) / 2;
            if (viewport.height <= viewport.width) {
                width = (viewport.height + viewport.width) / 2.5;
            //判断水印的显示位置
            if (watermarkPosition != "tile") {
                // 单个水印模式(九宫格位置)
                const textWidth = wmContext.measureText(watermarkText).width;
                const textHeight = fontSize;
                // 计算旋转后的文本边界框
                const angleRad = watermarkAngle * Math.PI / 180;
                const rotatedWidth = Math.abs(textWidth * Math.cos(angleRad)) + Math.abs(textHeight * Math.sin(angleRad));
                const rotatedHeight = Math.abs(textWidth * Math.sin(angleRad)) + Math.abs(textHeight * Math.cos(angleRad));
                // 计算安全边距,确保文本不会超出画布
                const safeMarginX = rotatedWidth / 2 + 10;
                const safeMarginY = rotatedHeight / 2 + 10;
                let x, y;
                // 根据选择的位置计算坐标
                switch (watermarkPosition) {
                    case 'topLeft':
                        x = Math.max(safeMarginX, wmCanvas.width * 0.1);
                        y = Math.max(safeMarginY, wmCanvas.height * 0.1);
                        break;
                    case 'topCenter':
                        x = wmCanvas.width / 2;
                        y = Math.max(safeMarginY, wmCanvas.height * 0.1);
                        break;
                    case 'topRight':
                        x = Math.min(wmCanvas.width - safeMarginX, wmCanvas.width * 0.9);
                        y = Math.max(safeMarginY, wmCanvas.height * 0.1);
                        break;
                    case 'middleLeft':
                        x = Math.max(safeMarginX, wmCanvas.width * 0.1);
                        y = wmCanvas.height / 2;
                        break;
                    case "":
                    case 'center':
                        x = wmCanvas.width / 2;
                        y = wmCanvas.height / 2;
                        break;
                    case 'middleRight':
                        x = Math.min(wmCanvas.width - safeMarginX, wmCanvas.width * 0.9);
                        y = wmCanvas.height / 2;
                        break;
                    case 'bottomLeft':
                        x = Math.max(safeMarginX, wmCanvas.width * 0.1);
                        y = Math.min(canvas.height - safeMarginY, wmCanvas.height * 0.9);
                        break;
                    case 'bottomCenter':
                        x = wmCanvas.width / 2;
                        y = Math.min(wmCanvas.height - safeMarginY, wmCanvas.height * 0.9);
                        break;
                    case 'bottomRight':
                        x = Math.min(wmCanvas.width - safeMarginX, wmCanvas.width * 0.9);
                        y = Math.min(wmCanvas.height - safeMarginY, wmCanvas.height * 0.9);
                        break;
                }
                wmContext.save();
                wmContext.translate(x, y);
                wmContext.rotate(watermarkAngle * Math.PI / 180);
                wmContext.fillText(watermarkText, 0, 0);
                wmContext.restore();
            } else {
                // 计算水印平铺参数
                const textWidth = wmContext.measureText(watermarkText).width;
                const textHeight = fontSize;
                const spacingX = textWidth * 1.2;
                const spacingY = textHeight * 3;
                // 平铺水印
                for (let x = -spacingX; x < wmCanvas.width + spacingX; x += spacingX) {
                    for (let y = -spacingY; y < wmCanvas.height + spacingY; y += spacingY) {
                        wmContext.save();
                        wmContext.translate(x, y);
                        wmContext.rotate(watermarkAngle * Math.PI / 180);
                        wmContext.fillText(watermarkText, 0, 0);
                        wmContext.restore();
                    }
                }
            }
            // 'height' is the watermake height
            let height = viewport.height / 3.24;
            width = Math.sqrt(viewport.height / 2 * viewport.height / 2 - height * height);
            width += metrics.width / 2;
            // change the origin coordinate to the middle of the context
            wmContext.translate(viewport.width / 2, 15);
            // rotate the context (so it's rotated around its center)
            wmContext.rotate(-Math.atan(viewport.height / viewport.width + 0.11));
            // as the origin is now at the center, just need to center the text
            wmContext.fillText(watermarkText, -width, height);
            //wmContext.fillText(watermarkText, -width, height);
            if (this.div.firstChild) {
                this.div.insertBefore(wmCanvas, this.div.firstChild);
@@ -18381,6 +18448,123 @@
      };
    }
  }, {
      key: "paintSecretPageOnCanvas",
      value: function paintSecretPageOnCanvas(wrapper) {
          var resolveRenderPromise, rejectRenderPromise;
          var promise = new Promise(function (resolve, reject) {
              resolveRenderPromise = resolve;
              rejectRenderPromise = reject;
          });
          var result = {
              promise: promise,
              onRenderContinue: function (cont) {
                  cont();
              },
              cancel: function () {
                  renderTask.cancel();
              }
          };
          var viewport = this.viewport;
          var canvas = document.createElement('canvas');
          canvas.id = 'page' + this.id;
          canvas.setAttribute('hidden', 'hidden');
          var isCanvasHidden = true;
          var currentDiv = this.div;
          var showCanvas = function () {//移除loading状态
              //alert($(currentDiv).html());
              $(currentDiv).children("*:gt(0)").remove();
          };
          wrapper.appendChild(canvas);
          this.canvas = canvas;
          canvas.mozOpaque = true;
          var ctx = canvas.getContext('2d', { alpha: false });
          var outputScale = this.outputScale = new _ui_utils.OutputScale();
          if (this.useOnlyCssZoom) {
              var actualSizeViewport = viewport.clone({
                  scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
              });
              outputScale.sx *= actualSizeViewport.width / viewport.width;
              outputScale.sy *= actualSizeViewport.height / viewport.height;
          }
          if (this.maxCanvasPixels > 0) {
              var pixelsInViewport = viewport.width * viewport.height;
              var maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
              if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
                  outputScale.sx = maxScale;
                  outputScale.sy = maxScale;
                  this.hasRestrictedScaling = true;
              } else {
                  this.hasRestrictedScaling = false;
              }
          }
          var sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
          var sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
          //canvas.width = roundToDivide(viewport.width * outputScale.sx, sfx[0]);
          //canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[0]);
          //canvas.style.width = roundToDivide(viewport.width, sfx[1]) + 'px';
          //canvas.style.height = roundToDivide(viewport.height, sfy[1]) + 'px';
          this.paintedViewportMap.set(canvas, viewport);
          /*******************add waterMake*****************/
          var wmCanvas = document.createElement("canvas");
          var width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
          var height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
          wmCanvas.width = width;
          wmCanvas.height = height;
          //wmCanvas.setAttribute("style", "position:absolute;border:1px solid black");
          var wmContext = wmCanvas.getContext('2d');
          var metrics = wmContext.measureText(secretShieldInfo);
          // get fontsize
          var fontSize = 30;
          // setup text for filling
          wmContext.font = fontSize + "px Microsoft YaHei";
          // change the origin coordinate to the middle of the context
          //wmContext.translate(canvas.width / 2, 15);
          // rotate the context (so it's rotated around its center)
          //wmContext.rotate(-Math.atan(canvas.height / canvas.width + 0.11));
          // as the origin is now at the center, just need to center the text
          wmContext.fillText(secretShieldInfo, 50, 50);
          if (this.div.firstChild) {
              this.div.insertBefore(wmCanvas, this.div.firstChild);
          }
          else {
              this.div.appendChild(wmCanvas);
          }
          /*******************add waterMake*****************/
          var transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
          var renderContext = {
              canvasContext: ctx,
              transform: transform,
              viewport: this.viewport,
              renderInteractiveForms: this.renderInteractiveForms
          };
          var renderTask = this.pdfPage.render(renderContext);
          renderTask.onContinue = function (cont) {
              showCanvas();
              if (result.onRenderContinue) {
                  result.onRenderContinue(cont);
              } else {
                  cont();
              }
          };
          renderTask.promise.then(function pdfPageRenderCallback() {
              showCanvas();
              resolveRenderPromise(undefined);
          }, function pdfPageRenderError(error) {
              showCanvas();
              rejectRenderPromise(error);
          });
          return result;
      }
  }, {
    key: "setPageLabel",
    value: function setPageLabel(label) {
      this.pageLabel = typeof label === "string" ? label : null;