Ejemplo n.º 1
0
 def test_insert_heading(self):
     body = self.body.clone()
     heading = odf_create_heading(2, u'An inserted heading',
                                  style='Heading_20_2')
     body.append(heading)
     last_heading = body.get_headings()[-1]
     self.assertEqual(last_heading.get_text(), u'An inserted heading')
Ejemplo n.º 2
0
 def test_insert_heading(self):
     body = self.body.clone()
     heading = odf_create_heading(2, 'An inserted heading',
                                  style='Heading_20_2')
     body.append(heading)
     last_heading = body.get_headings()[-1]
     self.assertEqual(last_heading.get_text(), 'An inserted heading')
Ejemplo n.º 3
0
def make_document(structure, body):
    for level, text, struct in structure:
        # Create the heading with the corresponding level
        heading = odf_create_heading(level, text=text)
        # Add the heading to the document's body
        body.append(heading)
        make_document(struct, body)
Ejemplo n.º 4
0
def make_document(structure, body):
    for level, text, struct in structure:
        # Create the heading with the corresponding level
        heading = odf_create_heading(level, text=text)
        # Add the heading to the document's body
        body.append(heading)
        make_document(struct, body)
Ejemplo n.º 5
0
def convert_title(node, context):
    level = context["heading-level"]
    if level == 0:
        # The document did not start with a section
        level = 1
    heading = odf_create_heading(level, node.astext(),
            style='Heading_20_%s' % level)
    context["body"].append_element(heading)
Ejemplo n.º 6
0
 def test_create_text_frame_element(self):
     heading = odf_create_heading(1, u"Zoé")
     frame = odf_create_text_frame(heading)
     expected = ('<draw:frame svg:width="1cm" svg:height="1cm" '
                   'text:anchor-type="paragraph">'
                   '<draw:text-box>'
                     '<text:h text:outline-level="1">Zo&#233;</text:h>'
                   '</draw:text-box>'
                 '</draw:frame>')
     self.assertEqual(frame.serialize(), expected)
Ejemplo n.º 7
0
 def test_create_text_frame_element(self):
     heading = odf_create_heading(1, "Zoé")
     frame = odf_create_text_frame(heading)
     expected = ('<draw:frame svg:width="1cm" svg:height="1cm" '
                   'draw:z-index="0">'
                   '<draw:text-box>'
                     '<text:h text:outline-level="1">Zo&#233;</text:h>'
                   '</draw:text-box>'
                 '</draw:frame>')
     self.assertEqual(frame.serialize(), expected)
Ejemplo n.º 8
0
from lpod.toc import odf_create_toc

# Creation of the document
document = odf_new_document_from_type('text')
body = document.get_body()

# Add (empty) Table of content
toc = odf_create_toc()
body.append(toc)

# Add Paragraph
paragraph = odf_create_paragraph(u'lpOD generated Document')
body.append(paragraph)

# Add Heading
heading = odf_create_heading(1, text=u'Lists')
body.append(heading)

#
# A list
#
my_list = odf_create_list([u'chocolat', u'café'])

item = odf_create_list_item(u'Du thé')
item.append(odf_create_list([u'thé vert', u'thé rouge']))
my_list.append_item(item)

# insert item by position
my_list.insert_item(u'Chicorée', position=1)

# insert item by relative position
Ejemplo n.º 9
0
# Hello messages
print 'lpod installation test'
print ' Version           : %s' %  __version__
print ' Installation path : %s' % __installation_path__
print
print 'Generating test_output/use_case1.odt ...'


# Go
document = odf_new_document_from_type('text')
body = document.get_body()

samples = vfs.open('samples')
for numero, filename in enumerate(samples.get_names()):
    # Heading
    heading = odf_create_heading(2, text=unicode(filename, 'utf-8'))
    body.append_element(heading)

    uri = samples.get_uri(filename)
    handler = get_handler(uri)
    if isinstance(handler, Image):
        # Add the image
        internal_name = 'Pictures/' + filename
        width, height = handler.get_size()
        paragraph = odf_create_paragraph('Standard')
        # 72 ppp
        frame = odf_create_frame('frame_%d' % numero, 'Graphics',
                                 str(width / 72.0) + 'in',
                                 str(height / 72.0) + 'in')
        image = odf_create_image(internal_name)
        frame.append_element(image)
def make_catalog():
    cat_list = []
    price = 10.0
    for p in range(5):
        cat_list.append(Product(chr(65 + p), price))
        price += 10.5
    return cat_list

tax_rate = .196

if __name__=="__main__":
    commercial = odf_new_document('text')
    body = commercial.get_body()
    catalog = make_catalog()

    title1 = odf_create_heading(1, u"Basic commercial document")
    body.append(title1)
    title11 = odf_create_heading(2, u"Available products")
    body.append(title11)
    paragraph = odf_create_paragraph(u"Here the list:")
    body.append(paragraph)

    # List of products in a list :
    product_list = odf_create_list()
    body.append(product_list)
    for product in catalog:
        item = odf_create_list_item(u"%-10s, price: %.2f €" % (
                                            product.name, product.price))
        product_list.append(item)

    title12 = odf_create_heading(2, u"Your command")
    except:
        text = u"Almost no text."
    return text


# Imports from lpod
from lpod.document import odf_new_document
from lpod.heading import odf_create_heading
from lpod.paragraph import odf_create_paragraph

# Create the document
my_document = odf_new_document('text')
body = my_document.get_body()

# Add content (See Create_a_basic_document.py)
title1 = odf_create_heading(1, random_text(1)[:70])
body.append(title1)
for p in range(3):
    title = odf_create_heading(2, random_text(1)[:70])
    body.append(title)
    paragraph = odf_create_paragraph(random_text(10))

    # Adding Annotation
    # Annotations are notes that don’t appear in the document but
    # typically on a side bar in a desktop application. So they are not printed.

    # Now we add some annotation on each paragraph
    some_word = paragraph.get_text(True).split()[3]
    # choosing the 4th word of the paragraph to insert the note

    paragraph.insert_annotation(
Ejemplo n.º 12
0
from lpod.table import odf_create_column, odf_create_table

# Hello messages
print 'lpod installation test'
print ' Version           : %s' % __version__
print ' Installation path : %s' % __installation_path__
print
print 'Generating test_output/use_case1.odt ...'

# Go
document = odf_new_document('text')
body = document.get_body()

for numero, filename in enumerate(listdir('samples')):
    # Heading
    heading = odf_create_heading(1, text=unicode(filename, 'utf-8'))
    body.append(heading)
    path = join('samples', filename)
    mimetype, _ = guess_type(path)
    if mimetype is None:
        mimetype = 'application/octet-stream'
    if mimetype.startswith('image/'):
        # Add the image
        internal_name = 'Pictures/' + filename
        image = Image.open(path)
        width, height = image.size
        paragraph = odf_create_paragraph('Standard')
        # 72 ppp
        frame = odf_create_frame('frame_%d' % numero, 'Graphics',
                                 str(width / 72.0) + 'in',
                                 str(height / 72.0) + 'in')
Ejemplo n.º 13
0
from lpod.table import odf_create_column, odf_create_table

# Hello messages
print('lpod installation test')
print(' Version           : %s' % __version__)
print(' Installation path : %s' % __installation_path__)
print()
print('Generating test_output/use_case1.odt ...')

# Go
document = odf_new_document('text')
body = document.get_body()

for numero, filename in enumerate(listdir('samples')):
    # Heading
    heading = odf_create_heading(1, text=str(filename, 'utf-8'))
    body.append(heading)
    path = join('samples', filename)
    mimetype, _ = guess_type(path)
    if mimetype is None:
        mimetype = 'application/octet-stream'
    if mimetype.startswith('image/'):
        # Add the image
        internal_name = 'Pictures/' + filename
        image = Image.open(path)
        width, height = image.size
        paragraph = odf_create_paragraph('Standard')
        # 72 ppp
        frame = odf_create_frame('frame_%d' % numero, 'Graphics',
                                 str(width / 72.0) + 'in',
                                 str(height / 72.0) + 'in')
        text = urllib.urlopen(uri).read().decode("iso8859-1")
    except:
        text = u"Almost no text."
    return text

# Imports from lpod
from lpod.document import odf_new_document
from lpod.heading import odf_create_heading
from lpod.paragraph import odf_create_paragraph

# Create the document
my_document = odf_new_document('text')
body = my_document.get_body()

# Add content (See Create_a_basic_document.py)
title1 = odf_create_heading(1, random_text(1)[:70])
body.append(title1)
for p in range(3):
    title = odf_create_heading(2, random_text(1)[:70])
    body.append(title)
    paragraph = odf_create_paragraph(random_text(10))

    # Adding Annotation
    # Annotations are notes that don’t appear in the document but
    # typically on a side bar in a desktop application. So they are not printed.

    # Now we add some annotation on each paragraph
    some_word = paragraph.get_text(True).split()[3]
    # choosing the 4th word of the paragraph to insert the note

    paragraph.insert_annotation(
Ejemplo n.º 15
0
                         str(width / 72.0) + 'in',
                         str(height / 72.0) + 'in')
internal_name = 'Pictures/image.png'
image = odf_create_image(internal_name)
frame.append(image)
paragraph.append(frame)
body.append(paragraph)

# And store the data
container = document.container
container.set_part(internal_name, open('samples/image.png').read())


# 1- Congratulations (=> style on paragraph)
# ------------------------------------------
heading = odf_create_heading(1, text=u'Congratulations !')
body.append(heading)

# The style
style = odf_create_style('paragraph', u"style1", parent=u"Standard",
        area='text', color=rgb2hex('blue'), background_color=rgb2hex('red'))
document.insert_style(style)

# The paragraph
text =  u'This document has been generated by the lpOD installation test.'
paragraph = odf_create_paragraph(text, style=u"style1")
body.append(paragraph)


# 2- Your environment (=> a table)
# --------------------------------
Ejemplo n.º 16
0
def create_heading(level, text, style=None):
    text = u" {}".format(text)

    return odf_create_heading(level, text)
# -*- coding: UTF-8 -*-
# Let's add another section to make our document clear:
# Annotations are notes that don’t appear in the document but typically on a
# side bar in a desktop application. So they are not printed.
from lpod.document import odf_new_document
from lpod.paragraph import odf_create_paragraph

from lpod.heading import odf_create_heading

document = odf_new_document("text")
body = document.get_body()

body.append(odf_create_heading(1, u"Annotations"))
paragraph = odf_create_paragraph(u"A paragraph with an annotation in the middle.")
body.append(paragraph)

# Annotations are inserted like notes but they are simpler:

paragraph.insert_annotation(after=u"annotation", body=u"It's so easy!", creator=u"Luis")

# Annotation arguments are quite different:
# after   =>  The word after what the annotation is inserted.
# body    =>  The annotation itself, at the end of the page.
# creator =>  The author of the annotation.
# date    =>  A datetime value, by default datetime.now().
def make_coords(side, vpos):
    orig = complex((17 - side)/2.0, vpos)
    v1 = Vector(orig, orig + complex(side, 0))
    v2 = Vector(v1.b, orig + cmath.rect(side, cmath.pi / 3))
    v3 = Vector(v2.b, orig)
    center = (v1.a + v1.b + v2.b) / 3
    vlist = koch([v1, v2, v3], cycle = 5)
    return center, vlist

if __name__=="__main__":

    document = odf_new_document('text')
    body = document.get_body()

    print "Making some Koch fractal"
    title = odf_create_heading(1, "Some Koch fractal")
    body.append(title)

    style = document.get_style('graphic')
    style.set_properties({"svg:stroke_color" : "#0000ff"})
    style.set_properties(fill_color = "#ffffcc")

    para = odf_create_paragraph(u"")
    body.append(para)

    # some computation of oordinates
    center, vlist = make_coords(side=12.0, vpos=8.0)

    # create a circle
    rad = 8.0
    pos = center - complex(rad, rad)
Ejemplo n.º 19
0
# -*- coding: UTF-8 -*-
from lpod.document import odf_new_document

document = odf_new_document('text')
body = document.get_body()

from lpod.heading import odf_create_heading

title1 = odf_create_heading(1, u"The Title")
body.append(title1)
# -*- coding: UTF-8 -*-
# Let's add another section to make our document clear:
# Annotations are notes that don’t appear in the document but typically on a
# side bar in a desktop application. So they are not printed.
from lpod.document import odf_new_document
from lpod.paragraph import odf_create_paragraph

from lpod.heading import odf_create_heading

document = odf_new_document('text')
body = document.get_body()

body.append(odf_create_heading(1, u"Annotations"))
paragraph = odf_create_paragraph(
    u"A paragraph with an annotation in the middle.")
body.append(paragraph)

# Annotations are inserted like notes but they are simpler:

paragraph.insert_annotation(after=u"annotation",
                            body=u"It's so easy!",
                            creator=u"Luis")

# Annotation arguments are quite different:
# after   =>  The word after what the annotation is inserted.
# body    =>  The annotation itself, at the end of the page.
# creator =>  The author of the annotation.
# date    =>  A datetime value, by default datetime.now().
Ejemplo n.º 21
0
from lpod.toc import odf_create_toc

# Creation of the document
document = odf_new_document_from_type('text')
body = document.get_body()

# Add (empty) Table of content
toc = odf_create_toc()
body.append(toc)

# Add Paragraph
paragraph = odf_create_paragraph(u'lpOD generated Document')
body.append(paragraph)

# Add Heading
heading = odf_create_heading(1, text=u'Lists')
body.append(heading)

#
# A list
#
my_list = odf_create_list([u'chocolat', u'café'])

item = odf_create_list_item(u'Du thé')
item.append(odf_create_list([u'thé vert', u'thé rouge']))
my_list.append_item(item)

# insert item by position
my_list.insert_item(u'Chicorée', position=1)

# insert item by relative position
Ejemplo n.º 22
0
# -*- coding: UTF-8 -*-
from lpod.document import odf_new_document
from lpod.heading import odf_create_heading
from lpod.paragraph import odf_create_paragraph

document = odf_new_document('text')
body = document.get_body()

# Let's add another section to make our document clear:

body.append(odf_create_heading(1, u"Tables"))
body.append(odf_create_paragraph(u"A 3x3 table:"))

# Creating a table :

from lpod.table import odf_create_table
table = odf_create_table(u"Table 1", width=3, height=3)
body.append(table)
# -*- coding: UTF-8 -*-
from lpod.document import odf_new_document

document = odf_new_document('text')
body = document.get_body()


from lpod.heading import odf_create_heading

title1 = odf_create_heading(1, u"The Title")
body.append(title1)
Ejemplo n.º 24
0
frame = odf_create_frame('frame1', 'Graphics',
                         str(width / 72.0) + 'in',
                         str(height / 72.0) + 'in')
internal_name = 'Pictures/image.png'
image = odf_create_image(internal_name)
frame.append(image)
paragraph.append(frame)
body.append(paragraph)

# And store the data
container = document.container
container.set_part(internal_name, open('samples/image.png').read())

# 2- Congratulations (=> style on paragraph)
# ------------------------------------------
heading = odf_create_heading(1, text=u'Congratulations !')
body.append(heading)

# The style
style = odf_create_style('paragraph',
                         u"style1",
                         parent=u"Standard",
                         area='text',
                         color=rgb2hex('blue'),
                         background_color=rgb2hex('red'))
document.insert_style(style)

# The paragraph
text = u'This document has been generated by the lpOD installation test.'
paragraph = odf_create_paragraph(text, style=u"style1")
body.append(paragraph)
Ejemplo n.º 25
0
    orig = complex((17 - side) / 2.0, vpos)
    v1 = Vector(orig, orig + complex(side, 0))
    v2 = Vector(v1.b, orig + cmath.rect(side, cmath.pi / 3))
    v3 = Vector(v2.b, orig)
    center = (v1.a + v1.b + v2.b) / 3
    vlist = koch([v1, v2, v3], cycle=5)
    return center, vlist


if __name__ == "__main__":

    document = odf_new_document('text')
    body = document.get_body()

    print "Making some Koch fractal"
    title = odf_create_heading(1, "Some Koch fractal")
    body.append(title)

    style = document.get_style('graphic')
    style.set_properties({"svg:stroke_color": "#0000ff"})
    style.set_properties(fill_color="#ffffcc")

    para = odf_create_paragraph(u"")
    body.append(para)

    # some computation of oordinates
    center, vlist = make_coords(side=12.0, vpos=8.0)

    # create a circle
    rad = 8.0
    pos = center - complex(rad, rad)