From 8037bddbf7ded3da795dc5acf0450891017eaaed Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 18 Jul 2019 13:46:14 +0900
Subject: [PATCH 01/11] Fixed an issue with resize(), fixes #62

---
 desktop/sources/scripts/ronin.js   |  1 -
 desktop/sources/scripts/surface.js | 14 ++++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js
index ea59299..1e229c7 100644
--- a/desktop/sources/scripts/ronin.js
+++ b/desktop/sources/scripts/ronin.js
@@ -15,7 +15,6 @@ function Ronin () {
   this.el.id = 'ronin'
 
   this.theme = new Theme(defaultTheme)
-
   this.source = new Source(this)
   this.commander = new Commander(this)
   this.surface = new Surface(this)
diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js
index a1bd5eb..7945b97 100644
--- a/desktop/sources/scripts/surface.js
+++ b/desktop/sources/scripts/surface.js
@@ -159,6 +159,8 @@ function Surface (ronin) {
   }
 
   this.resize = function (size, fit = false) {
+    const frame = this.getFrame()
+    if (frame.w === size.w && frame.h === size.h) { return }
     console.log('Surface', `Resize: ${size.w}x${size.h}`)
     this.el.width = size.w
     this.el.height = size.h
@@ -173,10 +175,14 @@ function Surface (ronin) {
     }
   }
 
+  this.getFrame = function () {
+    return { x: 0, y: 0, w: this.el.width, h: this.el.height, t: 'rect' }
+  }
+
   this.fitWindow = function (size) {
     const win = require('electron').remote.getCurrentWindow()
     const pad = { w: ronin.commander.isVisible === true ? 400 : 60, h: 60 }
-    win.setSize(size.w + pad.w, size.h + pad.h, false)
+    win.setSize(size.w + pad.w, size.h + pad.h, true)
   }
 
   this.maximize = function () {
@@ -191,10 +197,6 @@ function Surface (ronin) {
     ronin.log(`resize ${f.w}x${f.h}`)
   }
 
-  this.getFrame = function () {
-    return { x: 0, y: 0, w: this.el.width, h: this.el.height, t: 'rect' }
-  }
-
   this.getCrop = function (rect) {
     const newCanvas = document.createElement('canvas')
     newCanvas.width = rect.w
@@ -203,7 +205,7 @@ function Surface (ronin) {
     return newCanvas
   }
 
-  this.resizeImage = function (src, dst, type = 'image/jpeg', quality = 0.92) {
+  this.resizeImage = function (src, dst, type = 'image/png', quality = 1.0) {
     const tmp = new Image()
     let canvas
     let context

From 677b03bc28330c172ec17ca5bacc42a3b5fbc666 Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 18 Jul 2019 14:05:40 +0900
Subject: [PATCH 02/11] Added basics.lisp

---
 desktop/sources/scripts/lisp.js | 22 +++++++---------------
 examples/basics.lisp            |  9 +++++++++
 2 files changed, 16 insertions(+), 15 deletions(-)
 create mode 100644 examples/basics.lisp

diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js
index 3a38a83..ddc4b97 100644
--- a/desktop/sources/scripts/lisp.js
+++ b/desktop/sources/scripts/lisp.js
@@ -33,29 +33,21 @@ function Lisp (input, lib) {
     },
     def: function (input, context) {
       const identifier = input[1].value
-      const value = (input[2].type === TYPES.string) ? input[3] : input[2]
-      if (input[2].type === TYPES.string) {
-        // docstring
-        console.log(input[2].value)
-      }
+      const value = input[2].type === TYPES.string && input[3] ? input[3] : input[2]
       context.scope[identifier] = interpret(value, context)
       return value
     },
     defn: function (input, context) {
-      const identifier = input[1].value
-      const argumentNames = (input[2].type === TYPES.string) ? input[3] : input[2]
-      const functionBody = (input[2].type === TYPES.string) ? input[4] : input[3]
-      if (input[2].type === TYPES.string) {
-        // docstring
-        console.log(input[2].value)
-      }
-      context.scope[identifier] = async function () {
+      const fnName = input[1].value
+      const fnParams = input[2].type === TYPES.string && input[3] ? input[3] : input[2]
+      const fnBody = input[2].type === TYPES.string && input[4] ? input[4] : input[3]
+      context.scope[fnName] = async function () {
         const lambdaArguments = arguments
-        const lambdaScope = argumentNames.reduce(function (acc, x, i) {
+        const lambdaScope = fnParams.reduce(function (acc, x, i) {
           acc[x.value] = lambdaArguments[i]
           return acc
         }, {})
-        return interpret(functionBody, new Context(lambdaScope, context))
+        return interpret(fnBody, new Context(lambdaScope, context))
       }
     },
     lambda: function (input, context) {
diff --git a/examples/basics.lisp b/examples/basics.lisp
new file mode 100644
index 0000000..c1832ea
--- /dev/null
+++ b/examples/basics.lisp
@@ -0,0 +1,9 @@
+; basics
+( 
+  ; define a variable 
+  (def a 25) 
+  (echo a) 
+
+  ; define a function 
+  (defn add-two (a) (add 2 a)) 
+  (echo (add-two 4)))
\ No newline at end of file

From c8401c8cdc5a3457498bbef52efeda6a4bd99e44 Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 18 Jul 2019 14:44:12 +0900
Subject: [PATCH 03/11] Trying to fix the (rescale) async issue

---
 README.md                          |  8 +++---
 desktop/sources/scripts/library.js | 39 ++++++++++++++++--------------
 2 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md
index 36453b0..c953b45 100644
--- a/README.md
+++ b/README.md
@@ -62,13 +62,14 @@ npm start
 - `(range start end ~step)` 
 - `(get item key)` Gets an object's parameter with name.
 - `(set item key val)` Sets an object's parameter with name as value.
+- `(of h ...keys)` 
 - `(frame)` Returns a rect of the frame.
 - `(center)` Returns a position of the center of the frame.
 - `(scale rect w h)` 
-- `(resize ~w ~h)` 
+- `(resize w h)` Resizes the canvas to target w and h, returns the rect.
+- `(rescale w h)` Rescales the canvas to target ratio of w and h, returns the rect.
 - `(crop rect)` 
 - `(clone a b)` 
-- `(of h ...keys)` 
 - `(theme variable ~el)` 
 - `(gradient [x1 y1 x2 y2] ~colors 'black'])` 
 - `(pixels rect fn q)` 
@@ -79,10 +80,9 @@ npm start
 - `(open path)` Imports a graphic file and resizes the frame.
 - `(folder ~path)` Returns the content of a folder path.
 - `(exit ~force)` Exits Ronin.
-- `(ronin)` 
 - `(time)` Returns timestamp in milliseconds.
 - `(animate ~play)` Toggles animation.
-- `(js)` 
+- `(js)` Javascript interop.
 - `(test name a b)` 
 
 ## Extras
diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js
index e9b4b03..c03e8e4 100644
--- a/desktop/sources/scripts/library.js
+++ b/desktop/sources/scripts/library.js
@@ -212,6 +212,12 @@ function Library (ronin) {
     return item[key]
   }
 
+  this.of = (h, ...keys) => {
+    return keys.reduce((acc, key) => {
+      return acc[key]
+    }, h)
+  }
+
   // Frame
 
   this.frame = () => { // Returns a rect of the frame.
@@ -227,8 +233,18 @@ function Library (ronin) {
     return { x: rect.x, y: rect.y, w: rect.w * w, h: rect.h * h }
   }
 
-  this.resize = async (w = 1, h = 1) => {
-    const rect = w <= 1 || h <= 1 ? { x: 0, y: 0, w: this.frame().w * w, h: this.frame().h * h } : { x: 0, y: 0, w, h }
+  this.resize = async (w, h) => { // Resizes the canvas to target w and h, returns the rect.
+    const rect = { x: 0, y: 0, w, h }
+    const a = document.createElement('img')
+    const b = document.createElement('img')
+    a.src = ronin.surface.el.toDataURL()
+    ronin.surface.resizeImage(a, b)
+    ronin.surface.resize(rect, true)
+    return ronin.surface.draw(b, rect)
+  }
+
+  this.rescale = async (w, h) => { // Rescales the canvas to target ratio of w and h, returns the rect.
+    const rect = { x: 0, y: 0, w: this.frame().w * w, h: this.frame().h * h }
     const a = document.createElement('img')
     const b = document.createElement('img')
     a.src = ronin.surface.el.toDataURL()
@@ -241,21 +257,11 @@ function Library (ronin) {
     return ronin.surface.crop(rect)
   }
 
-  // Copy/Paste
-
   this.clone = (a, b) => {
     ronin.surface.clone(a, b)
     return [a, b]
   }
 
-  // TODO: Should remove (of) for (get)?
-
-  this.of = (h, ...keys) => {
-    return keys.reduce((acc, key) => {
-      return acc[key]
-    }, h)
-  }
-
   this.theme = (variable, el = document.documentElement) => {
     // ex. (theme "f_main") -> :root { --f_main: "#fff" }
     return getComputedStyle(el).getPropertyValue(`--${variable}`)
@@ -316,10 +322,6 @@ function Library (ronin) {
     ronin.source.quit(force)
   }
 
-  // Client
-  this.ronin = ronin
-
-  // Livecoding
   this.time = () => { // Returns timestamp in milliseconds.
     return Date.now
   }
@@ -328,8 +330,9 @@ function Library (ronin) {
     ronin.animate(play)
   }
 
-  // javascript interop
-  this.js = window
+  this.js = () => { // Javascript interop.
+    return window
+  }
 
   this.test = (name, a, b) => {
     if (`${a}` !== `${b}`) {

From 50e13e932d1634a4104e49808d852c6104d8c8b2 Mon Sep 17 00:00:00 2001
From: Quentin Leonetti <q.leonetti@gmail.com>
Date: Thu, 18 Jul 2019 10:54:13 +0200
Subject: [PATCH 04/11] update reduce and examples

---
 desktop/sources/scripts/library.js |  9 +++++++--
 examples/animate.lisp              |  7 ++++---
 examples/dejong.lisp               | 10 ++++++----
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js
index 1ea70c6..f639907 100644
--- a/desktop/sources/scripts/library.js
+++ b/desktop/sources/scripts/library.js
@@ -90,8 +90,13 @@ function Library (ronin) {
       })
   }
 
-  this.reduce = (fn, arr, acc = 0) => {
-    return arr.reduce(fn, acc)
+  this.reduce = async (fn, arr, acc) => {
+    const length = arr.length
+    let result = acc === undefined ? subject[0] : acc
+    for (let i = acc === undefined ? 1 : 0; i < length; i++) {
+      result = await fn(result, arr[i], i, arr)
+    }
+    return result;
   }
 
   this.len = (item) => {
diff --git a/examples/animate.lisp b/examples/animate.lisp
index b43d696..ed3eadf 100644
--- a/examples/animate.lisp
+++ b/examples/animate.lisp
@@ -1,12 +1,13 @@
 ; animate
 
 (
+  (clear)
   (def t (sin (div (time) 100)))
 
-  (def pos (add 200 (mul 30 t)))
+  (def pos (add 200 30 (mul 30 t)))
   (defn square (a) (rect a a a a))
   (stroke (square pos) 1 "red")
 
-  (animate)
-  ;(animate false) to stop animation
+  ; set false to stop 
+  (animate true)
 )
\ No newline at end of file
diff --git a/examples/dejong.lisp b/examples/dejong.lisp
index 9d19d27..c701fa7 100644
--- a/examples/dejong.lisp
+++ b/examples/dejong.lisp
@@ -1,13 +1,15 @@
 ; dejong attractor
 
 (
-  (clear)
-  (defn point (x y color) (fill (circle x y 0.1) color))
+  (clear) 
+  (defn point (x y color) 
+    (fill (rect x y 1 1) color))
+
   (defn _dejong (x y a b c d)
     (rest ((point 
       (add 300 (mul 100 x))
       (add 400 (mul 100 y))
-      "rgba(255,0,0,0.5)")
+      "red")
     (add (sin (mul a y)) (mul x (cos (mul b x))))
     (add (mul x (sin (mul x c))) (cos (mul d y)))
     ))
@@ -23,5 +25,5 @@
       (2 1)
     )
   )
-  (dejong 128000 1.4 -2.3 2.4 -2.1)
+  (dejong 1280 1.6 -2.3 2.4 -2.1)
 )

From a98e9a6b1ef7d270a496a3e78498477eca3d96aa Mon Sep 17 00:00:00 2001
From: Quentin Leonetti <q.leonetti@gmail.com>
Date: Thu, 18 Jul 2019 11:51:25 +0200
Subject: [PATCH 05/11] fix async

---
 desktop/sources/scripts/library.js |  7 +++--
 desktop/sources/scripts/lisp.js    |  5 ++-
 desktop/sources/scripts/surface.js | 50 ++++++++++++++++--------------
 examples/import.lisp               |  5 +++
 4 files changed, 40 insertions(+), 27 deletions(-)
 create mode 100644 examples/import.lisp

diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js
index 794af27..dd0ea70 100644
--- a/desktop/sources/scripts/library.js
+++ b/desktop/sources/scripts/library.js
@@ -238,13 +238,14 @@ function Library (ronin) {
     return { x: rect.x, y: rect.y, w: rect.w * w, h: rect.h * h }
   }
 
-  this.resize = async (w, h) => { // Resizes the canvas to target w and h, returns the rect.
+  this.resize = async (w, h, fit = true) => { // Resizes the canvas to target w and h, returns the rect.
     const rect = { x: 0, y: 0, w, h }
     const a = document.createElement('img')
     const b = document.createElement('img')
     a.src = ronin.surface.el.toDataURL()
-    ronin.surface.resizeImage(a, b)
-    ronin.surface.resize(rect, true)
+    await ronin.surface.resizeImage(a, b)
+    console.log(b)
+    ronin.surface.resize(rect, fit)
     return ronin.surface.draw(b, rect)
   }
 
diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js
index ddc4b97..74c1067 100644
--- a/desktop/sources/scripts/lisp.js
+++ b/desktop/sources/scripts/lisp.js
@@ -72,7 +72,10 @@ function Lisp (input, lib) {
     if (input.length > 0 && input[0].value in special) {
       return special[input[0].value](input, context)
     }
-    const list = await Promise.all(input.map(function (x) { return interpret(x, context) }))
+    const list = []
+    for(let i = 0; i < input.length; i++) {
+      list.push(await interpret(input[i], context))
+    }
     return list[0] instanceof Function ? list[0].apply(undefined, list.slice(1)) : list
   }
 
diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js
index 7945b97..6ee40ed 100644
--- a/desktop/sources/scripts/surface.js
+++ b/desktop/sources/scripts/surface.js
@@ -206,29 +206,33 @@ function Surface (ronin) {
   }
 
   this.resizeImage = function (src, dst, type = 'image/png', quality = 1.0) {
-    const tmp = new Image()
-    let canvas
-    let context
-    let cW = src.naturalWidth
-    let cH = src.naturalHeight
-    tmp.src = src.src
-    tmp.onload = function () {
-      canvas = document.createElement('canvas')
-      cW /= 2
-      cH /= 2
-      if (cW < src.width) {
-        cW = src.width
+    return new Promise(resolve => {
+      const tmp = new Image()
+      let canvas
+      let context
+      let cW = src.naturalWidth
+      let cH = src.naturalHeight
+      tmp.src = src.src
+      // resolve()
+      tmp.onload = () => {
+        canvas = document.createElement('canvas')
+        cW /= 2
+        cH /= 2
+        if (cW < src.width) {
+          cW = src.width
+        }
+        if (cH < src.height) {
+          cH = src.height
+        }
+        canvas.width = cW
+        canvas.height = cH
+        context = canvas.getContext('2d')
+        context.drawImage(tmp, 0, 0, cW, cH)
+        dst.src = canvas.toDataURL(type, quality)
+        if (cW <= src.width || cH <= src.height) { return resolve()}
+        tmp.src = dst.src
+        return resolve()
       }
-      if (cH < src.height) {
-        cH = src.height
-      }
-      canvas.width = cW
-      canvas.height = cH
-      context = canvas.getContext('2d')
-      context.drawImage(tmp, 0, 0, cW, cH)
-      dst.src = canvas.toDataURL(type, quality)
-      if (cW <= src.width || cH <= src.height) { return }
-      tmp.src = dst.src
-    }
+    })
   }
 }
diff --git a/examples/import.lisp b/examples/import.lisp
new file mode 100644
index 0000000..36841c2
--- /dev/null
+++ b/examples/import.lisp
@@ -0,0 +1,5 @@
+(
+(def a (import 
+  "../static/crystal.jpg" 
+  (rect 0 0 400 400)))
+(echo a))
\ No newline at end of file

From e8713f34aed55e611b95a29eb77e7417d7432200 Mon Sep 17 00:00:00 2001
From: Quentin Leonetti <q.leonetti@gmail.com>
Date: Thu, 18 Jul 2019 12:04:04 +0200
Subject: [PATCH 06/11] remove useless log and add async where needed

---
 desktop/sources/scripts/library.js | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js
index dd0ea70..ba5922d 100644
--- a/desktop/sources/scripts/library.js
+++ b/desktop/sources/scripts/library.js
@@ -244,7 +244,6 @@ function Library (ronin) {
     const b = document.createElement('img')
     a.src = ronin.surface.el.toDataURL()
     await ronin.surface.resizeImage(a, b)
-    console.log(b)
     ronin.surface.resize(rect, fit)
     return ronin.surface.draw(b, rect)
   }
@@ -254,7 +253,7 @@ function Library (ronin) {
     const a = document.createElement('img')
     const b = document.createElement('img')
     a.src = ronin.surface.el.toDataURL()
-    ronin.surface.resizeImage(a, b)
+    await ronin.surface.resizeImage(a, b)
     ronin.surface.resize(rect, true)
     return ronin.surface.draw(b, rect)
   }

From ad941de3a16e40f80b7ff0fd258cc7a760d4a320 Mon Sep 17 00:00:00 2001
From: Quentin Leonetti <q.leonetti@gmail.com>
Date: Thu, 18 Jul 2019 12:16:24 +0200
Subject: [PATCH 07/11] add benchmark function

---
 desktop/sources/scripts/library.js | 7 +++++++
 examples/dejong.lisp               | 8 +++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js
index ba5922d..dafbfe9 100644
--- a/desktop/sources/scripts/library.js
+++ b/desktop/sources/scripts/library.js
@@ -347,4 +347,11 @@ function Library (ronin) {
     }
     return a === b
   }
+
+  this.benchmark = async (fn) => { // logs time taken to execute a function
+    const start = Date.now()
+    const result = await fn()
+    console.log(`time taken: ${Date.now() - start}ms`)
+    return result
+  }
 }
diff --git a/examples/dejong.lisp b/examples/dejong.lisp
index c701fa7..9e3eac6 100644
--- a/examples/dejong.lisp
+++ b/examples/dejong.lisp
@@ -25,5 +25,11 @@
       (2 1)
     )
   )
-  (dejong 1280 1.6 -2.3 2.4 -2.1)
+  (benchmark (lambda ()
+    (dejong 12800 
+      (random -2 2)
+      (random -2 2)
+      (random -2 2)
+      (random -2 2) 
+  )))
 )

From 61d34036cd0b13426b62900b7635f699617bb8c3 Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 18 Jul 2019 19:33:32 +0900
Subject: [PATCH 08/11] Fixed issue with window resizing

---
 desktop/sources/scripts/library.js | 2 +-
 desktop/sources/scripts/lisp.js    | 2 +-
 desktop/sources/scripts/surface.js | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js
index dafbfe9..6898c47 100644
--- a/desktop/sources/scripts/library.js
+++ b/desktop/sources/scripts/library.js
@@ -173,7 +173,7 @@ function Library (ronin) {
     for (let i = acc === undefined ? 1 : 0; i < length; i++) {
       result = await fn(result, arr[i], i, arr)
     }
-    return result;
+    return result
   }
 
   this.len = (item) => { // Returns the length of a list.
diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js
index 74c1067..7459f97 100644
--- a/desktop/sources/scripts/lisp.js
+++ b/desktop/sources/scripts/lisp.js
@@ -73,7 +73,7 @@ function Lisp (input, lib) {
       return special[input[0].value](input, context)
     }
     const list = []
-    for(let i = 0; i < input.length; i++) {
+    for (let i = 0; i < input.length; i++) {
       list.push(await interpret(input[i], context))
     }
     return list[0] instanceof Function ? list[0].apply(undefined, list.slice(1)) : list
diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js
index 6ee40ed..578f1d9 100644
--- a/desktop/sources/scripts/surface.js
+++ b/desktop/sources/scripts/surface.js
@@ -182,7 +182,8 @@ function Surface (ronin) {
   this.fitWindow = function (size) {
     const win = require('electron').remote.getCurrentWindow()
     const pad = { w: ronin.commander.isVisible === true ? 400 : 60, h: 60 }
-    win.setSize(size.w + pad.w, size.h + pad.h, true)
+    if (size.w < 10 || size.h < 10) { return }
+    win.setSize(Math.floor(size.w + pad.w), Math.floor(size.h + pad.h), true)
   }
 
   this.maximize = function () {
@@ -229,7 +230,7 @@ function Surface (ronin) {
         context = canvas.getContext('2d')
         context.drawImage(tmp, 0, 0, cW, cH)
         dst.src = canvas.toDataURL(type, quality)
-        if (cW <= src.width || cH <= src.height) { return resolve()}
+        if (cW <= src.width || cH <= src.height) { return resolve() }
         tmp.src = dst.src
         return resolve()
       }

From e0a0be885d1674aa9bdefce0fa5547cded988e22 Mon Sep 17 00:00:00 2001
From: Quentin Leonetti <q.leonetti@gmail.com>
Date: Thu, 18 Jul 2019 12:37:34 +0200
Subject: [PATCH 09/11] fix (time)

---
 desktop/sources/scripts/library.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js
index dafbfe9..ad5571b 100644
--- a/desktop/sources/scripts/library.js
+++ b/desktop/sources/scripts/library.js
@@ -328,7 +328,7 @@ function Library (ronin) {
   }
 
   this.time = () => { // Returns timestamp in milliseconds.
-    return Date.now
+    return Date.now()
   }
 
   this.animate = (play = true) => { // Toggles animation.

From 4ab7d27367a5cb50f4c300def8c142a21e0755c4 Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 18 Jul 2019 20:02:42 +0900
Subject: [PATCH 10/11] Added retina support.

---
 desktop/sources/scripts/surface.js | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js
index 578f1d9..36ab155 100644
--- a/desktop/sources/scripts/surface.js
+++ b/desktop/sources/scripts/surface.js
@@ -15,6 +15,7 @@ function Surface (ronin) {
     this._guide.addEventListener('mousedown', ronin.commander.onMouseDown, false)
     this._guide.addEventListener('mousemove', ronin.commander.onMouseMove, false)
     this._guide.addEventListener('mouseup', ronin.commander.onMouseUp, false)
+    // this.context.imageSmoothingEnabled = false
     this.context.scale(this.ratio, this.ratio)
     this.guide.scale(this.ratio, this.ratio)
   }
@@ -164,12 +165,12 @@ function Surface (ronin) {
     console.log('Surface', `Resize: ${size.w}x${size.h}`)
     this.el.width = size.w
     this.el.height = size.h
-    this.el.style.width = size.w + 'px'
-    this.el.style.height = size.h + 'px'
+    this.el.style.width = (size.w / this.ratio) + 'px'
+    this.el.style.height = (size.h / this.ratio) + 'px'
     this._guide.width = size.w
     this._guide.height = size.h
-    this._guide.style.width = size.w + 'px'
-    this._guide.style.height = size.h + 'px'
+    this._guide.style.width = (size.w / this.ratio) + 'px'
+    this._guide.style.height = (size.h / this.ratio) + 'px'
     if (fit === true) {
       this.fitWindow(size)
     }
@@ -183,11 +184,11 @@ function Surface (ronin) {
     const win = require('electron').remote.getCurrentWindow()
     const pad = { w: ronin.commander.isVisible === true ? 400 : 60, h: 60 }
     if (size.w < 10 || size.h < 10) { return }
-    win.setSize(Math.floor(size.w + pad.w), Math.floor(size.h + pad.h), true)
+    win.setSize(Math.floor((size.w / this.ratio) + pad.w), Math.floor((size.h / this.ratio) + pad.h), true)
   }
 
   this.maximize = function () {
-    this.resize({ x: 0, y: 0, w: window.innerWidth - 60, h: window.innerHeight - 60, t: 'rect' })
+    this.resize({ x: 0, y: 0, w: (window.innerWidth * this.ratio) - 60, h: (window.innerHeight * this.ratio) - 60, t: 'rect' })
   }
 
   this.onResize = function () {

From 2d05a16f3d991312b41ae38765f39d4af2a8f698 Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 18 Jul 2019 20:17:49 +0900
Subject: [PATCH 11/11] Fixed issue with jpg export

---
 desktop/sources/scripts/library.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js
index 6898c47..2b0ff51 100644
--- a/desktop/sources/scripts/library.js
+++ b/desktop/sources/scripts/library.js
@@ -8,7 +8,7 @@ function Library (ronin) {
   this.export = (path, format = 'image/png', quality = 1.0) => { // Exports a graphic file with format.
     if (!path) { console.warn('Missing export path'); return path }
     var dataUrl = ronin.surface.el.toDataURL(format, quality)
-    const data = dataUrl.replace(/^data:image\/png;base64,/, '')
+    const data = dataUrl.replace(/^data:image\/png;base64,/, '').replace(/^data:image\/jpeg;base64,/, '')
     fs.writeFileSync(path, data, 'base64')
     return path
   }