styles.html 199 KB
Newer Older
Etienne Nadji's avatar
Etienne Nadji committed
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617


<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>pyscribus.styles &mdash; PyScribus 0.1 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> PyScribus
          

          
            
            <img src="../../_static/logo-300.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
              <div class="version">
                0.1
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../guide/en/quickstart.html">Quickstart</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guide/fr/general.html">[FR] Fonctionnement général</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guide/fr/dims.html">[FR] Mesures et autres nombres</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guide/en/psm.html">PyScribus Story Markup</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guide/en/templating.html">PyScribus templating</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/index.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../credits.html">Credits</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../thanks.html">Acknowledgements</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">PyScribus reference</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../articles/en/spec.html">[EN] SLA document-able attributes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../articles/en/spec-suggestions.html">SLA’s enhancement suggestions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../articles/fr/stories.html">[FR] Comment les <em>stories</em> de Scribus (semblent) fonctionner</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">PyScribus</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>pyscribus.styles</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for pyscribus.styles</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python3</span>
<span class="c1"># -*- coding:Utf-8 -*-</span>

<span class="c1"># PyScribus, python library for Scribus SLA</span>
<span class="c1"># Copyright (C) 2020 Étienne Nadji</span>
<span class="c1">#</span>
<span class="c1"># This program is free software: you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation, either version 3 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program.  If not, see &lt;https://www.gnu.org/licenses/&gt;.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">PyScribus classes for styles manipulation.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="c1"># Imports ===============================================================#</span>

<span class="kn">import</span> <span class="nn">lxml</span>
<span class="kn">import</span> <span class="nn">lxml.etree</span> <span class="k">as</span> <span class="nn">ET</span>

<span class="kn">import</span> <span class="nn">pyscribus.common.xml</span> <span class="k">as</span> <span class="nn">xmlc</span>
<span class="kn">import</span> <span class="nn">pyscribus.exceptions</span> <span class="k">as</span> <span class="nn">exceptions</span>
<span class="kn">import</span> <span class="nn">pyscribus.dimensions</span> <span class="k">as</span> <span class="nn">dimensions</span>

<span class="c1"># Variables globales ====================================================#</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Etienne Nadji &lt;etnadji@eml.cc&gt;&quot;</span>

<span class="c1"># Classes ===============================================================#</span>

<div class="viewcode-block" id="NoteStyle"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.NoteStyle">[docs]</a><span class="k">class</span> <span class="nc">NoteStyle</span><span class="p">(</span><span class="n">xmlc</span><span class="o">.</span><span class="n">PyScribusElement</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;SLA notes style (notesStyle)&quot;&quot;&quot;</span>

    <span class="n">range_type_xml</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;document&quot;</span><span class="p">:</span> <span class="s2">&quot;0&quot;</span><span class="p">,</span> <span class="s2">&quot;section&quot;</span><span class="p">:</span> <span class="s2">&quot;1&quot;</span><span class="p">,</span>
        <span class="s2">&quot;story&quot;</span><span class="p">:</span> <span class="s2">&quot;2&quot;</span><span class="p">,</span> <span class="s2">&quot;page&quot;</span><span class="p">:</span> <span class="s2">&quot;3&quot;</span><span class="p">,</span>
        <span class="s2">&quot;form&quot;</span><span class="p">:</span> <span class="s2">&quot;4&quot;</span>
    <span class="p">}</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">default</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fromdefault</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_type</span><span class="p">(</span><span class="s2">&quot;footnote&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">num_start</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">num_type</span> <span class="o">=</span> <span class="s2">&quot;decimal&quot;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">affixes</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;prefix&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="s2">&quot;suffix&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">}</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">auto_dims</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">}</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">auto_remove</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">auto_link</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">superscript</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;note&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="s2">&quot;mark&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">}</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">styles</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;mark&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="s2">&quot;note&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">}</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="s2">&quot;document&quot;</span>

<div class="viewcode-block" id="NoteStyle.set_numtype"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.NoteStyle.set_numtype">[docs]</a>    <span class="k">def</span> <span class="nf">set_numtype</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">numtype</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">numtype</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="n">NoteStyle</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">num_type</span> <span class="o">=</span> <span class="n">numtype</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="NoteStyle.set_type"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.NoteStyle.set_type">[docs]</a>    <span class="k">def</span> <span class="nf">set_type</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">note_type</span><span class="o">=</span><span class="s2">&quot;footnote&quot;</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">note_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;footnote&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">is_endnotes</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">is_footnotes</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">is_endnotes</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">is_footnotes</span> <span class="o">=</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="NoteStyle.toxml"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.NoteStyle.toxml">[docs]</a>    <span class="k">def</span> <span class="nf">toxml</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">xml</span> <span class="o">=</span> <span class="n">ET</span><span class="o">.</span><span class="n">Element</span><span class="p">(</span><span class="s2">&quot;notesStyle&quot;</span><span class="p">)</span>

        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;Name&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;Start&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">num_start</span><span class="p">)</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;Endnotes&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">bool_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">is_endnotes</span><span class="p">)</span>
        <span class="c1"># xml.attrib[&quot;Type&quot;] = NoteStyle.num_type_xml[self.num_type]</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;Type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">num_type_xml</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">num_type</span><span class="p">]</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;Range&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">NoteStyle</span><span class="o">.</span><span class="n">range_type_xml</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">range</span><span class="p">]</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;Prefix&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">affixes</span><span class="p">[</span><span class="s2">&quot;prefix&quot;</span><span class="p">]</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;Suffix&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">affixes</span><span class="p">[</span><span class="s2">&quot;suffix&quot;</span><span class="p">]</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;AutoHeight&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">bool_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">auto_dims</span><span class="p">[</span><span class="s2">&quot;height&quot;</span><span class="p">])</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;AutoWidth&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">bool_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">auto_dims</span><span class="p">[</span><span class="s2">&quot;width&quot;</span><span class="p">])</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;AutoRemove&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">bool_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">auto_remove</span><span class="p">)</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;AutoWeld&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">bool_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">auto_link</span><span class="p">)</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;SuperNote&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">bool_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">superscript</span><span class="p">[</span><span class="s2">&quot;note&quot;</span><span class="p">])</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;SuperMaster&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">bool_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">superscript</span><span class="p">[</span><span class="s2">&quot;mark&quot;</span><span class="p">])</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;MarksStyle&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">styles</span><span class="p">[</span><span class="s2">&quot;mark&quot;</span><span class="p">]</span>
        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;NotesStyle&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">styles</span><span class="p">[</span><span class="s2">&quot;note&quot;</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">xml</span></div>

<div class="viewcode-block" id="NoteStyle.fromxml"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.NoteStyle.fromxml">[docs]</a>    <span class="k">def</span> <span class="nf">fromxml</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">xml</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">num_start</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Start&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Name&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">affixes</span><span class="p">[</span><span class="s2">&quot;prefix&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Prefix&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">affixes</span><span class="p">[</span><span class="s2">&quot;suffix&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Suffix&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auto_link</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">num_to_bool</span><span class="p">(</span><span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;AutoWeld&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auto_remove</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">num_to_bool</span><span class="p">(</span><span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;AutoRemove&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auto_dims</span><span class="p">[</span><span class="s2">&quot;width&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;AutoWidth&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auto_dims</span><span class="p">[</span><span class="s2">&quot;height&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;AutoHeight&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">superscript</span><span class="p">[</span><span class="s2">&quot;note&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">num_to_bool</span><span class="p">(</span><span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;SuperNote&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">superscript</span><span class="p">[</span><span class="s2">&quot;mark&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">num_to_bool</span><span class="p">(</span><span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;SuperMaster&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">styles</span><span class="p">[</span><span class="s2">&quot;note&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;NotesStyle&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">styles</span><span class="p">[</span><span class="s2">&quot;mark&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;MarksStyle&quot;</span><span class="p">)</span>

        <span class="n">nt</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Type&quot;</span><span class="p">)</span>

        <span class="c1"># for h,x in NoteStyle.num_type_xml.items():</span>
        <span class="k">for</span> <span class="n">h</span><span class="p">,</span><span class="n">x</span> <span class="ow">in</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">num_type_xml</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">nt</span> <span class="o">==</span> <span class="n">x</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">num_type</span> <span class="o">=</span> <span class="n">h</span>
                <span class="k">break</span>

        <span class="n">rg</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Range&quot;</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">h</span><span class="p">,</span><span class="n">x</span> <span class="ow">in</span> <span class="n">NoteStyle</span><span class="o">.</span><span class="n">range_type_xml</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">rg</span> <span class="o">==</span> <span class="n">x</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="n">h</span>
                <span class="k">break</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="NoteStyle.fromdefault"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.NoteStyle.fromdefault">[docs]</a>    <span class="k">def</span> <span class="nf">fromdefault</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Default&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_type</span><span class="p">(</span><span class="s2">&quot;footnote&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">num_start</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">num_type</span> <span class="o">=</span> <span class="s2">&quot;decimal&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">affixes</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;prefix&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="s2">&quot;suffix&quot;</span><span class="p">:</span> <span class="s2">&quot;)&quot;</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auto_dims</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auto_remove</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auto_link</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">superscript</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;note&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="s2">&quot;mark&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">styles</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;mark&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="s2">&quot;note&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="s2">&quot;document&quot;</span>

        <span class="k">return</span> <span class="kc">True</span></div></div>

<span class="c1"># FIXME This is a giant class.</span>
<span class="c1"># When styles attributes list will be stable, we will need to :</span>
<span class="c1">#   - move the type-specific (to|from)xml code and class attributes to</span>
<span class="c1">#     inherited classes. StyleAbstract.toxml() already returns xml Element.</span>
<span class="c1">#   - move the type-specific functions to inherited classes</span>

<div class="viewcode-block" id="StyleAbstract"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.StyleAbstract">[docs]</a><span class="k">class</span> <span class="nc">StyleAbstract</span><span class="p">(</span><span class="n">xmlc</span><span class="o">.</span><span class="n">PyScribusElement</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Abstract class for paragraph, character, table, cell styles in SLA.</span>

<span class="sd">    :type style_type: str</span>
<span class="sd">    :param style_type: Style type. Must be &quot;paragraph&quot;, &quot;character&quot;, </span>
<span class="sd">        &quot;table&quot;, &quot;cell&quot;.</span>
<span class="sd">    :type default: boolean</span>
<span class="sd">    :param default: Use default settings (False by default)</span>
<span class="sd">    :type kwargs: dict</span>
<span class="sd">    :param kwargs: Quick setting (see kwargs tables of inherited classes)</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># TODO Reste des attributs</span>

    <span class="n">type_xml</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;paragraph&quot;</span><span class="p">:</span> <span class="s2">&quot;STYLE&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">:</span> <span class="s2">&quot;CHARSTYLE&quot;</span><span class="p">,</span>
        <span class="s2">&quot;table&quot;</span><span class="p">:</span> <span class="s2">&quot;TableStyle&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">:</span> <span class="s2">&quot;CellStyle&quot;</span>
    <span class="p">}</span>

    <span class="n">name_xml</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;NAME&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">],</span>
        <span class="s2">&quot;CNAME&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;character&quot;</span><span class="p">]</span>
    <span class="p">}</span>

    <span class="n">shortcut_xml</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;PSHORTCUT&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">],</span>
        <span class="s2">&quot;SHORTCUT&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;character&quot;</span><span class="p">]</span>
    <span class="p">}</span>

    <span class="n">parent_xml</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;PARENT&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">],</span>
        <span class="s2">&quot;CPARENT&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;character&quot;</span><span class="p">]</span>
    <span class="p">}</span>

    <span class="n">fshade_xml</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;FillShade&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">],</span>
        <span class="s2">&quot;FSHADE&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;character&quot;</span><span class="p">,</span> <span class="s2">&quot;paragraph&quot;</span><span class="p">]</span>
    <span class="p">}</span>

    <span class="n">fcolor_xml</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;FillColor&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">],</span>
        <span class="s2">&quot;FCOLOR&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;character&quot;</span><span class="p">,</span> <span class="s2">&quot;paragraph&quot;</span><span class="p">]</span>
    <span class="p">}</span>

    <span class="n">default_name</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;paragraph&quot;</span><span class="p">:</span> <span class="s2">&quot;Default Paragraph Style&quot;</span><span class="p">,</span>
        <span class="s2">&quot;character&quot;</span><span class="p">:</span> <span class="s2">&quot;Default Character Style&quot;</span><span class="p">,</span>
        <span class="s2">&quot;table&quot;</span><span class="p">:</span> <span class="s2">&quot;Default Table Style&quot;</span><span class="p">,</span>
        <span class="s2">&quot;cell&quot;</span><span class="p">:</span> <span class="s2">&quot;Default Cell Style&quot;</span>
    <span class="p">}</span>

    <span class="n">default_font</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Arial Regular&quot;</span><span class="p">,</span>
        <span class="s2">&quot;size&quot;</span><span class="p">:</span> <span class="mi">12</span><span class="p">,</span>
        <span class="s2">&quot;features&quot;</span><span class="p">:</span> <span class="p">[],</span>
        <span class="s2">&quot;color&quot;</span><span class="p">:</span> <span class="s2">&quot;Black&quot;</span><span class="p">,</span>
        <span class="s2">&quot;alignment&quot;</span><span class="p">:</span> <span class="s2">&quot;left&quot;</span>
    <span class="p">}</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">style_type</span><span class="p">,</span> <span class="n">doc_parent</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">doc_parent</span> <span class="o">=</span> <span class="n">doc_parent</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">style_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="n">StyleAbstract</span><span class="o">.</span><span class="n">type_xml</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unknown style type for StyleAbstract&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">=</span> <span class="n">style_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">is_default</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>
            <span class="c1"># TODO FIXME Handle font features as a dict instead</span>
            <span class="c1"># of a list, like in other styles</span>
            <span class="c1"># Features: -clig, inherit</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">font</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
                <span class="s2">&quot;size&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s2">&quot;features&quot;</span><span class="p">:</span> <span class="p">[],</span>
                <span class="s2">&quot;color&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
                <span class="s2">&quot;alignment&quot;</span><span class="p">:</span> <span class="s2">&quot;left&quot;</span>
            <span class="p">}</span>

            <span class="c1"># NOTE Weird, but FONTFEATURES is not the same as FEATURES</span>
            <span class="c1"># even if it has obviously an effect on fonts...</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">features</span> <span class="o">=</span> <span class="p">{</span>
            <span class="p">}</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">lang</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">shortcut</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">,</span> <span class="s2">&quot;paragraph&quot;</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fill</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s2">&quot;color&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
                <span class="s2">&quot;shade&quot;</span><span class="p">:</span> <span class="kc">None</span>
            <span class="p">}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">borders</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">==</span> <span class="s2">&quot;character&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s2">&quot;horizontal&quot;</span><span class="p">:</span> <span class="mi">100</span><span class="p">,</span>
                <span class="s2">&quot;vertical&quot;</span><span class="p">:</span> <span class="mi">100</span>
            <span class="p">}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">==</span> <span class="s2">&quot;cell&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s2">&quot;left&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;right&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s2">&quot;top&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;bottom&quot;</span><span class="p">:</span> <span class="mi">0</span>
            <span class="p">}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">==</span> <span class="s2">&quot;paragraph&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tabs</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">character_parent</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">space</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s2">&quot;after&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
                <span class="s2">&quot;before&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
            <span class="p">}</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">leading</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s2">&quot;mode&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
                <span class="s2">&quot;value&quot;</span><span class="p">:</span> <span class="n">dimensions</span><span class="o">.</span><span class="n">Dim</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="p">}</span>

        <span class="k">if</span> <span class="n">default</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fromdefault</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_quick_setup</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_quick_setup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method for defining style settings from class</span>
<span class="sd">        instanciation kwargs.</span>

<span class="sd">        :type settings: dict</span>
<span class="sd">        :param settings: Kwargs dictionnary</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">settings</span><span class="p">:</span>
            <span class="n">xmlc</span><span class="o">.</span><span class="n">PyScribusElement</span><span class="o">.</span><span class="n">_quick_setup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">settings</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">setting_name</span><span class="p">,</span> <span class="n">setting_value</span> <span class="ow">in</span> <span class="n">settings</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>

                    <span class="k">if</span> <span class="n">setting_name</span> <span class="o">==</span> <span class="s2">&quot;defaultstyle&quot;</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">setting_value</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">is_default</span> <span class="o">=</span> <span class="kc">True</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">is_default</span> <span class="o">=</span> <span class="kc">False</span>

                <span class="k">if</span> <span class="n">setting_name</span> <span class="o">==</span> <span class="s2">&quot;name&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">setting_value</span>

                <span class="k">if</span> <span class="n">setting_name</span> <span class="o">==</span> <span class="s2">&quot;parent&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">setting_value</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>

                    <span class="k">if</span> <span class="n">setting_name</span> <span class="o">==</span> <span class="s2">&quot;fontsize&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;size&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">setting_value</span>

                    <span class="k">if</span> <span class="n">setting_name</span> <span class="o">==</span> <span class="s2">&quot;font&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">setting_value</span>

    <span class="k">def</span> <span class="nf">_choose_att</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">atts_dict</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the correct XML attribute according to the</span>
<span class="sd">        StyleAbstract *class* attribute atts_dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">att</span><span class="p">,</span> <span class="n">types</span> <span class="ow">in</span> <span class="n">atts_dict</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="n">types</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">att</span>

        <span class="k">return</span> <span class="kc">False</span>

<div class="viewcode-block" id="StyleAbstract.fromdefault"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.StyleAbstract.fromdefault">[docs]</a>    <span class="k">def</span> <span class="nf">fromdefault</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">StyleAbstract</span><span class="o">.</span><span class="n">default_name</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">style_type</span><span class="p">]</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">font</span> <span class="o">=</span> <span class="n">StyleAbstract</span><span class="o">.</span><span class="n">default_font</span>

        <span class="c1"># TODO Le reste</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="StyleAbstract.fromxml"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.StyleAbstract.fromxml">[docs]</a>    <span class="k">def</span> <span class="nf">fromxml</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">xml</span><span class="p">,</span> <span class="n">onlybool</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>

        <span class="k">if</span> <span class="n">xml</span><span class="o">.</span><span class="n">tag</span> <span class="o">==</span> <span class="n">StyleAbstract</span><span class="o">.</span><span class="n">type_xml</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">style_type</span><span class="p">]:</span>

            <span class="c1">#--- Name ----------------------------------------------</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>
                <span class="n">name_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">name_xml</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">name</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name_att</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>

            <span class="c1">#--- Common attributes ---------------------------------</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">default</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;DefaultStyle&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">is_default</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">num_to_bool</span><span class="p">(</span><span class="n">default</span><span class="p">)</span>

            <span class="c1">#--- Specific attributes for paragraph -----------------</span>
            <span class="c1"># Moved in ParagraphStyle</span>

            <span class="c1">#--- Specific attributes for character -----------------</span>
            <span class="c1"># Moved in CharacterStyle</span>

            <span class="c1">#--- Specific attributes for table ---------------------</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">==</span> <span class="s2">&quot;table&quot;</span><span class="p">:</span>
                <span class="k">pass</span>

            <span class="c1">#--- Specific attributes for cell ----------------------</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">==</span> <span class="s2">&quot;cell&quot;</span><span class="p">:</span>

                <span class="k">for</span> <span class="n">case</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;left&quot;</span><span class="p">,</span> <span class="s2">&quot;right&quot;</span><span class="p">,</span> <span class="s2">&quot;top&quot;</span><span class="p">,</span> <span class="s2">&quot;bottom&quot;</span><span class="p">]:</span>
                    <span class="n">att</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">Padding&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">case</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()))</span>

                    <span class="k">if</span> <span class="n">att</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">[</span><span class="n">case</span><span class="p">]</span> <span class="o">=</span> <span class="n">att</span>

            <span class="c1">#--- Common attributes to paragraphs + characters ------</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>
                <span class="c1">#--- Font and font features ------------------------------</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">font</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;FONT&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">font</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">font_size</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;FONTSIZE&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;size&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">font_size</span><span class="p">)</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">font_features</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;FONTFEATURES&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;features&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">font_features</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">)</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">font_color</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;FCOLOR&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;color&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">font_color</span>

                <span class="c1"># NOTE Weird FEATURES duplicate</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">features</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;FEATURES&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">features</span> <span class="o">=</span> <span class="n">features</span>

                <span class="c1">#--- Lang ------------------------------------------------</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">lang</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LANGUAGE&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">lang</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">lang</span> <span class="o">=</span> <span class="n">lang</span>

                <span class="c1">#--- Parent style ----------------------------------------</span>

                <span class="n">parent_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">parent_xml</span><span class="p">)</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">parent</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">parent_att</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">parent</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">parent</span>

                <span class="c1">#--- Shortcut --------------------------------------------</span>

                <span class="n">shortcut_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">shortcut_xml</span><span class="p">)</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">shortcut</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">shortcut_att</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">shortcut</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">shortcut</span> <span class="o">=</span> <span class="n">shortcut</span>

            <span class="c1">#--- Common attributes to tables, celles, characters ---</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">,</span> <span class="s2">&quot;paragraph&quot;</span><span class="p">]:</span>
                <span class="n">fshade_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">fshade_xml</span><span class="p">)</span>
                <span class="n">fcolor_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">fcolor_xml</span><span class="p">)</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">fill_color</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">fcolor_att</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">fill</span><span class="p">[</span><span class="s2">&quot;color&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">fill_color</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">fill_shade</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">fshade_att</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">fill</span><span class="p">[</span><span class="s2">&quot;shade&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">fill_shade</span><span class="p">)</span>

            <span class="c1">#--- Childs --------------------------------------------</span>

            <span class="c1"># Moved StyleTabs check in ParagraphStyle</span>

            <span class="c1">#-------------------------------------------------------</span>

            <span class="c1">#--- FIXME This records undocumented attributes --------</span>

618
619
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;character&quot;</span><span class="p">,</span> <span class="s2">&quot;paragraph&quot;</span><span class="p">]:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">undocumented</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">all_undocumented_to_python</span><span class="p">(</span><span class="n">xml</span><span class="p">)</span>
Etienne Nadji's avatar
Etienne Nadji committed
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715

            <span class="c1"># ------------------------------------------------------</span>

            <span class="c1"># Returns lxml.etree._Element instead of True, for</span>
            <span class="c1"># inheritance purposes</span>

            <span class="k">if</span> <span class="n">onlybool</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">xml</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="StyleAbstract.toxml"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.StyleAbstract.toxml">[docs]</a>    <span class="k">def</span> <span class="nf">toxml</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">xml</span> <span class="o">=</span> <span class="n">ET</span><span class="o">.</span><span class="n">Element</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">type_xml</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">style_type</span><span class="p">])</span>

        <span class="c1">#--- Name ----------------------------------------------</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>
            <span class="n">name_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">name_xml</span><span class="p">)</span>

        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">name_att</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>

        <span class="c1">#--- Common attributes ---------------------------------</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_default</span><span class="p">:</span>
            <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;DefaultStyle&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">bool_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">is_default</span><span class="p">)</span>

        <span class="c1">#--- Specific attributes for table ---------------------</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">==</span> <span class="s2">&quot;table&quot;</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="c1">#--- Specific attributes for cell ----------------------</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">==</span> <span class="s2">&quot;cell&quot;</span><span class="p">:</span>

            <span class="k">for</span> <span class="n">case</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;left&quot;</span><span class="p">,</span> <span class="s2">&quot;right&quot;</span><span class="p">,</span> <span class="s2">&quot;top&quot;</span><span class="p">,</span> <span class="s2">&quot;bottom&quot;</span><span class="p">]:</span>
                <span class="n">att_name</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">Padding&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">case</span><span class="o">.</span><span class="n">capitalize</span><span class="p">())</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">att_name</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">[</span><span class="n">case</span><span class="p">]</span>

        <span class="c1">#--- Common attributes to paragraphs + characters ------</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;FONT&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">==</span> <span class="s2">&quot;character&quot;</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;FONTSIZE&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;size&quot;</span><span class="p">])</span>

            <span class="c1"># TODO FIXME Handle font features as a dict instead</span>
            <span class="c1"># of a list, like in other styles</span>
            <span class="c1"># xml.attrib[&quot;FONTFEATURES&quot;] = &quot; &quot;.join(self.font[&quot;features&quot;].keys())</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;features&quot;</span><span class="p">]:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;FONTFEATURES&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;features&quot;</span><span class="p">])</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;color&quot;</span><span class="p">]:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;FCOLOR&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;color&quot;</span><span class="p">]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">features</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;FEATURES&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">features</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lang</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;LANGUAGE&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lang</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">shortcut</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">shortcut_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">shortcut_xml</span><span class="p">)</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">shortcut_att</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">shortcut</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="c1"># Parent style of same style type</span>
                <span class="c1"># CPARENT -&gt; parent character style for this character style</span>
                <span class="c1"># PARENT  -&gt; parent paragraph style for this paragraph style</span>
                <span class="n">parent_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">parent_xml</span><span class="p">)</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">parent_att</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span>

        <span class="c1">#--- Common attributes to tables, celles, characters ---</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;table&quot;</span><span class="p">,</span> <span class="s2">&quot;cell&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>
            <span class="n">fshade_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">fshade_xml</span><span class="p">)</span>
            <span class="n">fcolor_att</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_choose_att</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="o">.</span><span class="n">fcolor_xml</span><span class="p">)</span>

            <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">fcolor_att</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">none_or_str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fill</span><span class="p">[</span><span class="s2">&quot;color&quot;</span><span class="p">])</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fill</span><span class="p">[</span><span class="s2">&quot;shade&quot;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">fshade_att</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">float_or_int_string</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">fill</span><span class="p">[</span><span class="s2">&quot;shade&quot;</span><span class="p">]</span>
                <span class="p">)</span>

        <span class="c1">#-------------------------------------------------------</span>

        <span class="c1">#--- FIXME This exports undocumented attributes -------</span>

        <span class="k">try</span><span class="p">:</span>
716
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="s2">&quot;character&quot;</span><span class="p">]:</span>
Etienne Nadji's avatar
Etienne Nadji committed
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
                <span class="n">xml</span><span class="p">,</span> <span class="n">undoc_attribs</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">all_undocumented_to_xml</span><span class="p">(</span>
                    <span class="n">xml</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">undocumented</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">+</span> <span class="s2">&quot; style&quot;</span>
                <span class="p">)</span>

        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="c1"># NOTE If fromxml was not used</span>
            <span class="k">pass</span>

        <span class="k">return</span> <span class="n">xml</span></div>

<div class="viewcode-block" id="StyleAbstract.fromstyle"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.StyleAbstract.fromstyle">[docs]</a>    <span class="k">def</span> <span class="nf">fromstyle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">override</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set attributes according to another style.</span>

<span class="sd">        :type style: ParagraphStyle, CharacterStyle, ...</span>
<span class="sd">        :param style: Style to load attributes from.</span>
<span class="sd">        :type override: boolean</span>
<span class="sd">        :param override: Override attributes that differs from style</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># TODO</span>
        <span class="k">pass</span></div></div>


<div class="viewcode-block" id="ParagraphStyle"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.ParagraphStyle">[docs]</a><span class="k">class</span> <span class="nc">ParagraphStyle</span><span class="p">(</span><span class="n">StyleAbstract</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Paragraph style in SLA (STYLE)</span>

<span class="sd">    :type default: boolean</span>
<span class="sd">    :param default: Use default settings (False by default)</span>
<span class="sd">    :type kwargs: dict</span>
<span class="sd">    :param kwargs: Quick setting (see kwargs table)</span>

<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | Kwargs       | Setting                            |</span>
<span class="sd">    +==============+====================================+</span>
<span class="sd">    | name         | Style name                         |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | defaultstyle | Scribus default paragraph style?   |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | parent       | Parent style name (paragraph)      |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | cparent      | Parent style name (character)      |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | alignment    | Text alignment. Must be in         |</span>
<span class="sd">    |              | ``pyscribus.common.xml.alignment`` |</span>
<span class="sd">    |              | keys                               |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | font         | Font name                          |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | fontsize     | Font size                          |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | spacebefore  | Space before paragraph             |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | spaceafter   | Space after paragraph              |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | leading      | Leading mode. Must be in           |</span>
<span class="sd">    |              | ``ParagraphStyle.leading_xml``.    |</span>
<span class="sd">    |              | If &quot;fixed&quot; mode, you must define   |</span>
<span class="sd">    |              | leadingValue setting.              |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | leadingValue | Leading value in pica points if    |</span>
<span class="sd">    |              | leading mode is &quot;fixed&quot;.           |</span>
<span class="sd">    +--------------+------------------------------------+</span>
<span class="sd">    | default      | Equivalent to a fromdefault        |</span>
<span class="sd">    |              | call, value being True or the      |</span>
<span class="sd">    |              | default name                       |</span>
<span class="sd">    +--------------+------------------------------------+</span>

<span class="sd">    :Example:</span>

<span class="sd">    .. code:: python</span>

<span class="sd">       title_style = styles.ParagraphStyle(</span>
<span class="sd">           name=&quot;Title&quot;, fontsize=18, alignment=&quot;center&quot;,</span>
<span class="sd">           leading=&quot;fixed&quot;, leadingValue=16</span>
<span class="sd">       )</span>

<span class="sd">       normal_style = styles.ParagraphStyle(</span>
<span class="sd">           name=&quot;Normal&quot;, fontsize=12, alignment=&quot;justify&quot;,</span>
<span class="sd">           leading=&quot;automatic&quot;</span>
<span class="sd">       )</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">leading_xml</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;fixed&quot;</span><span class="p">:</span> <span class="s2">&quot;0&quot;</span><span class="p">,</span>
        <span class="s2">&quot;automatic&quot;</span><span class="p">:</span> <span class="s2">&quot;1&quot;</span><span class="p">,</span>
        <span class="s2">&quot;grid&quot;</span><span class="p">:</span> <span class="s2">&quot;2&quot;</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">doc_parent</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">StyleAbstract</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;paragraph&quot;</span><span class="p">,</span> <span class="n">doc_parent</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span>
810
811
812
813
814
815
816

        <span class="bp">self</span><span class="o">.</span><span class="n">indentations</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;left&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
            <span class="s2">&quot;right&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
            <span class="s2">&quot;first-line&quot;</span><span class="p">:</span> <span class="kc">None</span>
        <span class="p">}</span>

Etienne Nadji's avatar
Etienne Nadji committed
817
818
819
820
821
822
823
        <span class="bp">self</span><span class="o">.</span><span class="n">_quick_setup</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>

<div class="viewcode-block" id="ParagraphStyle.fromxml"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.ParagraphStyle.fromxml">[docs]</a>    <span class="k">def</span> <span class="nf">fromxml</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">xml</span><span class="p">):</span>
        <span class="n">is_paragraph</span> <span class="o">=</span> <span class="n">StyleAbstract</span><span class="o">.</span><span class="n">fromxml</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">xml</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">is_paragraph</span><span class="p">:</span>

824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
            <span class="c1">#--- Indentation ------------------------------------------------</span>

            <span class="c1"># Left indentation of all paragraph lines</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">left</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;INDENT&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">indentations</span><span class="p">[</span><span class="s2">&quot;left&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dimensions</span><span class="o">.</span><span class="n">Dim</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">left</span><span class="p">))</span>

            <span class="c1"># Right indentation of all paragraph lines</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">right</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;RMARGIN&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">indentations</span><span class="p">[</span><span class="s2">&quot;right&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dimensions</span><span class="o">.</span><span class="n">Dim</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">right</span><span class="p">))</span>

            <span class="c1"># Indentation of the first line of the paragraph</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">first</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;FIRST&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">indentations</span><span class="p">[</span><span class="s2">&quot;first-line&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dimensions</span><span class="o">.</span><span class="n">Dim</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">first</span><span class="p">))</span>

Etienne Nadji's avatar
Etienne Nadji committed
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
            <span class="c1">#--- Lists ------------------------------------------------------</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">is_ul</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">is_ol</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span><span class="kc">False</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">is_bullet</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Bullet&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">is_bullet</span> <span class="o">==</span> <span class="s2">&quot;1&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">is_ul</span> <span class="o">=</span> <span class="kc">True</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">is_numeroted</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Numeration&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">is_numeroted</span> <span class="o">==</span> <span class="s2">&quot;1&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">is_ol</span> <span class="o">=</span> <span class="kc">True</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_ol</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_ul</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">exceptions</span><span class="o">.</span><span class="n">InsaneSLAValue</span><span class="p">(</span>
                    <span class="s2">&quot;Style </span><span class="si">{}</span><span class="s2"> is both bullet and numeroted list.&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_ul</span><span class="p">:</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">bullet_char</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;BulletStr&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="c1"># TODO</span>
                    <span class="k">pass</span>

            <span class="c1">#--- Parent character style -------------------------------------</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">character_parent</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;CPARENT&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">character_parent</span> <span class="o">=</span> <span class="n">character_parent</span>

            <span class="c1">#--- Leading ----------------------------------------------------</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">leading</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LINESPMode&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>

                <span class="k">for</span> <span class="n">human</span><span class="p">,</span> <span class="n">code</span> <span class="ow">in</span> <span class="n">ParagraphStyle</span><span class="o">.</span><span class="n">leading_xml</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">leading</span> <span class="o">==</span> <span class="n">code</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">leading</span><span class="p">[</span><span class="s2">&quot;mode&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">human</span>
                        <span class="k">break</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">leading</span><span class="p">[</span><span class="s2">&quot;mode&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;fixed&quot;</span><span class="p">:</span>
                    <span class="n">leading_value</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LINESP&quot;</span><span class="p">)</span>

                    <span class="k">if</span> <span class="n">leading_value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">leading</span><span class="p">[</span><span class="s2">&quot;value&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">leading_value</span><span class="p">)</span>

            <span class="c1">#--- Alignment --------------------------------------------------</span>

            <span class="k">if</span> <span class="p">(</span><span class="n">alignment</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;ALIGN&quot;</span><span class="p">))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">human</span><span class="p">,</span> <span class="n">code</span> <span class="ow">in</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">alignment</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">alignment</span> <span class="o">==</span> <span class="n">code</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;alignment&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">human</span>
                        <span class="k">break</span>

            <span class="c1">#--- Spaces before and after paragraph --------------------------</span>

            <span class="k">for</span> <span class="n">case</span> <span class="ow">in</span> <span class="p">[[</span><span class="s2">&quot;VOR&quot;</span><span class="p">,</span> <span class="s2">&quot;before&quot;</span><span class="p">],</span> <span class="p">[</span><span class="s2">&quot;NACH&quot;</span><span class="p">,</span> <span class="s2">&quot;after&quot;</span><span class="p">]]:</span>

                <span class="k">if</span> <span class="p">(</span><span class="n">space_att</span> <span class="p">:</span><span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">case</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">space</span><span class="p">[</span><span class="n">case</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="n">dimensions</span><span class="o">.</span><span class="n">Dim</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">space_att</span><span class="p">))</span>

            <span class="c1">#--- Tabs -------------------------------------------------------</span>

            <span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">xml</span><span class="p">:</span>

                <span class="k">if</span> <span class="n">child</span><span class="o">.</span><span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;Tabs&quot;</span><span class="p">:</span>
                    <span class="n">to</span> <span class="o">=</span> <span class="n">StyleTab</span><span class="p">()</span>

                    <span class="k">if</span> <span class="p">(</span><span class="n">success</span> <span class="p">:</span><span class="o">=</span> <span class="n">to</span><span class="o">.</span><span class="n">fromxml</span><span class="p">(</span><span class="n">child</span><span class="p">)):</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">tabs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">to</span><span class="p">)</span>

            <span class="c1">#--- End of parsing ---------------------------------------------</span>

910
911
            <span class="bp">self</span><span class="o">.</span><span class="n">undocumented</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">all_undocumented_to_python</span><span class="p">(</span><span class="n">xml</span><span class="p">)</span>

Etienne Nadji's avatar
Etienne Nadji committed
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="ParagraphStyle.toxml"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.ParagraphStyle.toxml">[docs]</a>    <span class="k">def</span> <span class="nf">toxml</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">xml</span> <span class="o">=</span> <span class="n">StyleAbstract</span><span class="o">.</span><span class="n">toxml</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="c1">#------------------------------------------------------------</span>

        <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;ALIGN&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">alignment</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;alignment&quot;</span><span class="p">]]</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">leading</span><span class="p">[</span><span class="s2">&quot;mode&quot;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;LINESPMode&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ParagraphStyle</span><span class="o">.</span><span class="n">leading_xml</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">leading</span><span class="p">[</span><span class="s2">&quot;mode&quot;</span><span class="p">]]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">leading</span><span class="p">[</span><span class="s2">&quot;mode&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;fixed&quot;</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;LINESP&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">leading</span><span class="p">[</span><span class="s2">&quot;value&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">toxmlstr</span><span class="p">()</span>

929
930
931
932
933
934
935
936
937
938
939
        <span class="c1">#--- Indentation --------------------------------------------</span>

        <span class="k">for</span> <span class="n">case</span> <span class="ow">in</span> <span class="p">[</span>
            <span class="p">[</span><span class="s2">&quot;left&quot;</span><span class="p">,</span> <span class="s2">&quot;INDENT&quot;</span><span class="p">],</span> <span class="p">[</span><span class="s2">&quot;right&quot;</span><span class="p">,</span> <span class="s2">&quot;RMARGIN&quot;</span><span class="p">],</span>
            <span class="p">[</span><span class="s2">&quot;first-line&quot;</span><span class="p">,</span> <span class="s2">&quot;FIRST&quot;</span><span class="p">]]:</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">indentations</span><span class="p">[</span><span class="n">case</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">case</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="s2">&quot;0&quot;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">case</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indentations</span><span class="p">[</span><span class="n">case</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">toxmlstr</span><span class="p">()</span>

Etienne Nadji's avatar
Etienne Nadji committed
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
        <span class="c1">#--- Parent character style ---------------------------------</span>

        <span class="c1"># NOTE To not confuse with parent paragraph style which is</span>
        <span class="c1"># in @PARENT, and handled in StyleAbstract</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">character_parent</span><span class="p">:</span>
            <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;CPARENT&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">character_parent</span>

        <span class="k">for</span> <span class="n">case</span> <span class="ow">in</span> <span class="p">[[</span><span class="s2">&quot;before&quot;</span><span class="p">,</span> <span class="s2">&quot;VOR&quot;</span><span class="p">],</span> <span class="p">[</span><span class="s2">&quot;after&quot;</span><span class="p">,</span> <span class="s2">&quot;NACH&quot;</span><span class="p">]]:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">space</span><span class="p">[</span><span class="n">case</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">case</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">space</span><span class="p">[</span><span class="n">case</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">toxmlstr</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># xml.attrib[&quot;VOR&quot;] = self.space[&quot;before&quot;].toxmlstr()</span>
        <span class="c1"># xml.attrib[&quot;NACH&quot;] = self.space[&quot;after&quot;].toxmlstr()</span>

        <span class="c1">#--- FONT SIZE ----------------------------------------------</span>

        <span class="n">font_size</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">[</span><span class="s2">&quot;size&quot;</span><span class="p">])</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">character_parent</span> <span class="ow">and</span> <span class="n">font_size</span> <span class="o">==</span> <span class="s2">&quot;0&quot;</span><span class="p">:</span>
            <span class="c1"># If the font size of the paragraph is not defined</span>
            <span class="c1"># because it is defined in a parent character style,</span>
            <span class="c1"># don&#39;t write FONTSIZE attribute</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">font_size</span> <span class="o">!=</span> <span class="s2">&quot;0&quot;</span><span class="p">:</span>
                <span class="n">xml</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;FONTSIZE&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">font_size</span>
            <span class="c1"># else:</span>
                <span class="c1"># raise exceptions.InsaneSLAValue(</span>
                    <span class="c1"># &quot;Paragraph style &#39;{}&#39; has no parent character style and a&quot;</span>
                    <span class="c1"># &quot;fontsize equal to zero.&quot;.format(</span>
                        <span class="c1"># self.name</span>
                    <span class="c1"># )</span>
                <span class="c1"># )</span>

        <span class="c1">#------------------------------------------------------------</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">xml</span><span class="p">,</span> <span class="n">undoc_attribs</span> <span class="o">=</span> <span class="n">xmlc</span><span class="o">.</span><span class="n">all_undocumented_to_xml</span><span class="p">(</span>
                <span class="n">xml</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">undocumented</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">style_type</span> <span class="o">+</span> <span class="s2">&quot; style&quot;</span>
            <span class="p">)</span>

        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="c1"># NOTE If fromxml was not used</span>
            <span class="k">pass</span>

        <span class="k">return</span> <span class="n">xml</span></div>

<div class="viewcode-block" id="ParagraphStyle.fromdefault"><a class="viewcode-back" href="../../pyscribus.html#pyscribus.styles.ParagraphStyle.fromdefault">[docs]</a>    <span class="k">def</span> <span class="nf">fromdefault</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">StyleAbstract</span><span class="o">.</span><span class="n">fromdefault</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">leading</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;mode&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
            <span class="s2">&quot;value&quot;</span><span class="p">:</span> <span class="n">dimensions</span><span class="o">.</span><span class="n">Dim</span><span class="p">(</span><span class="mi">12</span><span class="p">)</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="kc">True</span></div>

    <span class="k">def</span> <span class="nf">_quick_setup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
For faster browsing, not all history is shown. View entire blame