77
88from docx .oxml .parts .numbering import CT_NumPr
99from docx .oxml .shared import (
10- CT_String , nsdecls , OxmlBaseElement , OxmlElement , oxml_fromstring , qn
10+ CT_String ,
11+ nsdecls , OxmlBaseElement , OxmlElement , oxml_fromstring , qn
1112)
1213from docx .enum .text import WD_UNDERLINE
1314
@@ -102,6 +103,46 @@ def style(self, style):
102103 """
103104 pPr = self .get_or_add_pPr ()
104105 pPr .style = style
106+
107+ @property
108+ def jc (self ):
109+ """
110+ String contained in w:val attribute of <w:pPr><w:jc> child, or
111+ None if that element is not present.
112+ """
113+ pPr = self .pPr
114+ if pPr is None :
115+ return None
116+ return pPr .jc
117+
118+ @jc .setter
119+ def jc (self , jc ):
120+ """
121+ Set style of this <w:p> element to *jc*. If *jc* is None,
122+ remove the style element.
123+ """
124+ pPr = self .get_or_add_pPr ()
125+ pPr .jc = jc
126+
127+ @property
128+ def textDirection (self ):
129+ """
130+ String contained in w:val attribute of <w:pPr><w:textDirection> child,
131+ or None if that element is not present.
132+ """
133+ pPr = self .pPr
134+ if pPr is None :
135+ return None
136+ return pPr .textdirection
137+
138+ @textDirection .setter
139+ def textDirection (self , textdirection ):
140+ """
141+ Set style of this <w:p> element to *style*. If *style* is None,
142+ remove the style element.
143+ """
144+ pPr = self .get_or_add_pPr ()
145+ pPr .textdirection = textdirection
105146
106147 def _add_pPr (self ):
107148 """
@@ -133,6 +174,15 @@ def get_or_add_pStyle(self):
133174 if pStyle is None :
134175 pStyle = self ._add_pStyle ()
135176 return pStyle
177+
178+ def get_or_add_textDirectionElement (self ):
179+ """
180+ Return the textDirection child element, newly added if not present.
181+ """
182+ textDirection = self .textDirection
183+ if textDirection is None :
184+ textDirection = self ._add_textDirection ()
185+ return textDirection
136186
137187 @staticmethod
138188 def new ():
@@ -186,6 +236,80 @@ def style(self, style):
186236 self ._add_pStyle (style )
187237 else :
188238 self .pStyle .val = style
239+
240+ @property
241+ def jcElement (self ):
242+ """
243+ ``<w:jc>`` child element or None if not present.
244+ """
245+ return self .find (qn ('w:jc' ))
246+
247+ def remove_jcElement (self ):
248+ jcElement = self .jcElement
249+ if jcElement is not None :
250+ self .remove (jcElement )
251+
252+ @property
253+ def jc (self ):
254+ """
255+ String contained in <w:jc> child, or None if that element is
256+ not present.
257+ """
258+ jc = self .jcElement
259+ if jc is None :
260+ return None
261+ return jc .get (qn ('w:val' ))
262+
263+ @jc .setter
264+ def jc (self , jc ):
265+ """
266+ Set val attribute of <w:jc> child element to *jc*, adding a
267+ new element if necessary. If *jc* is |None|, remove the <w:jc>
268+ element if present.
269+ """
270+ if jc is None :
271+ self .remove_jcDirection ()
272+ elif self .jcElement is None :
273+ self ._add_jcElement (jc )
274+ else :
275+ self .jcElement .val = jc
276+
277+ @property
278+ def textDirectionElement (self ):
279+ """
280+ ``<w:pStyle>`` child element or None if not present.
281+ """
282+ return self .find (qn ('w:textDirection' ))
283+
284+ def remove_textDirectionElement (self ):
285+ textDirectionElement = self .textDirectionElement
286+ if textDirectionElement is not None :
287+ self .remove (textDirectionElement )
288+
289+ @property
290+ def textDirection (self ):
291+ """
292+ String contained in <w:textDirection> child, or None if that element is
293+ not present.
294+ """
295+ textDirection = self .textDirectionElement
296+ if textDirection is None :
297+ return None
298+ return textDirection .get (qn ('w:val' ))
299+
300+ @textDirection .setter
301+ def textDirection (self , textDirection ):
302+ """
303+ Set val attribute of <w:textDirection> child element to
304+ *textDirection*, adding a new element if necessary. If *textDirection*
305+ is |None|, remove the <w:textDirection> element if present.
306+ """
307+ if textDirection is None :
308+ self .remove_textDirectionElement ()
309+ elif self .textDirectionElement is None :
310+ self ._add_textDirectionElement (textDirection )
311+ else :
312+ self .textDirectionElement .val = textDirection
189313
190314 def _add_numPr (self ):
191315 numPr = CT_NumPr .new ()
@@ -194,6 +318,14 @@ def _add_numPr(self):
194318 def _add_pStyle (self , style ):
195319 pStyle = CT_String .new_pStyle (style )
196320 return self ._insert_pStyle (pStyle )
321+
322+ def _add_jcElement (self , jc ):
323+ jcElement = CT_String .new ('w:jc' , jc )
324+ return self ._insert_jcElement (jcElement )
325+
326+ def _add_textDirectionElement (self , textDirection ):
327+ textDirectionElement = CT_String .new ('w:textDirection' , textDirection )
328+ return self ._insert_textDirectionElement (textDirectionElement )
197329
198330 def _insert_numPr (self , numPr ):
199331 return self .insert_element_before (
@@ -210,7 +342,20 @@ def _insert_numPr(self, numPr):
210342 def _insert_pStyle (self , pStyle ):
211343 self .insert (0 , pStyle )
212344 return pStyle
213-
345+
346+ def _insert_jcElement (self , jc ):
347+ return self .insert_element_before (
348+ jc , 'w:textDirection' , 'w:textAlignment' , 'w:textboxTightWrap' ,
349+ 'w:outlineLvl' , 'w:divId' , 'w:cnfStyle' , 'w:rPr' , 'w:sectPr' ,
350+ 'w:pPrChange'
351+ )
352+
353+ def _insert_textDirectionElement (self , textDirection ):
354+ return self .insert_element_before (
355+ textDirection , 'w:textAlignment' , 'w:textboxTightWrap' ,
356+ 'w:outlineLvl' , 'w:divId' , 'w:cnfStyle' , 'w:rPr' , 'w:sectPr' ,
357+ 'w:pPrChange'
358+ )
214359
215360class CT_R (OxmlBaseElement ):
216361 """
0 commit comments