|
| 1 | +"""Helper to get paper sizes.""" |
| 2 | + |
| 3 | +from collections import namedtuple |
| 4 | + |
| 5 | +Dimensions = namedtuple("Dimensions", ["width", "height"]) |
| 6 | + |
| 7 | + |
| 8 | +class PaperSize(object): |
| 9 | + """(width, height) of the paper in portrait mode in pixels at 72 ppi.""" |
| 10 | + |
| 11 | + # Notes how to calculate it: |
| 12 | + # 1. Get the size of the paper in mm |
| 13 | + # 2. Convert it to inches (25.4 millimeters are equal to 1 inches) |
| 14 | + # 3. Convert it to pixels ad 72dpi (1 inch is equal to 72 pixels) |
| 15 | + |
| 16 | + # All Din-A paper sizes follow this pattern: |
| 17 | + # 2xA(n-1) = A(n) |
| 18 | + # So the height of the next bigger one is the width of the smaller one |
| 19 | + # The ratio is always approximately the ratio 1:2**0.5 |
| 20 | + # Additionally, A0 is defined to have an area of 1 m**2 |
| 21 | + # Be aware of rounding issues! |
| 22 | + A0 = Dimensions(2384, 3370) # 841mm x 1189mm |
| 23 | + A1 = Dimensions(1684, 2384) |
| 24 | + A2 = Dimensions(1191, 1684) |
| 25 | + A3 = Dimensions(842, 1191) |
| 26 | + A4 = Dimensions( |
| 27 | + 595, 842 |
| 28 | + ) # Printer paper, documents - this is by far the most common |
| 29 | + A5 = Dimensions(420, 595) # Paperback books |
| 30 | + A6 = Dimensions(298, 420) # Post cards |
| 31 | + A7 = Dimensions(210, 298) |
| 32 | + A8 = Dimensions(147, 210) |
| 33 | + |
| 34 | + # Envelopes |
| 35 | + C4 = Dimensions(649, 918) |
| 36 | + |
| 37 | + |
| 38 | +_din_a = [ |
| 39 | + PaperSize.A0, |
| 40 | + PaperSize.A1, |
| 41 | + PaperSize.A2, |
| 42 | + PaperSize.A3, |
| 43 | + PaperSize.A4, |
| 44 | + PaperSize.A5, |
| 45 | + PaperSize.A6, |
| 46 | + PaperSize.A7, |
| 47 | + PaperSize.A8, |
| 48 | +] |
0 commit comments