Open Source Software Technical Articles

Want the Best of the Wazi Blogs Delivered Directly to your Inbox?

Subscribe to Wazi by Email

Your email:

Connect with Us!

Current Articles | RSS Feed RSS Feed

Toward a more colorful LibreOffice

  
  
  

Recently, I was working on an Impress presentation, and I needed more colors than LibreOffice provides with its standard color picker. Specifically, I needed several light colors, but the standard color list includes only a few light blue possibilities. I could have defined my own colors manually using the Color Picker, but "mixing" colors by specifying RGB or CMYK numbers is a cumbersome, hit-or-miss process. LibreOffice also lets users load predefined color libraries, but none of the ones I found suited me. Instead, by working with web-standard colors plus a little bit of awk scripting, I managed to create my own color list, providing well-organized colors, grouped in families, with as many color variations as I wanted.

The Impress and Draw components let you load a new color list and add colors to it, which is an option if you just need one or two new colors and know how to define them. (An aside: Any color changes you make in Impress or Draw become available for all LibreOffice components.) Open Impress or Draw, go to Format -> Area -> Colors, and you'll see the table of all available colors, with their RGB and CMYK equivalents, along with commands for editing the list:

The standard LibreOffice color list

Modifying the standard color table is straightforward. To add a new color, enter a name for it, select its R, G, and B values, and click the Add button. Your new color is added at the bottom of the table. To modify an existing color, click on it, change its R, G, and B values, and click on Modify. You can select a color several different ways by clicking on the Edit button (see figure below). Finally, to delete a color from the color table, select it and click on Delete.

LibreOffice lets you handpick a color in several different ways

LibreOffice or OpenOffice?
LibreOffice was forked off OpenOffice in 2010, but the color lists you develop apply equally well to both, though you might need to make some adjustments to file names and locations.

If you were skilled enough, you could create a whole set of colors in the standard table by using these tools. LibreOffice saves its standard color table in the file standard.soc, whose location varies from distribution to distribution; openSUSE saves it in $HOME/.config/libreoffice/4-suse/user/config, but the standard place is $HOME/.libreoffice/4/user/config. You can learn the location by clicking on the Load Color List icon in the Format -> Colors dialog and taking note of the directory it shows.

(By the way, different distributions not only change the location of the file, but also its contents. For instance, Ubuntu includes three special colors – Ubuntu Orange, Ubuntu Yellow, and Ubuntu Red – and Red Hat includes Red Hat 1 through Red Hat 5.)

LibreOffice also provides alternate color lists, with different sets of colors. Click on the Load Color List icon in the Format -> Colors dialog to see a list of available *.soc files. (I assume, but couldn't verify, that "soc" stands for "set of colors.")

I tried out many tables, but despite getting more options than with the standard table, I still wasn't satisfied. I finally decided to produce my own color list, with enough variations to suit me, grouped in color families, so finding the right shade would be easier. I'll walk you through the process, but first you need to know a little about how computers represent colors.

Color models: RGB and CMYK

Since computers are digital machines, colors must be represented as numbers, and a color model is a way of doing just that. RGB is an additive model, based on red, green, and blue lights, which added together in varying intensities produce colors. Colors in the RGB model are specified by three numbers, from 0 (minimum) to 255 (maximum). Zero intensity for all lights produces no color at all (black) while maximum intensity for all colors gives white. If intensities are not all the same, you get variously colored hues. Higher component values mean lighter colors (all the way from black to white) so to get a lighter version of a RGB color, you have to increase its R, G, and B values, and for a darker version, you decrease those values.

Computers use RGB for screens, but for printed output CMYK is standard. CMYK is a subtractive color model based on four ink colors: cyan, magenta, yellow, and key (black). Using no inks at all is plain white. Each ink absorbs certain frequencies of light, so mixing inks in specific proportions can produce other colors. Mixing cyan, magenta, and yellow inks in maximum proportions (100%) should produce black, but actually gets you a dark muddy brown, and that's why CMYK uses a fourth ink, black. CMYK colors are given by four percentages, so a green color could be produced by something around (15%, 0%, 35%, 35%) meaning 15% intensity of cyan, no magenta at all, and 35% intensities of both yellow and black.

To produce darker and lighter variations, CMYK works the opposite way from RGB: Higher values (more ink) mean darker colors, and to get a lighter variation of a color (less ink) you have to lower its C, M, Y, and K values.

By default, LibreOffice uses RGB to specify screen colors, and we'll use it when we create our color table. In binary, each color is represented by a 24-bit number, so there are 2^24 possible variations, or 16,777,216 colors in all.

What's a .soc like?

So much for the way colors are represented. The next step is to determine the format for .soc files. While downloading the full source code for the LibreOffice suite and searching around for the correct description was one way to figure that out, I felt that the file format shouldn't be too hard to deduce, and when I looked at a few .soc files on my own, that proved to be the case.

Color lists are XML files that contain a <draw:color> element for each defined color, given by its RGB value in hexadecimal:

<?xml version="1.0" encoding="UTF-8"?>
<ooo:color-table xmlns:office=
"urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:draw=
"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:ooo="http://openoffice.org/2004/office">

<draw:color
    draw:name="Black" draw:color="#000000"/>
<draw:color
    draw:name="White" draw:color="#ffffff"/>
<draw:color
    draw:name="Blue" draw:color="#000080"/>
<draw:color
    draw:name="Green" draw:color="#008000"/>

...many lines snipped out...

<draw:color
    draw:name="Chart 10" draw:color="#ff950e"/>
<draw:color
    draw:name="Chart 11" draw:color="#c5000b"/>
<draw:color
    draw:name="Chart 12" draw:color="#0084d1"/>
</ooo:color-table>

Since XML files are text files, producing a table of such elements should be easy for a script – you just need to decide how to automatically generate variations for a table of colors and then write some awk code to do the actual work.

So how are we to produce color variations? Given a base color, we can produce darker or lighter variations of it by modifying its R, G, and B values, but not haphazardly. If we make a large variation in the R component it should be accompanied by proportionally large variations in the G and B components, or we'll end up with a totally different hue.

Of course, in order to accomplish this, we need a list of starting colors, which we can modify to get variations, and then do some calculations to actually produce the .soc file. To see how, read part two of this series.




This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.

Comments

Excellent
Posted @ Monday, May 13, 2013 6:00 PM by John
Good post and useful information. 
Thanks for sharing
Posted @ Wednesday, May 15, 2013 2:31 AM by RoseHosting
Glad I could be of help -- please do remember to check the second part of the article, at http://www.openlogic.com/wazi/bid/289690/
Posted @ Friday, May 17, 2013 3:58 PM by Federico Kereki
Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics