Пример #1
0
    def write(self):
        dn = {k:v for k, v in namespaces.iteritems() if k in {'w', 'r', 'm', 've', 'o', 'wp', 'w10', 'wne'}}
        E = ElementMaker(namespace=dn['w'], nsmap=dn)
        self.docx.document = doc = E.document()
        body = E.body()
        doc.append(body)
        for block in self.blocks:
            block.serialize(body)

        dn = {k:v for k, v in namespaces.iteritems() if k in 'wr'}
        E = ElementMaker(namespace=dn['w'], nsmap=dn)
        self.docx.styles = E.styles(
            E.docDefaults(
                E.rPrDefault(
                    E.rPr(
                        E.rFonts(**{w('asciiTheme'):"minorHAnsi", w('eastAsiaTheme'):"minorEastAsia", w('hAnsiTheme'):"minorHAnsi", w('cstheme'):"minorBidi"}),
                        E.sz(**{w('val'):'22'}),
                        E.szCs(**{w('val'):'22'}),
                        E.lang(**{w('val'):'en-US', w('eastAsia'):"en-US", w('bidi'):"ar-SA"})
                    )
                ),
                E.pPrDefault(
                    E.pPr(
                        E.spacing(**{w('after'):"0", w('line'):"276", w('lineRule'):"auto"})
                    )
                )
            )
        )
Пример #2
0
 def serialize(self, body):
     p = body.makeelement(w('p'))
     body.append(p)
     ppr = p.makeelement(w('pPr'))
     p.append(ppr)
     if self.keep_next:
         ppr.append(ppr.makeelement(w('keepNext')))
     for run in self.runs:
         run.serialize(p)
Пример #3
0
 def serialize(self, body):
     p = body.makeelement(w('p'))
     body.append(p)
     ppr = p.makeelement(w('pPr'))
     p.append(ppr)
     if self.keep_next:
         ppr.append(ppr.makeelement(w('keepNext')))
     ppr.append(ppr.makeelement(w('pStyle'), **{w('val'):self.style.id}))
     for run in self.runs:
         run.serialize(p)
Пример #4
0
 def serialize(self, p):
     r = p.makeelement(w('r'))
     p.append(r)
     for text, preserve_whitespace in self.texts:
         if text is None:
             r.append(r.makeelement(w('br'), **{w('clear'):preserve_whitespace}))
         else:
             t = r.makeelement(w('t'))
             r.append(t)
             t.text = text or ''
             if preserve_whitespace:
                 t.set('{http://www.w3.org/XML/1998/namespace}space', 'preserve')
Пример #5
0
 def serialize(self, p):
     r = p.makeelement(w('r'))
     p.append(r)
     rpr = r.makeelement(w('rPr'))
     rpr.append(rpr.makeelement(w('rStyle'), **{w('val'):self.style.id}))
     r.append(rpr)
     for text, preserve_whitespace in self.texts:
         if text is None:
             r.append(r.makeelement(w('br'), **{w('clear'):preserve_whitespace}))
         else:
             t = r.makeelement(w('t'))
             r.append(t)
             t.text = text or ''
             if preserve_whitespace:
                 t.set('{http://www.w3.org/XML/1998/namespace}space', 'preserve')
Пример #6
0
 def serialize(self, p):
     r = p.makeelement(w('r'))
     p.append(r)
     rpr = r.makeelement(w('rPr'))
     rpr.append(rpr.makeelement(w('rStyle'), **{w('val'):self.style.id}))
     r.append(rpr)
     for text, preserve_whitespace in self.texts:
         if text is None:
             r.append(r.makeelement(w('br'), **{w('clear'):preserve_whitespace}))
         elif hasattr(text, 'xpath'):
             r.append(text)
         else:
             t = r.makeelement(w('t'))
             r.append(t)
             t.text = text or ''
             if preserve_whitespace:
                 t.set('{http://www.w3.org/XML/1998/namespace}space', 'preserve')
Пример #7
0
 def margin(which):
     return w(which), str(int(getattr(self.opts, 'margin_'+which) * 20))
Пример #8
0
    def write(self):
        dn = {k:v for k, v in namespaces.iteritems() if k in {'w', 'r', 'm', 've', 'o', 'wp', 'w10', 'wne'}}
        E = ElementMaker(namespace=dn['w'], nsmap=dn)
        self.docx.document = doc = E.document()
        body = E.body()
        doc.append(body)
        for block in self.blocks:
            block.serialize(body)
        width, height = PAPER_SIZES[self.opts.docx_page_size]
        if self.opts.docx_custom_page_size is not None:
            width, height = map(float, self.opts.docx_custom_page_size.partition('x')[0::2])
        width, height = int(20 * width), int(20 * height)
        def margin(which):
            return w(which), str(int(getattr(self.opts, 'margin_'+which) * 20))
        body.append(E.sectPr(
            E.pgSz(**{w('w'):str(width), w('h'):str(height)}),
            E.pgMar(**dict(map(margin, 'left top right bottom'.split()))),
            E.cols(**{w('space'):'720'}),
            E.docGrid(**{w('linePitch'):"360"}),
        ))

        dn = {k:v for k, v in namespaces.iteritems() if k in 'wr'}
        E = ElementMaker(namespace=dn['w'], nsmap=dn)
        self.docx.styles = E.styles(
            E.docDefaults(
                E.rPrDefault(
                    E.rPr(
                        E.rFonts(**{w('asciiTheme'):"minorHAnsi", w('eastAsiaTheme'):"minorEastAsia", w('hAnsiTheme'):"minorHAnsi", w('cstheme'):"minorBidi"}),
                        E.sz(**{w('val'):'22'}),
                        E.szCs(**{w('val'):'22'}),
                        E.lang(**{w('val'):'en-US', w('eastAsia'):"en-US", w('bidi'):"ar-SA"})
                    )
                ),
                E.pPrDefault(
                    E.pPr(
                        E.spacing(**{w('after'):"0", w('line'):"276", w('lineRule'):"auto"})
                    )
                )
            )
        )
        self.styles_manager.serialize(self.docx.styles)