def __init__(self):
        super().__init__()

        self.mirror_pages = {
            "horizontal": False,
            "vertical": False
        }

        self.marks = {
            "crop": False,
            "bleed": False,
            "registration": False,
            "color": False
        }

        firstUse="1"

        # Print to file
        toFile="0"
        useAltPrintCommand="0"
        outputSeparations="0"

        # Whether to use spot colors
        useSpotColors="0"
        useColor="0"

        # Use ICC color profiles
        useICC="0"
        # Whether to have grey component replacement
        doGCR="0"

        doClip="0"
        setDevParam="0"

        includePDFMarks="0"

        # The postscrip level
        PSLevel="0"

        # Which printer description language
        PDLanguage="0"
        markLength="7.185302734375"
        markOffset="0"

        # --- Bleeds --------------------------------------------

        self.bleeds = collections.OrderedDict()
        self.bleeds["top"] = dimensions.Dim(0),
        self.bleeds["left"] = dimensions.Dim(0),
        self.bleeds["right"] = dimensions.Dim(0),
        self.bleeds["bottom"] = dimensions.Dim(0),
        self.bleeds["document"] = False

        # -------------------------------------------------------

        printer=""
        filename=""
        separationName=""
        printerCommand=""
Exemple #2
0
    def __init__(self):
        self.pages = []
        self.page_objects = []

        self.bleed = {
            "top": dimensions.Dim(0),
            "right": dimensions.Dim(0),
            "left": dimensions.Dim(0),
            "bottom": dimensions.Dim(0)
        }
Exemple #3
0
    def fromxml(self, xml):
        self.side = False

        # Find the side of the table border -------------------------

        if xml.tag in TableBorder.sides_xml.values():

            for h, x in TableBorder.sides_xml.items():
                if x == xml.tag:
                    self.side = h
                    break

        if not self.side:
            msg = "Invalid side for TableBorder"

            if self.style_type == "table":
                msg += " in TableStyle"

            if self.style_type == "cell":
                msg += " in CellStyle"

            raise exceptions.InsaneSLAValue(msg)

        # If the table border's side was found ----------------------

        # -------------------------------------------------

        if (width := xml.get("Width")) is not None:
            self.width = dimensions.Dim(float(width))
    def __init__(self):
        super().__init__()

        self.pyscribus_defaults = [l[0] for l in LPI.DEFAULTS]

        # Linescreening angle
        self.angle = dimensions.Dim(0, "deg")

        # Name of the Colour for which these settings are ment
        self.color = ""

        # How many lines per Inch are used
        self.frequency = dimensions.Dim(133, "lpi")

        # Code for the used Spotfunction
        self.spot = "ellipse"
Exemple #5
0
    def fromxml(self, xml):
        is_paragraph = StyleAbstract.fromxml(self, xml, True)

        if is_paragraph:

            #--- Indentation ------------------------------------------------

            # Left indentation of all paragraph lines

            if (left := xml.get("INDENT")) is not None:
                self.indentations["left"] = dimensions.Dim(float(left))

            # Right indentation of all paragraph lines

            if (right := xml.get("RMARGIN")) is not None:
                self.indentations["right"] = dimensions.Dim(float(right))
Exemple #6
0
    def fromxml(self, xml):
        is_character = StyleAbstract.fromxml(self, xml, True)

        if is_character:
            #--- Hyphenation ------------------------------------------------

            if (hyphen_word := xml.get("HyphenWordMin")) is not None:
                try:
                    word_length = int(hyphen_word)

                    if word_length < 3:
                        raise InsaneSLAValue(
                            "HyphenWordMin in '{}' character style must be an integer >= 3."
                            .format(self.name))

                    self.hyphen_word_min = word_length

                except ValueError:
                    raise InsaneSLAValue(
                        "HyphenWordMin in '{}' character style must be an integer >= 3."
                        .format(self.name))

            #--- Font settings ----------------------------------------------

            if (wordtrack := xml.get("wordTrack")) is not None:
                self.font["space_width"] = dimensions.Dim(
                    float(wordtrack), "pcdecim")
Exemple #7
0
    def __init__(self, doc_parent, default=False, **kwargs):
        StyleAbstract.__init__(self, "character", doc_parent, default)
        StyleAbstract._quick_setup(self, kwargs)

        self.font["space_width"] = dimensions.Dim(1, "pcdecim")
        self.font["kerning"] = None

        self.hyphen_word_min = None
Exemple #8
0
    def _quick_setup(self, settings):
        """
        Method for defining style settings from class
        instanciation kwargs.

        :type settings: dict
        :param settings: Kwargs dictionnary
        """

        if settings:
            StyleAbstract._quick_setup(self, settings)

            for setting_name, setting_value in settings.items():

                if setting_name == "spacebefore":
                    self.space["before"] = dimensions.Dim(float(setting_value))

                if setting_name == "spaceafter":
                    self.space["after"] = dimensions.Dim(float(setting_value))

                if setting_name == "cparent":
                    self.character_parent = setting_value

                if setting_name == "leading":
                    if setting_value in ParagraphStyle.leading_xml:
                        self.leading["mode"] = setting_value

                if setting_name == "leadingValue":
                    self.leading["value"] = dimensions.Dim(
                        float(setting_value))

                if setting_name == "alignment":

                    if setting_value.lower() in xmlc.alignment.keys():
                        self.font["alignment"] = setting_value
                    else:
                        raise ValueError(
                            "Wrong alignement setting '{}'. "
                            "Alignement setting must be {}".format(
                                setting_value,
                                ", ".join(xmlc.alignment.keys())))
Exemple #9
0
    def fromxml(self, xml: ET._Element):
        """
        """

        if xml.tag == "Pattern":

            if (name := xml.get("Name")) is not None:
                self.name = name

            for dim in ["width", "height"]:

                if (att := xml.get(dim)) is not None:
                    self.dims[dim] = dimensions.Dim(float(att))
Exemple #10
0
class Pattern(PyScribusElement):
    """
    Pattern in SLA (Pattern)

    :type sla_parent: pyscribus.sla.SLA
    :param sla_parent: SLA parent instance
    :type doc_parent: pyscribus.document.Document
    :param doc_parent: SLA DOCUMENT instance
    """

    # <Pattern
    #     xoffset="0"
    #     yoffset="0"
    # >

    def __init__(self, sla_parent=False, doc_parent=False):
        super().__init__()

        self.name = None

        self.items = []

        self.sla_parent = sla_parent
        self.doc_parent = doc_parent

        # NOTE We do not set a dimensions.DimBox because patterns is not meant
        # to be used directly on the page

        self.dims = {"width": None, "height": None}

        self.scale = {"x": None, "y": None}

    def fromxml(self, xml: ET._Element):
        """
        """

        if xml.tag == "Pattern":

            if (name := xml.get("Name")) is not None:
                self.name = name

            for dim in ["width", "height"]:

                if (att := xml.get(dim)) is not None:
                    self.dims[dim] = dimensions.Dim(float(att))

            for scale in ["x", "x"]:
                att_name = "scale{}".format(scale.upper())

                if (att := xml.get(att_name)) is not None:
                    self.scale[scale] = dimensions.Dim(float(att), "pcdecim")
Exemple #11
0
class CharacterStyle(StyleAbstract):
    """
    Character style in SLA (CHARSTYLE)

    :type default: boolean
    :param default: Use default settings (False by default)
    :type kwargs: dict
    :param kwargs: Quick setting (see kwargs table)

    +--------------+-----------------------------+----------+
    | Kwargs       | Setting                     | Type     |
    +==============+=============================+==========+
    | name         | Style name                  | string   |
    +--------------+-----------------------------+----------+
    | defaultstyle | Scribus default character   | boolean  |
    |              | style ?                     | boolean  |
    +--------------+-----------------------------+----------+
    | parent       | Parent style name           | string   |
    +--------------+-----------------------------+----------+
    | font         | Font name                   | string   |
    +--------------+-----------------------------+----------+
    | fontsize     | Font size                   | string   |
    +--------------+-----------------------------+----------+
    | default      | Equivalent to a fromdefault | boolean, |
    |              | call, value being True or   | string   |
    |              | the default name.           |          |
    +--------------+-----------------------------+----------+
    """
    def __init__(self, doc_parent, default=False, **kwargs):
        StyleAbstract.__init__(self, "character", doc_parent, default)
        StyleAbstract._quick_setup(self, kwargs)

        self.font["space_width"] = dimensions.Dim(1, "pcdecim")
        self.font["kerning"] = None

        self.hyphen_word_min = None

    def fromxml(self, xml):
        is_character = StyleAbstract.fromxml(self, xml, True)

        if is_character:
            #--- Hyphenation ------------------------------------------------

            if (hyphen_word := xml.get("HyphenWordMin")) is not None:
                try:
                    word_length = int(hyphen_word)

                    if word_length < 3:
                        raise InsaneSLAValue(
                            "HyphenWordMin in '{}' character style must be an integer >= 3."
                            .format(self.name))

                    self.hyphen_word_min = word_length

                except ValueError:
                    raise InsaneSLAValue(
                        "HyphenWordMin in '{}' character style must be an integer >= 3."
                        .format(self.name))

            #--- Font settings ----------------------------------------------

            if (wordtrack := xml.get("wordTrack")) is not None:
                self.font["space_width"] = dimensions.Dim(
                    float(wordtrack), "pcdecim")

            if (kerning := xml.get("KERN")) is not None:
                self.font["kerning"] = dimensions.Dim(float(kerning), "pc")
Exemple #12
0
    def __init__(self):
        super().__init__()

        self.type = False
        self.fill = False
        self.position = dimensions.Dim(0, "pica")
Exemple #13
0
                if (font_size := xml.get("FONTSIZE")) is not None:
                    self.font["size"] = float(font_size)

                if (font_features := xml.get("FONTFEATURES")) is not None:
                    self.font["features"] = font_features.split(",")

                if (font_color := xml.get("FCOLOR")) is not None:
                    self.font["color"] = font_color

                # NOTE Weird FEATURES duplicate
                if (features := xml.get("FEATURES")) is not None:
                    self.features = features

                if (strike_width := xml.get("TXTSTW")) is not None:
                    self.font["strike"]["width"] = dimensions.Dim(
                        float(strike_width), "pcdecim")

                if (strike_offset := xml.get("TXTSTP")) is not None:
                    self.font["strike"]["offset"] = dimensions.Dim(
                        float(strike_offset), "pcdecim")

                if (underline_width := xml.get("TXTULW")) is not None:
                    self.font["underline"]["width"] = dimensions.Dim(
                        float(underline_width), "pcdecim")

                if (underline_offset := xml.get("TXTULP")) is not None:
                    self.font["underline"]["offset"] = dimensions.Dim(
                        float(underline_offset), "pcdecim")

                if (shadow_hoffset := xml.get("TXTSHX")) is not None:
                    self.font["shadow"]["hoffset"] = dimensions.Dim(
Exemple #14
0
class ParagraphStyle(StyleAbstract):
    """
    Paragraph style in SLA (STYLE)

    :type default: boolean
    :param default: Use default settings (False by default)
    :type kwargs: dict
    :param kwargs: Quick setting (see kwargs table)

    +--------------+------------------------------------+
    | Kwargs       | Setting                            |
    +==============+====================================+
    | name         | Style name                         |
    +--------------+------------------------------------+
    | defaultstyle | Scribus default paragraph style?   |
    +--------------+------------------------------------+
    | parent       | Parent style name (paragraph)      |
    +--------------+------------------------------------+
    | cparent      | Parent style name (character)      |
    +--------------+------------------------------------+
    | alignment    | Text alignment. Must be in         |
    |              | ``pyscribus.common.xml.alignment`` |
    |              | keys                               |
    +--------------+------------------------------------+
    | font         | Font name                          |
    +--------------+------------------------------------+
    | fontsize     | Font size                          |
    +--------------+------------------------------------+
    | spacebefore  | Space before paragraph             |
    +--------------+------------------------------------+
    | spaceafter   | Space after paragraph              |
    +--------------+------------------------------------+
    | leading      | Leading mode. Must be in           |
    |              | ``ParagraphStyle.leading_xml``.    |
    |              | If "fixed" mode, you must define   |
    |              | leadingValue setting.              |
    +--------------+------------------------------------+
    | leadingValue | Leading value in pica points if    |
    |              | leading mode is "fixed".           |
    +--------------+------------------------------------+
    | default      | Equivalent to a fromdefault        |
    |              | call, value being True or the      |
    |              | default name                       |
    +--------------+------------------------------------+

    :Example:

    .. code:: python

       title_style = styles.ParagraphStyle(
           name="Title", fontsize=18, alignment="center",
           leading="fixed", leadingValue=16
       )

       normal_style = styles.ParagraphStyle(
           name="Normal", fontsize=12, alignment="justify",
           leading="automatic"
       )

    """

    leading_xml = {
        "fixed": "0",
        "automatic": "1",
        "grid": "2",
    }

    def __init__(self, doc_parent, default=False, **kwargs):
        StyleAbstract.__init__(self, "paragraph", doc_parent, default)

        self.indentations = {"left": None, "right": None, "first-line": None}

        self.listing = {"type": None, "char": None}

        self._quick_setup(kwargs)

    def fromxml(self, xml):
        is_paragraph = StyleAbstract.fromxml(self, xml, True)

        if is_paragraph:

            #--- Indentation ------------------------------------------------

            # Left indentation of all paragraph lines

            if (left := xml.get("INDENT")) is not None:
                self.indentations["left"] = dimensions.Dim(float(left))

            # Right indentation of all paragraph lines

            if (right := xml.get("RMARGIN")) is not None:
                self.indentations["right"] = dimensions.Dim(float(right))

            # Indentation of the first line of the paragraph

            if (first := xml.get("FIRST")) is not None:
                self.indentations["first-line"] = dimensions.Dim(float(first))
Exemple #15
0
    def __init__(self, style_type, doc_parent, default=False, **kwargs):
        super().__init__()

        self.doc_parent = doc_parent

        if not style_type.lower() in StyleAbstract.type_xml.keys():
            raise ValueError("Unknown style type for StyleAbstract")

        self.style_type = style_type.lower()

        self.name = ""
        self.parent = None

        self.is_default = False

        if self.style_type in ["paragraph", "character"]:
            # TODO FIXME Handle font features as a dict instead
            # of a list, like in other styles
            # Features: -clig, inherit

            self.font = {
                "name": "",
                "size": 0,
                "features": [],
                "color": "",
                "alignment": "left",
                "strike": {
                    "width": None,
                    "offset": None
                },
                "underline": {
                    "width": None,
                    "offset": None
                },
                "shadow": {
                    "hoffset": None,
                    "voffset": None
                },
                # NOTE There is no offset setting for outline, obviously
                "outline": {
                    "width": None
                },
            }

            # NOTE Weird, but FONTFEATURES is not the same as FEATURES
            # even if it has obviously an effect on fonts...
            self.features = {}

            self.lang = None
            self.shortcut = None

        if self.style_type in ["table", "cell", "character", "paragraph"]:
            self.fill = {"color": None, "shade": None}

        if self.style_type in ["table", "cell"]:
            self.borders = []

        if self.style_type == "character":
            self.scale = {"horizontal": 100, "vertical": 100}

        if self.style_type == "cell":
            self.padding = {"left": 0, "right": 0, "top": 0, "bottom": 0}

        if self.style_type == "paragraph":
            self.tabs = []
            self.character_parent = ""

            self.space = {
                "after": None,
                "before": None,
            }

            self.leading = {"mode": None, "value": dimensions.Dim(0)}

        if default:
            self.fromdefault()

        if kwargs:
            self._quick_setup(kwargs)
Exemple #16
0
 def fromdefault(self):
     self.end = "flat"
     self.join = "pointy"
     self.opacity = dimensions.Dim(100, "pc")
Exemple #17
0
class RuleStyleLine(xmlc.PyScribusElement):
    """
    Sub-line in rule style in SLA (MultiLine/SubLine)
    """

    # Line end human <-> XML
    lineend_xml = {"square": "16", "round": "32", "flat": "0"}

    # Line join human <-> XML
    linejoin_xml = {"pointy": "0", "bevelled": "64", "round": "128"}

    # Line style human <-> XML
    dash_xml = {
        # Most common and named line styles
        "line": "1",
        "dashed": "2",
        "dots": "3",
        "line-dash": "4",
        "line-dash-dash": "5",

        # Here be dragons, and a lot of untitled line styles
        "untitled-6": "6",
        "untitled-7": "7",
        "untitled-8": "8",
        "untitled-9": "9",
        "untitled-10": "10",
        "untitled-11": "11",
        "untitled-12": "12",
        "untitled-13": "13",
        "untitled-14": "14",
        "untitled-15": "15",
        "untitled-16": "16",
        "untitled-17": "17",
        "untitled-18": "18",
        "untitled-19": "19",
        "untitled-20": "20",
        "untitled-21": "21",
        "untitled-22": "22",
        "untitled-23": "23",
        "untitled-24": "24",
        "untitled-25": "25",
        "untitled-26": "26",
        "untitled-27": "27",
        "untitled-28": "28",
        "untitled-29": "29",
        "untitled-30": "30",
        "untitled-31": "31",
        "untitled-32": "32",
        "untitled-33": "33",
        "untitled-34": "34",
        "untitled-35": "35",
        "untitled-36": "36",
        "untitled-37": "37",
    }

    def __init__(self):
        super().__init__()

        self.color = None
        self.shortcut = ""

        self.width = None
        self.opacity = None

        self.end = None
        self.join = None
        self.style = None

    def fromdefault(self):
        self.end = "flat"
        self.join = "pointy"
        self.opacity = dimensions.Dim(100, "pc")

    def fromxml(self, xml):
        """
        """

        if xml.tag == "SubLine":
            # --- Shortcut -----------------------------------------------

            if (shortcut := xml.get("Shortcut")) is not None:
                self.shortcut = shortcut

            # --- Color and opacity --------------------------------------

            if (color := xml.get("Color")) is not None:
                self.color = color

            if (opacity := xml.get("Shade")) is not None:
                self.opacity = dimensions.Dim(float(opacity), "pc")
Exemple #18
0
    def fromdefault(self):
        self.type = "left"
        self.fill = False
        self.position = dimensions.Dim(0, "pica")

        return True
    def __init__(self):
        super().__init__()

        self.lpi = []

        self.text_compression = True
        self.image_compression = {
            "method": "automatic",
            "quality": "max"
        }

        #-------------------------------------------------------

        # Flag, set to 1 when Presentation effects should be used
        PresentMode="0"

        #-------------------------------------------------------

        # Flag, set to 1 when Downsample Images is checked in the PDF-Options Dialog
        RecalcPic="0"
        # Resolution for downsampling Images
        PicRes="300"
        # Resolution for embedded EPS-Pictures or PDF's
        Resolution="300"

        #-------------------------------------------------------

        # (optional) Flag, set to 1 when Output should be in RGB
        RGBMode="1"

        # TODO : fromxml / toxml of this dict

        self.profiles = {
            "colors": {
                # (optional) Flag, set to 1 when ICC-Profiles should be used
                # for solid colours
                # UseProfiles="0"
                "used": False,
                # (optional) ICC-Profile for solid colours
                # SolidP="sRGB IEC61966-2.1"
                "name": "sRGB IEC61966-2.1"
            },
            "images": {
                # (optional) Flag, set to 1 when ICC-Profiles should be used
                # for images
                # UseProfiles2="0"
                "used": False,
                # ICC-Profile for images ?
                # ImageP="sRGB IEC61966-2.1"
                "name": "sRGB IEC61966-2.1"
            },
            "printer": {
                # (optional) ICC-Profile for the Printer, only used for 
                # PDF-X/3 output
                # PrintP="Fogra27L CMYK Coated Press"
                "name": "Fogra27L CMYK Coated Press"
            }
        }

        #-------------------------------------------------------

        self.bleeds = collections.OrderedDict()
        self.bleeds["top"] = dimensions.Dim(0),
        self.bleeds["left"] = dimensions.Dim(0),
        self.bleeds["right"] = dimensions.Dim(0),
        self.bleeds["bottom"] = dimensions.Dim(0),
        self.bleeds["document"] = False

        #-------------------------------------------------------

        bleedMarks="0"
        cropMarks="0"
        registrationMarks="0"
        colorMarks="0"
        docInfoMarks="0"
        markLength="20.0012598425197"
        markOffset="0"

        #-------------------------------------------------------

        self.encryption = {
            "pass": {"owner": "", "user": ""},
            "settings": {"permissions": "-4", "encrypted": False}
        }

        #-- FIXME Documented but to organize -------------------

        # (optional) Flag, set to 1 when the informations in the LPI tags should be used
        # for Linescreening
        UseLpi="0"
        # Binding for the PDF-Document 0 = Left Binding 1 = Right Binding
        Binding="0"
        # PDF-Version which should be generated 12 = PDF-X/3 13 = PDF-1.3 14 = PDF-1.4
        Version="14"
        # Flag, set to 1 when Generate Thumbnails is checked in the PDF-Options Dialog
        Thumbnails="0"
        # Flag, set to 1 when use PDF-Articles is checked in the PDF-Options Dialog
        Articles="0"
        # Flag, set to 1 when include Bookmarks is checked in the PDF-Options Dialog
        Bookmarks="0"
Exemple #20
0
    def fromdefault(self):
        StyleAbstract.fromdefault(self)

        self.leading = {"mode": None, "value": dimensions.Dim(12)}

        return True