Coverage for pyWebLayout/style/page_style.py: 100%

35 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-08 20:34 +0000

1from typing import Tuple 

2from dataclasses import dataclass, field 

3 

4from pyWebLayout.style.alignment import Alignment 

5 

6 

7@dataclass 

8class PageStyle: 

9 """ 

10 Defines the styling properties for a page including borders, spacing, and layout. 

11 """ 

12 

13 # Alignment applied to body text that does not specify its own. Headings are 

14 # never justified regardless of this setting. 

15 default_alignment: Alignment = Alignment.JUSTIFY 

16 

17 # Border properties 

18 border_width: int = 0 

19 border_color: Tuple[int, int, int] = (0, 0, 0) 

20 

21 # Spacing properties 

22 line_spacing: int = 5 # Additional pixels between lines (added to font size) 

23 inter_block_spacing: int = 15 # Pixels between blocks (paragraphs, headings, etc.) 

24 word_spacing: int = 0 # Additional pixels between words (0 = use font defaults) 

25 

26 # Padding (top, right, bottom, left) 

27 padding: Tuple[int, int, int, int] = (20, 20, 20, 20) 

28 

29 # Background color 

30 background_color: Tuple[int, int, int] = (255, 255, 255) 

31 

32 # Typography properties 

33 max_font_size: int = 72 # Maximum font size allowed on a page 

34 

35 @property 

36 def padding_top(self) -> int: 

37 return self.padding[0] 

38 

39 @property 

40 def padding_right(self) -> int: 

41 return self.padding[1] 

42 

43 @property 

44 def padding_bottom(self) -> int: 

45 return self.padding[2] 

46 

47 @property 

48 def padding_left(self) -> int: 

49 return self.padding[3] 

50 

51 @property 

52 def total_horizontal_padding(self) -> int: 

53 """Get total horizontal padding (left + right)""" 

54 return self.padding_left + self.padding_right 

55 

56 @property 

57 def total_vertical_padding(self) -> int: 

58 """Get total vertical padding (top + bottom)""" 

59 return self.padding_top + self.padding_bottom 

60 

61 @property 

62 def total_border_width(self) -> int: 

63 """Get total border width (both sides)""" 

64 return self.border_width * 2