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 add_child_elems(self, elems): """Helper to add elems to self as children""" # TODO: kill this ugly typeswitching if (len(self._elements) and isinstance(self._elements[-1], odf_draw_page) and not isinstance(elems[0], odf_draw_page)): # stick additional frame content into last existing one for child in self._elements[-1].get_elements( 'descendant::draw:frame'): if child.get_presentation_class() == u'outline': text_box = child.get_children()[0] for elem in wrap_spans(elems): text_box.append(elem) return # special-case image frames - append to pages literally! if isinstance(elems[0], odf_frame): for child in elems: self._elements[-1].append(child) else: # no outline frame found, create new one with elems content elems = wrap_spans(elems) self._elements[-1].append( odf_create_text_frame( elems, presentation_style=u'md2odp-OutlineText', size=(u'%s' % self.outline_size[0], u'%s' % self.outline_size[1]), position=(u'%s' % self.outline_position[0], u'%s' % self.outline_position[1]), presentation_class=u'outline')) else: self._elements += elems
def test_create_text_frame(self): frame = odf_create_text_frame("Zoé") expected = ('<draw:frame svg:width="1cm" svg:height="1cm" ' 'draw:z-index="0">' '<draw:text-box>' '<text:p>Zoé</text:p>' '</draw:text-box>' '</draw:frame>') self.assertEqual(frame.serialize(), expected)
def test_create_text_frame(self): frame = odf_create_text_frame(u"Zoé") expected = ('<draw:frame svg:width="1cm" svg:height="1cm" ' 'draw:z-index="0">' '<draw:text-box>' '<text:p>Zoé</text:p>' '</draw:text-box>' '</draw:frame>') self.assertEqual(frame.serialize(), expected)
def test_create_text_frame(self): frame = odf_create_text_frame(u"Zoé") expected = ('<draw:frame svg:width="1cm" svg:height="1cm" ' 'text:anchor-type="paragraph">' '<draw:text-box>' '<text:p>Zoé</text:p>' '</draw:text-box>' '</draw:frame>') self.assertEqual(frame.serialize(), expected)
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é</text:h>' '</draw:text-box>' '</draw:frame>') self.assertEqual(frame.serialize(), expected)
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é</text:h>' '</draw:text-box>' '</draw:frame>') self.assertEqual(frame.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 block_code(self, code, language=None): if language == 'Comment': para = odf_create_paragraph(style=u'md2odp-NoteText') notes = odf_create_element('presentation:notes') # no lang given, use plain monospace formatting for elem in handle_whitespace(code): if isinstance(elem, basestring): span = odf_create_element('text:span') span.set_text(elem) para.append(span) else: para.append(elem) frame = odf_create_text_frame( para, presentation_style=u'md2odp-OutlineText', size=(u'18cm', u'25cm'), position=(u'2cm', u'2cm'), presentation_class=u'title') notes.append(frame) return ODFPartialTree.from_metrics_provider([notes], self) elif language is not None: # explicit lang given, use syntax highlighting para = odf_create_paragraph(style=u'md2odp-ParagraphCodeStyle') lexer = get_lexer_by_name(language) for span in self.formatter.format(lexer.get_tokens(code)): para.append(span) else: # no lang given, use plain monospace formatting para = odf_create_paragraph(style=u'md2odp-ParagraphCodeStyle') for elem in handle_whitespace(code): if isinstance(elem, basestring): span = odf_create_element('text:span') span.set_text(elem) para.append(span) else: para.append(elem) return ODFPartialTree.from_metrics_provider([para], self)
def add_child_elems(self, elems): """Helper to add elems to self as children""" # TODO: kill this ugly typeswitching if (len(self._elements) and isinstance( self._elements[-1], odf_draw_page) and not isinstance( elems[0], odf_draw_page)): # stick additional frame content into last existing one for child in self._elements[-1].get_elements( 'descendant::draw:frame'): if child.get_presentation_class() == u'outline': text_box = child.get_children()[0] for elem in wrap_spans(elems): text_box.append(elem) return # special-case image frames - append to pages literally! if isinstance(elems[0], odf_frame): for child in elems: self._elements[-1].append(child) else: # no outline frame found, create new one with elems content elems = wrap_spans(elems) self._elements[-1].append( odf_create_text_frame( elems, presentation_style=u'md2odp-OutlineText', size=(u'%s' % self.outline_size[0], u'%s' % self.outline_size[1]), position=(u'%s' % self.outline_position[0], u'%s' % self.outline_position[1]), presentation_class=u'outline')) else: self._elements += elems
# 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'), position=('0.5cm', '0.5cm'), style=u"Standard", text_style=u"Standard") # Append all the component, do not forget to add the actuel image file # into the Picture global directory of the presentation file with set_part page.append(text_frame) page.append(image_frame) presentation_body.append(page) # for the same operation from a local filesystem image, just use: #presentation_output.add_file(uri) media_type = manifest_source.get_media_type(uri) presentation_manifest.add_full_path(uri, media_type) presentation_output.set_part(uri, doc_source.get_part(uri)) # Finally save the result
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) if not os.path.exists('test_output'): os.mkdir('test_output') output = os.path.join('test_output', output_filename) presentation.save(target=output, pretty=True)
# 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'), position = ('0.5cm', '0.5cm'), style = u"Standard", text_style = u"Standard") # Append all the component, do not forget to add the actuel image file # into the Picture global directory of the presentation file with set_part page.append(text_frame) page.append(image_frame) presentation_body.append(page) # for the same operation from a local filesystem image, just use: #presentation_output.add_file(uri) media_type = manifest_source.get_media_type(uri) presentation_manifest.add_full_path(uri, media_type) presentation_output.set_part(uri, doc_source.get_part(uri)) # Finally save the result
# 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 big = odf_create_style('paragraph', u"big", area='paragraph', align="center") big.set_style_properties(area='text', size="32pt") document.insert_style(big, automatic=True) # Set a text frame text_frame = odf_create_text_frame([u"lpOD", u"Presentation", u"Cookbook"], size=('7cm', '5cm'), position=('11cm', '8cm'), style=u"colored", text_style=u"big") page1.append(text_frame) # Add a transition for this page page1.set_transition("fade", "fadeOverColor") # # Image Frame # # Start a new page page2 = odf_create_draw_page(u"page2") body.append(page2) # Embed an image from a file name
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 big = odf_create_style('paragraph', u"big", area='paragraph', align="center") big.set_style_properties(area='text', size="32pt") document.insert_style(big, automatic=True) # Set a text frame text_frame = odf_create_text_frame([u"lpOD", u"Presentation", u"Cookbook"], size=('7cm', '5cm'), position=('11cm', '8cm'), style=u"colored", text_style=u"big") page1.append(text_frame) # Add a transition for this page page1.set_transition("fade", "fadeOverColor") # # Image Frame # # Start a new page page2 = odf_create_draw_page(u"page2") body.append(page2)
# In text application, image must be inserted in a paragraph if context["top"].get_tagname() == "office:text": container = odf_create_paragraph() context["top"].append_element(container) else: container = context["top"] if caption: paragraph = odf_create_paragraph() image_frame = odf_create_image_frame(local_uri, size=size, style=image_style.get_style_name()) paragraph.append_element(image_frame) paragraph.append_element(caption) # A new frame, we fix only the width text_frame = odf_create_text_frame(paragraph, size=(size[0], None), style=caption_style.get_style_name()) container.append_element(text_frame) else: image_frame = odf_create_image_frame(local_uri, size=size, style=image_style.get_style_name()) container.append_element(image_frame) def convert_image(node, context): image = node.get("uri") width = node.get('width') height = node.get('height') _add_image(image, None, context, width=width, height=height)
# -*- 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")
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) if not os.path.exists('test_output'): os.mkdir('test_output') output = os.path.join('test_output', output_filename) presentation.save(target=output, pretty=True)