|
| 1 | + |
| 2 | +Paragraph Style |
| 3 | +=============== |
| 4 | + |
| 5 | +A paragraph style provides character formatting (font) as well as paragraph |
| 6 | +formatting properties. Character formatting is inherited from |
| 7 | +|_CharacterStyle| and is predominantly embodied in the :attr:`font` property. |
| 8 | +Likewise, most paragraph-specific properties come from the |ParagraphFormat| |
| 9 | +object available on the :attr:`paragraph_format` property. |
| 10 | + |
| 11 | +A handful of other properties are specific to a paragraph style. |
| 12 | + |
| 13 | + |
| 14 | +next_paragraph_style |
| 15 | +-------------------- |
| 16 | + |
| 17 | +The `next_paragraph_style` property provides access to the style that will |
| 18 | +automatically be assigned by Word to a new paragraph inserted after |
| 19 | +a paragraph with this style. This property is most useful for a style that |
| 20 | +would normally appear only once in a sequence, such as a heading. |
| 21 | + |
| 22 | +The default is to use the same style for an inserted paragraph. This |
| 23 | +addresses the most common case; for example, a body paragraph having `Body |
| 24 | +Text` style would normally be followed by a paragraph of the same style. |
| 25 | + |
| 26 | + |
| 27 | +Expected usage |
| 28 | +~~~~~~~~~~~~~~ |
| 29 | + |
| 30 | +The priority use case for this property is to provide a working style that |
| 31 | +can be assigned to a paragraph. The property will always provide a valid |
| 32 | +paragraph style, defaulting to the current style whenever a more specific one |
| 33 | +cannot be determined. |
| 34 | + |
| 35 | +While this obscures some specifics of the situation from the API, it |
| 36 | +addresses the expected most common use case. Developers needing to detect, |
| 37 | +for example, missing styles can readily use the oxml layer to inspect the |
| 38 | +XML and further features can be added if those use cases turn out to be more |
| 39 | +common than expected. |
| 40 | + |
| 41 | + |
| 42 | +Behavior |
| 43 | +~~~~~~~~ |
| 44 | + |
| 45 | +**Default.** The default next paragraph style is the same paragraph style. |
| 46 | + |
| 47 | +The default is used whenever the next paragraph style is not specified or is |
| 48 | +invalid, including these conditions: |
| 49 | + |
| 50 | +* No `w:next` child element is present |
| 51 | +* A style having the styleId specified in `w:next/@w:val` is not present in |
| 52 | + the document. |
| 53 | +* The style specified in `w:next/@w:val` is not a paragraph style. |
| 54 | + |
| 55 | +In all these cases the current style (`self`) is returned. |
| 56 | + |
| 57 | + |
| 58 | +Example XML |
| 59 | +~~~~~~~~~~~ |
| 60 | + |
| 61 | +.. highlight:: xml |
| 62 | + |
| 63 | +paragraph_style.next_paragraph_style is styles['Bar']:: |
| 64 | + |
| 65 | + <w:style w:type="paragraph" w:styleId="Foo"> |
| 66 | + <w:name w:val="Foo"/> |
| 67 | + <w:next w:val="Bar"/> |
| 68 | + </w:style> |
| 69 | + |
| 70 | +**Semantics.** The `w:next` child element is optional. |
| 71 | + |
| 72 | +* When omitted, the next style is the same as the current style. |
| 73 | +* If no style with a matching styleId exists, the `w:next` element is ignored |
| 74 | + and the next style is the same as the current style. |
| 75 | +* If a style is found but is of a style type other than paragraph, the |
| 76 | + `w:next` element is ignored and the next style is the same as the current |
| 77 | + style. |
| 78 | + |
| 79 | + |
| 80 | +Candidate protocol |
| 81 | +~~~~~~~~~~~~~~~~~~ |
| 82 | + |
| 83 | +.. highlight:: python |
| 84 | + |
| 85 | +:: |
| 86 | + |
| 87 | + >>> styles = document.styles |
| 88 | + |
| 89 | + >>> paragraph_style = styles['Foo'] |
| 90 | + >>> paragraph_style.next_paragraph_style == paragraph_style |
| 91 | + True |
| 92 | + |
| 93 | + >>> paragraph_style.next_paragraph_style = styles['Bar'] |
| 94 | + >>> paragraph_style.next_paragraph_style == styles['Bar'] |
| 95 | + True |
| 96 | + |
| 97 | + >>> paragraph_style.next_paragraph_style = None |
| 98 | + >>> paragraph_style.next_paragraph_style == paragraph_style |
| 99 | + True |
| 100 | + |
| 101 | + |
| 102 | +Schema excerpt |
| 103 | +-------------- |
| 104 | + |
| 105 | +.. highlight:: xml |
| 106 | + |
| 107 | +:: |
| 108 | + |
| 109 | + <xsd:complexType name="CT_Style"> |
| 110 | + <xsd:sequence> |
| 111 | + <xsd:element name="name" type="CT_String" minOccurs="0"/> |
| 112 | + <xsd:element name="aliases" type="CT_String" minOccurs="0"/> |
| 113 | + <xsd:element name="basedOn" type="CT_String" minOccurs="0"/> |
| 114 | + <xsd:element name="next" type="CT_String" minOccurs="0"/> |
| 115 | + <xsd:element name="link" type="CT_String" minOccurs="0"/> |
| 116 | + <xsd:element name="autoRedefine" type="CT_OnOff" minOccurs="0"/> |
| 117 | + <xsd:element name="hidden" type="CT_OnOff" minOccurs="0"/> |
| 118 | + <xsd:element name="uiPriority" type="CT_DecimalNumber" minOccurs="0"/> |
| 119 | + <xsd:element name="semiHidden" type="CT_OnOff" minOccurs="0"/> |
| 120 | + <xsd:element name="unhideWhenUsed" type="CT_OnOff" minOccurs="0"/> |
| 121 | + <xsd:element name="qFormat" type="CT_OnOff" minOccurs="0"/> |
| 122 | + <xsd:element name="locked" type="CT_OnOff" minOccurs="0"/> |
| 123 | + <xsd:element name="personal" type="CT_OnOff" minOccurs="0"/> |
| 124 | + <xsd:element name="personalCompose" type="CT_OnOff" minOccurs="0"/> |
| 125 | + <xsd:element name="personalReply" type="CT_OnOff" minOccurs="0"/> |
| 126 | + <xsd:element name="rsid" type="CT_LongHexNumber" minOccurs="0"/> |
| 127 | + <xsd:element name="pPr" type="CT_PPrGeneral" minOccurs="0"/> |
| 128 | + <xsd:element name="rPr" type="CT_RPr" minOccurs="0"/> |
| 129 | + <xsd:element name="tblPr" type="CT_TblPrBase" minOccurs="0"/> |
| 130 | + <xsd:element name="trPr" type="CT_TrPr" minOccurs="0"/> |
| 131 | + <xsd:element name="tcPr" type="CT_TcPr" minOccurs="0"/> |
| 132 | + <xsd:element name="tblStylePr" type="CT_TblStylePr" minOccurs="0" maxOccurs="unbounded"/> |
| 133 | + </xsd:sequence> |
| 134 | + <xsd:attribute name="type" type="ST_StyleType"/> |
| 135 | + <xsd:attribute name="styleId" type="s:ST_String"/> |
| 136 | + <xsd:attribute name="default" type="s:ST_OnOff"/> |
| 137 | + <xsd:attribute name="customStyle" type="s:ST_OnOff"/> |
| 138 | + </xsd:complexType> |
| 139 | + |
| 140 | + <xsd:complexType name="CT_String"> |
| 141 | + <xsd:attribute name="val" type="s:ST_String" use="required"/> |
| 142 | + </xsd:complexType> |
0 commit comments