Commit b44cd6c7 authored by Etienne Nadji's avatar Etienne Nadji
Browse files

Text object : padding, vertical align, is_autotext

	modifié :         articles/en/spec.rst
	modifié :         pyscribus/exceptions.py
	modifié :         pyscribus/pageobjects.py
parent 700d4af4
[EN] SLA document-able attributes
=================================
In all XPath location path listed here, we omit ``/SCRIBUSUTF8NEW/DOCUMENT``.
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| XML | Explanation | Value | Default | Optional |
| element/attribute | | | | |
+===================================+=======================+====================+==================+==========+
| ``/@DPInCMYK`` | ICC profile for CMYK | string | | Yes |
| | images | | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/@DPIn3`` | ICC profile for CMYK | string | | Yes |
| | colors | | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/@PAGEC`` | Scribus GUI page | hexadecimal color | ``#ffffff`` | |
| | background | | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/LAYERS/@FLOW`` | | integer as boolean | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/LAYERS/@TRANS`` | Layer’s opacity | percentage | ``1`` | |
| | | 0 -> 1 | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/LAYERS/@BLEND`` | Layer blend mode | | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/LAYERS/@OUTL`` | Flag for wireframe | integer as boolean | ``0`` | |
| | view | | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/LAYERS/@LAYERS`` | Color outline of the | hexadecimal color | | |
| | layer’s frames | | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/CHARSTYLE/@DefaultStyle`` | Same as STYLE, but | string | | |
| | not documented | | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/CHARSTYLE/@wordTrack`` | Space width | Percentage | | |
| | | 0 -> 1 | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/CHARSTYLE/@KERN`` | Kerning | Percentage | | |
| | | 0 -> 100 | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/Sections/Section/@FillChar`` | | Unicode code | ``0`` | |
| | | point of character | (NULL character) | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/Sections/Section/@FieldWidth`` | | | ``0`` | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/PAGEOBJECT/@path`` | Path data | SVG path/@d string | ``0`` | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
| ``/PAGEOBJECT/@copath`` | Path data | Same as @path | | |
+-----------------------------------+-----------------------+--------------------+------------------+----------+
DOCUMENT
--------
Omitted XPath : ``/SCRIBUSUTF8NEW/DOCUMENT``.
+--------------------+-----------------------+--------------------+-------------+----------+
| XML | Explanation | Value | Default | Optional |
| element/attribute | | | | |
+====================+=======================+====================+=============+==========+
| ``/@DPInCMYK`` | ICC profile for CMYK | string | | Yes |
| | images | | | |
+--------------------+-----------------------+--------------------+-------------+----------+
| ``/@DPIn3`` | ICC profile for CMYK | string | | Yes |
| | colors | | | |
+--------------------+-----------------------+--------------------+-------------+----------+
| ``/@PAGEC`` | Scribus GUI page | hexadecimal color | ``#ffffff`` | |
| | background | | | |
+--------------------+-----------------------+--------------------+-------------+----------+
| ``/LAYERS/@FLOW`` | | integer as boolean | | |
+--------------------+-----------------------+--------------------+-------------+----------+
| ``/LAYERS/@TRANS`` | Layer’s opacity | percentage | ``1`` | |
| | | 0 -> 1 | | |
+--------------------+-----------------------+--------------------+-------------+----------+
DOCUMENT/LAYERS
---------------
Omitted XPath : ``/SCRIBUSUTF8NEW/DOCUMENT``.
+---------------------+-----------------------+--------------------+---------+----------+
| XML | Explanation | Value | Default | Optional |
| element/attribute | | | | |
+=====================+=======================+====================+=========+==========+
| ``/LAYERS/@BLEND`` | Layer blend mode | | | |
+---------------------+-----------------------+--------------------+---------+----------+
| ``/LAYERS/@OUTL`` | Flag for wireframe | integer as boolean | ``0`` | |
| | view | | | |
+---------------------+-----------------------+--------------------+---------+----------+
| ``/LAYERS/@LAYERS`` | Color outline of the | hexadecimal color | | |
| | layer’s frames | | | |
+---------------------+-----------------------+--------------------+---------+----------+
DOCUMENT/CHARSTYLE
------------------
Omitted XPath : ``/SCRIBUSUTF8NEW/DOCUMENT``.
+------------------------------+--------------------+------------+---------+----------+
| XML | Explanation | Value | Default | Optional |
| element/attribute | | | | |
+==============================+====================+============+=========+==========+
| ``/CHARSTYLE/@DefaultStyle`` | Same as STYLE, but | string | | |
| | not documented | | | |
+------------------------------+--------------------+------------+---------+----------+
| ``/CHARSTYLE/@wordTrack`` | Space width | Percentage | | |
| | | 0 -> 1 | | |
+------------------------------+--------------------+------------+---------+----------+
| ``/CHARSTYLE/@KERN`` | Kerning | Percentage | | |
| | | 0 -> 100 | | |
+------------------------------+--------------------+------------+---------+----------+
DOCUMENT/Sections
-----------------
Omitted XPath : ``/SCRIBUSUTF8NEW/DOCUMENT``.
+-------------------------------------+-------------+--------------------+------------------+----------+
| XML | Explanation | Value | Default | Optional |
| element/attribute | | | | |
+=====================================+=============+====================+==================+==========+
| ``/Sections/Section/@FillChar`` | | Unicode code | ``0`` | |
| | | point of character | (NULL character) | |
+-------------------------------------+-------------+--------------------+------------------+----------+
| ``/Sections/Section/@FieldWidth`` | | | ``0`` | |
+-------------------------------------+-------------+--------------------+------------------+----------+
DOCUMENT/PAGEOBJECT
-------------------
Omitted XPath : ``/SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT``.
+--------------------------+--------------------+--------------------+---------+----------+
| XML | Explanation | Value | Default | Optional |
| element/attribute | | | | |
+==========================+====================+====================+=========+==========+
| ``/@path`` | Path data | SVG path/@d string | ``0`` | |
+--------------------------+--------------------+--------------------+---------+----------+
| ``/@copath`` | Path data | Same as @path | | |
+--------------------------+--------------------+--------------------+---------+----------+
| ``[@PTYPE="4"]/@VAlign`` | Vertical alignment | Same as @path | ``0`` | No |
| | of the text within | 0 = top | | |
| | the frame | 1 = center | | |
| | | 2 = bottom | | |
+--------------------------+--------------------+--------------------+---------+----------+
Notes
-----
......
......@@ -64,6 +64,14 @@ class UnknownOrEmptyItemAttributeType(Exception):
"""
pass
# --- Quick setup ----------------------------------------------
class QuickSetupInvalidValue(Exception):
"""
Exception raised when a quick setup value is invalid.
"""
pass
# --- Unknown SLA references -----------------------------------
class UnknownLayer(Exception):
......
......@@ -524,15 +524,6 @@ class PageObject(xmlc.PyScribusElement):
if (pattern := xml.get("pattern")) is not None:
self.pattern = pattern
# --- Text object attributes ---------------------------------
# FIXME FIXME FIXME Gné ? C’est déjà dans TextObject
if self.ptype == "text":
colsgap = xml.get("COLGAP")
if colsgap is not None:
self.columns["gap"].value = float(colsgap)
# --- Page objects specific children -------------------------
# Moved in TableObject
# Moved in TableObject
......@@ -670,21 +661,6 @@ class PageObject(xmlc.PyScribusElement):
if self.ptype in ["image", "render"]:
xml.attrib["EMBEDDED"] = xmlc.bool_to_num(self.use_embedded_icc)
# ------------------------------------------------------------
if self.ptype == "text":
xml.attrib["COLUMNS"] = str(self.columns["count"])
xml.attrib["COLGAPS"] = self.columns["gap"].toxmlstr()
if self.alignment is not None:
xml.attrib["ALIGN"] = xmlc.alignment[self.alignment]
if self.have_stories:
for story in self.stories:
sx = story.toxml()
xml.append(sx)
# --- Previous / Next item -----------------------------------
# NOTE @NEXTITEM must be the @ItemID of the next EXISTING item
......@@ -705,7 +681,7 @@ class PageObject(xmlc.PyScribusElement):
#--- FIXME This exports undocumented attributes -------
if self.ptype not in ["table", "group"]:
if self.ptype not in ["table", "group", "text"]:
try:
xml, undoc_attribs = xmlc.all_undocumented_to_xml(
......@@ -1586,6 +1562,12 @@ class TextObject(PageObject):
+------------+-------------------------------+-----------+
"""
vertical_alignment_xml = {
"top": "0",
"center": "1",
"bottom": "2"
}
def __init__(self, sla_parent=False, doc_parent=False, **kwargs):
PageObject.__init__(self, "text", sla_parent, doc_parent)
......@@ -1598,7 +1580,17 @@ class TextObject(PageObject):
"count": 0
}
self.is_autotext = False
self.padding = {
"left": dimensions.Dim(0),
"right": dimensions.Dim(0),
"bottom": dimensions.Dim(0),
"top": dimensions.Dim(0),
}
self.alignment = None
self.vertical_alignment = "top"
#--- Then, quick setup -------------------------------------------
......@@ -1618,6 +1610,23 @@ class TextObject(PageObject):
for setting_name, setting_value in settings.items():
if setting_name == "valign":
setting_value = setting_value.lower()
if setting_value in TextObject.vertical_alignment_xml:
self.vertical_alignment = setting_value
else:
raise exceptions.QuickSetupInvalidValue(
"valign setting value must be in [{}].".format(
", ".join(
[
"'{}'".format(v)
for v in TextObject.vertical_alignment_xml.values()
]
)
)
)
if setting_name == "columns":
self.columns["count"] = int(setting_value)
......@@ -1655,10 +1664,39 @@ class TextObject(PageObject):
# --- Attributes ---------------------------------------------
# NOTE FIXME
# PLTSHOW |(optional) Set to 1 if the path of a Text on a path
# |should be shown
# BASEOF |(optional) Offset for the text from its path for text
# |on a path
# NOTE FIXME
# Undocumented :
#
# textPathType
# textPathFlipped
# FLOP
if (valign := xml.get("VAlign")) is not None:
for human, code in TextObject.vertical_alignment_xml.items():
if valign == code:
self.vertical_alignment = human
break
if (autotext := xml.get("AUTOTEXT")) is not None:
self.is_autotext = xmlc.num_to_bool(autotext)
for case in [
["left", "EXTRA"], ["right", "REXTRA"],
["bottom", "BEXTRA"], ["top", "TEXTRA"]]:
if (padding_arg := xml.get(case[1])) is not None:
self.padding[case[0]].value = float(padding_arg)
if (columns := xml.get("COLUMNS")) is not None:
self.columns["count"] = int(columns)
if (columnsgap := xml.get("COLGAPS")) is not None:
if (columnsgap := xml.get("COLGAP")) is not None:
self.columns["gap"].value = float(columnsgap)
if (alignment := xml.get("ALIGN")) is not None:
......@@ -1706,6 +1744,59 @@ class TextObject(PageObject):
return False
def toxml(self):
"""
:rtype: lxml.etree._Element
:returns: Table object as LXML element
"""
xml = PageObject.toxml(self)
if isinstance(xml, ET._Element):
#--- Attributes ----------------------------------------------
xml.attrib["COLUMNS"] = str(self.columns["count"])
xml.attrib["COLGAP"] = self.columns["gap"].toxmlstr()
if self.alignment is not None:
xml.attrib["ALIGN"] = xmlc.alignment[self.alignment]
xml.attrib["VAlign"] = TextObject.vertical_alignment_xml[self.vertical_alignment]
# Padding
for case in [
["left", "EXTRA"], ["right", "REXTRA"],
["bottom", "BEXTRA"], ["top", "TEXTRA"]]:
xml.attrib[case[1]] = self.padding[case[0]].toxmlstr(True)
xml.attrib["AUTOTEXT"] = xmlc.bool_to_num(self.is_autotext)
#--- FIXME This exports undocumented attributes --------------
try:
xml, undoc_attribs = xmlc.all_undocumented_to_xml(
xml, self.undocumented, True,
self.ptype + " frame '" + self.name + "'"
)
except AttributeError:
# NOTE If fromxml was not used
pass
# --- Children -----------------------------------------------
if self.have_stories:
for story in self.stories:
sx = story.toxml()
xml.append(sx)
return xml
return False
class TextOnPathObject(PageObject):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment