فهرست منبع

【编辑工具】背景、水印 预览调整为单页模式

lizhe 1 سال پیش
والد
کامیت
1039e319d3

+ 1 - 0
PDF Office/PDF Master/Class/PDFTools/Background/New/View/KMAddBackgroundView.swift

@@ -133,6 +133,7 @@ class KMAddBackgroundView: KMBaseXibView, NSComboBoxDelegate {
 //        pdfView.background = background
 //        pdfView.document = pdfDocument
         pdfView.autoScales = true
+        pdfView.setDisplay(.singlePage)
 //        pdfView.documentView?.enclosingScrollView?.hasVerticalScroller = false
 //        pdfView.documentView?.enclosingScrollView?.hasHorizontalScroller = false
 

+ 7 - 6
PDF Office/PDF Master/Class/PDFTools/Watermark/New/View/KMWatermarkView.swift

@@ -128,13 +128,14 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
     }
     
     override func setup() {
+        pdfView.setDisplay(.singlePage)
         
-        if (pdfView.documentView() != nil) {
-            pdfView.setDisplay(.singlePage)
-            pdfView.documentView().enclosingScrollView?.scrollerStyle = .overlay
-            pdfView.documentView().enclosingScrollView?.hasVerticalScroller = false
-            pdfView.documentView().enclosingScrollView?.hasHorizontalScroller = false
-        }
+//        if (pdfView.documentView() != nil) {
+//            pdfView.setDisplay(.singlePage)
+//            pdfView.documentView().enclosingScrollView?.scrollerStyle = .overlay
+//            pdfView.documentView().enclosingScrollView?.hasVerticalScroller = false
+//            pdfView.documentView().enclosingScrollView?.hasHorizontalScroller = false
+//        }
         
         for i in 0..<3 {
             for j in 0..<3 {

+ 20 - 17
PDF Office/PDF Master/Class/PDFTools/Watermark/View/KMWatermarkPDFView.swift

@@ -387,6 +387,9 @@ class KMWatermarkPDFView: CPDFView {
         guard let headerFooter = headerFooter else { return }
 
         let pageBounds = page.bounds(for: .cropBox)
+        let xMargin = 0.0//pageBounds.origin.x * 2
+        let yMargin = 0.0//pageBounds.origin.y * 2
+        
         NSGraphicsContext.saveGraphicsState()
 
         if context != nil {
@@ -421,7 +424,7 @@ class KMWatermarkPDFView: CPDFView {
                                    attributes: attributes).size
 
         var posY = min(pageBounds.size.height - (headerFooter.topMargin), pageBounds.size.height - size.height)
-        tString.draw(in: CGRect(x: headerFooter.leftMargin, y: posY, width: size.width, height: size.height), withAttributes: attributes)
+        tString.draw(in: CGRect(x: headerFooter.leftMargin + xMargin, y: posY + yMargin, width: size.width, height: size.height), withAttributes: attributes)
     
 
         let topCenterString = headerFooter.topCenterString
@@ -432,7 +435,7 @@ class KMWatermarkPDFView: CPDFView {
                                    attributes: attributes).size
 
         posY = min(pageBounds.size.height - (headerFooter.topMargin), pageBounds.size.height - size.height)
-        tString.draw(in: CGRect(x: pageBounds.size.width/2 - size.width/2, y: posY, width: size.width, height: size.height), withAttributes: attributes)
+        tString.draw(in: CGRect(x: pageBounds.size.width/2 - size.width/2 + xMargin, y: posY + yMargin, width: size.width, height: size.height), withAttributes: attributes)
         
 
         let topRightString = headerFooter.topRightString
@@ -443,8 +446,8 @@ class KMWatermarkPDFView: CPDFView {
                                    attributes: attributes).size
 
         posY = min(pageBounds.size.height - (headerFooter.topMargin), pageBounds.size.height - size.height)
-        tString.draw(in: CGRect(x: pageBounds.size.width - (headerFooter.rightMargin) - size.width,
-                                y: posY,
+        tString.draw(in: CGRect(x: pageBounds.size.width - (headerFooter.rightMargin) - size.width + xMargin,
+                                y: posY + yMargin,
                                 width: size.width,
                                 height: size.height),
                       withAttributes: attributes)
@@ -458,7 +461,7 @@ class KMWatermarkPDFView: CPDFView {
                                    attributes: attributes).size
 
         posY = max((headerFooter.bottomMargin) - size.height, 0)
-        tString.draw(in: CGRect(x: headerFooter.leftMargin, y: posY, width: size.width, height: size.height), withAttributes: attributes)
+        tString.draw(in: CGRect(x: headerFooter.leftMargin + xMargin, y: posY + yMargin, width: size.width, height: size.height), withAttributes: attributes)
         
 
         let bottomCenterString = headerFooter.bottomCenterString
@@ -469,8 +472,8 @@ class KMWatermarkPDFView: CPDFView {
                                    attributes: attributes).size
 
         posY = max((headerFooter.bottomMargin) - size.height, 0)
-        tString.draw(in: CGRect(x: pageBounds.size.width/2 - size.width/2,
-                                y: posY,
+        tString.draw(in: CGRect(x: pageBounds.size.width/2 - size.width/2 + xMargin,
+                                y: posY + yMargin,
                                 width: size.width,
                                 height: size.height),
                       withAttributes: attributes)
@@ -484,8 +487,8 @@ class KMWatermarkPDFView: CPDFView {
                                    attributes: attributes).size
 
         posY = max((headerFooter.bottomMargin) - size.height, 0)
-        tString.draw(in: CGRect(x: pageBounds.size.width - (headerFooter.rightMargin) - size.width,
-                                y: posY,
+        tString.draw(in: CGRect(x: pageBounds.size.width - (headerFooter.rightMargin) - size.width + xMargin,
+                                y: posY + yMargin,
                                 width: size.width,
                                 height: size.height),
                       withAttributes: attributes)
@@ -494,17 +497,17 @@ class KMWatermarkPDFView: CPDFView {
         context.setStrokeColor(NSColor(red: 51.0/255.0, green: 186.0/255.0, blue: 234.0/255.0, alpha: 1.0).cgColor)
         context.setLineWidth(1.0)
 
-        context.move(to: CGPoint(x: 0, y: headerFooter.bottomMargin + bottomOffset))
-        context.addLine(to: CGPoint(x: pageBounds.size.width, y: headerFooter.bottomMargin + bottomOffset))
+        context.move(to: CGPoint(x: xMargin, y: headerFooter.bottomMargin + bottomOffset))
+        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width, y: headerFooter.bottomMargin + bottomOffset))
 
-        context.move(to: CGPoint(x: headerFooter.leftMargin, y: 0))
-        context.addLine(to: CGPoint(x: headerFooter.leftMargin, y: pageBounds.size.height))
+        context.move(to: CGPoint(x: xMargin + headerFooter.leftMargin, y: 0))
+        context.addLine(to: CGPoint(x: xMargin + headerFooter.leftMargin, y: pageBounds.size.height))
 
-        context.move(to: CGPoint(x: pageBounds.size.width - (headerFooter.rightMargin), y: 0))
-        context.addLine(to: CGPoint(x: pageBounds.size.width - (headerFooter.rightMargin), y: pageBounds.size.height))
+        context.move(to: CGPoint(x: xMargin + pageBounds.size.width - (headerFooter.rightMargin), y: 0))
+        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width - (headerFooter.rightMargin), y: pageBounds.size.height))
 
-        context.move(to: CGPoint(x: 0, y: pageBounds.size.height - (headerFooter.topMargin) - topOffset))
-        context.addLine(to: CGPoint(x: pageBounds.size.width, y: pageBounds.size.height - (headerFooter.topMargin) - topOffset))
+        context.move(to: CGPoint(x: xMargin, y: pageBounds.size.height - (headerFooter.topMargin) - topOffset))
+        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width, y: pageBounds.size.height - (headerFooter.topMargin) - topOffset))
 
         let arr: [CGFloat] = [8, 1]
         context.setLineDash(phase: 0, lengths: arr)