-
Notifications
You must be signed in to change notification settings - Fork 423
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
SVG images with height and/or width being percentages #2674
Comments
Just tested, in which QT version the SVG size calculation changed. Up to (and including) QT 5.10.1 it uses the percentage as height/width in pixel. As I'm using the QT embedded in the PyQT5 PyPI package I can't (easily) test the QT version 5.11.0. But I'm pretty confident, that the change happens in v5.11.1, see this bug report: |
Currently I see two possibilities to deal with that: a) It's possible to tell QT, what image size we want, without too much changes in GNS3 b) It's not easy to tell QT our desired size Here a small script, that I created to resize SVGs: svg_resize |
* Default for missing height/width is "100%" as defined in the SVG specification * Better error message, if viewBox attribute is missing * Removal of "%" in percent more fault tolerant by using rstrip("%")
I initially wanted to tell Qt to scale the QGraphicsSvgItem corresponding to nodes when the SVG symbol is above 80px by using something like this:
It worked excepting that the node label was resized too, this resulted in a really small label. I tried to block the scaling for the label but this created other drawing issues, for instance when hovering the node. I finally opted to take part of your code (thanks!) to resize the SVG data directly from the QSvgRender. I tested with both Qt 5.9.1 and Qt 5.11.2, everything seems to work well. Only thing left is I think the 80px limit should be user configurable. I will probable back-port this to the 2.1 branch once everything is in order. |
Looks good, just two comments:
|
Should we have a setting to limit node symbols to a max height/width of 80px or should we have one to resize all node symbols to a user preference? |
This is correct, we need to handle the width too.
Indeed, I thought about it but was a bit lazy ;) |
Work on str instead of binary when resizing SVG symbol.
I think, that resizing to a one height/width might be not the best choice. For example the standard symbols all have different sizes, because that way they are creating a consistent look. Limiting is also not nice, it's more a guard against too big symbols. The best way would be, when the user can scale each non-standard symbols individually to the size, that looks best. But that would require a new symbol importer/resizer dialog, what's a bit too much. GNS3 is a network simulator, not a network diagram program. So I would just implement a limitation of the height to guard against too big symbols, maybe with an option to disable that limit. |
Looks good for me. Close it? |
Sounds good however still wondering if I should take the risk to back-port this to the 2.1 branch. We will release version 2.1.12 this week. I don't think we should do it because this is not a critical fix, just a nice to have feature. Any thoughts? |
Normally I would agree, this is 2.2 stuff. The only reason I'm also unsure is, that users using the affinity symbols (promoted by David Bombal) will get really big symbols, if a v2.1 version will use QT 5.12. |
Actually we have plan to use the latest Qt 5.12 LTS #2636 when PyQt 5.12 is released on https://pypi.org/project/PyQt5/ Therefore it makes a lot of sense to do it now. There is still the option to disable to limit in case something goes wrong ;) |
* Default for missing height/width is "100%" as defined in the SVG specification * Better error message, if viewBox attribute is missing * Removal of "%" in percent more fault tolerant by using rstrip("%") (cherry picked from commit e3757a8)
(cherry picked from commit c14d79a)
Work on str instead of binary when resizing SVG symbol. (cherry picked from commit 938e912)
Resize SVG node symbols that are too big. Fixes #2674
Implemented in 2.1 too now. Thanks for everything 👍 |
I was investigating, how GNS3 handles SVG images with height and/or width being percentages. I found commit GNS3/gns3-server@fd5df00, which implements that.
In this commit I found an error. In case the width or height are percentages, it sets width_attr and height_attr, but not width and height. So the get_size function returns the default, normally 0.
I fixed that, but that didn't change anything. The size of SVG symbols stays the same, no matter what get_size() returns. So fixing that doesn't have any impact.
But I found another strange behavior.
Older QT versions (verified with 5.9.2) use the percentage as height/width in pixel. So SVG images with height/width of 100% are 100 pixel high/wide. The viewBox is completely ignored for calculating the image size.
Newer QT versions (tested with 5.11.2) multiply the percent value with the viewBox value. So a height of 20% and a viewBox height of 300 results in a symbol height of 60 pixel.
This has a big impact of users using the affinity symbols https://github.com/ecceman/affinity as shown by David Bobal in https://youtu.be/51zaAHhdgzQ. Currently (with QT 5.9) the symbols are a bit bigger than normal (100x100px), but that's manageable. When QT gets upgraded the image are three times bigger (300x300px), that's really big. And I see no way to solve this.
Just for reference here my patch to calculate the SVG image size as it's done by newer QT versions. As I said it has no impact. GNS3/QT seems to ignore the size returned by get_size(), at least for SVG:
Update: Some additional fine tuning:
I'm using re.split(), because the SVG specification allows whitespace and/or a comma as separators.
The text was updated successfully, but these errors were encountered: