Libreoffice作家:如何为每个字母设置不同的颜色?

时间:2016-05-16 17:33:32

标签: fonts libreoffice-writer

我正在为一个性生活困难的孩子写一些阅读材料。为了方便他,我想在每个字母中使用不同的颜色(即所有“a”用红色,所有“e”用蓝色等)。

我是手动完成的,这很痛苦。试图使用搜索/替换,但它不接受颜色或格式。

有没有办法为每个字母定义颜色?

2 个答案:

答案 0 :(得分:2)

这是一个python宏:

import string

def get_color_dict():
    color_list = []
    #color_range = range(0xFF + 1)  # all possible colors
    color_range = [0, 128, 200]
    for r in color_range:
        for g in color_range:
            for b in color_range:
                color_list.append("%02x%02x%02x" % (r, g, b))
    letter_color = {}
    for letter in string.ascii_lowercase:
        letter_color[letter] = color_list.pop(0)
    return letter_color

def colorize_text():
    letter_colors = get_color_dict()
    doc = XSCRIPTCONTEXT.getDocument()
    oVC = doc.getCurrentController().getViewCursor()
    oVC.gotoStart(False)
    oVC.collapseToEnd()
    while oVC.goRight(1, True):
        letter = oVC.getString()
        if letter:
            letter = letter.lower()
        if letter in letter_colors:
            oVC.CharColor = int(letter_colors[letter], 16)
        oVC.goRight(0, False)  # deselect
        oVC.collapseToEnd()

# Functions that can be called from Tools -> Macros -> Run Macro.
g_exportedScripts = colorize_text

要运行宏,请将其另存为纯文本文件。创建Scripts/python子文件夹并将文件放入其中,如here所述。

以下是使用“Lorem ipsum”的示例结果(关注@tohuwawohu):

enter image description here

答案 1 :(得分:1)

AFAIK实现此目的的唯一方法是进行搜索/替换,在替换时指定字体颜色。要在替换时自动更改字符颜色,请打开Find & replace对话框(菜单Edit - > Find & Replace CTRL + H ),然后选择" Other Options":

enter image description here

现在,有一个按钮 Format

enter image description here

单击 Format 按钮将显示通常的字符样式对话框。在那里,切换到"字体效果"选项卡并设置特定字符的字体颜色:

enter image description here

选择颜色后,它将显示在"替换为"组合框(要删除它,请单击无格式按钮):

enter image description here

以下是以a文字中的自定义字体颜色自行替换eLorem ipsum的结果:

enter image description here