Rewrite colors into shortest possible name

Improve the code for rewriting colors into recognising that some
colors are shorter by name.  This commit enables scour to rewrite
`rgb(255, 0, 0)` into `red` which is slightly shorter than `#f00`
(ditto for `tan` and `pink`).

When the color name ties in length with the hexcode, then scour will
leave it as-is if the input file used a variant of same length
(e.g. `blue`, `cyan` and `aqua` will be left as-is).  But if scour is
rewriting the color code, it will prefer the hex code variant.

Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
Niels Thykier 2021-02-23 18:35:57 +00:00
parent 7a83e7148d
commit 551c88754e
No known key found for this signature in database
GPG key ID: A65B78DBE67C7AAC
3 changed files with 248 additions and 166 deletions

View file

@ -9,4 +9,6 @@
<rect id="rect" width="100" height="100" fill="rgb(15,16,17)" stroke="darkgrey" />
<circle id="circle" cx="100" cy="100" r="30" fill="url(#g1)" stroke="url(#c1)" />
<ellipse id="ellipse" cx="100" cy="100" rx="30" ry="30" style="fill:#ffffff" fill="black" />
<rect id="short_color" width="100" height="100" fill="rgb(255,0, 0)" stroke="#ff0000" />
<rect id="tied_color" width="100" height="100" fill="blue" stroke="rgb(0, 0, 255)" />
</svg>

Before

Width:  |  Height:  |  Size: 589 B

After

Width:  |  Height:  |  Size: 768 B

Before After
Before After