def header(self, text, level, raw=None): page = None if level == 1: page = odf_create_draw_page('page1', name=hasher(), master_page=self.break_master, presentation_page_layout=u'AL3T19') page.append( odf_create_text_frame( wrap_spans(text.get()), presentation_style=u'md2odp-BreakTitleText', size=(u'%s' % self.breakheader_size[0], u'%s' % self.breakheader_size[1]), position=(u'%s' % self.breakheader_position[0], u'%s' % self.breakheader_position[1]), presentation_class=u'title')) elif level == 2: page = odf_create_draw_page('page1', name=hasher(), master_page=self.content_master, presentation_page_layout=u'AL3T1') page.append( odf_create_text_frame( wrap_spans(text.get()), presentation_style=u'md2odp-TitleText', size=(u'%s' % self.header_size[0], u'%s' % self.header_size[1]), position=(u'%s' % self.header_position[0], u'%s' % self.header_position[1]), presentation_class=u'title')) else: raise RuntimeError('Unsupported heading level: %d' % level) return ODFPartialTree.from_metrics_provider([page], self)
def test_create_line(self): page = odf_create_draw_page('Page1') line = odf_create_line(p1=('2cm', '2cm'), p2=('1cm', '1cm')) page.append_element(line) expected = ('<draw:page draw:id="Page1">\n' ' <draw:line svg:x1="2cm" svg:y1="2cm" svg:x2="1cm" ' 'svg:y2="1cm"/>\n' '</draw:page>\n') self.assertEqual(page.serialize(pretty=True), expected)
def test_create_complex_page(self): element = odf_create_draw_page('id1', name=u"Introduction", master_page='prs-novelty', page_layout='AL1T0', style='dp1') expected = ('<draw:page draw:id="id1" draw:name="Introduction" ' 'draw:style-name="dp1" ' 'draw:master-page-name="prs-novelty" ' 'presentation:presentation-page-layout-name="AL1T0"/>') self.assertEqual(element.serialize(), expected)
def test_create_line(self): page = odf_create_draw_page('Page1') line = odf_create_line(p1=('2cm', '2cm'), p2=('1cm', '1cm')) page.append(line) expected = ('<draw:page draw:id="Page1">\n' ' <draw:line svg:x1="2cm" svg:y1="2cm" svg:x2="1cm" ' 'svg:y2="1cm"/>\n' '</draw:page>\n') self.assertEqual(page.serialize(pretty=True), expected)
def test_create_rectangle(self): page = odf_create_draw_page('Page1') rectangle = odf_create_rectangle(size=('2cm', '1cm'), position=('3cm', '4cm')) page.append(rectangle) expected = ('<draw:page draw:id="Page1">\n' ' <draw:rect svg:width="2cm" svg:height="1cm" svg:x="3cm"' ' svg:y="4cm"/>\n' '</draw:page>\n') self.assertEqual(page.serialize(pretty=True), expected)
def test_create_rectangle(self): page = odf_create_draw_page('Page1') rectangle = odf_create_rectangle(size=('2cm', '1cm'), position=('3cm', '4cm')) page.append_element(rectangle) expected = ('<draw:page draw:id="Page1">\n' ' <draw:rect svg:width="2cm" svg:height="1cm" svg:x="3cm"' ' svg:y="4cm"/>\n' '</draw:page>\n') self.assertEqual(page.serialize(pretty=True), expected)
def test_create_complex_page(self): element = odf_create_draw_page('id1', name=u"Introduction", master_page='prs-novelty', presentation_page_layout='AL1T0', style='dp1') expected = ('<draw:page draw:id="id1" draw:name="Introduction" ' 'draw:style-name="dp1" ' 'draw:master-page-name="prs-novelty" ' 'presentation:presentation-page-layout-name="AL1T0"/>') self.assertEqual(element.serialize(), expected)
def header(self, text, level, raw=None): page = None if level == 1: page = odf_create_draw_page( 'page1', name=hasher(), master_page=self.break_master, presentation_page_layout=u'AL3T19') page.append( odf_create_text_frame( wrap_spans(text.get()), presentation_style=u'md2odp-BreakTitleText', size=(u'%s' % self.breakheader_size[0], u'%s' % self.breakheader_size[1]), position=(u'%s' % self.breakheader_position[0], u'%s' % self.breakheader_position[1]), presentation_class=u'title')) elif level == 2: page = odf_create_draw_page( 'page1', name=hasher(), master_page=self.content_master, presentation_page_layout=u'AL3T1') page.append( odf_create_text_frame( wrap_spans(text.get()), presentation_style=u'md2odp-TitleText', size=(u'%s' % self.header_size[0], u'%s' % self.header_size[1]), position=(u'%s' % self.header_position[0], u'%s' % self.header_position[1]), presentation_class=u'title')) else: raise RuntimeError('Unsupported heading level: %d' % level) return ODFPartialTree.from_metrics_provider([page], self)
def test_create_ellipse(self): page = odf_create_draw_page('Page1') svg_attrs = { 'svg:width': '2cm', 'svg:height': '2cm', 'svg:x': '2cm', 'svg:y': '2cm'} ellipse = odf_create_ellipse(size=('2cm', '1cm'), position=('3cm', '4cm')) page.append_element(ellipse) expected = ('<draw:page draw:id="Page1">\n' ' <draw:ellipse svg:width="2cm" svg:height="1cm" ' 'svg:x="3cm" svg:y="4cm"/>\n' '</draw:page>\n') self.assertEqual(page.serialize(pretty=True), expected)
def test_create_ellipse(self): page = odf_create_draw_page('Page1') svg_attrs = { 'svg:width': '2cm', 'svg:height': '2cm', 'svg:x': '2cm', 'svg:y': '2cm' } ellipse = odf_create_ellipse(size=('2cm', '1cm'), position=('3cm', '4cm')) page.append(ellipse) expected = ('<draw:page draw:id="Page1">\n' ' <draw:ellipse svg:width="2cm" svg:height="1cm" ' 'svg:x="3cm" svg:y="4cm"/>\n' '</draw:page>\n') self.assertEqual(page.serialize(pretty=True), expected)
def test_create_connector(self): page = odf_create_draw_page('Page1') rectangle = odf_create_rectangle(size=('2cm', '1cm'), position=('3cm', '4cm'), shape_id='rectangle') ellipse = odf_create_ellipse(size=('2cm', '1cm'), position=('3cm', '4cm'), shape_id='ellipse') connector = odf_create_connector(connected_shapes=(rectangle, ellipse), glue_points=(1, 2)) page.append(rectangle) page.append(ellipse) page.append(connector) expected = ('<draw:page draw:id="Page1">\n' ' <draw:rect draw:id="rectangle" svg:width="2cm" ' 'svg:height="1cm" svg:x="3cm" svg:y="4cm"/>\n' ' <draw:ellipse draw:id="ellipse" svg:width="2cm" ' 'svg:height="1cm" svg:x="3cm" svg:y="4cm"/>\n' ' <draw:connector draw:start-shape="rectangle" ' 'draw:end-shape="ellipse" draw:start-glue-point="1" ' 'draw:end-glue-point="2"/>\n' '</draw:page>\n') self.assertEqual(page.serialize(pretty=True), expected)
def test_create_connector(self): page = odf_create_draw_page('Page1') rectangle = odf_create_rectangle(size=('2cm', '1cm'), position=('3cm', '4cm'), shape_id='rectangle') ellipse = odf_create_ellipse(size=('2cm', '1cm'), position=('3cm', '4cm'), shape_id='ellipse') connector = odf_create_connector(connected_shapes=(rectangle, ellipse), glue_points=(1, 2)) page.append_element(rectangle) page.append_element(ellipse) page.append_element(connector) expected = ('<draw:page draw:id="Page1">\n' ' <draw:rect draw:id="rectangle" svg:width="2cm" ' 'svg:height="1cm" svg:x="3cm" svg:y="4cm"/>\n' ' <draw:ellipse draw:id="ellipse" svg:width="2cm" ' 'svg:height="1cm" svg:x="3cm" svg:y="4cm"/>\n' ' <draw:connector draw:start-shape="rectangle" ' 'draw:end-shape="ellipse" draw:start-glue-point="1" ' 'draw:end-glue-point="2"/>\n' '</draw:page>\n') self.assertEqual(page.serialize(pretty=True), expected)
# Making o lot of variations variants = [10, 11, 14, 16, 20, 24, 32, 40, 44] text_sz = [95, 80, 65, 50, 40, 30, 20, 10, 5] for size in variants: variant_style = base_style.clone() variant_style.set_attribute('style:name', 'Gloup%s' % size) variant_style.set_properties(area='text', size="%spt" % size) presentation.insert_style(variant_style) count = 0 for blurb in lst: count += 1 text = blurb.decode(encoding) name = u"%s - %s" % (count, text[:10]) page = odf_create_draw_page(name) # choosing some style: size = 48 for i, max_size in enumerate(text_sz): if len(text) > max_size: size = variants[i] break text_frame = odf_create_text_frame(text, size=('24cm', '2cm'), position=('2cm', '8cm'), style='Gloup%s' % size, text_style='Gloup%s' % size) page.append(text_frame) presentation_body.append(page)
# weight = len(doc_source.get_part(uri)) # only for info # print "image %s , size in bytes: %s" % (uri, weight) part = doc_source.get_part(uri) # actual image content name = uri.split('/')[-1] # lets make a file name for image # Compute the display size of the image on the final page ratio = embedded_image_ratio(uri, part) max_border = 16.0 # max size of the greatest border, in cm a = max_border * ratio b = max_border if ratio > 1.0: a /= ratio b /= ratio # Create an underlying page for the image and the text page = odf_create_draw_page("page "+name) # Create a frame for the image image_frame = odf_create_image_frame( url = uri, text = "", # Text over the image object size = ("%scm" % a, "%scm" % b), # Display size of image anchor_type = 'page', page_number = None, position = ('3.5cm','3.5 cm'), style = None ) # Add some text object somehere on the frame, with a text frame legend = "Image %s from Wikipedia document / %s" % (name, filename) text_frame = odf_create_text_frame(
PPC = 72 * 2.54 # Creation of the document document = odf_new_document_from_type('presentation') body = document.get_body() # Change the default graphic fill color standard = document.get_style('graphic', u"standard") standard.set_style_properties({'draw:fill-color': '#ffffff'}) # # Work on pages and add textframes # page1 = odf_create_draw_page('page1', name=u"Page 1") body.append(page1) # # Text Frame # # Set the frame color colored = odf_create_style('graphic', name=u"colored", display_name=u"Colored", parent="standard") colored.set_style_properties({'draw:fill-color': "#ad7fa8"}, area='graphic') colored.set_style_properties(color="#ffffff", area='text') document.insert_style(colored) # A paragraph style with big font
netloc = '%s:%s' % (result.hostname, result.port) else: netloc = result.hostname url = urlunsplit( (scheme, netloc, result.path, result.query, result.fragment)) password_mgr = HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, url, result.username, result.password) handler = HTTPBasicAuthHandler(password_mgr) opener = build_opener(handler) file = opener.open(url) else: file = urlopen(filename) input_document = odf_get_document(file) # Page page = odf_create_draw_page(name=u"page%d" % (i + 1), master_page=first_master_page) # Title Frame title_frame = get_title_frame(first_master_page) name = unicode(filename.split('/')[-1]) source = u"filesystem" if not scheme else scheme title_frame.set_text_content(u"%s (%s)" % (name, source)) page.append(title_frame) # Get info info = [] input_meta = input_document.get_part(ODF_META) info.append(u"Title: %s" % input_meta.get_title()) stats = input_meta.get_statistic() info.append(u"# pages: %s" % stats['meta:page-count']) input_body = input_document.get_body() info.append(u"# images: %s" % len(input_body.get_images())) info.append(u"# tables: %s" % len(input_body.get_tables()))
text_sz = [95,80,65,50,40,30,20,10,5] for size in variants: variant_style = base_style.clone() variant_style.set_attribute('style:name', 'Gloup%s' % size) variant_style.set_properties( area = 'text', size = "%spt" % size ) presentation.insert_style(variant_style) count = 0 for blurb in lst: count += 1 text = blurb.decode(encoding) name = u"%s - %s" % (count, text[:10]) page = odf_create_draw_page(name) # choosing some style: size = 48 for i, max_size in enumerate(text_sz): if len(text) > max_size: size = variants[i] break text_frame = odf_create_text_frame( text, size = ('24cm', '2cm'), position = ('2cm', '8cm'), style = 'Gloup%s' % size, text_style = 'Gloup%s' % size) page.append(text_frame)
from lpod.style import odf_create_style PPC = 72 * 2.54 # Creation of the document document = odf_new_document_from_type('presentation') body = document.get_body() # Change the default graphic fill color standard = document.get_style('graphic', u"standard") standard.set_style_properties({'draw:fill-color': '#ffffff'}) # # Work on pages and add textframes # page1 = odf_create_draw_page('page1', name=u"Page 1") body.append(page1) # # Text Frame # # Set the frame color colored = odf_create_style('graphic', name=u"colored", display_name=u"Colored", parent="standard") colored.set_style_properties({'draw:fill-color': "#ad7fa8"}, area='graphic') colored.set_style_properties(color="#ffffff", area='text') document.insert_style(colored)
# -*- coding: UTF-8 -*- # I want to write "Hello World" in the middle of the first page. from lpod.document import odf_new_document from lpod.frame import odf_create_text_frame from lpod.draw_page import odf_create_draw_page document = odf_new_document('presentation') body = document.get_body() page = odf_create_draw_page('page1', name=u"Page 1") body.append(page) text_frame = odf_create_text_frame([u"Hello", u"World"], size=('7cm', '5cm'), position=('11cm', '8cm'), style=u"colored", text_style=u"big")
def test_create_simple_page(self): element = odf_create_draw_page('id1') expected = '<draw:page draw:id="id1"/>' self.assertEqual(element.serialize(), expected)
# weight = len(doc_source.get_part(uri)) # only for info # print "image %s , size in bytes: %s" % (uri, weight) part = doc_source.get_part(uri) # actual image content name = uri.split('/')[-1] # lets make a file name for image # Compute the display size of the image on the final page ratio = embedded_image_ratio(uri, part) max_border = 16.0 # max size of the greatest border, in cm a = max_border * ratio b = max_border if ratio > 1.0: a /= ratio b /= ratio # Create an underlying page for the image and the text page = odf_create_draw_page("page " + name) # Create a frame for the image image_frame = odf_create_image_frame( url=uri, text="", # Text over the image object size=("%scm" % a, "%scm" % b), # Display size of image anchor_type='page', page_number=None, position=('3.5cm', '3.5 cm'), style=None) # Add some text object somehere on the frame, with a text frame legend = "Image %s from Wikipedia document / %s" % (name, filename) text_frame = odf_create_text_frame(legend, size=('26cm', '2cm'),
netloc = '%s:%s' % (result.hostname, result.port) else: netloc = result.hostname url = urlunsplit((scheme, netloc, result.path, result.query, result.fragment)) password_mgr = HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, url, result.username, result.password) handler = HTTPBasicAuthHandler(password_mgr) opener = build_opener(handler) file = opener.open(url) else: file = urlopen(filename) input_document = odf_get_document(file) # Page page = odf_create_draw_page(name=u"page%d" % (i + 1), master_page=first_master_page) # Title Frame title_frame = get_title_frame(first_master_page) name = unicode(filename.split('/')[-1]) source = u"filesystem" if not scheme else scheme title_frame.set_text_content(u"%s (%s)" % (name, source)) page.append(title_frame) # Get info info = [] input_meta = input_document.get_part(ODF_META) info.append(u"Title: %s" % input_meta.get_title()) stats = input_meta.get_statistic() info.append(u"# pages: %s" % stats['meta:page-count']) input_body = input_document.get_body() info.append(u"# images: %s" % len(input_body.get_images())) info.append(u"# tables: %s" % len(input_body.get_tables()))
# Creation of the output Presentation document : # presentation = odf_new_document_from_type('presentation') # 092 presentation = odf_new_document('presentation') # Presentation got a body in which content is stored presentation_body = presentation.get_body() # For each image, we create a page in the presentation and display the image # and some text on this frame for image in images_pool: # add the file to the document uri = presentation.add_file(image.path) # Create an underlying page for the image and the text page = odf_create_draw_page("Page "+ image.name) # Create a frame for the image image_frame = odf_create_image_frame( url = uri, name = image.name, text = "", # Text over the image object size = (image.disp_w, image.disp_h), # Display size of image anchor_type = 'page', page_number = None, position = (image.pos_x, image.pos_y), style = None ) # Append all the component page.append(image_frame)