def highlight(odf_file_url, pattern, color=None, background_color=None, italic=False, bold=False, target=None, pretty=True): # Make display_name and name display_name = [u"Highlight"] if color and color != 'none': display_name.append(unicode(color).capitalize()) if background_color and background_color != 'none': display_name.append(unicode(background_color).capitalize()) if italic: display_name.append(u"Italic") if bold: display_name.append(u"Bold") display_name = u" ".join(display_name) name = display_name.replace(u" ", u"_20_") # Is our style already installed? style = document.get_style('text', name) if style is None: color = rgb2hex(color) if color != 'none' else None background_color = (rgb2hex(background_color) if background_color != 'none' else None) style = odf_create_style('text', name, italic=italic, bold=bold, color=color, background_color=background_color) document.insert_style(style, automatic=True) # Patch! body = document.get_body() i = -1 for i, paragraph in enumerate(body.get_paragraphs(content=pattern) + body.get_headings(content=pattern)): # Don't colour the table of content if paragraph.get_parent().get_tag() in ('text:index-title', 'text:index-body'): continue paragraph.set_span(name, regex=pattern) document.save(target=target, pretty=pretty) printinfo(str((i + 1)), "paragraphs changed (0 error, 0 warning).")
def test_color_tuple(self): color = (171, 205, 239) expected = '#ABCDEF' self.assertEqual(rgb2hex(color), expected)
def test_color_name(self): color = 'violet' expected = '#EE82EE' self.assertEqual(rgb2hex(color), expected)
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) # -------------------------------- heading = odf_create_heading(1, text=u'Your environment') body.append(heading) data = []
border_rl = make_table_cell_border_string(thick='0.20cm', color='white') border_bt = make_table_cell_border_string( thick='0.80cm', color='white', ) style = odf_create_table_cell_style( color='grey', background_color=cell_value, border_right=border_rl, border_left=border_rl, border_bottom=border_bt, border_top=border_bt, ) name = document.insert_style(style=style, automatic=True) cell = odf_create_cell(value=rgb2hex(cell_value), style=name) row.append_cell(cell) table.append_row(row) row_style = odf_create_style('table-row', height='1.80cm') name_style_row = document.insert_style(style=row_style, automatic=True) for row in table.get_rows(): row.set_style(name_style_row) table.set_row(row.y, row) col_style = odf_create_style('table-column', width='3.6cm') name = document.insert_style(style=col_style, automatic=True) for column in table.get_columns(): column.set_style(col_style) table.set_column(column.x, column)
color = 'white' ) border_bt = make_table_cell_border_string( thick = '0.80cm', color = 'white', ) style = odf_create_table_cell_style( color = 'grey' , background_color = cell_value, border_right = border_rl, border_left = border_rl, border_bottom = border_bt, border_top = border_bt, ) name = document.insert_style(style=style, automatic=True) cell = odf_create_cell(value=rgb2hex(cell_value), style=name) row.append_cell(cell) table.append_row(row) row_style = odf_create_style('table-row', height='1.80cm') name_style_row = document.insert_style(style=row_style, automatic=True) for row in table.get_rows(): row.set_style(name_style_row) table.set_row(row.y, row) col_style = odf_create_style('table-column', width='3.6cm') name = document.insert_style(style=col_style, automatic=True) for column in table.get_columns(): column.set_style(col_style) table.set_column(column.x, column)
# 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) # -------------------------------- heading = odf_create_heading(1, text=u'Your environment') body.append(heading) data = []