Skip to content

Commit

Permalink
Adding .soc & .acb generation (LibreOffice + AutoCAD)
Browse files Browse the repository at this point in the history
In addition,
- `--all` flag behaviour for `process` is now enabled by default
- `pantone` & `ral` were re-enabled (fixed)
- FAQ added to `README.md`, explaining where palette files go
- Improving readability of `README.md`
  • Loading branch information
S1SYPHOS committed May 6, 2019
1 parent f594211 commit 14101c4
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 8 deletions.
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ This library provides an easy way to generate [*color palettes*](https://www.ety
> *Swatches* are named colors, tints, gradients, and patterns.
> [Adobe Illustrator](https://helpx.adobe.com/illustrator/using/using-creating-swatches.html)
.. featuring [PANTONE®](https://www.pantone.com), [RAL®](https://www.ral-farben.de), [Dulux®](https://www.dulux.com.au) as well as [Copic®](https://www.copicmarker.com) and [Prismacolor®](https://www.prismacolor.com) (proprietary color spaces). For now, `we-love-colors` creates master palettes for use in [Scribus](https://www.scribus.net), an open source desktop publishing program, as well as [GIMP](https://www.gimp.org) and [Inkscape](https://inkscape.org).
.. featuring the following (proprietary) color spaces:
- [PANTONE®](https://www.pantone.com)
- [RAL®](https://www.ral-farben.de)
- [Dulux®](https://www.dulux.com.au)
- [Copic®](https://www.copicmarker.com)
- [Prismacolor®](https://www.prismacolor.com)

For now, `we-love-colors` creates master palettes for use in
- [Scribus](https://www.scribus.net) (XML)
- [GIMP](https://www.gimp.org) and [Inkscape](https://inkscape.org) (GPL)
- [AutoCAD](https://www.autodesk.com/products/autocad) (ACB)
- [LibreOffice](https://www.libreoffice.org) (SOC)

## Getting started
Depending on your setup you might prefer a ..
Expand All @@ -36,16 +47,30 @@ Commands:
process ARGS: pantone | ral | dulux | copic | prismacolor
```


Using its commands `fetch` and `process` is fairly easy, like that:

```bash
# Example 1 - Gotta fetch 'em `--all`:
$ python main.py fetch --all && python main.py process --all
$ python main.py fetch --all && python main.py process

# Example 2 - Fetching two sets & processing them:
$ python main.py fetch copic dulux && python main.py process copic dulux # or simply `--all`
# Example 2 - Fetching specific sets & processing them:
$ python main.py fetch copic dulux && python main.py process copic dulux
```

### FAQ
**Q: But where do all those files go?**
**A:** That depends, ..
- .. `.xml` files may be loaded individually with `Edit - Colours & Fills - Solid Colours - Import` (Scribus)
- .. `.soc` files belong here:
- `~\AppData\Roaming\libreoffice\3\user` (Windows + PowerShell, otherwise `%userprofile%`)
- `~/Library/Application Support/libreoffice/4/user/config` (Mac)
- `~/.config/libreoffice/4/user/config` (Linux)
- .. installing `.gpl` files boils down to:
- moving them to any path specified in `Edit - Preferences - Folders - Palettes` (GIMP)
- moving them to `palettes` under directory specified in `Edit - Preferences - System - User Config` (Inkscape)
- .. installing `.acb` files is [pretty straightforward](https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-Core/files/GUID-17E00AB3-3065-4F1B-A1C3-C4963396D2CB-htm.html)


## Color samples
If you are looking for a quick way to browse PANTONE® colors, check out the [Pantone Finder](https://github.com/picorana/Pantone_finder) package or [visit their website](https://picorana.github.io/Pantone_finder) to get started.

Expand Down
7 changes: 4 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@


class_map = {
'pantone': Pantone,
'ral': RAL,
'dulux': Dulux,
'copic': Copic,
'prismacolor': Prismacolor,
Expand Down Expand Up @@ -61,15 +63,14 @@ def fetch(sets, fetch_all):

@cli.command()
@click.argument('sets', nargs=-1)
@click.option('--all', 'process_all', flag_value=True, help='Process all available color sets & generate color palettes.')
def process(sets, process_all):
def process(sets):
"""
ARGS:
pantone | ral | dulux | copic | prismacolor
"""
valid_sets = list(class_map.keys())

if process_all == True:
if len(sets) == 0:
sets = valid_sets

for set in sets:
Expand Down
103 changes: 103 additions & 0 deletions palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def make_palettes(self):
rgb = color['rgb'][4:-1].split(',')
name = color['name'].title() if color['name'] != '' else color['code']
entry = etree.SubElement(root, 'COLOR')

entry.set('NAME', name)
entry.set('SPACE', 'RGB')
entry.set('R', rgb[0])
Expand Down Expand Up @@ -137,3 +138,105 @@ def make_palettes(self):
file.write(' '.join(line) + '\n')

print('Generating %s .. done' % gpl_file)


##
# Building ACB color palettes for AutoCAD
##
root = etree.Element('colorbook')
title = etree.SubElement(root, 'bookName')
color_page = etree.SubElement(root, 'colorPage')
page_color = etree.SubElement(color_page, 'pageColor')
rgb8 = etree.SubElement(page_color, 'RGB8')
page_background = {
'red': '100',
'green': '100',
'blue': '100',
}
for color, value in page_background.items():
entry = etree.SubElement(rgb8, color)
entry.text = value

title.text = file_name.title() if self.identifier != 'pantone' else file_name.replace('colors', 'Colors')
comment = etree.Comment(self.copyright.get('xml', default_copyright['xml']))
root.insert(0, comment)
for color in data:
rgb = color['rgb'][4:-1].split(',')
name = color['name'].title() if color['name'] != '' else color['code']

entry = etree.SubElement(color_page, 'colorEntry')
color_name = etree.SubElement(entry, 'colorName')
color_name.text = name

keys = ['red', 'green', 'blue']
rgb_dict = {k: v for k, v in zip(keys, rgb)}
rgb8 = etree.SubElement(entry, 'RGB8')

for color, value in rgb_dict.items():
entry = etree.SubElement(rgb8, color)
entry.text = value

# Creating directories for XML color palettes (if it doesn't exist already)
output_path = os.path.dirname(path).replace('/json', '/acb')
os.makedirs(output_path, exist_ok=True)

# Writing XML color palettes to disk (mirroring JSON source structure)
acb_file = output_path + '/' + file_name + '.acb'
tree = etree.ElementTree(root)
tree.write(acb_file, xml_declaration=True, encoding='UTF-8', pretty_print=True)

print('Generating %s .. done' % acb_file)


##
# Building SOC color palettes for Open/LibreOffice
##
namespaces = {
'office': 'http://openoffice.org/2000/office',
'style': 'http://openoffice.org/2000/style',
'text': 'http://openoffice.org/2000/text',
'table': 'http://openoffice.org/2000/table',
'draw': 'http://openoffice.org/2000/drawing',
'fo': 'http://www.w3.org/1999/XSL/Format',
'xlink': 'http://www.w3.org/1999/xlink',
'dc': 'http://purl.org/dc/elements/1.1/',
'meta': 'http://openoffice.org/2000/meta',
'number': 'http://openoffice.org/2000/datastyle',
'svg': 'http://www.w3.org/2000/svg',
'chart': 'http://openoffice.org/2000/chart',
'dr3d': 'http://openoffice.org/2000/dr3d',
'math': 'http://www.w3.org/1998/Math/MathML',
'form': 'http://openoffice.org/2000/form',
'script': 'http://openoffice.org/2000/script',
'config': 'http://openoffice.org/2001/config',
}
root = etree.Element('color-table', nsmap=namespaces)
comment = etree.Comment(self.copyright.get('xml', default_copyright['xml']))
root.insert(0, comment)
for color in data:
name = color['name'].title() if color['name'] != '' else color['code']
entry = etree.SubElement(root, 'color')

entry.set('name', name)
entry.set('color', color['hex'])

# Creating directories for XML color palettes (if it doesn't exist already)
output_path = os.path.dirname(path).replace('/json', '/soc')
os.makedirs(output_path, exist_ok=True)

# Writing XML color palettes to disk (mirroring JSON source structure)
soc_file = output_path + '/' + file_name + '.soc'
tree = etree.ElementTree(root)
tree.write(soc_file, xml_declaration=True, encoding='UTF-8', pretty_print=True)

with open(soc_file, 'r') as input:
data = input.read()
data = data.replace('color-table', 'office:color-table')
data = data.replace('<color', '<draw:color')
data = data.replace('name=', 'draw:name=')
data = data.replace('color=', 'draw:color=')

with open(soc_file, 'w') as output:
output.write(data)

print('Generating %s .. done' % soc_file)

0 comments on commit 14101c4

Please sign in to comment.