File: text.py

package info (click to toggle)
python-docx 0.8.11%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,640 kB
  • sloc: xml: 25,311; python: 21,911; makefile: 168
file content (352 lines) | stat: -rw-r--r-- 10,689 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# encoding: utf-8

"""
Enumerations related to text in WordprocessingML files
"""

from __future__ import absolute_import, print_function, unicode_literals

from .base import alias, EnumMember, XmlEnumeration, XmlMappedEnumMember


@alias('WD_ALIGN_PARAGRAPH')
class WD_PARAGRAPH_ALIGNMENT(XmlEnumeration):
    """
    alias: **WD_ALIGN_PARAGRAPH**

    Specifies paragraph justification type.

    Example::

        from docx.enum.text import WD_ALIGN_PARAGRAPH

        paragraph = document.add_paragraph()
        paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
    """

    __ms_name__ = 'WdParagraphAlignment'

    __url__ = 'http://msdn.microsoft.com/en-us/library/office/ff835817.aspx'

    __members__ = (
        XmlMappedEnumMember(
            'LEFT', 0, 'left', 'Left-aligned'
        ),
        XmlMappedEnumMember(
            'CENTER', 1, 'center', 'Center-aligned.'
        ),
        XmlMappedEnumMember(
            'RIGHT', 2, 'right', 'Right-aligned.'
        ),
        XmlMappedEnumMember(
            'JUSTIFY', 3, 'both', 'Fully justified.'
        ),
        XmlMappedEnumMember(
            'DISTRIBUTE', 4, 'distribute', 'Paragraph characters are distrib'
            'uted to fill the entire width of the paragraph.'
        ),
        XmlMappedEnumMember(
            'JUSTIFY_MED', 5, 'mediumKashida', 'Justified with a medium char'
            'acter compression ratio.'
        ),
        XmlMappedEnumMember(
            'JUSTIFY_HI', 7, 'highKashida', 'Justified with a high character'
            ' compression ratio.'
        ),
        XmlMappedEnumMember(
            'JUSTIFY_LOW', 8, 'lowKashida', 'Justified with a low character '
            'compression ratio.'
        ),
        XmlMappedEnumMember(
            'THAI_JUSTIFY', 9, 'thaiDistribute', 'Justified according to Tha'
            'i formatting layout.'
        ),
    )


class WD_BREAK_TYPE(object):
    """
    Corresponds to WdBreakType enumeration
    http://msdn.microsoft.com/en-us/library/office/ff195905.aspx
    """
    COLUMN = 8
    LINE = 6
    LINE_CLEAR_LEFT = 9
    LINE_CLEAR_RIGHT = 10
    LINE_CLEAR_ALL = 11  # added for consistency, not in MS version
    PAGE = 7
    SECTION_CONTINUOUS = 3
    SECTION_EVEN_PAGE = 4
    SECTION_NEXT_PAGE = 2
    SECTION_ODD_PAGE = 5
    TEXT_WRAPPING = 11


WD_BREAK = WD_BREAK_TYPE


@alias('WD_COLOR')
class WD_COLOR_INDEX(XmlEnumeration):
    """
    Specifies a standard preset color to apply. Used for font highlighting and
    perhaps other applications.
    """

    __ms_name__ = 'WdColorIndex'

    __url__ = 'https://msdn.microsoft.com/EN-US/library/office/ff195343.aspx'

    __members__ = (
        XmlMappedEnumMember(
            None, None, None, 'Color is inherited from the style hierarchy.'
        ),
        XmlMappedEnumMember(
            'AUTO', 0, 'default', 'Automatic color. Default; usually black.'
        ),
        XmlMappedEnumMember(
            'BLACK', 1, 'black', 'Black color.'
        ),
        XmlMappedEnumMember(
            'BLUE', 2, 'blue', 'Blue color'
        ),
        XmlMappedEnumMember(
            'BRIGHT_GREEN', 4, 'green', 'Bright green color.'
        ),
        XmlMappedEnumMember(
            'DARK_BLUE', 9, 'darkBlue', 'Dark blue color.'
        ),
        XmlMappedEnumMember(
            'DARK_RED', 13, 'darkRed', 'Dark red color.'
        ),
        XmlMappedEnumMember(
            'DARK_YELLOW', 14, 'darkYellow', 'Dark yellow color.'
        ),
        XmlMappedEnumMember(
            'GRAY_25', 16, 'lightGray', '25% shade of gray color.'
        ),
        XmlMappedEnumMember(
            'GRAY_50', 15, 'darkGray', '50% shade of gray color.'
        ),
        XmlMappedEnumMember(
            'GREEN', 11, 'darkGreen', 'Green color.'
        ),
        XmlMappedEnumMember(
            'PINK', 5, 'magenta', 'Pink color.'
        ),
        XmlMappedEnumMember(
            'RED', 6, 'red', 'Red color.'
        ),
        XmlMappedEnumMember(
            'TEAL', 10, 'darkCyan', 'Teal color.'
        ),
        XmlMappedEnumMember(
            'TURQUOISE', 3, 'cyan', 'Turquoise color.'
        ),
        XmlMappedEnumMember(
            'VIOLET', 12, 'darkMagenta', 'Violet color.'
        ),
        XmlMappedEnumMember(
            'WHITE', 8, 'white', 'White color.'
        ),
        XmlMappedEnumMember(
            'YELLOW', 7, 'yellow', 'Yellow color.'
        ),
    )


class WD_LINE_SPACING(XmlEnumeration):
    """
    Specifies a line spacing format to be applied to a paragraph.

    Example::

        from docx.enum.text import WD_LINE_SPACING

        paragraph = document.add_paragraph()
        paragraph.line_spacing_rule = WD_LINE_SPACING.EXACTLY
    """

    __ms_name__ = 'WdLineSpacing'

    __url__ = 'http://msdn.microsoft.com/en-us/library/office/ff844910.aspx'

    __members__ = (
        EnumMember(
            'ONE_POINT_FIVE', 1, 'Space-and-a-half line spacing.'
        ),
        XmlMappedEnumMember(
            'AT_LEAST', 3, 'atLeast', 'Line spacing is always at least the s'
            'pecified amount. The amount is specified separately.'
        ),
        EnumMember(
            'DOUBLE', 2, 'Double spaced.'
        ),
        XmlMappedEnumMember(
            'EXACTLY', 4, 'exact', 'Line spacing is exactly the specified am'
            'ount. The amount is specified separately.'
        ),
        XmlMappedEnumMember(
            'MULTIPLE', 5, 'auto', 'Line spacing is specified as a multiple '
            'of line heights. Changing the font size will change the line sp'
            'acing proportionately.'
        ),
        EnumMember(
            'SINGLE', 0, 'Single spaced (default).'
        ),
    )


class WD_TAB_ALIGNMENT(XmlEnumeration):
    """
    Specifies the tab stop alignment to apply.
    """

    __ms_name__ = 'WdTabAlignment'

    __url__ = 'https://msdn.microsoft.com/EN-US/library/office/ff195609.aspx'

    __members__ = (
        XmlMappedEnumMember(
            'LEFT', 0, 'left', 'Left-aligned.'
        ),
        XmlMappedEnumMember(
            'CENTER', 1, 'center', 'Center-aligned.'
        ),
        XmlMappedEnumMember(
            'RIGHT', 2, 'right', 'Right-aligned.'
        ),
        XmlMappedEnumMember(
            'DECIMAL', 3, 'decimal', 'Decimal-aligned.'
        ),
        XmlMappedEnumMember(
            'BAR', 4, 'bar', 'Bar-aligned.'
        ),
        XmlMappedEnumMember(
            'LIST', 6, 'list', 'List-aligned. (deprecated)'
        ),
        XmlMappedEnumMember(
            'CLEAR', 101, 'clear', 'Clear an inherited tab stop.'
        ),
        XmlMappedEnumMember(
            'END', 102, 'end', 'Right-aligned.  (deprecated)'
        ),
        XmlMappedEnumMember(
            'NUM', 103, 'num', 'Left-aligned.  (deprecated)'
        ),
        XmlMappedEnumMember(
            'START', 104, 'start', 'Left-aligned.  (deprecated)'
        ),
    )


class WD_TAB_LEADER(XmlEnumeration):
    """
    Specifies the character to use as the leader with formatted tabs.
    """

    __ms_name__ = 'WdTabLeader'

    __url__ = 'https://msdn.microsoft.com/en-us/library/office/ff845050.aspx'

    __members__ = (
        XmlMappedEnumMember(
            'SPACES', 0, 'none', 'Spaces. Default.'
        ),
        XmlMappedEnumMember(
            'DOTS', 1, 'dot', 'Dots.'
        ),
        XmlMappedEnumMember(
            'DASHES', 2, 'hyphen', 'Dashes.'
        ),
        XmlMappedEnumMember(
            'LINES', 3, 'underscore', 'Double lines.'
        ),
        XmlMappedEnumMember(
            'HEAVY', 4, 'heavy', 'A heavy line.'
        ),
        XmlMappedEnumMember(
            'MIDDLE_DOT', 5, 'middleDot', 'A vertically-centered dot.'
        ),
    )


class WD_UNDERLINE(XmlEnumeration):
    """
    Specifies the style of underline applied to a run of characters.
    """

    __ms_name__ = 'WdUnderline'

    __url__ = 'http://msdn.microsoft.com/en-us/library/office/ff822388.aspx'

    __members__ = (
        XmlMappedEnumMember(
            None, None, None, 'Inherit underline setting from containing par'
            'agraph.'
        ),
        XmlMappedEnumMember(
            'NONE', 0, 'none', 'No underline. This setting overrides any inh'
            'erited underline value, so can be used to remove underline from'
            ' a run that inherits underlining from its containing paragraph.'
            ' Note this is not the same as assigning |None| to Run.underline'
            '. |None| is a valid assignment value, but causes the run to inh'
            'erit its underline value. Assigning ``WD_UNDERLINE.NONE`` cause'
            's underlining to be unconditionally turned off.'
        ),
        XmlMappedEnumMember(
            'SINGLE', 1, 'single', 'A single line. Note that this setting is'
            'write-only in the sense that |True| (rather than ``WD_UNDERLINE'
            '.SINGLE``) is returned for a run having this setting.'
        ),
        XmlMappedEnumMember(
            'WORDS', 2, 'words', 'Underline individual words only.'
        ),
        XmlMappedEnumMember(
            'DOUBLE', 3, 'double', 'A double line.'
        ),
        XmlMappedEnumMember(
            'DOTTED', 4, 'dotted', 'Dots.'
        ),
        XmlMappedEnumMember(
            'THICK', 6, 'thick', 'A single thick line.'
        ),
        XmlMappedEnumMember(
            'DASH', 7, 'dash', 'Dashes.'
        ),
        XmlMappedEnumMember(
            'DOT_DASH', 9, 'dotDash', 'Alternating dots and dashes.'
        ),
        XmlMappedEnumMember(
            'DOT_DOT_DASH', 10, 'dotDotDash', 'An alternating dot-dot-dash p'
            'attern.'
        ),
        XmlMappedEnumMember(
            'WAVY', 11, 'wave', 'A single wavy line.'
        ),
        XmlMappedEnumMember(
            'DOTTED_HEAVY', 20, 'dottedHeavy', 'Heavy dots.'
        ),
        XmlMappedEnumMember(
            'DASH_HEAVY', 23, 'dashedHeavy', 'Heavy dashes.'
        ),
        XmlMappedEnumMember(
            'DOT_DASH_HEAVY', 25, 'dashDotHeavy', 'Alternating heavy dots an'
            'd heavy dashes.'
        ),
        XmlMappedEnumMember(
            'DOT_DOT_DASH_HEAVY', 26, 'dashDotDotHeavy', 'An alternating hea'
            'vy dot-dot-dash pattern.'
        ),
        XmlMappedEnumMember(
            'WAVY_HEAVY', 27, 'wavyHeavy', 'A heavy wavy line.'
        ),
        XmlMappedEnumMember(
            'DASH_LONG', 39, 'dashLong', 'Long dashes.'
        ),
        XmlMappedEnumMember(
            'WAVY_DOUBLE', 43, 'wavyDouble', 'A double wavy line.'
        ),
        XmlMappedEnumMember(
            'DASH_LONG_HEAVY', 55, 'dashLongHeavy', 'Long heavy dashes.'
        ),
    )