Example #1
0
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((i + 1), "paragraphs changed (0 error, 0 warning).")
Example #2
0
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_paragraph_list(content=pattern) +
                                  body.get_heading_list(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((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)
Example #5
0
# 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)

# 3- Your environment (=> a table)
# --------------------------------
heading = odf_create_heading(1, text=u'Your environment')
body.append(heading)

data = []
Example #6
0
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)


# 3- Your environment (=> a table)
# --------------------------------
heading = odf_create_heading(1, text=u'Your environment')
body.append(heading)

data = []
Example #7
0
 def test_color_tuple(self):
     color = (171, 205, 239)
     expected = '#ABCDEF'
     self.assertEqual(rgb2hex(color), expected)
Example #8
0
 def test_color_name(self):
     color = 'violet'
     expected = '#EE82EE'
     self.assertEqual(rgb2hex(color), expected)