Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
fix: make paper size pydantic compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Midnighter committed Aug 8, 2020
1 parent 79f67b9 commit a3c64a5
Showing 1 changed file with 45 additions and 30 deletions.
75 changes: 45 additions & 30 deletions src/structurizr/view/paper_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,58 @@
class PaperSize(Enum):
"""Represent paper sizes in pixels at 300dpi."""

A6_Portrait = ("A6", Orientation.Portrait, 1240, 1748)
A6_Landscape = ("A6", Orientation.Landscape, 1748, 1240)
def __new__(
cls,
value: str,
size: str,
orientation: Orientation,
width: int,
height: int,
**kwargs
) -> "PaperSize":
"""
Construct a specific paper size but with a string value.
A5_Portrait = ("A5", Orientation.Portrait, 1748, 2480)
A5_Landscape = ("A5", Orientation.Landscape, 2480, 1748)
References:
https://docs.python.org/3/library/enum.html#when-to-use-new-vs-init
A4_Portrait = ("A4", Orientation.Portrait, 2480, 3508)
A4_Landscape = ("A4", Orientation.Landscape, 3508, 2480)
"""
obj = object.__new__(cls)
obj._value_ = value
obj.size = size
obj.orientation = orientation
obj.width = width
obj.height = height

A3_Portrait = ("A3", Orientation.Portrait, 3508, 4961)
A3_Landscape = ("A3", Orientation.Landscape, 4961, 3508)
return obj

A2_Portrait = ("A2", Orientation.Portrait, 4961, 7016)
A2_Landscape = ("A2", Orientation.Landscape, 7016, 4961)
A6_Portrait = ("A6_Portrait", "A6", Orientation.Portrait, 1240, 1748)
A6_Landscape = ("A6_Landscape", "A6", Orientation.Landscape, 1748, 1240)

A1_Portrait = ("A1", Orientation.Portrait, 7016, 9933)
A1_Landscape = ("A1", Orientation.Landscape, 9933, 7016)
A5_Portrait = ("A5_Portrait", "A5", Orientation.Portrait, 1748, 2480)
A5_Landscape = ("A5_Landscape", "A5", Orientation.Landscape, 2480, 1748)

A0_Portrait = ("A0", Orientation.Portrait, 9933, 14043)
A0_Landscape = ("A0", Orientation.Landscape, 14043, 9933)
A4_Portrait = ("A4_Portrait", "A4", Orientation.Portrait, 2480, 3508)
A4_Landscape = ("A4_Landscape", "A4", Orientation.Landscape, 3508, 2480)

Letter_Portrait = ("Letter", Orientation.Portrait, 2550, 3300)
Letter_Landscape = ("Letter", Orientation.Landscape, 3300, 2550)
A3_Portrait = ("A3_Portrait", "A3", Orientation.Portrait, 3508, 4961)
A3_Landscape = ("A3_Landscape", "A3", Orientation.Landscape, 4961, 3508)

Legal_Portrait = ("Legal", Orientation.Portrait, 2550, 4200)
Legal_Landscape = ("Legal", Orientation.Landscape, 4200, 2550)
A2_Portrait = ("A2_Portrait", "A2", Orientation.Portrait, 4961, 7016)
A2_Landscape = ("A2_Landscape", "A2", Orientation.Landscape, 7016, 4961)

Slide_4_3 = ("Slide 4:3", Orientation.Landscape, 3306, 2480)
Slide_16_9 = ("Slide 16:9", Orientation.Landscape, 3508, 1973)
Slide_16_10 = ("Slide 16:10", Orientation.Landscape, 3508, 2193)
A1_Portrait = ("A1_Portrait", "A1", Orientation.Portrait, 7016, 9933)
A1_Landscape = ("A1_Landscape", "A1", Orientation.Landscape, 9933, 7016)

def __init__(
self, name: str, orientation: Orientation, width: int, height: int, **kwargs
) -> None:
"""Initialize a specific paper size."""
super().__init__(**kwargs)
self.size_name = name
self.orientation = orientation
self.width = width
self.height = height
A0_Portrait = ("A0_Portrait", "A0", Orientation.Portrait, 9933, 14043)
A0_Landscape = ("A0_Landscape", "A0", Orientation.Landscape, 14043, 9933)

Letter_Portrait = ("Letter_Portrait", "Letter", Orientation.Portrait, 2550, 3300)
Letter_Landscape = ("Letter_Landscape", "Letter", Orientation.Landscape, 3300, 2550)

Legal_Portrait = ("Legal_Portrait", "Legal", Orientation.Portrait, 2550, 4200)
Legal_Landscape = ("Legal_Landscape", "Legal", Orientation.Landscape, 4200, 2550)

Slide_4_3 = ("Slide_4_3", "Slide 4:3", Orientation.Landscape, 3306, 2480)
Slide_16_9 = ("Slide_16_9", "Slide 16:9", Orientation.Landscape, 3508, 1973)
Slide_16_10 = ("Slide_16_10", "Slide 16:10", Orientation.Landscape, 3508, 2193)

0 comments on commit a3c64a5

Please sign in to comment.