Skip to content

Commit

Permalink
Support (predefined) A3 paper size for printing.
Browse files Browse the repository at this point in the history
  • Loading branch information
litan committed Oct 28, 2019
1 parent a9fc243 commit 61f7dd3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
10 changes: 7 additions & 3 deletions src/main/scala/net/kogics/kojo/lite/Builtins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,19 @@ Here's a partial list of the available commands:
}

def setDrawingCanvasToA4(): Unit = {
setDrawingCanvasAspectRatio(210.0 / 297.0)
setDrawingCanvasAspectRatio(A4.aspectRatio)
}

def setDrawingCanvasToA4Landscape(): Unit = {
setDrawingCanvasAspectRatio(297.0 / 210.0)
setDrawingCanvasAspectRatio(A4Landscape.aspectRatio)
}

def setDrawingCanvasToA3(): Unit = {
setDrawingCanvasAspectRatio(297.0 / 420.0)
setDrawingCanvasAspectRatio(A3.aspectRatio)
}

def setDrawingCanvasToA3Landscape(): Unit = {
setDrawingCanvasAspectRatio(A3Landscape.aspectRatio)
}

val hueMod = Utils.hueMod _
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/net/kogics/kojo/lite/SettingsWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class SettingsWindow(owner: JFrame) extends JDialog(owner) {
Builtins.instance.setDrawingCanvasToA4()
case A4Landscape =>
Builtins.instance.setDrawingCanvasToA4Landscape()
case A3 =>
Builtins.instance.setDrawingCanvasToA3()
case A3Landscape =>
Builtins.instance.setDrawingCanvasToA3Landscape()
}
Utils.runLaterInSwingThread {
setCurrentAspectRatio()
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/net/kogics/kojo/lite/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.kogics.kojo.lite
object Versions {
val KojoMajorVersion = "2.7"
val KojoVersion = "2.7.08"
val KojoRevision = "r16"
val KojoRevision = "r17"
val KojoBuildDate = "28 October 2019"
val JavaVersion = {
val jrv = System.getProperty("java.runtime.version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ class SpriteCanvas(val kojoCtx: core.KojoCtx) extends PSwingCanvas with SCanvas
val inches = Utils.appProperty("export.image.inches") match {
case Some(inchVal) =>
PaperSize.fromString(inchVal) match {
case Some(ps) => if (dim == "height") ps.height else ps.width
case Some(ps) => if (dim == "height") ps.heightInches else ps.widthInches
case None => inchVal.toDouble
}
case None => 1.0
Expand Down
31 changes: 24 additions & 7 deletions src/main/scala/net/kogics/kojo/lite/papersizes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@ package net.kogics.kojo.lite

trait PaperSize {
def name: String
def width: Double
def height: Double
def widthMm: Double
def heightMm: Double
def widthInches = widthMm / 25.4
def heightInches = heightMm / 25.4
def aspectRatio = widthMm / heightMm
}

case object A4 extends PaperSize {
val name = "A4"
val width = 8.268
val height = 11.693
val widthMm = 210.0
val heightMm = 297.0
}

case object A4Landscape extends PaperSize {
val name = "A4 Landscape"
val width = 11.693
val height = 8.268
val widthMm = 297.0
val heightMm = 210.0
}

case object A3 extends PaperSize {
val name = "A3"
val widthMm = 297.0
val heightMm = 420.0
}

case object A3Landscape extends PaperSize {
val name = "A3 Landscape"
val widthMm = 420.0
val heightMm = 297.0
}

object PaperSize {
Expand All @@ -27,12 +42,14 @@ object PaperSize {
s.toLowerCase.trim match {
case "a4" => Some(A4)
case "a4 landscape" => Some(A4Landscape)
case "a3" => Some(A3)
case "a3 landscape" => Some(A3Landscape)
case _ => None
}
}
}

def allSizes: Seq[String] = {
List(A4, A4Landscape).map(_.name)
List(A4, A4Landscape, A3, A3Landscape).map(_.name)
}
}

0 comments on commit 61f7dd3

Please sign in to comment.