Skip to content

Commit

Permalink
Automatically scale SVGs to correct size
Browse files Browse the repository at this point in the history
So the actual intrinsic size of the SVG now doesn't matter any more. Small SVGs will properly be upscaled without any interpolation necessary.
This can also improve performance, depending on the size you're displaying the zoomed image at. The original zoomed image was meant to be downscaled for all but the largest screens, so for all but the largest screens the performance should be a little better when there's SVGs involved.
  • Loading branch information
Ghostkeeper committed Sep 7, 2019
1 parent 98ee851 commit 193aadc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ Diagrams should be submitted in SVG format. Also for these there are a number of
* Gradients are not supported.
* Animations are not supported.
* Patterns are not supported.
* The image gets rendered by Qt at a fixed resolution matching the viewport of your image, and then scaled to the resolution that the user needs to display it at. For better quality, the SVG's viewport needs to be very large. Several thousand units is usually fine even for high DPI screens.

It is up to the discretion of the package maintainer to decide whether images are too big or not. A major factor in this decision is whether the image is any bigger than strictly necessary.
3 changes: 2 additions & 1 deletion resources/qml/ArticleImages.qml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ GridLayout {
id: thumbnail
source: modelData.substring(0, modelData.indexOf("|"))
fillMode: Image.PreserveAspectFit
mipmap: true
anchors.fill: parent
sourceSize.width: width
sourceSize.height: height
}

Image {
Expand Down
19 changes: 16 additions & 3 deletions resources/qml/SettingsGuide.qml
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,33 @@ Window {
}

Rectangle {
width: zoom_image.paintedWidth
height: zoom_image.paintedHeight
width: zoom_image.visible ? zoom_image.paintedWidth : zoom_image_svg.paintedWidth
height: zoom_image.visible ? zoom_image.paintedHeight : zoom_image_svg.paintedWidth
color: "white" //Always white regardless of theme, to serve as background to the image.
anchors.centerIn: parent

AnimatedImage {
id: zoom_image
source: settingsGuideBase.zoomed_image
source: visible ? settingsGuideBase.zoomed_image : "" //Don't even try to render for SVG.
anchors.centerIn: parent
width: zoom_layer.width * 2 / 3
height: zoom_layer.height * 2 / 3
fillMode: Image.PreserveAspectFit
mipmap: true
onStatusChanged: playing = (status == AnimatedImage.Ready)
visible: settingsGuideBase.zoomed_image.split('.').pop() !== "svg" //Only for non-SVG.
}

Image { //Special one for SVG that automatically adjusts sourceSize. sourceSize is not supported for AnimatedImage, and AnimatedImage doesn't support animated SVG anyway.
id: zoom_image_svg
source: visible ? settingsGuideBase.zoomed_image : "" //Don't even try to render for non-SVG.
anchors.centerIn: parent
width: zoom_image.width
height: zoom_image.height
fillMode: Image.PreserveAspectFit
sourceSize.width: width
sourceSize.height: height
visible: !zoom_image.visible //Only for SVG.
}
}
}
Expand Down

0 comments on commit 193aadc

Please sign in to comment.