|
2 | 2 | Styles |
3 | 3 | ====== |
4 | 4 |
|
| 5 | +.. toctree:: |
| 6 | + :titlesonly: |
| 7 | + |
| 8 | + styles |
| 9 | + style |
| 10 | + latent-styles |
| 11 | + |
5 | 12 | Word supports the definition of *styles* to allow a group of formatting |
6 | 13 | properties to be easily and consistently applied to a paragraph, run, table, |
7 | | -or numbering scheme; all at once. The mechanism is similar to how Cascading |
| 14 | +or numbering scheme, all at once. The mechanism is similar to how Cascading |
8 | 15 | Style Sheets (CSS) works with HTML. |
9 | 16 |
|
10 | 17 | Styles are defined in the ``styles.xml`` package part and are keyed to |
11 | 18 | a paragraph, run, or table using the `styleId` string. |
12 | 19 |
|
13 | | - |
14 | | -Latent style candidate protocol |
15 | | -------------------------------- |
16 | | - |
17 | | -:: |
18 | | - |
19 | | - >>> latent_styles = document.styles.latent_styles |
20 | | - >>> latent_styles |
21 | | - <docx.styles.LatentStyles object at 0x1045dd550> |
22 | | - |
23 | | - >>> latent_styles.default_locked_state |
24 | | - False |
25 | | - >>> latent_styles.default_locked_state = True |
26 | | - >>> latent_styles.default_locked_state |
27 | | - True |
28 | | - |
29 | | - >>> latent_styles.default_hidden |
30 | | - False |
31 | | - >>> latent_styles.default_hidden = True |
32 | | - >>> latent_styles.default_hidden |
33 | | - True |
34 | | - |
35 | | - >>> exception = latent_styles.exceptions[0] |
36 | | - |
37 | | - >>> exception.name |
38 | | - 'Normal' |
39 | | - |
40 | | - >>> exception.priority |
41 | | - None |
42 | | - >>> exception.priority = 10 |
43 | | - >>> exception.priority |
44 | | - True |
45 | | - |
46 | | - >>> exception.locked |
47 | | - None |
48 | | - >>> exception.locked = True |
49 | | - >>> exception.locked |
50 | | - True |
51 | | - |
52 | | - >>> exception.quick_style |
53 | | - None |
54 | | - >>> exception.quick_style = True |
55 | | - >>> exception.quick_style |
56 | | - True |
57 | | - |
58 | | - |
59 | | -Latent style behavior |
60 | | ---------------------- |
61 | | - |
62 | | -* A style has two categories of attribute, *behavioral* and *formatting*. |
63 | | - Behavioral attributes specify where and when the style should appear in the |
64 | | - user interface. Behavioral attributes can be specified for latent styles |
65 | | - using the ``<w:latentStyles>`` element and its ``<w:lsdException>`` child |
66 | | - elements. The 5 behavioral attributes are: |
67 | | - |
68 | | - + locked |
69 | | - + uiPriority |
70 | | - + semiHidden |
71 | | - + unhideWhenUsed |
72 | | - + qFormat |
73 | | - |
74 | | -* **locked**. The `locked` attribute specifies that the style should not |
75 | | - appear in any list or the gallery and may not be applied to content. This |
76 | | - behavior is only active when restricted formatting is turned on. |
77 | | - |
78 | | - Locking is turned on via the menu: Developer Tab > Protect Document > |
79 | | - Formatting Restrictions (Windows only). |
80 | | - |
81 | | -* **uiPriority**. The `uiPriority` attribute acts as a sort key for |
82 | | - sequencing style names in the user interface. Both the lists in the styles |
83 | | - panel and the Style Gallery are sensitive to this setting. Its effective |
84 | | - value is 0 if not specified. |
85 | | - |
86 | | -* **semiHidden**. The `semiHidden` attribute causes the style to be excluded |
87 | | - from the recommended list. The notion of *semi* in this context is that |
88 | | - while the style is hidden from the recommended list, it still appears in |
89 | | - the "All Styles" list. This attribute is removed on first application of |
90 | | - the style if an `unhideWhenUsed` attribute set |True| is also present. |
91 | | - |
92 | | -* **unhideWhenUsed**. The `unhideWhenUsed` attribute causes any `semiHidden` |
93 | | - attribute to be removed when the style is first applied to content. Word |
94 | | - does *not* remove the `semiHidden` attribute just because there exists an |
95 | | - object in the document having that style. The `unhideWhenUsed` attribute is |
96 | | - not removed along with the `semiHidden` attribute when the style is |
97 | | - applied. |
98 | | - |
99 | | - The `semiHidden` and `unhideWhenUsed` attributes operate in combination to |
100 | | - produce *hide-until-used* behavior. |
101 | | - |
102 | | - *Hypothesis.* The persistance of the `unhideWhenUsed` attribute after |
103 | | - removing the `semiHidden` attribute on first application of the style is |
104 | | - necessary to produce appropriate behavior in style inheritance situations. |
105 | | - In that case, the `semiHidden` attribute may be explictly set to |False| to |
106 | | - override an inherited value. Or it could allow the `semiHidden` attribute |
107 | | - to be re-set to |True| later while preserving the hide-until-used behavior. |
108 | | - |
109 | | -* **qFormat**. The `qFormat` attribute specifies whether the style should |
110 | | - appear in the Style Gallery when it appears in the recommended list. |
111 | | - A style will never appear in the gallery unless it also appears in the |
112 | | - recommended list. |
113 | | - |
114 | | -* Latent style attributes are only operative for latent styles. Once a style |
115 | | - is defined, the attributes of the definition exclusively determine style |
116 | | - behavior; no attributes are inherited from its corresponding latent style |
117 | | - definition. |
118 | | - |
119 | | - |
120 | 20 | Style visual behavior |
121 | 21 | --------------------- |
122 | 22 |
|
@@ -217,34 +117,6 @@ definition if it is no longer applied to any content. The definition of each |
217 | 117 | of the styles ever used in a document are accumulated in its ``styles.xml``. |
218 | 118 |
|
219 | 119 |
|
220 | | -Candidate protocol |
221 | | ------------------- |
222 | | - |
223 | | -:: |
224 | | - |
225 | | - >>> styles = document.styles # default styles part added if not present |
226 | | - >>> list_styles = [s for s in styles if s.type == WD_STYLE_TYPE.LIST] |
227 | | - >>> list_styles[0].type |
228 | | - WD_STYLE_TYPE.LIST (4) |
229 | | - |
230 | | - >>> style = styles.add_style('Citation', WD_STYLE_TYPE.PARAGRAPH) |
231 | | - |
232 | | - >>> document.add_paragraph(style='undefined-style') |
233 | | - KeyError: no style with id 'undefined-style' |
234 | | - |
235 | | - |
236 | | -Feature Notes |
237 | | -------------- |
238 | | - |
239 | | -* could add a default builtin style from known specs on first access via |
240 | | - WD_BUILTIN_STYLE enumeration:: |
241 | | - |
242 | | - >>> style = document.styles['Heading1'] |
243 | | - KeyError: no style with id or name 'Heading1' |
244 | | - >>> style = document.styles[WD_STYLE.HEADING_1] |
245 | | - >>> assert style == document.styles['Heading1'] |
246 | | - |
247 | | - |
248 | 120 | Related MS API *(partial)* |
249 | 121 | -------------------------- |
250 | 122 |
|
@@ -280,19 +152,6 @@ Enumerations |
280 | 152 | * WdBuiltinStyle |
281 | 153 |
|
282 | 154 |
|
283 | | -Spec text |
284 | | ---------- |
285 | | - |
286 | | - This element specifies all of the style information stored in the |
287 | | - WordprocessingML document: style definitions as well as latent style |
288 | | - information. |
289 | | - |
290 | | - Example: The Normal paragraph style in a word processing document can have |
291 | | - any number of formatting properties, e.g. font face = Times New Roman; font |
292 | | - size = 12pt; paragraph justification = left. All paragraphs which reference |
293 | | - this paragraph style would automatically inherit these properties. |
294 | | - |
295 | | - |
296 | 155 | Example XML |
297 | 156 | ----------- |
298 | 157 |
|
|
0 commit comments