Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-2d

Source of release 0.5.1

0.5.1 / src / type_options.luc

## The Text tool's settings, as its header shows them: the family and style,
## the size in pixels, the alignment (0 left, 1 center, 2 right, 3
## justified), the tracking in thousandths of an em, and the leading (0: the
## face's). A text layer being edited takes them over; its color is the
## foreground color.
from luce_image.canvas import Canvas
import platform

pub class TypeOptions:
    pub var family: str = "Helvetica"
    pub var style: str = "Regular"
    pub var size: float = 48.0
    pub var alignment: int = 0
    pub var tracking: float = 0.0
    pub var leading: float = 0.0

    pub func init(self):
        # The platform's plain sans face until one is chosen.
        self.family = "Helvetica" if platform.macos else ("Arial" if platform.windows else "DejaVu Sans")

    ## Take the settings of the text layer at `index`.
    pub func take(self, canvas: Canvas, index: int) -> unit!:
        self.family = canvas.layer_font_family(index)
        self.style = canvas.layer_font_style(index)
        self.size = canvas.layer_type_value(index, 0)
        self.alignment = int(canvas.layer_type_value(index, 7))
        self.tracking = canvas.layer_type_value(index, 8)
        self.leading = canvas.layer_type_value(index, 9)