Skip to content

Commit

Permalink
add implicit import
Browse files Browse the repository at this point in the history
  • Loading branch information
duantihua committed Apr 7, 2024
1 parent b7c5075 commit d568928
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions pdf/src/main/scala/org/beangle/doc/core/PrintOptions.scala
Expand Up @@ -17,6 +17,9 @@

package org.beangle.doc.core

import org.beangle.commons.lang.Strings
import scala.math.BigDecimal.RoundingMode

object PrintOptions {
def defaultOptions: PrintOptions = {
new PrintOptions()
Expand Down Expand Up @@ -59,11 +62,35 @@ object Orientation {
def fromId(id: Int): Orientation = fromOrdinal(id - 1)
}

import org.beangle.commons.lang.Strings
import org.beangle.doc.core.Millimeter.given
object Millimeter {
def apply(m: String): Millimeter = {
val s = m.toLowerCase
if (s.endsWith("mm")) {
new Millimeter(Strings.replace(s, "mm", "").toInt)
} else {
new Millimeter(s.toInt)
}
}

import scala.math.BigDecimal.RoundingMode
given Conversion[Int, Millimeter] = Millimeter(_)
}

case class Millimeter(v: Int) {
def mm: String = s"${v}mm"

def inches: Double = {
BigDecimal(v / 25.4d).setScale(3, RoundingMode.HALF_UP).doubleValue
}

def inches(postfix: String = "in"): String = {
String.format("%.3f" + postfix, v / 25.4d)
}

override def toString: String = s"${v}mm"
}

import org.beangle.doc.core.Millimeter.given
import scala.language.implicitConversions
/** 纸张大小
* 定义常规的纸张大小
*/
Expand Down Expand Up @@ -105,30 +132,3 @@ object PageMargin {
}

case class PageMargin(top: Millimeter, bottom: Millimeter, left: Millimeter, right: Millimeter)

object Millimeter {
def apply(m: String): Millimeter = {
val s = m.toLowerCase
if (s.endsWith("mm")) {
new Millimeter(Strings.replace(s, "mm", "").toInt)
} else {
new Millimeter(s.toInt)
}
}

given Conversion[Int, Millimeter] = Millimeter(_)
}

case class Millimeter(v: Int) {
def mm: String = s"${v}mm"

def inches: Double = {
BigDecimal(v / 25.4d).setScale(3, RoundingMode.HALF_UP).doubleValue
}

def inches(postfix: String = "in"): String = {
String.format("%.3f" + postfix, v / 25.4d)
}

override def toString: String = s"${v}mm"
}

0 comments on commit d568928

Please sign in to comment.