DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:odt:csscolorshelper

ODT Plugin homepage

Helper for quering CSS color values

From version 2014-10-12 on the ODT plugin includes a helper plugin which can be used to query the color value for a given CSS color name. This is especially required for ODT export because ODT does not understand CSS color names. So CSS color names need to be converted to their corresponding value before they can be used in a ODT document.

Example usage

This is an example of how to query the value for a specific CSS color name:

    /** @var helper_plugin_odt_csscolors $odt_colors*/
    $odt_colors = plugin_load('helper', 'odt_csscolors');
    if ($odt_colors != NULL) {
        $value = $odt_colors->getColorValue('red');
 
        // Now, $name is set to 'Red' for further use...
    }

Please notice that the color name is case insensitive. For long names like 'LightGoldenRodYellow' you can also write 'lightgoldenrodyellow', the result is the same. If a color name is unknown to the helper plugin the default value '#000000' will be returned.

The conversion in the other direction is also supported:

    /** @var helper_plugin_odt_csscolors $odt_colors */
    $odt_colors = plugin_load('helper', 'odt_csscolors');
    if ($odt_colors != NULL) {
        $name = $odt_colors->getValueName('#FF0000');
 
        // Now, $value is set to '#FF0000' for further use...
    }

If a color value is unknown to the helper plugin the default name 'Black' will be returned.

plugin/odt/csscolorshelper.txt · Last modified: 2015-06-10 13:58 by 130.112.1.3