Skip to content

Commit 8cec2c5

Browse files
committed
Switch to exponential scaling
1 parent 0d965f9 commit 8cec2c5

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

SKIA-WX-GPU-SVG-Viewer.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def __init__(self, parent, size):
4141
self.zoom = 1.0
4242

4343
self.svg_picture = None
44-
self.svg_size = None
45-
self.scale = 0
44+
self.img_size = None
45+
self.img_scale_enum = 0
46+
self.img_zoom = 1.0
4647

4748
self.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_left_down)
4849
self.Bind(wx.EVT_LEFT_UP, self.on_mouse_left_up)
@@ -83,11 +84,10 @@ def on_paint(self, event):
8384

8485
def on_key_down(self, event):
8586
keycode = event.GetKeyCode()
86-
if (keycode == 43): # '+'
87-
self.scale += 2
88-
self.Refresh()
89-
if (keycode == 45): # '-'
90-
self.scale -= 2
87+
if ((keycode == 43) or # '+'
88+
(keycode == 45)): # '-'
89+
self.img_scale_enum += (44 - keycode)
90+
self.img_zoom = 1.2 ** self.img_scale_enum
9191
self.Refresh()
9292
event.Skip()
9393

@@ -160,11 +160,11 @@ def on_draw(self):
160160
self.canvas.translate(self.offset_x, self.offset_y)
161161

162162
if self.svg_picture:
163-
self.canvas.scale(1 + self.scale * 0.1, 1 + self.scale * 0.1)
164-
self.canvas.translate(-self.svg_size.width()/2, -self.svg_size.height()/2)
163+
self.canvas.scale(self.img_zoom, self.img_zoom)
164+
self.canvas.translate(-self.img_size.width()/2, -self.img_size.height()/2)
165165
self.svg_picture.render(self.canvas)
166-
self.canvas.translate(self.svg_size.width()/2, self.svg_size.height()/2)
167-
self.canvas.scale(1/(1 + self.scale * 0.1), 1/(1 + self.scale * 0.1))
166+
self.canvas.translate(self.img_size.width()/2, self.img_size.height()/2)
167+
self.canvas.scale(1/self.img_zoom, 1/self.img_zoom)
168168

169169
self.canvas.restore()
170170
self.surface.flushAndSubmit()
@@ -212,7 +212,7 @@ def on_open_file(self, event):
212212
try:
213213
svgstream = skia.Stream.MakeFromFile(path)
214214
self.canvas.svg_picture = skia.SVGDOM.MakeFromStream(svgstream)
215-
self.canvas.svg_size = self.canvas.svg_picture.containerSize()
215+
self.canvas.img_size = self.canvas.svg_picture.containerSize()
216216
self.canvas.Refresh()
217217
self.canvas.SetFocus()
218218
except Exception as e:

0 commit comments

Comments
 (0)