diff --git a/docx/oxml/text/parfmt.py b/docx/oxml/text/parfmt.py index 466b11b1b..bf1210ae4 100644 --- a/docx/oxml/text/parfmt.py +++ b/docx/oxml/text/parfmt.py @@ -22,6 +22,7 @@ class CT_Ind(BaseOxmlElement): left = OptionalAttribute('w:left', ST_SignedTwipsMeasure) right = OptionalAttribute('w:right', ST_SignedTwipsMeasure) firstLine = OptionalAttribute('w:firstLine', ST_TwipsMeasure) + firstLineChars = OptionalAttribute('w:firstLineChars', ST_TwipsMeasure) hanging = OptionalAttribute('w:hanging', ST_TwipsMeasure) @@ -91,6 +92,37 @@ def first_line_indent(self, value): else: ind.firstLine = value + @property + def first_line_chars_indent(self): + """ + A |Length| value calculated from the values of `w:ind/@w:firstLineChars` + and `w:ind/@w:hanging`. Returns |None| if the `w:ind` child is not + present. + """ + ind = self.ind + if ind is None: + return None + hanging = ind.hanging + if hanging is not None: + return Length(-hanging) + firstLine = ind.firstLineChars + if firstLine is None: + return None + return firstLine + + @first_line_chars_indent.setter + def first_line_chars_indent(self, value): + if self.ind is None and value is None: + return + ind = self.get_or_add_ind() + ind.firstLineChars = ind.hanging = None + if value is None: + return + elif value < 0: + ind.hanging = -value + else: + ind.firstLineChars = value + @property def ind_left(self): """ diff --git a/docx/text/parfmt.py b/docx/text/parfmt.py index 37206729c..c9b1cdab7 100644 --- a/docx/text/parfmt.py +++ b/docx/text/parfmt.py @@ -58,6 +58,25 @@ def first_line_indent(self, value): pPr = self._element.get_or_add_pPr() pPr.first_line_indent = value + @property + def first_line_chars_indent(self): + """ + |Length| value specifying the relative difference in indentation for + the first line of the paragraph. A positive value causes the first + line to be indented. A negative value produces a hanging indent. + |None| indicates first line indentation is inherited from the style + hierarchy. + """ + pPr = self._element.pPr + if pPr is None: + return None + return pPr.first_line_chars_indent + + @first_line_chars_indent.setter + def first_line_chars_indent(self, value): + pPr = self._element.get_or_add_pPr() + pPr.first_line_chars_indent = value + @property def keep_together(self): """