Bug 437068 - Python - Weird Zoom Bug
Summary: Python - Weird Zoom Bug
Status: CONFIRMED
Alias: None
Product: krita
Classification: Applications
Component: Scripting (show other bugs)
Version: 4.4.3
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-14 02:45 UTC by keyth_qcfx2
Modified: 2021-07-03 15:25 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description keyth_qcfx2 2021-05-14 02:45:29 UTC
SUMMARY
I was working on a new python plugin and I came across a odd behavior with the zoomLevel command in the Canvas class. I spoke of it in the Krita-Artists and it seems it is known but I think it even the solution makes no sense when trading notes to what one would expect and should be treated as a bug all things considered. I will give 2 examples the first one works (for comparison) and then the second will fail showing the error in contrast.

STEPS TO REPRODUCE (Works == Expected results)
1. open Krita and create a simply image with 72 DPI's
2. open the Scriptor Plugin and run this code:
"""
import krita

n = 0.5
c = Krita.instance().activeWindow().activeView().canvas()
c.setZoomLevel(n)  # The Zom level is set
s = c.zoomLevel()  # Ask what is the Zoom Level to Print it
print(s)
"""
3. Output will be
"""
======================================
0.5
"""
4. this is good, input is n=0.5 and when reading the level is 0.5.

STEPS TO REPRODUCE (BUGGED)
1. open Krita and create a simple image with DPI's higher or different from 72, you can use 300
2. open the Scriptor Plugin and run this code:
"""
import krita

n = 0.5
c = Krita.instance().activeWindow().activeView().canvas()
c.setZoomLevel(n)  # The Zom level is set
s = c.zoomLevel()  # Ask what is the Zoom Level to Print it
print(s)
"""
3. Output will be
"""
======================================
5.615234375
"""
4. this is bad as input is n=0.5 and when readding the level is 5.615234375.

KRITA-ARTISTS QUERRY
After speaking with other scriptors I was told that is was related to the amount of DPI's of the image. Because of that I created extra code like

"""
c = Krita.instance().activeWindow().activeView().canvas()
ad = Krita.instance().activeDocument()
c_zoom = c.zoomLevel()
d_resolution = ad.resolution()

# Zoom and Dpi disparity
self.dpi = d_resolution / 72
c_zoom = c_zoom / self.dpi
"""

Despite the weirdness it shows the double standard on how to use the value itself. When reading the value I need to do a divide for self.dpi however when I apply the zoom value after to Krita instead of doing:

"""
Krita.instance().activeWindow().activeView().canvas().setZoomLevel(self.c_zoom * self.dpi)
"""

to convert it to the DPI influenced Zoom value I have to use:

"""
Krita.instance().activeWindow().activeView().canvas().setZoomLevel(self.c_zoom)
"""

ignoring the use of self.dpi when sending the value back in.

FINAL THOUGHTS
My idea is that the value for zoomLevel() and setZoomLevel() should both use the same scale of values, influenced by the amount of DPI's or not. Also if the zoomLevel() API command uses DPI in it and setZoomLevel() does not it seems relevant to indicate it in the Libkis site also, as I was only able to see the DPI was the cause by word of mouth alone.



SOFTWARE/OS VERSIONS
Windows: 10
Qt Version:  5.12.9

ADDITIONAL INFORMATION