summaryrefslogtreecommitdiff
path: root/components/file-manager/creaetWaterMarks.tsx
blob: 524b18ee713d5cbe8c9c78faf91e8706b7923978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
export const createCustomWatermark: CreateCustomWatermark = ({
    text,
    fontSize,
    color,
    opacity,
    rotation = -45,
    fontFamily = "Helvetica",
  }) => {
    return (ctx, pageNumber, pageWidth, pageHeight) => {
      if (!text) return;
   
      const lines = text.split("\n"); // 줄바꿈 기준 멀치 처리
   
      ctx.save();
      ctx.translate(pageWidth / 2, pageHeight / 2);
      ctx.rotate((rotation * Math.PI) / 180);
      ctx.fillStyle = color;
      ctx.textAlign = "center";
      ctx.textBaseline = "middle";
   
      const lineHeights = lines.map((s) => {
        return fontSize;
      });
   
      const totalHeight =
        lineHeights.reduce((sum, h) => sum + h, 0) - lineHeights[0]; // 첫 줄은 기준선 0
   
      let yOffset = -totalHeight / 2;
   
      lines.forEach((line, i) => {
        ctx.font = `900 ${fontSize}px ${fontFamily}`;
        ctx.fillText(line, 0, yOffset);
        yOffset += lineHeights[i];
      });
   
      ctx.restore();
    };
  };
   

  import { Core, WebViewerInstance } from "@pdftron/webviewer";

export interface WaterMarkOption {
  fontSize: number;
  color: string;
  opacity: number;
  rotation: number;
  fontFamily: string;
  split: boolean;
  shipNameCheck: boolean;
  shipName: string;
  ownerNameCheck: boolean;
  ownerName: string;
  classNameCheck: boolean;
  className: string;
  classList: string[];
  customCheck: boolean;
  text: string;
}

type CreateCustomWatermark = ({
  text,
  fontSize,
  color,
  opacity,
  rotation,
  fontFamily,
}: Pick<
  WaterMarkOption,
  "text" | "fontSize" | "color" | "opacity" | "rotation" | "fontFamily"
>) => Core.DocumentViewer.CustomWatermarkCallback;