datatypes.data_paragraphprops

 1from dataclasses import dataclass
 2from .data_fontprops import DFontProps
 3from lib import helpers
 4
 5
 6@dataclass
 7class DParagraphProps(DFontProps):
 8    """Font properties extended with paragraph-level formatting for FormattedString.
 9
10    Extends DFontProps with spacing, indentation, and separator properties that
11    control paragraph-level layout in DrawBot's FormattedString.
12
13    Example:
14        ```python
15        heading = DParagraphProps(
16            fontSize=32,
17            leading=1.1,
18            letterSpacing=-10,
19            fontData=font,
20            paragraphTopSpacing=20,
21            indent=10
22        )
23
24        fs = drawBot.FormattedString()
25        fs.append("Heading\\n", **heading.calc())
26        ```
27    """
28
29    paragraphTopSpacing: float = 0
30    """Space before the paragraph in points."""
31
32    paragraphBottomSpacing: float = 0
33    """Space after the paragraph in points."""
34
35    indent: float = 0
36    """First-line indent in points."""
37
38    tailIndent: float = 0
39    """Right margin indent in points (use negative values to extend right)."""
40
41    def getArgs(self, clean=False, pick: list[str] = None) -> dict:
42        """Get properties as a dictionary, including paragraph-level properties.
43
44        Args:
45            clean: If True, remove falsy properties.
46            pick: List of property keys to include.
47
48        Returns:
49            Dictionary of font and paragraph properties.
50        """
51        # Get base font properties from parent
52        asDict = super().getArgs(clean=False, pick=None)
53
54        # Add paragraph-level properties
55        asDict["paragraphTopSpacing"] = self.paragraphTopSpacing
56        asDict["paragraphBottomSpacing"] = self.paragraphBottomSpacing
57        asDict["indent"] = self.indent
58        asDict["tailIndent"] = self.tailIndent
59
60        if pick:
61            asDict = helpers.pick(asDict, pick)
62
63        if clean:
64            return helpers.omitBy(asDict)
65        else:
66            return asDict
67
68    def calc(self, clean=True) -> dict:
69        """Calculate keyword arguments for FormattedString().
70
71        Extends parent's calc() to include paragraph-level formatting properties.
72
73        Args:
74            clean: If True, remove falsy properties.
75
76        Returns:
77            Dictionary of keyword arguments for FormattedString().
78        """
79        return self.getArgs(
80            clean=clean,
81            pick=[
82                "font",
83                "fontSize",
84                "lineHeight",
85                "tracking",
86                "align",
87                "openTypeFeatures",
88                "paragraphTopSpacing",
89                "paragraphBottomSpacing",
90                "indent",
91                "tailIndent",
92            ],
93        )
@dataclass
class DParagraphProps(datatypes.data_fontprops.DFontProps):
 7@dataclass
 8class DParagraphProps(DFontProps):
 9    """Font properties extended with paragraph-level formatting for FormattedString.
10
11    Extends DFontProps with spacing, indentation, and separator properties that
12    control paragraph-level layout in DrawBot's FormattedString.
13
14    Example:
15        ```python
16        heading = DParagraphProps(
17            fontSize=32,
18            leading=1.1,
19            letterSpacing=-10,
20            fontData=font,
21            paragraphTopSpacing=20,
22            indent=10
23        )
24
25        fs = drawBot.FormattedString()
26        fs.append("Heading\\n", **heading.calc())
27        ```
28    """
29
30    paragraphTopSpacing: float = 0
31    """Space before the paragraph in points."""
32
33    paragraphBottomSpacing: float = 0
34    """Space after the paragraph in points."""
35
36    indent: float = 0
37    """First-line indent in points."""
38
39    tailIndent: float = 0
40    """Right margin indent in points (use negative values to extend right)."""
41
42    def getArgs(self, clean=False, pick: list[str] = None) -> dict:
43        """Get properties as a dictionary, including paragraph-level properties.
44
45        Args:
46            clean: If True, remove falsy properties.
47            pick: List of property keys to include.
48
49        Returns:
50            Dictionary of font and paragraph properties.
51        """
52        # Get base font properties from parent
53        asDict = super().getArgs(clean=False, pick=None)
54
55        # Add paragraph-level properties
56        asDict["paragraphTopSpacing"] = self.paragraphTopSpacing
57        asDict["paragraphBottomSpacing"] = self.paragraphBottomSpacing
58        asDict["indent"] = self.indent
59        asDict["tailIndent"] = self.tailIndent
60
61        if pick:
62            asDict = helpers.pick(asDict, pick)
63
64        if clean:
65            return helpers.omitBy(asDict)
66        else:
67            return asDict
68
69    def calc(self, clean=True) -> dict:
70        """Calculate keyword arguments for FormattedString().
71
72        Extends parent's calc() to include paragraph-level formatting properties.
73
74        Args:
75            clean: If True, remove falsy properties.
76
77        Returns:
78            Dictionary of keyword arguments for FormattedString().
79        """
80        return self.getArgs(
81            clean=clean,
82            pick=[
83                "font",
84                "fontSize",
85                "lineHeight",
86                "tracking",
87                "align",
88                "openTypeFeatures",
89                "paragraphTopSpacing",
90                "paragraphBottomSpacing",
91                "indent",
92                "tailIndent",
93            ],
94        )

Font properties extended with paragraph-level formatting for FormattedString.

Extends DFontProps with spacing, indentation, and separator properties that control paragraph-level layout in DrawBot's FormattedString.

Example:
heading = DParagraphProps(
    fontSize=32,
    leading=1.1,
    letterSpacing=-10,
    fontData=font,
    paragraphTopSpacing=20,
    indent=10
)

fs = drawBot.FormattedString()
fs.append("Heading\n", **heading.calc())
DParagraphProps( fontSize: int = 24, leading: float = 1.25, letterSpacing: int = 0, trackingStrategy: Literal['relative', 'absolute'] = 'relative', fontData: 'KFont | DFontList | list[KFont]' = None, align: Literal['left', 'center', 'right'] = None, openType: Union[Literal['liga', 'dlig', 'calt', 'locl', 'titl', 'case', 'pnum', 'lnum', 'onum', 'tnum', 'zero', 'subs', 'sups', 'numr', 'dnom', 'frac', 'ordn', 'kern', 'ss01', 'ss02', 'ss03', 'ss04', 'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'ss10'], list[Literal['liga', 'dlig', 'calt', 'locl', 'titl', 'case', 'pnum', 'lnum', 'onum', 'tnum', 'zero', 'subs', 'sups', 'numr', 'dnom', 'frac', 'ordn', 'kern', 'ss01', 'ss02', 'ss03', 'ss04', 'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'ss10']], dict[Literal['liga', 'dlig', 'calt', 'locl', 'titl', 'case', 'pnum', 'lnum', 'onum', 'tnum', 'zero', 'subs', 'sups', 'numr', 'dnom', 'frac', 'ordn', 'kern', 'ss01', 'ss02', 'ss03', 'ss04', 'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'ss10'], bool]] = None, paragraphTopSpacing: float = 0, paragraphBottomSpacing: float = 0, indent: float = 0, tailIndent: float = 0)
paragraphTopSpacing: float = 0

Space before the paragraph in points.

paragraphBottomSpacing: float = 0

Space after the paragraph in points.

indent: float = 0

First-line indent in points.

tailIndent: float = 0

Right margin indent in points (use negative values to extend right).

def getArgs(self, clean=False, pick: list[str] = None) -> dict:
42    def getArgs(self, clean=False, pick: list[str] = None) -> dict:
43        """Get properties as a dictionary, including paragraph-level properties.
44
45        Args:
46            clean: If True, remove falsy properties.
47            pick: List of property keys to include.
48
49        Returns:
50            Dictionary of font and paragraph properties.
51        """
52        # Get base font properties from parent
53        asDict = super().getArgs(clean=False, pick=None)
54
55        # Add paragraph-level properties
56        asDict["paragraphTopSpacing"] = self.paragraphTopSpacing
57        asDict["paragraphBottomSpacing"] = self.paragraphBottomSpacing
58        asDict["indent"] = self.indent
59        asDict["tailIndent"] = self.tailIndent
60
61        if pick:
62            asDict = helpers.pick(asDict, pick)
63
64        if clean:
65            return helpers.omitBy(asDict)
66        else:
67            return asDict

Get properties as a dictionary, including paragraph-level properties.

Arguments:
  • clean: If True, remove falsy properties.
  • pick: List of property keys to include.
Returns:

Dictionary of font and paragraph properties.

def calc(self, clean=True) -> dict:
69    def calc(self, clean=True) -> dict:
70        """Calculate keyword arguments for FormattedString().
71
72        Extends parent's calc() to include paragraph-level formatting properties.
73
74        Args:
75            clean: If True, remove falsy properties.
76
77        Returns:
78            Dictionary of keyword arguments for FormattedString().
79        """
80        return self.getArgs(
81            clean=clean,
82            pick=[
83                "font",
84                "fontSize",
85                "lineHeight",
86                "tracking",
87                "align",
88                "openTypeFeatures",
89                "paragraphTopSpacing",
90                "paragraphBottomSpacing",
91                "indent",
92                "tailIndent",
93            ],
94        )

Calculate keyword arguments for FormattedString().

Extends parent's calc() to include paragraph-level formatting properties.

Arguments:
  • clean: If True, remove falsy properties.
Returns:

Dictionary of keyword arguments for FormattedString().