Conversation
|
Thank you so much for your contribution. |
simple_svg_1.0.0.hpp
Outdated
| public: | ||
| Stroke(double width = -1, Color color = Color::Transparent, bool nonScalingStroke = false) | ||
| : width(width), color(color), nonScaling(nonScalingStroke) { } | ||
| enum class Cap { Butt, Round, Square }; |
There was a problem hiding this comment.
This library is quite old, and may be used with older compilers.
I'm not sure enum class is really required here - that would require C++11 at least.
Perhaps a regular enum is sufficient.
Also, IIUC the old behaviour did not specify the stroke-linecap attribute at all (so e.g. something else like a CSS may have set some default externally). I suggest adding a new enum value of NotSpecified as the default value such that when that is set the attribute will not get written at all. See more below.
simple_svg_1.0.0.hpp
Outdated
| Stroke(double width = -1, Color color = Color::Transparent, bool nonScalingStroke = false) | ||
| : width(width), color(color), nonScaling(nonScalingStroke) { } | ||
| enum class Cap { Butt, Round, Square }; | ||
| enum class Join { Miter, Round, Bevel }; |
| Cap capStyle = Cap::Butt, Join joinStyle = Join::Miter) | ||
| : width(width), color(color), nonScaling(nonScalingStroke), | ||
| capStyle(capStyle), joinStyle(joinStyle) | ||
| { } |
There was a problem hiding this comment.
capStyle and joinStyle always initialized with some enum value and thus... (cont. below)
| if(joinStyle == Join::Miter) ss << attribute("stroke-linejoin", "miter"); | ||
| else if(joinStyle == Join::Round) ss << attribute("stroke-linejoin", "round"); | ||
| else if(joinStyle == Join::Bevel) ss << attribute("stroke-linejoin", "bevel"); | ||
|
|
There was a problem hiding this comment.
... they always have a value here so without the NotSpecified value, the stroke-line* attribute will always be written (unlike old the behavior).
Also, you should use a switch statement here for clarity.
There was a problem hiding this comment.
You're right, an enum class is c++11, I didn't think of that. I had used that to mitigate the duplication in Round. Now all the enum values have the type as prefix, e.g. JoinRound and CapRound. The switch also looks much cleaner, thanks for that suggestion. I was unsure if I should add separate cases for Cap/JoinUndefined and a throw for the default case, but then decided against it. If you wish otherwise, I can add that too.
I made a small enhancement to the Stroke class, that allows to specify the styles for caps and line joins as additional arguments to the constructor. The previous behavior is preserved. The main.cpp now has a little demo object for it with round joins.