-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite colors into shortest possible name #270
base: master
Are you sure you want to change the base?
Conversation
Would this still create a group and propagate the
|
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 <[email protected]>
5802a65
to
551c887
Compare
Neither the old nor the new code gets this consistently right because that is governed by another part of the code. For reference, the new code gets your particular example correct. However, I would expect both the old and the new code to fail that test with e.g. For that to (always) work, then we would also have to change:
Notably, the |
Yep, you're right, as long as we convert consistently (even if it's not shorter but the same length) we should be fine optimization-wise. We should probably add a few testcases for these border cases as well... Remaining questions I'm mulling about:
|
It replaces `--disable-simplify-colors` (although the old name is still accepted). Signed-off-by: Niels Thykier <[email protected]>
This enables scour to consistently perform other optimizations that rely on string equality to determine if two attributes are identical. Signed-off-by: Niels Thykier <[email protected]>
Signed-off-by: Niels Thykier <[email protected]>
Ok, I have:
|
As for mixing color codes with color names - scour is here to write short svg files, not beautiful ones. :) Also, if your beef with this is about consistency, then we are trading one consistency (form) for another (shortest length). 😄 |
Signed-off-by: Niels Thykier <[email protected]>
s = s.lower() | ||
color = colors.get(s) | ||
# Short cut: if we know the color (either by name or hex code) then skip the | ||
# parsing logic. This makes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an incomplete thought.
As someone who independently developed a rough version of this, I'd find this functionality useful. Could a Scour maintainer chime in to note what could move this PR forward? |
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)
intored
which is slightly shorter than#f00
(ditto for
tan
andpink
).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
andaqua
will be left as-is). But if scour isrewriting the color code, it will prefer the hex code variant.
Signed-off-by: Niels Thykier [email protected]