Преглед изворни кода

Update BS PNP to create guides and outer cropmarks

These are now needed as Button Shy has changed their PNPs to a different
standard, most notably the cards are now smaller by 1mm in each
dimension.

Rather than use the new PNPs directly, extract the card images (using
`pdfimages -all`) and arrange them on these guides and inner/outer
cropmarks which the old format. This allows our PNPs to be of the same
dimensions as previous ones.
Weiyi Lou пре 2 година
родитељ
комит
7d6b1c80cc
1 измењених фајлова са 42 додато и 9 уклоњено
  1. 42 9
      bs_pnp_tools_docker/bs_pnp_tools_docker.py

+ 42 - 9
bs_pnp_tools_docker/bs_pnp_tools_docker.py

@@ -1,5 +1,5 @@
 from krita import DockWidget
-from PyQt5.QtWidgets import QWidget, QDialog, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QPushButton
+from PyQt5.QtWidgets import QWidget, QDialog, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QCheckBox, QPushButton
 from PyQt5.QtCore import QByteArray
 
 DOCKER_TITLE = 'Button Shy PNP Tools'
@@ -38,6 +38,18 @@ class BsPnpTools(DockWidget):
         crop4Button.setIcon( Krita.instance().icon('animation_play') )
         layout.addWidget(crop4Button)
 
+        self.outerCheck = QCheckBox('Outer')
+        self.outerCheck.setChecked(True)
+        self.innerCheck = QCheckBox('Inner')
+        self.innerCheck.setChecked(True)
+        self.guidesCheck = QCheckBox('Guides')
+        self.guidesCheck.setChecked(True)
+        row1 = QHBoxLayout()
+        row1.addWidget(self.outerCheck)
+        row1.addWidget(self.innerCheck)
+        row1.addWidget(self.guidesCheck)
+        layout.addLayout(row1)
+
         # Add a stretch to prevent the rest of the content from stretching.
         layout.addStretch()
 
@@ -105,8 +117,8 @@ class BsPnpTools(DockWidget):
         cropMarkWidth = 61
         cropMarkHeight = 2
         cropMark = QByteArray(blackPixel * cropMarkWidth * cropMarkHeight)
-        midX = doc.width() / 2
-        midY = doc.height() / 2
+        midX = int(doc.width() / 2)
+        midY = int(doc.height() / 2)
         ySet = [ midY - 1085, midY - 38, midY + 37, midY + 1085 ]
         for x in [midX - 1706, midX + 1645]:
             for y in ySet:
@@ -153,8 +165,8 @@ class BsPnpTools(DockWidget):
         root.addChildNode(layer, None)
 
         # Calculate grid dimensions, assuming page is in centre position.
-        midX = doc.width() / 2
-        midY = doc.height() / 2
+        midX = int(doc.width() / 2)
+        midY = int(doc.height() / 2)
         xSet = []
         ySet = []
 
@@ -170,15 +182,36 @@ class BsPnpTools(DockWidget):
             xSet = [ midX - 1609, midX - 857, midX - 787, midX - 35, midX + 35, midX + 787, midX + 857, midX + 1609 ]
             ySet = [ midY - 1085, midY - 38, midY + 37, midY + 1085 ]
 
-        # Create cropmarks.
+        # Create inner and outer cropmarks.
         blackPixel = b'\x00\x00\x00\xff'
         cropMarkWidth = 2
         cropMarkHeight = 48
         cropMark = QByteArray(blackPixel * cropMarkWidth * cropMarkHeight)
-        for x in xSet:
+
+        if self.outerCheck.checkState():
+            for x in xSet:
+                layer.setPixelData(cropMark, x-1, ySet[0]-35-48, cropMarkWidth, cropMarkHeight) # top vertical line
+                layer.setPixelData(cropMark, x-1, ySet[-1]+35, cropMarkWidth, cropMarkHeight) # bottom vertical line
             for y in ySet:
-                layer.setPixelData(cropMark, x - 1, y - cropMarkHeight/2, cropMarkWidth, cropMarkHeight) # vertical line
-                layer.setPixelData(cropMark, x - cropMarkHeight/2, y - 1, cropMarkHeight, cropMarkWidth) # horizontal line
+                layer.setPixelData(cropMark, xSet[0]-35-48, y-1, cropMarkHeight, cropMarkWidth) # left horizontal line
+                layer.setPixelData(cropMark, xSet[-1]+35, y-1, cropMarkHeight, cropMarkWidth) # right horizontal line
+
+        if self.innerCheck.checkState():
+            for x in xSet:
+                for y in ySet:
+                    layer.setPixelData(cropMark, x-1, int(y - cropMarkHeight/2), cropMarkWidth, cropMarkHeight) # vertical line
+                    layer.setPixelData(cropMark, int(x - cropMarkHeight/2), y-1, cropMarkHeight, cropMarkWidth) # horizontal line
+
+        # Create guides.
+        if self.guidesCheck.checkState():
+            vList = doc.verticalGuides()
+            hList = doc.horizontalGuides()
+            vList.clear()
+            hList.clear()
+            doc.setVerticalGuides(xSet)
+            doc.setHorizontalGuides(ySet)
+            doc.setGuidesLocked(True)
+            doc.setGuidesVisible(True)
 
         # Refresh the view, or the cropmarks will not be immediately shown.
         doc.refreshProjection()