Convert colour palettes to LibreOffice format
Find a file
Andy Piper 5fd2373301
fix readme again
Signed-off-by: Andy Piper <andypiper@users.noreply.github.com>
2025-06-18 22:53:23 +01:00
LICENSE initial commit 2025-06-18 22:43:29 +01:00
README.md fix readme again 2025-06-18 22:53:23 +01:00
sample.gpl initial commit 2025-06-18 22:43:29 +01:00
sample.txt initial commit 2025-06-18 22:43:29 +01:00
soc_converter.py initial commit 2025-06-18 22:43:29 +01:00

Color Palette to LibreOffice SOC Converter

A converter for color palette files (JSON, text, GIMP GPL) to LibreOffice SOC format

This tool converts various color palette formats into LibreOffice SOC (StarOffice/OpenOffice Color) palette files that can be imported into LibreOffice applications.

Table of Contents

Background

LibreOffice uses SOC (StarOffice/OpenOffice Color) files to define custom color palettes that are available across all applications (Writer, Calc, Impress, Draw). These files use a specific XML format that defines colors with names and hex values.

This tool bridges the gap between various color palette formats and LibreOffice's color palette system, making it easy to use consistent brand colors across all your LibreOffice documents. It supports:

  • JSON files with color definitions (common in web development)
  • Text files with simple "Name: #HEXCODE" format
  • GIMP GPL files with RGB color definitions (widely used in graphics software)

Features

  • Supports JSON, text, and GIMP GPL input formats
  • Auto-detects input file format by extension and content
  • Converts RGB values to hex format automatically (GPL files)
  • Validates hex color codes and RGB values
  • Normalizes color names for XML compatibility
  • Terminal output with color previews

Install

This script requires Python 3.12 or higher and uses the following dependencies:

  • click - Command-line interface framework
  • rich - Rich text and beautiful formatting in the terminal

Prerequisites

Ensure you have Python 3.12+ installed:

python --version

Running the Script

Since this is a single-file script with embedded dependencies, you can run it directly:

python soc_converter.py --help

The script will automatically handle the dependencies when run in a compatible Python environment.

Alternative: Install Dependencies Manually

If you prefer to install dependencies manually:

pip install click rich

Usage

Basic Usage

Convert a JSON color file:

python soc_converter.py brand_colors.json

Convert a text color file:

python soc_converter.py my_colors.txt

Convert a GIMP GPL palette file:

python soc_converter.py my_palette.gpl

Advanced Usage

# Specify output file and palette name
python soc_converter.py brand_colors.json -o my_colors.soc -n "My Brand Colors"

# Skip color preview
python soc_converter.py my_palette.gpl --no-preview

# Force input format (useful for files with non-standard extensions)
python soc_converter.py colors.dat -f gpl

Input File Formats

JSON Format

{
    "colors": {
        "Primary Blue": "#007BFF",
        "Secondary Green": "#28A745",
        "Accent Red": "#DC3545"
    }
}

Or direct color mapping:

{
    "Primary Blue": "#007BFF",
    "Secondary Green": "#28A745",
    "Accent Red": "#DC3545"
}

Text Format

Primary Blue: #007BFF
Secondary Green: #28A745
Accent Red: #DC3545

GIMP GPL Format

GIMP Palette
Name: My Brand Colors
Columns: 4
#
# Color definitions
  0 123 255 Primary Blue
 40 167  69 Secondary Green
220  53  69 Accent Red
  0   0   0 Black
255 255 255 White

GPL files use RGB values (0-255) and automatically convert them to hex format.

Installing the Generated SOC File

After generating the SOC file, copy it to your LibreOffice palette directory:

Linux

# System-wide (requires admin privileges)
sudo cp output.soc /usr/lib/libreoffice/share/palette/

# User-specific
cp output.soc ~/.config/libreoffice/4/user/config/

Windows

Copy to one of these locations:

  • C:\Program Files\LibreOffice\share\palette\ (system-wide)
  • %APPDATA%\LibreOffice\4\user\config\ (user-specific)

macOS

# System-wide
sudo cp output.soc /Applications/LibreOffice.app/Contents/share/palette/

# User-specific
cp output.soc ~/Library/Application\ Support/LibreOffice/4/user/config/

Important: Restart LibreOffice after copying the file for the palette to appear in the color picker dropdown.

Command-Line Options

Option Short Description Default
--output -o Output SOC file path <input_file>.soc
--name -n Palette name for XML comments "Custom Colors"
--preview / --no-preview Show/hide color preview table --preview
--format -f Force input format (auto, json, text, gpl) auto
--help Show help message

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.