多单位版国产化地质资料管理系统
zhai
2025-12-13 fc0cc9fff4b4cbdc7cbb52b4a96c947530fcbba0
src/main/webapp/static/plugins/pdfjs/web/viewer.js
@@ -1863,6 +1863,10 @@
    if (!this.pdfViewer.currentScaleValue) {
      this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
    }
    if(initComplate instanceof Function){
      initComplate();
    }
  },
  cleanup: function cleanup() {
    if (!this.pdfDocument) {
@@ -12722,41 +12726,104 @@
      /******************add waterMake******************/
      if (enableWatermark) {
        var wmCanvas = document.createElement("canvas");
        const wmCanvas = document.createElement("canvas");
        wmCanvas.width = viewport.width;
        wmCanvas.height = viewport.height;
        wmCanvas.setAttribute("style", "position:absolute;border:1px solid blank");
        var wmContext = wmCanvas.getContext('2d');
        const wmContext = wmCanvas.getContext('2d');
        wmContext.globalAlpha = watermarkTransparency;
        // get fontsize
        //var fontSize = (canvas.height + canvas.width) / 20;
        var fontSize = watermarkFontsize * this.scale;
        //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
        var metrics = wmContext.measureText(watermarkText);
        console.log(metrics);
        var width = (canvas.height + canvas.width) / 2;
        if (viewport.height <= viewport.width) {
          width = (viewport.height + viewport.width) / 2.5;
        const metrics = wmContext.measureText(watermarkText);
        //判断水印的显示位置
        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
        var 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);